Print a Python stacktrace of a running process
To print a Python stacktrace of a running process you need two script
:: The ignore-error.py
class IgnoreErrorsCommand (gdb.Command): """Execute a single command, ignoring all errors. Only one-line commands are supported. This is primarily useful in scripts.""" def __init__ (self): super (IgnoreErrorsCommand, self).__init__ ("ignore-errors", gdb.COMMAND_OBSCURE, # FIXME... gdb.COMPLETE_COMMAND) def invoke (self, arg, from_tty): try: gdb.execute (arg, from_tty) except: pass IgnoreErrorsCommand () |
:: and the gdb script pygdb
- be sure gdb and python2.7-dbg are installed:
apt-get install gdb python2.7/dbg
# sudo apt-get install gdb python2.7-dbg # to run: # sudo gdb python # (gdb) bt_pid <pid> source /home/samuel/tmp/ignore-errors.py define bt_pid attach $arg0 t a a ignore-errors py-bt t a a bt detach end |
To run this script and have the stacktrace:
giovanni@ol-home:~$ sudo gdb python (gdb) source pygdb (gdb) bt_pid <PID> |