From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16128 invoked by alias); 22 Dec 2009 23:24:51 -0000 Mailing-List: contact archer-help@sourceware.org; run by ezmlm Sender: Precedence: bulk List-Post: List-Help: List-Subscribe: List-Id: Received: (qmail 16119 invoked by uid 22791); 22 Dec 2009 23:24:49 -0000 X-SWARE-Spam-Status: No, hits=-2.6 required=5.0 tests=BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org Subject: Pretty-printing backtraces when "python" is the inferior process From: David Malcolm To: archer@sourceware.org Content-Type: text/plain; charset="UTF-8" Date: Tue, 22 Dec 2009 23:24:00 -0000 Message-Id: <1261524321.2228.70.camel@brick> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit X-SW-Source: 2009-q4/txt/msg00129.txt.bz2 I'm experimenting with archer, and adding python hooks for when the inferior process is itself Python. Python already has a gdbinit file with plenty of domain-specific hooks for debugging CPython; it's written in the gdb language, rather than python; you can see it here: http://svn.python.org/view/python/trunk/Misc/gdbinit?view=markup (is there a meaningful place to install that in distributions? In Fedora we currently just drop it in a doc subdirectory in our python-devel rpm) I get a lot of python and pygtk backtraces assigned to me in the Fedora bug tracker, so I'm keen on extending the GLib backtrace hooks described at: http://tromey.com/blog/?p=522 so that Python parts of a gdb backtrace report the python source file, line number and function, and perhaps even the locals as well (ultimately I want to fully reimplement the gdbinit file above in Python, which should be more robust since more logic and error handling can be moved from the inferior process to gdb; backtrace handling is probably the biggest win from my own sanity POV right now). I've attempted to do this, but am running into an issue. (this is on Fedora 12 i386) I've cloned the git repo, and checked out this branch: $ git checkout --track -b archer-tromey-python origin/archer-tromey-python $ ./configure --with-separate-debug-dir=/usr/lib/debug $ make $ sudo make install I'm trying to use a freshly-built gdb to debug a pygtk app named "istanbul" (using system python and system copy of instanbul): $ ./gdb/gdb --args /usr/bin/python /usr/bin/istanbul GNU gdb (GDB) 6.8.50.20090910-cvs Copyright (C) 2009 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i686-pc-linux-gnu". For bug reporting instructions, please see: ... Reading symbols from /usr/bin/python...Reading symbols from /usr/lib/debug/usr/bin/python2.6.debug...done. (no debugging symbols found)...done. (gdb) run Starting program: /usr/bin/python /usr/bin/istanbul [Thread debugging using libthread_db enabled] (snip some debug prints from the pygtk app) ^C Program received signal SIGINT, Interrupt. 0x00f68424 in __kernel_vsyscall () (gdb) frame 9 #9 PyEval_EvalFrameEx (f=, throwflag=) at Python/ceval.c:2389 2389 x = call_function(&sp, oparg); I'd like to access the local "PyCodeObject *co" at this point: (gdb) p co $5 = (PyCodeObject *) 0x81274e8 Doing so using the gdbinit macros mentioned above is fruitful: (gdb) pyo co object : type : code refcount: 2 address : 0x81274e8 $4 = void and I want to use analogous code to implement archer prettyprinting of the python backtraces. This API hook works: (gdb) python print gdb.parse_and_eval("co") 0x81274e8 But this one doesn't: (gdb) python print gdb.selected_frame().read_var('co') Traceback (most recent call last): File "", line 1, in ValueError: variable 'co' not found Error while executing Python code. I'm a novice at the internals of gdb; I've tried attaching to the first gdb with a second and putting a breakpoint on py-frame.c's frapy_read_var; ultimately lookup_symbol (name=0xc3e1dc8 "co", block=0xcb6d904, domain=VAR_DOMAIN, is_a_field_of_this=0x0) at symtab.c:1265 is returning NULL. Any ideas on what's going wrong? FWIW, The URL for my efforts is here: https://fedoraproject.org/wiki/DaveMalcolm/FeatureEasierPythonDebugging#Detailed_Description Thanks! Dave