Custom Search

Thursday, September 10, 2015

How to debug Multithreaded Python Application with gdb


https://wiki.python.org/moin/DebuggingWithGdb

1)
Install gdb and Python debugging extensions
$ sudo apt-get install gdb python2.7-dbg

2)
If the process is already running, you can attach to it provided you know the process ID.
$ gdb python [process id]

Attaching to a running process like this will cause it to stop. You can tell it to continue running with c command.

3)
If the hang occurs in some thread, the following commands may be handy:
(gdb) info threads

Current thread is marked with *. To see where it is in Python code, use py-list:
(gdb) py-list

4)
Example:
https://code.google.com/p/spyderlib/wiki/HowToDebugDeadlock

http://fedoraproject.org/wiki/Features/EasierPythonDebugging


1 comment:

  1. (gdb) help info

    Generic command for showing things about the program being debugged.

    List of info subcommands:

    info address -- Describe where symbol SYM is stored
    info all-registers -- List of all registers and their contents
    info args -- Argument variables of current stack frame
    info auto-load -- Print current status of auto-loaded files
    info auto-load-scripts -- Print the list of automatically loaded Python scripts
    info auxv -- Display the inferior's auxiliary vector
    info bookmarks -- Status of user-settable bookmarks
    info breakpoints -- Status of specified breakpoints (all user-settable breakpoints if no argument)
    info checkpoints -- IDs of currently known checkpoints
    info classes -- All Objective-C classes
    info common -- Print out the values contained in a Fortran COMMON block
    info copying -- Conditions for redistributing copies of GDB
    info dcache -- Print information on the dcache performance
    info display -- Expressions to display when program stops
    info exceptions -- List all Ada exception names
    info extensions -- All filename extensions associated with a source language
    info files -- Names of targets and files being debugged
    info float -- Print the status of the floating point unit
    info frame -- All about selected stack frame
    info frame-filter -- List all registered Python frame-filters
    info functions -- All function names
    info handle -- What debugger does when program gets various signals
    info inferiors -- IDs of specified inferiors (all inferiors if no argument)
    info line -- Core addresses of the code for a source line
    info locals -- Local variables of current stack frame
    info macro -- Show the definition of MACRO
    info macros -- Show the definitions of all macros at LINESPEC
    info mem -- Memory region attributes
    info os -- Show OS data ARG
    info pretty-printer -- GDB command to list all registered pretty-printers
    info probes -- Show available static probes
    info proc -- Show /proc process information about any running process
    ---Type to continue, or q to quit---
    info program -- Execution status of the program
    info record -- Info record options
    info registers -- List of integer registers and their contents
    info scope -- List the variables local to a scope
    info selectors -- All Objective-C selectors
    info set -- Show all GDB settings
    info sharedlibrary -- Status of loaded shared object libraries
    info signals -- What debugger does when program gets various signals
    info skip -- Display the status of skips
    info source -- Information about the current source file
    info sources -- Source files in the program
    info stack -- Backtrace of the stack
    info static-tracepoint-markers -- List target static tracepoints markers
    info symbol -- Describe what symbol is at location ADDR
    info target -- Names of targets and files being debugged
    info tasks -- Provide information about all known Ada tasks
    info terminal -- Print inferior's saved terminal status
    info threads -- Display currently known threads
    info tracepoints -- Status of specified tracepoints (all tracepoints if no argument)
    info tvariables -- Status of trace state variables and their values
    info type-printers -- GDB command to list all registered type-printers
    info types -- All type names
    info variables -- All global and static variable names
    info vector -- Print the status of the vector unit
    info vtbl -- Show the virtual function table for a C++ object
    info warranty -- Various kinds of warranty you do not have
    info watchpoints -- Status of specified watchpoints (all watchpoints if no argument)
    info win -- List of all displayed windows

    Type "help info" followed by info subcommand name for full documentation.
    Type "apropos word" to search for commands related to "word".
    Command name abbreviations are allowed if unambiguous.
    (gdb)

    ReplyDelete