From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7294 invoked by alias); 8 Nov 2009 03:01:27 -0000 Received: (qmail 7111 invoked by uid 22791); 8 Nov 2009 03:01:25 -0000 X-SWARE-Spam-Status: No, hits=0.1 required=5.0 tests=AWL,BAYES_00,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail-yw0-f188.google.com (HELO mail-yw0-f188.google.com) (209.85.211.188) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 08 Nov 2009 03:01:17 +0000 Received: by ywh26 with SMTP id 26so1998130ywh.12 for ; Sat, 07 Nov 2009 19:01:15 -0800 (PST) Received: by 10.150.127.18 with SMTP id z18mr10735200ybc.61.1257649275693; Sat, 07 Nov 2009 19:01:15 -0800 (PST) Received: from ?128.12.239.131? (tsukiakari.Stanford.EDU [128.12.239.131]) by mx.google.com with ESMTPS id 23sm567088ywh.33.2009.11.07.19.01.14 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sat, 07 Nov 2009 19:01:15 -0800 (PST) Message-ID: <4AF63479.7010602@gmail.com> Date: Sun, 08 Nov 2009 15:08:00 -0000 From: Arjun Roy User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.4pre) Gecko/20091014 Fedora/3.0-2.8.b4.fc11 Thunderbird/3.0b4 MIME-Version: 1.0 To: gdb@sourceware.org Subject: Python Scripting Question Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org X-SW-Source: 2009-11/txt/msg00076.txt.bz2 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 : movq $0x0,-0x8(%rbp) End of assembler dump. Traceback (most recent call last): File "", line 2, in 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 : movq $0x0,-0x8(%rbp) End of assembler dump. Dump of assembler code from 0x400479 to 0x40047a: 0x0000000000400479 : 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