disconnect3d / disconnect3d.github.io

1 stars 3 forks source link

2024/08/04/debugging-cpython-live/ #6

Open utterances-bot opened 1 month ago

utterances-bot commented 1 month ago

Debugging running Python scripts with PDB via GDB

Disconnect3d's blog.

http://disconnect3d.pl//2024/08/04/debugging-cpython-live/

disconnect3d commented 2 weeks ago

Hi, I guess it really depends on the interpreter but in most of them it should be a matter of 1) finding a place to stop at, and 2) finding a way/API to execute code from a string. Probably as long as we are not talking about JITted code.

Regarding tracing C calls, this is possible in multiple ways:

  1. The ltrace could be used for tracing library functions (well, with modern security mitigations -- relocations read-only and bind now -- ltrace often fails and do not work, but it could be fixed...)
  2. GDB or any other debugger could be used to trace specific functions (e.g., the dprintf <location> <fmtstr>, <args> command in GDB)

However, keep in mind that it may not be possible to trace all of the functions since, e.g., functions defined with static keyword are often inlined etc.