[Python] How to change the Python Interpreter that gdb uses?

Discussão em 'Python' iniciado por Stack, Maio 28, 2025.

  1. Stack

    Stack Membro Participativo

    I'm using ubuntu 14.04, where python3 is a default system package.

    I want to debug Python2.7 programs with gdb, but I seem to encounter this issue:

    When i'm in gdb, using the py command puts me in an interpreter, so i ran these commands in the interpreter:

    First I check the interpreter version:

    (gdb) py
    >import sys
    >print(sys.version)
    >end
    3.4.0 (default, Apr 11 2014, 13:08:40)
    [GCC 4.8.2]


    Then I check what interpreter executable is being used

    (gdb) py
    >import sys
    >print(sys.executable)
    >end
    /usr/bin/python
    (gdb)


    Then in bash, I check the interpreter:

    12:34]hostname ~ $ls -l /usr/bin/python
    lrwxrwxrwx 1 root root 9 Dec 21 2013 /usr/bin/python -> python2.7


    So although gdb says it's using my 2.7 interpreter, it's actually using another one. I need a 2.7 interpreter to be able to use it with the python specific extensions that the ubuntu package 'python2.7-dbg' provides, because as far as i know there's no such package for python 3.4 yet, and even if there was, the programs that i want to debug run python 2.7

    My question is how do i make it use the interpreter I want?

    [EDIT] Do not uninstall python3 btw. I did it on ubuntu 14.04 and it wrecked my system. Couldn't manage to get it up again. I'm currently using it with no window-manager (it's cool and 1337), but you get the idea.

    Continue reading...

Compartilhe esta Página