This is the mail archive of the
mailing list for the Archer project.
Pretty-printing backtraces when "python" is the inferior process
- From: David Malcolm <dmalcolm at redhat dot com>
- To: archer at sourceware dot org
- Date: Tue, 22 Dec 2009 18:25:21 -0500
- Subject: Pretty-printing backtraces when "python" is the inferior process
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:
(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
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
$ 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) 22.214.171.12490910-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
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
(no debugging symbols found)...done.
Starting program: /usr/bin/python /usr/bin/istanbul
[Thread debugging using libthread_db enabled]
(snip some debug prints from the pygtk app)
Program received signal SIGINT, Interrupt.
0x00f68424 in __kernel_vsyscall ()
(gdb) frame 9
#9 PyEval_EvalFrameEx (f=<value optimized out>, throwflag=<value
optimized out>) 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 : <code object main at 0x81274e8, file "/usr/lib/python2.6/site-packages/istanbul/main/main.py", line 87>
type : code
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")
But this one doesn't:
(gdb) python print gdb.selected_frame().read_var('co')
Traceback (most recent call last):
File "<string>", line 1, in <module>
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
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: