From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 32740 invoked by alias); 28 Jun 2010 15:11:55 -0000 Received: (qmail 32639 invoked by uid 22791); 28 Jun 2010 15:11:52 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: sourceware.org Received: from ey-out-1920.google.com (HELO ey-out-1920.google.com) (74.125.78.145) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 28 Jun 2010 15:11:47 +0000 Received: by ey-out-1920.google.com with SMTP id 4so153605eyg.42 for ; Mon, 28 Jun 2010 08:11:45 -0700 (PDT) MIME-Version: 1.0 Received: by 10.213.4.5 with SMTP id 5mr1573842ebp.99.1277737904984; Mon, 28 Jun 2010 08:11:44 -0700 (PDT) Received: by 10.213.109.2 with HTTP; Mon, 28 Jun 2010 08:11:44 -0700 (PDT) In-Reply-To: References: Date: Mon, 28 Jun 2010 15:11:00 -0000 Message-ID: Subject: Re: gdb "automation" question From: Steffen Dettmer To: gdb@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2010-06/txt/msg00136.txt.bz2 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 to continue, or q 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