This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gdb "automation" question


Hi,

thanks to Tom and others I made progress to automatically display
my remote log messages using python-enabled gdb-7.1.

:-)

Thank you, I have a much better situation now.

However, a bit more tuning would be great :)



First let me summarize what I did:

in C code:

   static char *logStaticLogBuffer ...
   static void logTrace() { }

at the end of some log function added:

   strncat(logStaticLogBuffer, formattedMessage, len);
   logTrace(); /* empty function, just to have a symbol to break at */

This can be used with (from `~/.gdbinit')

  define show_log
    if logStaticLogBuffer != 0 && logStaticLogBuffer[0] != 0
      printf "%s", logStaticLogBuffer
      set logStaticLogBuffer[0] = 0
    end
  end

to get it printed right after a record was added (from `~/.gdbinit.py'):

  class ShowClogPy (gdb.Function):
      """Shows the static log buffer"""

      def __init__ (self):
          super (ShowClogPy, self).__init__ ("show_log_py")

      def invoke (self):
          gdb.execute("show_log")
          return False

  ShowClogPy()

interactively this can be `enabled' by:

  (gdb) break logTrace if $show_log_py()

and this works. My connect command

  disable
  target remote ...
  monitor ...
  symbol-file image.elf"

unfortunately must `disable' - otherwise, `target remote' fails with:

  Warning:
  Cannot insert breakpoint 1.
  Error accessing memory address 0xd2b44: Unknown error 4294967295.

the error remains for any following commands.




Now my questions how I can improve:

#1 When several messages were printed, I get
     ---Type <return> to continue, or q <return> to quit---
   is there a way to avoid it?



#2 How do I write show_log in Python? According to the online manual
   `Python representation of symbols' I understood that I have to
   use gdb.lookup_symbol. Is this right? I tried
     gdb.lookup_symbol("logStaticLogBuffer")
   but this only leads to
     AttributeError: 'module' object has no attribute 'lookup_symbol'



#3 my connect command has to disable breakpoints.
   I cannot re-enable them, because it does not know which
   breakpoints were enabled and which not.
   I've read about `save breakpoints' and tried it:

     (gdb) i b
     Num     Type           Disp Enb Address    What
     1       breakpoint     keep y   0x000d2b44 in logTrace
                                            at xxx.c:123
             stop only if $show_log_py()

     (gdb) save breakpoints tmpfile
     warning: save-tracepoints: no tracepoints to save.

     (gdb) source tmpfile
     tmpfile: No such file or directory.

   Would `save breakpoints' help to re-enable my breakpoints?
   How do I use it correctly?



#4 How do I source ~/.gdbinit.py if and only if I have a python-enabled
   gdb?
   If not possible:
   Would it be an idea for a future version to add such a feature?



#5 How can I automake `break logTrace if $show_log_py()' to be executed
   only if
     - Python avialable (would be solved by #4)
     - symbol logTrace and logStaticLogBuffer both exist
   I though I'd need some `if gdb.lookup_symbol("logTrace")',
   but failed because of #2



#6 BTW, why does `source ~/.gdbinit.py' work? Is the file name
   extension telling that it contains Python syntax?
   Otherwise I got errors (and had expected that I have to start
   with some `python' command and end with `end').



I'm sorry for my long (and frequent) posting, but I hope to give
all details that could be helpful in case someone finds time to
point me to the right place.

oki,

Steffen


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]