Vscode configuration for debugging CPython.
- Install Docker
- Install vscode with remote-development plugin
-
Clone Cpython.
-
Clone/Download this repo in another location apart from where you cloned Cpython.
-
Copy and Paste the
.devcontainer
and.vscode
directories into the directory where you cloned CPython. -
Open Cpython in vscode.
-
Click on the green Remote action button "
><
" at the lower leftmost corner in vscode(as shown in the image) and select Remote-Containers: Open Folder in Container... from the commands popup that appears, vscode will now start building the container and then build Cpython with relevant flags.
Inside the .vscode/launch.json
resides the debug configurations, there are three types of debugging configured:
-
Cpython test
Debug a CPython test case.
The best way to read the code of any open source project is to debug using the test cases. CPython's test cases are inside
Lib/tests
. Open any of the test case, for egLib/tests/test_list.py
, these are the test cases for good ol python list, each object in Python has its respective implementations inside the directoryObjects
and you can find the list implementation inObjects/listobject.c
, open the same and set a debug point inPyList_GetItem
at line 199. Now go back to thetest_list.py
and start the debugger, Voila, the debugger breaks exactly atPyList_GetItem
. -
python -c
Debug the python process by executing using the
python -c
option.Change the statement that you want the Python interpreter to run in the
args
option; currently it is"args": ["-c", "print(\"hello\")"]
; i.epython -c "print('hello')"
. -
python
Launches a Python interpreter and from there you can provide a statement for the interpreter to execute and you can follow along.
Head to Exploring Cpython, the Additional References section has all the exhaustive resources for you to get started with CPython walkthrough! Happy Hacking.