Why did my program crash - PowerPoint PPT Presentation

About This Presentation
Title:

Why did my program crash

Description:

Before we start Bad news. Chalmers University of Technology. Fabian Peng K rrholm ... cfdTools/general/adjustPhi/adjustPhi.C:42 ... – PowerPoint PPT presentation

Number of Views:88
Avg rating:3.0/5.0
Slides: 22
Provided by: tfdCha
Category:

less

Transcript and Presenter's Notes

Title: Why did my program crash


1
Why did my program crash? or How to debug your
OpenFOAM codes using GDB
2
Running your code
  • Coding your own software good bad
  • Programming your own codes without bugs is near
    impossible
  • even for Weller Jasak

3
Debugging your code
  • Debugging is a necessary evil to resolve bugs and
    examine crashes when developing all codes, and
    OpenFOAM is not an exception
  • Built-in debug feature shows more details, but
    gives only passive information

4
Debugging your code built-in
  • Debugflags available in
  • .OpenFOAM-1.4.1/controlDict
  • lduMatrix 2
  • Will give output for each matrix-iteration
  • DICPCG Iteration 475 residual 0.542126
  • No Recompilation of code needed.
  • Flags set in code by
  • defineTypeNameAndDebug(PCG, 0)

5
Debugging your code
  • Alternative way
  • Inserting
  • Info ltlt "U is " ltlt Ucelli ltlt endl
  • Requires Re-compilation (usually many times)

6
GDB - Introduction
  • GDB is the GNU project debugger
  • It can be used for
  • - Programs written in C, C, Ada, Pascal etc
  • - Run Stop at specific positions
  • - Examine variables at run-time
  • - Change your program at run-time

7
Before we start Bad news
You need to recompile EVERYTHING! Debug version
of OpenFOAM requires 1 Gb of diskspace, vs 64 Mb
for Opt It is also slower Even slower when run
with GDB
  • You need to recompile

8
Compiling with Debug
  • File
  • .OpenFOAM-1.4.1/bashrc
  • Comment
  • setenv WM_COMPILE_OPTION Opt
  • Uncomment
  • setenv WM_COMPILE_OPTION Debug
  • Then run the Allwmake script and go for a very
    long break.
  • When you're back, some packages (e.g. the
    paraview reader) will have failed

9
Compiling with Debug
  • These packages can be compiled seperately with
    debug flags
  • Quick Solution
  • Use the Opt version, as we're most likely not
    interested in debugging such packages
  • Done by simple copy of libPackageName.so

10
Setup on Student Installation
  • Pre-compiled version of Debug done by Håkan
  • Used by copying
  • .OpenFOAM-1.4.1 from local installation to
  • /chalmers/users/userdir/
  • And editing .cshrc/.bashrc like described before

11
First Debug
  • Objective To find out what a part of the code
    does
  • Code icoFoam - for incompressible, laminar flow
  • Simple code, suitable to start debugging, as
    there are not that many files included.

12
Example icoFoam
  • 73 U rUAUEqn.H()
  • 74 phi (fvcinterpolate(U) mesh.Sf())
  • fvcddtPhiCorr(rUA, U, phi)
  • 77 adjustPhi(phi, U, p)
  • 79 for (int nonOrth0 nonOrthltnNonOrthCorr
    nonOrth)
  • fvScalarMatrix pEqn
  • (
  • fvmlaplacian(rUA, p) fvcdiv(phi)
  • )

What does adjustPhi do?
13
Example - icoFoam
  • Start GDB in case directory
  • gdb icoFoam
  • GNU gdb 6.5 ...
  • (gdb)

Start off by inserting a breakpoint where we want
to inspect the code
b icoFoam.C77
14
Starting the Debug
  • Program can be started in two ways
  • start ltrootgt ltcasegt - Stops at main
  • or
  • run . . - Runs Program
  • If all is well, program should now stop at line
    77 of icoFoam

Breakpoint 1, main (argc3, argv0x7fffc346b128)
at icoFoam.C77 77
adjustPhi(phi, U, p)
15
Two Ways of Stepping
  • Next n Step until next line in the current
    program, will not debug functions and included
    files
  • Step s Step until next source line, will
    debug subfunctions
  • Both commands can be followed by a number to step
    a certain amount of lines

16
adjustPhi
  • where shows which file we are debugging and
    which file called it
  • list gives a listing of the source code around
    the current line, e.g. list 40,60 lists lines
    40-60
  • Now in
  • cfdTools/general/adjustPhi/adjustPhi.C42
  • Stepping and listing the code will show how
    adjustPhi ensures continuity

17
Useful Commands
  • See GDBCommands.pdf for a quick guide to the
    commands available in GDB. This list is by no
    means complete and a full listing is available
    at
  • http//sourceware.org/gdb/documentation/

18
Tutorial Example
  • Why does Xoodles crash when starting the
    pitzDaily3D case?
  • Known error from forums, output from Opt
  • 6 main in "/c3se/users/f98faka/OpenFOAM/OpenFOAM
    -1.4.1/applications/bin/linux64GccDPOpt/Xoodles"
  • 7 __libc_start_main in "/lib64/tls/libc.so.6"
  • With Debug version of OF
  • 7 main at /OpenFOAM/OpenFOAM-
  • 1.4.1/applications/solvers/combustion/Xoodles/../X
    iFoam/bEqnn.H79
  • 8 __libc_start_main in "/lib64/libc.so.6"

19
Tutorial Example
  • Start Xoodles with GDB and a breakpoint at this
    location
  • Breakpoint 1, main (argc3, argv0x7fffb8830fc8)
    at ../XiFoam/bEqn.H79
  • 79 volScalarField tauEta sqrt(thermo-gtmuu()/(rho
    uepsilon))
  • Possible issue with division, inspection of some
    epsilon values shows low epsilon.

20
Post-debugging
  • Codes run without gdb that crash
  • Set system to dump core-file
  • Core-files can be used to inspect where errors
    occurred
  • In cshrc
  • limit coredumpsize unlimited
  • In bashrc
  • ulimit -c unlimited
  • Then simply loaded in gdb by core-file
    ltcorefilenamegt

21
Questions GDB can answer
  • What does .flux do?
  • What happens when .solve is issued?
  • When does my variable go below x?
  • How does scheme x work?
  • Where did my code crash?

22
End
  • Thanks for listening!
Write a Comment
User Comments (0)
About PowerShow.com