GDB

Contents

GDB#

Run the offending model through gdb:

gdb Integrated_Model

Type "apropos word" to search for commands related to "word"...
Reading symbols from /home/jamie/git/anl/polaris-linux/build/linux/gcc/relwithdebinfo/bin/Integrated_Model...

(gdb) break Integrated_Model.cpp:536

Breakpoint 1 at 0x30d6b1: Integrated_Model.cpp:536. (2 locations)

(gdb) run scenario_abm.json 20

Starting program: /home/.../Integrated_Model jan.json 20
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
2024-03-12 22:03:20,990 Thread: 140737339038656 | [  INFO] Successfully initialized logging from property file: ./log/log4cpp.property

This is only useful if the error is reproducible though, if not, it is possible to write a small script that runs your model through gdb over and over until it does fail.

#!/usr/bin/env bash

exe="/mnt/p/ShareAndFileTransfer/For Jamie/segfault/Integrated_Model"
json=scenario_abm.modified.json
threads=10

while true; do
   gdb "${exe}" -ex "set confirm on" -ex "catch throw" -ex "run ${json} ${threads}" -ex quit
   rm -rf *iteration_*
done

This will run the executable inside gdb (with the given args) and if it runs to completion, it will quit. If a breakpoint is triggered, it will try to quit but because ‘set confirm on’ was specified it will prompt the user (Y/N) before doing so. Say ‘no’ and it will drop you back into the running debugger.

Some useful gdb commands to know:

command

description

bt

prints a full backtrace

frame

prints info about the current frame

info frame

prints detailed info about the current frame

info args

list the available arguments to the current function

info locals

list the available local variables

print x

prints out the value of the variable x

print *x

prints out the object pointed to by x

ctrl-C

break at current point of execution

c

continue execution (F5)

break File:line

set a breakpoint at the given location

s

step to next statement

Installing GDB#

Often the version of gdb that ships with ubuntu is out of date and can’t run our executable. In that case you will need to compile your own version of the latest gdb.

TODO: Add Instructions