Debugging PDF
Debugging PDF
DebugSwitches
{
Analytical 0;
APIdiffCoefFunc 0;
Ar 0;
...
}
What is a DebugSwitch?
• Let’s have a look at the lduMatrix DebugSwitch, which is set to 1.
• The lduMatrix class is implemented in
$FOAM_SRC/OpenFOAM/matrices/lduMatrix/lduMatrix
• Looking inside lduMatrix.C, we see a line:
defineTypeNameAndDebug(Foam::lduMatrix, 1);
This line defines the DebugSwitch name lduMatrix, and sets its default value to 1.
• In $FOAM_SRC/OpenFOAM/matrices/lduMatrix/solvers/PBiCG/PBiCG.C, you can find:
if (lduMatrix::debug >= 2)
{
Info<< " Normalisation factor = " << normFactor << endl;
}
• Boolean debug corresponds to the lduMatrix DebugSwitch, and it is true if the DebugSwitch
is greater than 0, and the above if-statement is done if it is equal to or greater than 2.
• The default value, both in the class definition, and in the global controlDict is 1. Try
setting it to 2 in your own copy of the global controlDict, and run the cavity case.
• Now you know how to compile all, or parts of, OpenFOAM in Debug mode.
• Now it is time to learn the basics of GDB...
• Do this in OF23xDebug
GDB in emacs
• In the cavity case, run emacs
• Click Tools/Debugger (GDB)
• Type icoFoam (appears at the bottom of emacs, as part of a GDB command)
• Type b icoFoam.C:80, as before.
• Click on GO
The execution stops at line 80 in icoFoam.C, and emacs shows the output of icoFoam in the
lower window, and the surrounding code in the upper window.
• Mark phiHbyA in the upper window and click Gud/Watch Expression, and you should
get a window (Speedbar) showing which class it belongs to and the possibility to examine it
more.
• Click Next Line until you are at the line with if (nonOrth == nNonOrthCorr). Add
nonOrth and nNonOrthCorr to Gud/Watch Expression, and you see that they are the
same, i.e. the if-statement is true (check by clicking on Next Line again!). Let’s examine
that line closer by clicking Step Line. Emacs will ask if you want to follow a symbolic link
- just type yes. We now see that we are in fvMatrix.C.
GDB in emacs
• Will we enter the if-statement? Mark in the lower window:
!psi_.mesh().fluxRequired(psi_.name())
and click on Gud/Watch Expression
This returns false, so we will not enter (check with Next Line). Note that you can change
from false to true in the Speedbar.
• Click Next Line until you are at the line with forAll, then click on Step Line and type
yes on the question on the symbolic link.
• The size() function returns the size of member data ptrs_ in the templated PtrList
class. Click Step Line and type yes.
• The PtrList seems to be pointing at the List class to evaluate the size() function. Click
on Step Line twice and we are back to the PtrList. Click on Step Line again, and we
are in a forAll loop in the fvMatrix.C file.
• Click on GO (or Gud/Continue) to continue to the next breakpoint or to terminate normally
• Let’s not dig any further, so click on Finish Function to get back to icoFoam.C, and we
can continue the execution on the highest level.
• Exit emacs.
run
rm -r pitzDaily
cp -r $FOAM_TUTORIALS/incompressible/simpleFoam/pitzDaily .
cd pitzDaily
blockMesh
sed -i s/0.375/0/g 0/k
int main()
{
const int constantInt=5;
int zeroInt;
cout << "Please type the integer number zero!" << endl;
cin >> zeroInt;
cout << "constantInt = " << constantInt << endl;
cout << "zeroInt = " << zeroInt << endl;
cout << "constantInt/zeroInt = " << constantInt/zeroInt << endl;
return(0);
}
Compile and debug with:
g++ -g nonFailSafeCode.C -o nonFailSafeCode