Difference between revisions of "HowTo debugging"

From OpenFOAMWiki
(Combined all mentioned debuggers in a section 'Tools', moved limitations to gdb)
(Tools: All mentioned serial debuggers are gdb frontends, thus moved 'Limitations' to more appropriate spot)
Line 43: Line 43:
  
 
  gdb xxxFoam
 
  gdb xxxFoam
 
'''Limitations'''
 
 
gdb seems to have problems to step into expressions like
 
 
<cpp>
 
return autoPtr<basicThermo>(cstrIter()(mesh));
 
</cpp>
 
  
 
==== nemiver ====
 
==== nemiver ====
Line 63: Line 55:
  
 
  ddd --args xxxFoam <FoamOptions>
 
  ddd --args xxxFoam <FoamOptions>
 +
 +
==== Limitations ====
 +
 +
gdb seems to have problems to step into expressions like
 +
 +
<cpp>
 +
return autoPtr<basicThermo>(cstrIter()(mesh));
 +
</cpp>
  
 
=== Parallel debuggers ===
 
=== Parallel debuggers ===
Line 79: Line 79:
  
 
[http://www.totalviewtech.com Totalview] is a commercial debugger with many features. It can debug your application in parallel out of the box.
 
[http://www.totalviewtech.com Totalview] is a commercial debugger with many features. It can debug your application in parallel out of the box.
 
  
 
== Additional Info ==
 
== Additional Info ==

Revision as of 09:04, 24 September 2012

1 FULLDEBUG - libraries

If your application crashes it will usually output a stack trace, e.g.

  1. 0 Foam::error::printStack(Foam::-Ostream&) in "/home/ivan/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/libOpenFOAM.so"
  2. 1 Foam::sigFpe::sigFpeHandler(int) in "/home/ivan/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/libOpenFOAM.so"
  3. 2 Uninterpreted: [0xb7f8b420]
  4. 3 Foam::divide(Foam::Field<double>&, Foam::UList<double> const&, Foam::UList<double> const&) in "/home/ivan/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/libOpenFOAM.so"
  5. 4 void Foam::divide<foam::fvpatchfield,>(Foam::GeometricField<double,>&, Foam::GeometricField<double,> const&, Foam::GeometricField<double,> const&) in "/home/ivan/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/libincompressibleTurbulenc eModels.so"
  6. 5 Foam::tmp<foam::geometricfield<double,> > Foam::operator/<foam::fvpatchfield,>(Foam::tmp<foam::geometricfield<double,> > const&, Foam::GeometricField<double,> const&) in "/home/ivan/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/libincompressibleTurbulenc eModels.so"
  7. 6 Foam::turbulenceModels::kEpsilon::correct() in "/home/ivan/OpenFOAM/OpenFOAM-1.4.1/lib/linuxGccDPOpt/libincompressibleTurbulenc eModels.so"


There is lots of interesting information in there. It shows the type of error (sigFpe which means a division by zero or any other operation causing an invalid floating point number) and who causes it (operator/ of an fvPatchField). Further down the line is the originator, kEpsilon::correct() which obviously does some divisions. A good guess is that one of the patch fields of k or epsilon is 0.

From experience sigfpe originate from three sources:

  • as above - division by 0 from having an initial field set to 0.
  • when using floatTransfer = 1. This will truncate doubles into floats before doing parallel transfer so if the double does not fit it will produce a sigfpe. Check the traceback for a call to 'compressedSend'.
  • when using FOAM_SETNAN (initialises allocated memory to NaN) and accessing uninitialised memory.

The other common error is a segmentation violation (sigSegv) which is caused by an application accessing memory outside the allocated space. This are nearly always caused by a programming error.

2 Top-Level debugging

If you want to find out more but not create a complete debugging build.

  • Find out from the printed stack trace which files contain the functions that crash. Copy these into your local directory.
  • Add the files to your Make/files
  • in Make/options: add

-DFULLDEBUG -g -O0

to EXE_INC and recompile. The 'FULLDEBUG' causes amongst others full range checking on Lists.

In order to go step by step through the sources of the full debug objects, you'll need a debugger

3 Tools

3.1 Serial debuggers

3.1.1 gdb

Can be invoked on the command line like

gdb xxxFoam

3.1.2 nemiver

Is a nice GTK+ based GUI frontend for gdb. Your solver can be launched like

nemiver xxxFoam <FoamOptions>

3.1.3 ddd

Is another more complex frontend for gbd. You can launch your solver with the following command

ddd --args xxxFoam <FoamOptions>

3.1.4 Limitations

gdb seems to have problems to step into expressions like

 
return autoPtr<basicThermo>(cstrIter()(mesh));

3.2 Parallel debuggers

3.2.1 mpirunDebug

Is a bash script which can start each process of the parallel run in an extra gdb session. This script can easily extended to start a gdb frontend for each process (download patched mpirunDebug file). Once this is done you'll get a separate GUI instance for each process, where you can set breakpoints etc. separately. This behaviour is similar to Totalview. Maybe one can utilise the session features from the GUI's in order to remember e.g. breakpoints.

mpirunDebug -np 2 xxxFoam -parallel

3.2.2 Eclipse PTP

Eclipse PTP - Parallel Tools Platform [1] is an open-source platform that provides a highly integrated environment specifically designed for parallel application development. In parallel it provides and manages a graphical user interface to a number of serial gdb processes.

3.2.3 Totalview

Totalview is a commercial debugger with many features. It can debug your application in parallel out of the box.

4 Additional Info

Sometimes it might be helpful to set an endless loop somewhere into solver, and change the variable inside the debugger after launching

 
int myi = 0;
while (0 == myi)
    Foam::sleep(5);