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

Discussion in 'Python' started by Timothy Madden, Sep 16, 2009.

  1. 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
     
    Timothy Madden, Sep 16, 2009
    #1
    1. Advertising

  2. Re: Debugging with gdb: pystack macro for gdb to show python stacktrace

    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
     
    Timothy Madden, Sep 17, 2009
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rajatag
    Replies:
    4
    Views:
    411
    rajatag
    Feb 20, 2007
  2. seba
    Replies:
    1
    Views:
    1,449
    mlimber
    Mar 22, 2007
  3. Chris Newby
    Replies:
    0
    Views:
    776
    Chris Newby
    Jul 28, 2008
  4. henq
    Replies:
    1
    Views:
    125
    Peter Scott
    Jan 2, 2004
  5. Replies:
    1
    Views:
    172
    dieter
    Mar 2, 2013
Loading...

Share This Page