Where should I put the breakpoint that VS debugger will activate when I enter something in Python interpreter?

Viewed 161

I'm trying to learn about how the Python interpreter works via debugging it in interactive mode.

I've managed to compile cpython with Visual Studio 2019 on windows 10, using the PCbuild\pcbuild.sln solution.

I tried debug from python.c as the file is the only one in "Source Files" panel.

enter image description here

and then I tracked it to main.c

enter image description here

enter image description here

I tried to put breakpoints there, pressed F5, VS activated the breakpoints during launching the interpreter.

However, when I entered something in the interpreter being debugged, VS didn't activate any breakpoint.

enter image description here

Where should I put the breakpoint that VS debugger will activate when I enter something in Python interpreter?

PS:

I also tried put another line there

enter image description here

and got same situation, that is, debugger hits the breakpoint only once when VS launches the console. After that, debugger never hits the breakpoint again.

enter image description here

enter image description here

pymain_init

enter image description here

stop the program

enter image description here

enter image description here

enter image description here

1 Answers

I would probably start by making sure that the code path you are expecting is actually being called. For example, add something like this:

fprintf(stderr, "This is interesting...!\n");

Add a breakpoint to the same line. Build and run. If the message appears, but the debugger doesn't stop execution then you've hit a not uncommon bug that breakpoints stop working. Double check your solution/project settings and make sure everything looks right and you are doing a debug build. If that all looks ok then try "VS > Tools > Import and Export Settings… > Reset all settings."

Anyway, back to Python! This site has some great "internal" to give you an idea of where to start: https://realpython.com/cpython-source-code-guide/#reading-filesinput

I would look at Modules/main.c and breakpoint all the pymain_run_* functions.

Related