From: Yogesh Mundada <yogesh.mundada@gmail.com>
To: gdb@sourceware.org
Subject: Some help required with gdb-python scripting
Date: Sat, 27 Mar 2010 11:59:00 -0000 [thread overview]
Message-ID: <1957618c1003270459v78686a64wcfe050bd24ff5742@mail.gmail.com> (raw)
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 <return> to continue, or q <return> 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
next reply other threads:[~2010-03-27 11:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-27 11:59 Yogesh Mundada [this message]
2010-03-29 15:12 ` Tom Tromey
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1957618c1003270459v78686a64wcfe050bd24ff5742@mail.gmail.com \
--to=yogesh.mundada@gmail.com \
--cc=gdb@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox