How to debug loadable module in visual studio?

I have compiled slicer through the source code. Then i created a module (C++) and compiled it using cmake to generate module.sln. I want to debug this module using visual studio. What should I do?

Should I add this module project to slicer’s source project? I found some documentation on python debugging, but no tutorials on C++ modules I do?

There is documentation about this (however it seems to be a bit outdated):
https://www.slicer.org/wiki/Documentation/Nightly/Developers/Tutorials/Debug_Instructions#Using_Visual_Studio

Basically you need to start Visual Studio using the launcher:
.\S4D\Slicer-build\Slicer.exe --VisualStudio

If you want to debug your own extension then you’ll need to add AdditionalLauncherSettings. The way I open VS for debugging SlicerRT:
.\S4D\Slicer-build\Slicer.exe --VisualStudio --launcher-no-splash --launcher-additional-settings ./SlicerRT_D/inner-build/AdditionalLauncherSettings.ini c:\d\_Extensions\SlicerRT_D\inner-build\SlicerRT.sln
It also opens the solution.

Then you need to set basically any project as startup, then set the command to
[superbuild_path]\Slicer-build\bin\Debug\SlicerApp-real.exe
then just start debugging.

2 Likes

@cpinter I’ve updated the instructions based on your comments.

2 Likes

Thanks @cpinter. I followed you tutorials, it works.

This may be related to my visual studio version (I am using 2022), but when I follow these instructions, my module is not available in slicer.

To fix this, I needed to copy the --additional-module-paths from inner-build\SlicerWithMyExtensionLauncherSettings.ini and add them as command arguments to my startup project.

Which extension are you trying to debug? Is it a superbuild extension? It would help if we could talk about it as a concrete case.

It is an internal development making some proprietary functionality available in Slicer. Unfortunately, I am not at liberty to share this.

I mainly posted this here, to document my finding, so that the next person having that same problem could benefit from it.