Often I'm writing Python code and want to call the debugger at some point. If you know the situation you want to call in advance, you can simply specify a breakpoint in pdb or embed "import pdb; pdb.set_trace ()" in your code, but it's completely "arbitrary" timing. That is not the case. When I investigated whether it was possible to attach to a running process in gdb, StackOverflow had an elegant method, so I will record it here.
python - Attaching a process with pdb - Stack Overflow
python
import signal
def handle_pdb(sig, frame):
import pdb
pdb.Pdb().set_trace(frame)
if __name__ == '__main__':
signal.signal(signal.SIGUSR1, handle_pdb)
What we're doing is simply calling the pdb when the signal SIGUSR1 is called. You can use it unless you are already using SIGUSR1 for other purposes. You may use other available signals.
Python is integrated in gdb nowadays, and advanced operations are possible. If you have a python debug symbol running, I think it's possible to attach it directly with gdb and trace the source code at the python level. The Material presented by Mr. Nojima at the Grand Unified Debian Study Group in 2013 will be helpful. Here we are doing source level debugging of php. The handling of debug symbols differs depending on the OS, distribution, and installation method, so please read that point as appropriate.
Recommended Posts