From: Arjun Roy <roy.arjun@gmail.com>
To: gdb@sourceware.org
Subject: Python Scripting Question
Date: Sun, 08 Nov 2009 15:08:00 -0000 [thread overview]
Message-ID: <4AF63479.7010602@gmail.com> (raw)
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
next reply other threads:[~2009-11-08 3:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-08 15:08 Arjun Roy [this message]
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
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=4AF63479.7010602@gmail.com \
--to=roy.arjun@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