public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
* Pretty-printing backtraces when "python" is the inferior process
@ 2009-12-22 23:24 David Malcolm
  2009-12-23 19:33 ` Tom Tromey
  2011-01-06 14:55 ` Tom Tromey
  0 siblings, 2 replies; 4+ messages in thread
From: David Malcolm @ 2009-12-22 23:24 UTC (permalink / raw)
  To: archer

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
<http://gnu.org/licenses/gpl.html>
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:
<http://www.gnu.org/software/gdb/bugs/>...
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=<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
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 "<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:
https://fedoraproject.org/wiki/DaveMalcolm/FeatureEasierPythonDebugging#Detailed_Description

Thanks!
Dave

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-01-06 14:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-22 23:24 Pretty-printing backtraces when "python" is the inferior process David Malcolm
2009-12-23 19:33 ` Tom Tromey
2009-12-23 21:28   ` David Malcolm
2011-01-06 14:55 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).