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

Timothy Madden terminatorul at gmail.com
Thu Sep 17 13:47:26 CEST 2009


Timothy Madden wrote:
> 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



More information about the Python-list mailing list