0

I have been reading about the sys.monitoring API that has been released for Python 3.12. I understand a bit of its working and can point sys.breakpointhook to my own function and print out simple debugging information.

I now want to pause the execution of my script when I hit a breakpoint instead of just printing out information but cannot understand how this can be implemented. Let us just say, I am trying to implement a very basic debugger myself. I know that there are ready to use debuggers out there but I want to understand how they work so I would like to try and implement one myself.

It would be great if someone could point out how Bdb does it as I have browsed the source but haven't figured out much. Is there a sys module call that is used to do this?

4
  • 1
    As you know Stackoverflow is for specific coding issues, rather than tutorials and research, so this question is off topic. Debuggers have to interrupt code and simulate actions based on the instruction in the source code. Which is a non-trivial task at the best of times. Commented Jul 5 at 13:30
  • 1
    The standard debugger presumably calls an internal function of the REPL, Commented Jul 5 at 15:44
  • 1
    Why not use code.interact()? It is mentioned on docs.python.org/3/library/pdb.html#pdbcommand-interact. It blocks execution, allows you to run debugging commands, e.g. locals().keys() then you Ctrl D to drop back into normal execution Commented Jul 5 at 16:43
  • I have seen the source for code.interact(). I think most debuggers at some level flash a banner and then block using input() or an equivalent. I will see if this is sufficient for me to get started. Commented Jul 5 at 17:28

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.