Debugging with gdb: pystack macro for gdb to show python stack trace

T

Timothy Madden

Hello

I have an application with several threads that sometimes just freezes.

I installed the debug symbols for python interpreter, and the gdb
macros, as instructed on the wiki
http://wiki.python.org/moin/DebuggingWithGdb
so I can debug with gdb.

gdb loads many files with python debugging simbols, and it is loading
the macros file ~/.gdbinit, but still the macros for working with python
are not working. The pystack command just freezes the debugger until I
press ^C, and other macros complain about undefined symbols. I would
like to see the python stack trace so I know where my application
freezes. All I could see from the gdb native stack trace (with bt) was
that my 3 threads were waiting to acquire a lock, but I could not figure
out where and my program logic should not allow this to happen.

Can I get the python stack trace working under gdb ?

Synaptic Package Manager on my Ubuntu netbook shows packages
python2.6 (2.6.2-0ubuntu1)
python2.6-dbg (2.6.2-0ubuntu1)
as installed, and I extracted the Misc/gdbinit file from
Python-2.6.2.tar.bz2 source archive from python.org. I have gdb 6.8-debian.
So I suppose everything should be right ...


Thank you,
Timothy Madden
 
T

Timothy Madden

Timothy said:
Hello
[...]

Can I get the python stack trace working under gdb ?
[...]

Ok I found some other gdb macros on linked from the wiki page and I had
to change them to get the stack trace work.

I had to change the symbol PyEval_EvalFrame to PyEval_EvalFrameEx and
then I could see the stack trace. The resulting gdb macro was:

define pbt
set $i = 0
set $j = 0
while $i < 1000
select $i
if $eip >= &PyEval_EvalFrameEx
if $eip < &PyEval_EvalCodeEx
echo c frame #
p $i
echo py frame #
p $j
set $j = $j+1
x/s ((PyStringObject*)f->f_code->co_filename)->ob_sval
x/s ((PyStringObject*)f->f_code->co_name)->ob_sval
echo line #
p f->f_lineno
end
end
set $i = $i+1
end
end
document pbt
show python backtrace
end

Thank you,
Timothy Madden
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top