This is the mail archive of the gdb@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Python Scripting Question


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]