Debugging compiled code used from pyroot

Hello Everyone,

I’m just curious if it exists handy method to debug compiled libraries loaded from pyroot.

Using gdb or valgrind, I found not other way than debugging the full python process, which is not very convenient. Are there better options ?




gdb can attached later to the running process, which speeds things up. We use this in athena:[code]def hookDebugger(debugger=‘gdb’):
""“debugging helper, hooks debugger to running interpreter process
import os
pid = os.spawnvp(os.P_NOWAIT,
debugger, [debugger, ‘-q’, ‘python’, str(os.getpid())])

# give debugger some time to attach to the python process
import time
time.sleep( 1 )

# verify the process' existence (will raise OSError if failed)
os.waitpid( pid, os.WNOHANG )
os.kill( pid, 0 )

which can then be attached programmatically from the python script.


Thanks a lot Wim !

As I understand, I just need to define this function in my script and call it when I need to start gdb, correct ?

Anything similar for valgrind ? (just replace ‘gdb’ by ‘valgrind’ ?)


yes to the first question, no to the second. It is possible to “focus” valgrind on specific pieces of code, for some of its tools, but that would have to be done from C++, using the valgrind API.