python Of c Language version of the source code cpython It can be downloaded from github Download the ( See reference 1).
How to run and debug the source code ?
The author is in Windows 10 On the use of Visual Studio Community2019 debug , Steps are as follows :
download cpython Source code , The author from the reference 2 Downloaded python3.10.4 Source code
double-click ( use Visual Studio) Open the source directory PCbuild/pcbuild.sln file
VS Set in the for Debug,Win32 Pattern
stay Solution, Right click , choice properties, choice Configuration Properties, choice Configuration, How to choose Build Select only python and pythoncore, The details are shown in the following figure
And then run directly debug You can debug . The interface obtained after operation and direct operation python The command gets exactly the same interface , As shown in the figure below :
We know , stay python shell in , Enter a statement , Will execute and get results , Then enter another statement and execute it to get the result , Like an endless loop, you can always input 、 perform . How does this process work in the source code ?
int _PyRun_InteractiveLoopObject()
{
do {
// In this cycle , Run interactive statements
ret = PyRun_InteractiveOneObjectEx(fp, filename, flags);
} while (ret != E_EOF);
return err;
}
stay Windows 10 On the use of Visual Studio Community2019, Can debug python Source code ,python The source code also comes with a suitable VS Open taxi .sln file , Very convenient for debugging .