For the latest Slicer developers documentation, visit the Nightly page.
Back to Developers Information←
The executable Slicer application Slicer-Superbuild/Slicer-build/Slicer (or Slicer.exe) is the launcher of the real application binary Slicer-Superbuild/Slicer-build/bin/SlicerQT-real.
Analyze a segmentation fault
$ ulimit -c unlimited $ ./Slicer ... make it crash $ ./Slicer --gdb ./bin/SlicerQT-real (gdb) core core (gdb) backtrace ...
GDB debug with launch arguments
The Slicer app launcher provides options to start other programs with the Slicer environment settings.
--launch <executable> [<parameters>]: executes an arbitrary program. For example,
Slicer --launch /usr/bin/gnome-terminalstarts gnome-terminal (then run GDB directly on SlicerQT-real)
--gdb: runs GDB then executes SlicerQT-real from within the debugger environment.
GDB debug by attaching to running process
Now, run "ps -Afww | grep SlicerQT-real" and note the PID of this binary.
Now, run "gdb --pid $PIDABOVE"
GDB debug by using exec-wrapper
An alternative approach is to use a wrapper script to emulate the functionality of the app launcher. This will allow you to use gdb or a gdb-controlling program such as an IDE, in order to interactively debug directly from GDB without attaching.
The general idea of the wrapper is to set all of the appropriate environment variables as they would be set by the app launcher. From SlicerLauncherSettings:
- [LibraryPath] contents should be in LD_LIBRARY_PATH
- [Paths] contents should be in PATH
- [EnvironmentVariables] should each be set
Now, start gdb and do the following:
(gdb) set exec-wrapper ./WrapSlicer4 (gdb) exec-file ./bin/SlicerQT-real (gdb) run
Since VTK and ITK include many multithreaded filters, by default you will see lots of messages like the following from gdb during rendering and processing:
[New Thread 0x7fff8378f700 (LWP 20510)] [Thread 0x7fff8b0aa700 (LWP 20506) exited]
These can be turned off with this command:
set print thread-events off
GDB debug in CodeLite IDE
For VisualStudio it's also possible to run the IDE with the correct environment to debug slicer.
The launcher gets configured with a special --VisualStudio option for this purpose.
Note that because CMake re-creates the solution file from within the build process, visual studio will sometimes need to stop and reload the project, requiring manual button pressing on your part. To avoid this, you can use a script to kick off the build and then re-start the IDE.
If you use cygwin, you can create simple shell scripts, for example in /usr/local/bin, which these several steps at once when run from the Slicer4-superbuild directory:
- s4build (slicer4 build)
(cd Slicer-build; cmake.exe -VV --debug-output . && ./Slicer.exe --VisualStudio Slicer.sln /out buildlog.txt /build) (cd Slicer-build; ./Slicer.exe --VisualStudio Slicer.sln)
- s4sbuild (slicer4 super build)
(cmake.exe -VV --debug-output . && ./Slicer-build/Slicer.exe --VisualStudio Slicer.sln /out buildlog.txt /build) (cd Slicer-build; ./Slicer.exe --VisualStudio Slicer.sln)
The s4build command re-runs cmake and then runs the build of Slicer only. When this completes, it launches visual studio with slicer loaded for debugging.
s4sbuild is similar, but it runs the superbuild process so that all the dependency libraries are updated. This takes longer, but is sometimes needed when there has been a change to CTK or other tools.
Note the buildlog.txt files for checking if anything went wrong.