From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 661 invoked by alias); 27 Mar 2010 11:59:52 -0000 Received: (qmail 648 invoked by uid 22791); 27 Mar 2010 11:59:51 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=BAYES_00,SARE_MSGID_LONG40 X-Spam-Check-By: sourceware.org Received: from qw-out-1920.google.com (HELO qw-out-1920.google.com) (74.125.92.149) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 27 Mar 2010 11:59:47 +0000 Received: by qw-out-1920.google.com with SMTP id 4so2665516qwk.24 for ; Sat, 27 Mar 2010 04:59:46 -0700 (PDT) MIME-Version: 1.0 Received: by 10.229.99.146 with HTTP; Sat, 27 Mar 2010 04:59:45 -0700 (PDT) Date: Sat, 27 Mar 2010 11:59:00 -0000 Received: by 10.229.217.206 with SMTP id hn14mr1240984qcb.70.1269691185972; Sat, 27 Mar 2010 04:59:45 -0700 (PDT) Message-ID: <1957618c1003270459v78686a64wcfe050bd24ff5742@mail.gmail.com> Subject: Some help required with gdb-python scripting From: Yogesh Mundada 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-03/txt/msg00210.txt.bz2 Hi, Sorry about this lengthy email. I am writing a few python functions to collect some information about breakpoints execution. I am putting two break points in the object file and want my functions to get called as these breakpoints are reached to collect some information. I am running the latest source code(03/26) from archer-tromey-python branch. My python functions are defined as follows: ----------------- #!/home/yogesh/build/gdb/gdb -P import gdb import pdb brk_340 = 0 brk_379 = 0 class call_profiler (gdb.Function): """Profiles calls""" def __init__ (self): super (call_profiler, self).__init__ ("call_profiler") def invoke (self): #pdb.set_trace() global brk_340 global brk_379 fr = gdb.selected_frame() fisa = fr.find_sal() if '340' in str(fisa.line): brk_340 += 1 elif '379' in str(fisa.line): brk_379 += 1 else: print "In some weird break point" return True class print_variables(gdb.Function): """Prints brk_340, brk_379""" def __init__(self): super (print_variables, self).__init__ ("print_variables") def invoke(self): global brk_340 global brk_379 print "Break at 340: %d, Break at 379: %d" % (brk_340, brk_379) return True call_profiler() print_variables() ---------------- I am starting the debugging as follows: #gdb (gdb) file vmlinux Reading symbols from /mnt/tmp/yogesh/linux-2.6.24-yhm-custom/vmlinux...done. (gdb) source /home/yogesh/profile_call.py (gdb) b arch/x86/kernel/entry_32.S:340 Breakpoint 1 at 0xc01043bb: file arch/x86/kernel/entry_32.S, line 340. (gdb) b arch/x86/kernel/entry_32.S:379 Breakpoint 2 at 0xc010443b: file arch/x86/kernel/entry_32.S, line 379. (gdb) commands 1 Type commands for when breakpoint 1 is hit, one per line. End with a line saying just "end". >silent >call $call_profiler() >continue >end (gdb) commands 2 Type commands for when breakpoint 2 is hit, one per line. End with a line saying just "end". >silent >call $call_profiler() >continue >end (gdb) target remote localhost:7732 (gdb) c Continuing. ------------------------------- This works until it asks me to press enter because the screen is full of output from 'return 1' statements in the call_profiler(). ---------------------------- $2 = 1 $3 = 1 .. .. $45 = 1 $46 = 1 ---Type to continue, or q to quit--- ---------------------------- Thus, I have to press enter after the breakpoint is reached every 45 times or so. I tried to return nothing in the call_profiler(), but then the python interpreter gives an error. My questions are: 1. Is there any way to disable this 'more' type editor feature after every few lines? 2. How can I examine value of eax register in the function call_profiler()? I tried - fr.read_var('%eax'), fr.read_var('$eax') and fr.read_var('eax') - but all of them give me an error saying that the variable not found. 3. Is there any way to stop execution and give control back to the user if some condition is true? Something like: if eax == 1: gdb.cli() I see that gdb has a cli built-in method. But if I call it, I get following error: (Pdb) gdb.cli() *** RuntimeError: cannot invoke CLI recursively 4. Is there any way to make this process completely automated without me ever requiring to set breakpoints or put commands for breakpoints? I think I can import object file and set break points as follows in the script: gdb.execute("file /mnt/tmp/yogesh/vmware-ubuntu/linux-2.6.24-yhm-custom/vmlinux") gdb.execute("b arch/x86/kernel/entry_32.S:340") gdb.execute("b arch/x86/kernel/entry_32.S:379") gdb.execute("target remote localhost:7732") But, after that, how do I set commands to be executed for breakpoints 1 and 2? If I just do gdb.execute("commands 1"), that starts some scripting prompt. -Yogesh