Difference between revisions of "Documentation/4.0/Developers/Tutorials/Debug Instructions"

From Slicer Wiki
Jump to: navigation, search
(Prepend documentation/versioncheck template. See http://na-mic.org/Mantis/view.php?id=2887)
 
(4 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
<noinclude>{{documentation/versioncheck}}</noinclude>
 
Back to [[Documentation/{{documentation/version}}/Developers|Developers Information]]&larr;
 
Back to [[Documentation/{{documentation/version}}/Developers|Developers Information]]&larr;
  
 
==Background==
 
==Background==
The executable Slicer application is: Slicer-build/Slicer (or Slicer.exe)
+
The executable Slicer application ''Slicer-Superbuild/Slicer-build/Slicer'' (or Slicer.exe) is the [[Documentation/{{documentation/version}}/Developers/Launcher|launcher]] of the real application binary ''Slicer-Superbuild/Slicer-build/bin/SlicerQT-real''.
 
 
This is actually a wrapper created using the [http://www.commontk.org/index.php/Tools:_Application_launcher CTK AppLauncher]. The wrapper exists to set library and environment paths before launching the real application binary in Slicer-build/bin/SlicerQT-real
 
*The wrapper is configured in Slicer4/Applications/QTGUI/CMakeLists.txt under the heading "Configure Slicer Launcher"
 
*The AppLauncher source code is here: https://github.com/commontk/AppLauncher
 
*The launcher configuration is put here: Slicer-build/SlicerLauncherSettings.ini
 
  
 
==Linux==
 
==Linux==
 +
===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===
 
===GDB debug with launch arguments===
 
The Slicer app launcher provides options to start other programs with the Slicer environment settings.  
 
The Slicer app launcher provides options to start other programs with the Slicer environment settings.  
  
*--launch: execute arbitrary program. For example, start gnome-terminal (then run GDB directly on SlicerQT-real)
+
*<code>--launch <executable> [<parameters>]</code>: executes an arbitrary program. For example, <code>Slicer --launch /usr/bin/gnome-terminal</code> starts gnome-terminal (then run GDB directly on SlicerQT-real)
*--gdb: run GDB. then exec SlicerQT-real from within the debugger environment.
+
*<code>--gdb</code>: runs GDB then executes SlicerQT-real from within the debugger environment.
  
 
===GDB debug by attaching to running process===
 
===GDB debug by attaching to running process===
Line 39: Line 43:
 
(gdb) run
 
(gdb) run
 
</pre>
 
</pre>
 +
 +
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===
 
===GDB debug in CodeLite IDE===

Latest revision as of 07:29, 14 June 2013

Home < Documentation < 4.0 < Developers < Tutorials < Debug Instructions


For the latest Slicer documentation, visit the read-the-docs.


Back to Developers Information

Background

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.

Linux

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-terminal starts 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

Run ./Slicer-build/Slicer

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

See this example script

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

Linux debugging with CodeLite IDE

Windows

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.