This is the mail archive of the mailing list for the Archer 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]

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
$ 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)
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
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)
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/", line 87>
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")

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
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:


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