Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set breakpoint in gdb on array out of bounds for gfortran program

I have a Fortran program compiled with gfortran with the -fcheck=bounds compiler option. This causes the code to report "array out of bounds" errors and subsequently exit.

I would like to debug my program using gdb to find the cause of the error. Unfortunately in gdb the code will still just exit on an out of bounds error.

Is there a way to tell gdb to stop execution when an out of bounds error occurs?

like image 470
Holger Schmitz Avatar asked Jun 15 '16 14:06

Holger Schmitz


1 Answers

Compile with -g to get debugging information. Then, first, I placed a break point on exit, this works fine, once the program stops you'll be able to backtrace from exit to the point of the error.

The backtrace also passes through a function called _gfortran_runtime_error_at, so you might have more luck placing the breakpoint there, this worked for me, and obviously will only trigger when you get a run time error.

like image 154
Andrew Avatar answered Jan 03 '23 06:01

Andrew