Unable to enable py-bt for gdb

I downloaded and compiled Python 3.5 on a CentOS 6.5 machine. It works without a problem. The problem is that I have to use gdb to debug a subtle error related to excessive CPU usage during the execution of my python program.

From the official Python documentation on the gdb extension , they say that the only thing to do is add

add-auto-load-safe-path /path/to/dir/with/python-gdb.py

to ~/.gdbinit . I tested it with

 gdb --args /path/to/python3.5/binary (gdb) py-bt 

but i get

 Undefined command: "py-bt" 

gdb is version 7.2 and python support is included.

+5
source share
2 answers

Found! You must add /PATH_TO_PYTHON_SRC/Tools/gdb to PYTHONPATH , then in gdb you can do:

 python import libpython 

Source: https://sumitkgaur.wordpress.com/2014/05/13/python-debugging/

+2
source

gdb automatically loads the gdb CLI scripts (either Python or Scheme) by looking at the directory trees embedded in directories in the scripts-directory search path. For each downloadable executable or shared object, gdb looks for scripts with the name objfile-gdb.gdb (or objfile-gdb.py or objfile-gdb.scm ).

One way to automatically download gdb extensions for python is to download the python-gdb.py file that you downloaded under one of the directories in your path to the script files. For example, the python2.7-dbg package on Ubuntu installs these files:

 -rwxr-xr-x /usr/lib/debug/usr/bin/python2.7-gdb.py lrwxrwxrwx /usr/lib/debug/usr/lib/libpython2.7.so.1.0-gdb.py -> ../bin/python2.7-gdb.py 

Here's a gdb session that shows how the python2.7-gdb.py script loads automatically when I start debugging the /usr/bin/python executable:

 (gdb) show auto-load scripts-directory List of directories from which to load auto-loaded scripts is $debugdir:$datadir/auto-load. (gdb) set debug auto-load (gdb) file /usr/bin/python Reading symbols from /usr/bin/python...Reading symbols from /usr/lib/debug//usr/bin/python2.7...done. auto-load: Attempted file "/usr/lib/debug/usr/bin/python2.7-gdb.gdb" does not exist. auto-load: Expanded $-variables to "/usr/lib/debug:/usr/share/gdb/auto-load". auto-load: Searching 'set auto-load scripts-directory' path "$debugdir:$datadir/auto-load". auto-load: Attempted file "/usr/share/gdb/auto-load/usr/lib/debug/usr/bin/python2.7-gdb.gdb" does not exist. auto-load: Attempted file "/usr/lib/debug/usr/bin/python2.7-gdb.py" exists. auto-load: Loading python script "/usr/lib/debug/usr/bin/python2.7-gdb.py" by extension for objfile "/usr/lib/debug/usr/bin/python2.7". 
0
source

Source: https://habr.com/ru/post/1261313/


All Articles