Debugging CC3D using Visual Studio
This demonstrates how to debug compiled C++ code. It assumes that you have compiled with RelWithDebInfo mode in Visual Studio.
Note
This doc was written with Windows in mind. It might still work on other operating systems.
For debugging purposes, it is often best to launch a CC3D simulation and either pause it immediately or step through the simulation incrementally. This allows you to attach a debugger, inspect internal state, and verify execution flow early in the run.
First, start the CompuCell3D Player from a command prompt of your choice, such as the Miniforge Prompt or cmd.exe.
conda activate your-cc3d-env
python -m cc3d.player5
See also How to run CC3D from the command line.
Run Visual Studio as Administrator. Select the COMPUCELL3D.sln file from your CompuCell3D_build folder.
From the navigation menu, select Debug -> Attach to Process…
In the window that appears, search for python.exe:
Click “Attach.” This should start debugging mode. If you have trouble finding the process, try checking the box for “Show processes for all users.” Then, click Refresh.
Add a breakpoint in Potts3D.cpp. At the time of writing, there is a line that is run every MCS that will be a good target for your first breakpoint.
unsigned int Potts3D::metropolisFast(const unsigned int steps, const double temp) {
// ...
oss << "Metropolis Fast" << endl;
oss << "total number of pixel copy attempts=" << numberOfAttempts;
// ...
}
Run a simulation in Player and ensure that the breakpoint is hit.
Troubleshooting
The debugger should be attached using the same software that you used to build CompuCell3D. For example, if you compiled using VS 2019, then you cannot debug using VS 2022.
Building CompuCell3D with Debug mode in Visual Studio may produce errors. RelWithDebInfo mode is preferred.
