* Some help required with gdb-python scripting
@ 2010-03-27 11:59 Yogesh Mundada
2010-03-29 15:12 ` Tom Tromey
0 siblings, 1 reply; 2+ messages in thread
From: Yogesh Mundada @ 2010-03-27 11:59 UTC (permalink / raw)
To: gdb
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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Some help required with gdb-python scripting
2010-03-27 11:59 Some help required with gdb-python scripting Yogesh Mundada
@ 2010-03-29 15:12 ` Tom Tromey
0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2010-03-29 15:12 UTC (permalink / raw)
To: Yogesh Mundada; +Cc: gdb
>>>>> "Yogesh" == Yogesh Mundada <yogesh.mundada@gmail.com> writes:
Yogesh> 1. Is there any way to disable this 'more' type editor feature after
Yogesh> every few lines?
"set pagination off"
Inside gdb you can use the _unfiltered functions to bypass the
pagination. These aren't exposed to Python, however.
In your particular case, you could avoid the use of `call', and not get
things printed out. You could either do this by writing a new command
instead of a convenience function, or by simply having your breakpoint
commands invoke the Python directly using the 'python' command.
Yogesh> 2. How can I examine value of eax register in the function
Yogesh> call_profiler()? I tried - fr.read_var('%eax'),
Yogesh> fr.read_var('$eax') and fr.read_var('eax') - but all of them
Yogesh> give me an error saying that the variable not found.
Try gdb.parse_and_eval('$eax')
Yogesh> 3. Is there any way to stop execution and give control back to the
Yogesh> user if some condition is true?
No. I want to say "not yet" but I am not sure about that.
Yogesh> 4. Is there any way to make this process completely automated without
Yogesh> me ever requiring to set breakpoints or put commands for breakpoints?
I am not sure.
Maybe you could try gdb.execute with an argument containing newlines.
I don't know if that will work or not.
If not, then I don't think there is a very good way at present.
You can make a temporary file and source it -- yuck.
The archer-tromey-python branch has some more direct support for
breakpoints. Maybe you can set the commands directly there; I don't
remember offhand. Phil is in the process of merging this upstream.
Tom
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2010-03-29 15:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-27 11:59 Some help required with gdb-python scripting Yogesh Mundada
2010-03-29 15:12 ` Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox