Debugging the Windows build

From CSP

Using the Visual Studio debugger with CSP as a collection of Python extension libs is not as easy as with a project based on a simple .exe file. There are means to debug Python extensions from within Visual Studio, but these would require a special build configuration (You have to build your own debug version of Python, for instance). As we don't want to maintain a build environment especially for Windows (we had this situation until quite recently), we prefer to use an alternative: Instead of starting the sim in Visual Studio's debug mode, we attach the debugger to the already running process.

Build CSPSIM with Debug Info

  • To make sure all necessary components are rebuilt, you should first clean the directories with scons -c all. Rebuild CSP with scons all debug=1
  • After the rebuild, change to the /bin directory, and run the sim with sim.py --pause. This option stops the execution after loading the Python extension modules.

Known issue for builds on multicore CPUs: Although SCons supports parallel builds on multicore CPUs, no debug symbols (the .PDB file) will be added. The linker only prints a warning, but when attaching the debugger, an error about missing debug symbols will be displayed. To avoid this, do not use the -j option with SCons.


Attach the Debugger to the running CSP process

  • Open the Visual Studio solution file located in csp/csp_vs.
  • Now you are ready to attach the debugger to the python process that contains the sim: Start Visual Studio, and go to Debug --> Attach to Process. In the list of the running processes you should find one instance of python.exe. Highlight this entry, and click Attach.
  • Now switch back to the CSP window, and un-pause the sim. Everything should run as usual, just a bit slower, as we're using debug code now.
  • To enter debug mode, select Debug --> Break All. This will stop the sim, and show the current line of code in the debugger. Now you can single-step through the code, and use all the other features the debugger provides.
  • If you want to break at a certain area of the code, you can set a breakpoint with the sim in pause mode. Execution will stop when the application reaches the selected line of code, and debug mode will be entered.