pythonpython-2.7debugginggdbgdb-python

How to debug python script in C level using GDB. Give me a simple example for this


How to debug python script in C level using GDB. Give me a simple example for this.My primary goal is to get the trace of libc function called from my python script.


Solution

  • See the thing is for binary(.so) files, you surely cannot apply breakpoint to a particular line, but surely you can apply breakpoint to a function. Say using

    (gdb) b func_name
    

    you can easily apply breakpoint to a function and thereby obtain the backtrace whenever the breakpoint is found. First run your python sc

    1. Start gdb:

      gdb -ex r --args python demo.py
      
    2. Apply breakpoint:

      (gdb) b func_name
      
    3. Run:

      (gdb) run
      

    This should work for your case.