Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't enable py-bt for gdb

Tags:

I have downloaded and compiled Python 3.5 on a CentOS 6.5 machine. It works without problems. The problem is I have to use gdb to debug a subtle bug involving cpu overuse during my python program execution.

From official Python documentation about gdb extension, they says the only thing to do is to 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 have python support enabled.

like image 331
Marco Sulla Avatar asked Dec 15 '16 09:12

Marco Sulla


People also ask

Does GDB work with Python?

A set of GDB macros are distributed with Python that aid in debugging the Python process. You can install them by adding the contents of Misc/gdbinit in the Python sources to ~/. gdbinit -- or copy it from Subversion.

How do I import GDB into Python?

Explanation. GDB embeds the Python interpreter so it can use Python as an extension language. You can't just import gdb from /usr/bin/python like it's an ordinary Python library because GDB isn't structured as a library. What you can do is source MY-SCRIPT.py from within gdb (equivalent to running gdb -x MY-SCRIPT.py ) ...


1 Answers

Basing on blog post by Debugging of CPython processes with gdb One more way to resolve the issue is to source python3.5-gdb.py file. Run command info auto-load to check that files are loaded (if so) and if not -- load it manually: source /usr/share/gdb/auto-load/usr/bin/python3.5-gdb.py (! path may be different).

Then py-bt should work!

EDITED: changed py version

like image 62
Alex Bender Avatar answered Sep 21 '22 15:09

Alex Bender