How to use gdb python debugging extension inside virtualenv

前端 未结 4 775
栀梦
栀梦 2020-12-25 07:57

I\'m running ubuntu, and installed the python-dbg package. When trying to use the installed version directly everything works great:

$ gdb python2.7-dbg
GNU          


        
相关标签:
4条回答
  • 2020-12-25 08:39

    In Debian 11 with Python 3.7, gdb debugging works out of the box inside virtualenv.

    Make sure that you created the venv with the same Python3 version than the python3-dbg package version installed.

    In case symbols don't load correctly, rebuild the venv from scratch and try again.

    0 讨论(0)
  • 2020-12-25 08:57

    I've solved the problem by using strace on gdb, grepping the "open" syscalls.

    It seems that gdb makes a search for python-gdb.py in several paths it guesses (according to the python binary), and whenever the file is not found it just fails silently.

    Eventually the way to solve the problem is to link /usr/lib/debug/usr/bin/python2.7-gdb.py into the env's bin directory. The name of the link should be <python binary name>-gdb.py, being in my case python2.7-dbg-gdb.py (...).

    After that, everything seems to work.

    0 讨论(0)
  • 2020-12-25 08:58

    @itai's answer only partially worked for me on Ubuntu Trusty (14.04). I found a couple of other things worked better:

    sudo apt-get install python2.7-dbg

    then, in the virtualenv:

    . bin/activate
    mkdir bin/.debug
    ln -s /usr/lib/debug/usr/bin/python2.7-gdb.py bin/.debug/python-gdb.py
    ln -s /usr/lib/debug/usr/bin/python2.7 bin/.debug/
    
    gdb --args bin/python2.7 ...
    

    This helped gdb find the python debugging symbols as well as the py-bt etc commands.

    0 讨论(0)
  • 2020-12-25 09:02

    On Ubuntu 12.04, @craigds's answer was very helpful but didn't get me quite all the way there: I was still running into:

    IOError: invalid Python installation: unable to open /path/to/venv/lib/python2.7/config_d/Makefile (No such file or directory)
    

    Fixed that, then I ran into:

    IOError: invalid Python installation: unable to open /path/to/venv/local/include/python2.7_d/pyconfig.h (No such file or directory)
    

    So the full steps for me to fix up my virtualenv were:

    source /path/to/venv/bin/activate
    mkdir /path/to/venv/bin/.debug
    ln -s /usr/lib/debug/usr/bin/python2.7-gdb.py /path/to/venv/bin/.debug/python-gdb.py
    ln -s /usr/lib/debug/usr/bin/python2.7 /path/to/venv/bin/.debug/
    ln -s /usr/lib/python2.7/config_d/ /path/to/venv/lib/python2.7/config_d
    ln -s /usr/include/python2.7_d/ /path/to/venv/local/include/python2.7_d
    ln -s /usr/lib/debug/usr/bin/python2.7-gdb.py /path/to/venv/bin/python-gdb.py
    
    0 讨论(0)
提交回复
热议问题