Topic: Backtrace doesn't seem to be working

I have bounds checking turned on. When a bounds error occurs, I get a message of which routine and line it occurs on but no backtrace. Do I have to change some setting to get this? Here is a sample of what I get.

At line 19 of file .\qjutil.F90FORTRAN runtime error: Index '0' of dimension 1 of array 'rstart' below bound of 1
Error termination. Backtrace:

Then nothing more. The routine in question is called several levels deep from different places in the program and I'd sure like to know from where without having to put in a lot of debugging statements.

Re: Backtrace doesn't seem to be working

Do you currently have debugging enabled?  It might be necessary to enable debugging to produce a valid backtrace.  I would also suggest disabling any optimizations. 

Also, what architecture (32- or 64-bit) are you currently using?  Are you on Windows?  I'll see if I can reproduce the issue.

Jeff Armstrong
Approximatrix, LLC

3 (edited by franceint 2016-07-23 16:06:47)

Re: Backtrace doesn't seem to be working

I have Enable Debugging checked in the Code Generation tab of the Project Options. I have the following compiler flags:

-fbounds-check -finit-local-zero -fbacktrace

I am using Windows 7.0. I have not specifically enabled any optimizations. How do I turn them off?
Here is a simple program with the above settings that demonstrates the problem

program testmain
implicit none
integer :: x(10)

Call ChangeX(x,0)

stop
end
subroutine changex(x,n)
implicit none
integer :: x(10),n
x(n) = 1
return
end

Re: Backtrace doesn't seem to be working

It is 32-bit architecture. Under 64-bit, it says:

Could not print backtrace: libbacktrace could not find executable to open
and then follows what looks like a register dump

Re: Backtrace doesn't seem to be working

It appears to be a compiler bug.  I'll have to look into the problem in more detail, but I'll update this thread as I go.

Jeff Armstrong
Approximatrix, LLC

Re: Backtrace doesn't seem to be working

I'm still pursuing this bug.  The backtrace functionality in the runtime diagnostics first appeared in GNU Fortran 6.1, and it does not appear to be working in our distribution.  There were some initial problems related to Windows, specifically determining the currently running executable, that are now fixed, but I'm still tracking down why the stack addresses are not reported properly.

Jeff Armstrong
Approximatrix, LLC

Re: Backtrace doesn't seem to be working

Thanks. It's surprising that no one reported this before, as it seems to happen no matter what the code executed is.