1

there may very well be an answer to this question, but it's really hard to google for.

you can add commands to gdb by writing them in python. I am interested in debugging one of those python scripts that's running in gdb session.

my best guess is to run gdb on gdb and execute the user added command and somehow magically break on the python program code?

has anybody done anything like this before? I don't know the mechanism by which gdb calls python code, so if it's not in the same process space as the gdb that's calling it, I don't see how I'd be able to set breakpoints in the python program.

or do I somehow get pdb to run in gdb? I guess I can put pdb.set_trace() in the python program, but here's the extra catch: I'd like to be able to do all this from vscode.

so I guess my question is: what order of what things do I need to run to be able to vscode debug a python script that was initiated by gdb?

anybody have any idea?

thanks.

stu
  • 8,461
  • 18
  • 74
  • 112

1 Answers1

1

so I figured it out. it's kinda neat.

you run gdb to debug your program as normal, then in another window you attach to a running python program. in this case the running python program is the gdb process. once you attach, you can set breakpoints in the python program, and then when you run commands in the first window where the gdb session is, if it hits a breakpoint in the python code, it will pop up in the second window.

the tipoff was that when you run gdb there does not appear to be any other python process that's a child of gdb or related anywhere, so I figured gdb must dynamically link to some python library so that the python compiler/interpreter must be running in the gdb process space, so I figured I'd try attaching to that, and it worked.

stu
  • 8,461
  • 18
  • 74
  • 112