Mirror of the gdb mailing list
 help / color / mirror / Atom feed
* Python Scripting Question
@ 2009-11-08 15:08 Arjun Roy
  2009-11-09 17:16 ` Tom Tromey
  0 siblings, 1 reply; 10+ messages in thread
From: Arjun Roy @ 2009-11-08 15:08 UTC (permalink / raw)
  To: gdb

I have a question regarding the python scripting capabilities for GDB.
(running GDB on Fedora 11).

I'd like to be able to figure out the instruction mix for an arbitrary
program. I know I could step through it using nexti and disassemble, but
would like to script it out using python. So a couple of questions:

1. I'm getting some buggy behavior when I do the following:

(gdb) run
Starting program

Breakpoint 1, main () at test.c:3
3      long i = 0;
(gdb) python
>gdb.execute("disassemble $pc $pc+1")
>gdb.execute("disassemble $pc $pc+1")
>end
Dump of assembler code from 0x400478 to 0x400479:
0x0000000000400478 <main+4>:    movq   $0x0,-0x8(%rbp)
End of assembler dump.
Traceback (most recent call last):
  File "<string>", line 2, in <module>
TypeError: argument 1 must be string without null bytes, not str
Error while executing Python code.

Basically, running gdb.execute on the same disassemble statement (which
I assume should just print out the same asm twice, right?) has an issue.
But, if I execute this:

(gdb) python
>gdb.execute("disassemble $pc $pc+1")
>gdb.execute("disassemble $pc+1 $pc+2")
>end
Dump of assembler code from 0x400478 to 0x400479:
0x0000000000400478 <main+4>:    movq   $0x0,-0x8(%rbp)
End of assembler dump.
Dump of assembler code from 0x400479 to 0x40047a:
0x0000000000400479 <main+5>:    movl   $0x0,-0x8(%rbp)
End of assembler dump.

Then it works.

Is this a bug, am I misunderstanding the right way to do it, or what?

2. Ideally, I'd like to write a really simple script that:
- starts running a program
- steps through each instruction one by one, recording the opcode for
each instruction performed
- and stops when the program is over.

Does gdb-python support that? The issues I'm having are the one I
described above, and also not knowing how to check if the program is
done (I know it returns an exception when one tries to call nexti on a
finished program, but I'd rather do something like a "while
programNotDone()" ).

Thanks for the read.

-Arjun Roy


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2009-11-16 17:55 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-08 15:08 Python Scripting Question Arjun Roy
2009-11-09 17:16 ` Tom Tromey
2009-11-09 17:23   ` Tom Tromey
2009-11-09 17:44     ` Daniel Jacobowitz
2009-11-09 18:12       ` Tom Tromey
2009-11-09 20:22   ` Arjun Roy
2009-11-09 21:12     ` Tom Tromey
2009-11-13 14:36       ` scott snyder
2009-11-13 23:06         ` Arjun Roy
2009-11-18 20:43         ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox