This session is created to help the users to find and, possibly, debug problems in GEOtop.
Debugging with GDB
A special thank to Thomas Egger upon whose instruction this session is based. The GNU debugger (GDB) http://www.gnu.org/software/gdb/ allows you to step through code, watch values, and monitor execution from the command-line. In order to debug GEOtop with GDB you have compile the code with the debugging flag. Therefore you need to copy all the files of the code, i.e. the files .c and .h contained in:
- EXTERN
- KMacKenzie
- LIBRARIES/ASCII
- LIBRARIES/FLUIDTURTLE
- LIBRARIES/GEOMORPHOLOGYLIB
LIBRARIES/KeyPalette
- LIBRARIES/MATH2
in a folder. Let us call this folder "src". Then open a terminal a go inside the "src" folder:
$ cd src
and then compile the code:
$ gcc -g -c *.c $ gcc -o GEOtop *.o -lm
After you should obtain the executable GEOtop. Now you are ready to open the code in debug mode: type:
$ gdb ./GEOtop
Now you are inside the gdb mode of the code. At this time, if you want to set a breakpoint on a particular function, i.e. malloc, type:
(gdb) break malloc_error_break
This will allow you later to track back the stack. You may obtain the following:
$ Function "malloc_error_break" not defined. Make breakpoint pending on future shared library load? (y or [n]) y
Then just run the model. For this purpose, put the folder with your data (e.g. "Template") inside the folder "src" and then run:
(gdb) run ./Template/
Once the code arrives to the breakpoint, it stops. Once it stops then type:
(gdb) backtrace
to see where you are in the stack and then you have to start interpreting the problem. An example could be the following information:
Breakpoint 1, 0x930334a9 in malloc_error_break () (gdb) backtrace #0 0x930334a9 in malloc_error_break () #1 0x9302e497 in szone_error () #2 0x92f58523 in szone_free () #3 0x92f5838d in free () #4 0x00059c6d in write_output (times=0x100570, wat=0x100260, cnet=0x1002a0, par=0x800000, top=0x100160, land=0x100240, sl=0x1001e0, egy=0x1002d0, snow=0x1003b0, glac=0x100490, met=0x1004f0) at output.09375.c:760 #5 0x0002cd6e in time_loop (all=0x100130) at geotop.09375.c:161 #6 0x0002c9b0 in main (argc=2, argv=0xbffff880) at geotop.09375.c:108
which means that there is an error in the function write_output in file output.09375.c at the line 760. To exit from gdb please type:
(gdb) q
