Let’s say we have the following mega-simple Python script:
print "Initializing"....
a=10
print "Variable value is %d" % (a)
print "All done!"
… and say, I’d like to debug this script by placing a breakpoint at line a=10, and then stepping through the script.
Now, I’d like to use gdb for this, because I’d like to debug Python bindings that may come as a part of a shared object (.so) library – hence, I’d ideally place a breakpoint on a Python code line, and then “step into” the C part of the shared object… (Note that DebuggingWithGdb – PythonInfo Wiki doesn’t really explicitly state that this is possible)
The problem is: gdb on its own cannot really recognize breakpoints, placed on a Python script line:
$ gdb python
GNU gdb (GDB) 7.3.50.20110806-cvs
...
Reading symbols from /usr/bin/python...(no debugging symbols found)...done.
(gdb) b test.py:3
No symbol table is loaded. Use the "file" command.
Make breakpoint pending on future shared library load? (y or [n]) y
Breakpoint 1 (test.py:3) pending.
(gdb) run test.py
Starting program: /usr/bin/python test.py
...
… and while the entire Python script does run within gdb, the breakpoint is simply never reached.
So – is what I want to do, at all possible with gdb; and if not, what other alternatives would I have for something similar?
Very interesting question. Here’s my approach. Create
signal_test.py:Then you can run it under gdb:
And when you run it, it will go until you reach the call to
kill():You can then look at a backtrace:
If you continue on, the rest of the program will run normally.
You can, instead, step through in the appropriate frame until you reach the statement you’re interested in. You’re probably going to want to run a debugging Python for this to make much sense.