How to obtain a backtrace after stop or abort

How to obtain a backtrace after stop or abort

Hi all,

Upon detecting an error, a program can be terminated with something
like

if(error) stop 1       ! normal termination
if(error) error stop 1 ! error termination, f2008
if(error) call abort   ! nonstandard

With gfortran, the last option produces a backtrace, while the first
two do not (see also
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52594 )

My question is whether there is a way to obtain a backtrace with ifort
with anyone of these program termination, possibly by choosing the
proper compiler options.

Thank you, regards,
   Marco Restelli

5 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

DId you build with -traceback or -g?   What happens then if you call abort (gcc or libgfortran implementation of the standard C function)  or call sys_abort() directly?  These would require iso_c_interop as they are plain C function calls, no underscore decoration.

Tim, yes, I tried and I didn't see the backtrace, but after double
checking I see a rather erratic behaviour. Consider the attached code:
on one machine with ifort Version 14.0 Build 20130728 to see the
backtrace I have to include the line `` write(*,*) "Test" '':

$ ifort -g -traceback test.f90 -o test
$ ifort -g -traceback test.f90 -o test # without line 8
$ ./test
abort:

$ ifort -g -traceback test.f90 -o test # with line 8
$ ./test
 Test
 Test
 Test
 Test
 Test
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source             
test               0000000000471289  Unknown               Unknown  Unknown
test               000000000046FC00  Unknown               Unknown  Unknown
test               0000000000449A12  Unknown               Unknown  Unknown
test               0000000000436763  Unknown               Unknown  Unknown
test               000000000040359B  Unknown               Unknown  Unknown
libpthread.so.0    00007F762767EBF0  Unknown               Unknown  Unknown
test               000000000047226E  Unknown               Unknown  Unknown
test               0000000000402F9A  Unknown               Unknown  Unknown
test               0000000000402E8D  m_mp_f_                    10  test.f90
test               0000000000402EB2  m_mp_f_                    12  test.f90
test               0000000000402EB2  m_mp_f_                    12  test.f90
test               0000000000402EB2  m_mp_f_                    12  test.f90
test               0000000000402EB2  m_mp_f_                    12  test.f90
test               0000000000402EF2  MAIN__                     19  test.f90
test               0000000000402DE6  Unknown               Unknown  Unknown
libc.so.6          00007F76270E660D  Unknown               Unknown  Unknown
test               0000000000402CB9  Unknown               Unknown  Unknown

On another machine with ifort Version 13.1.2.183 Build 20130514 I
can't see any backtrace, no matter what.

Could you reproduce this behaviour, or is it somehow related to my
settings?

I still have not done the test with  sys_abort()  .

Thank you, Marco

module m
 implicit none
contains
 recursive function f(x) result(y)
  real, intent(in) :: x
  real :: y

   write(*,*) "Test" ! add this line to see the backtrace
   if(x.gt.10.0) &
    call abort

   y = f(2.0*x)
 end function f
end module m

program test
 use m
 implicit none
 write(*,*) f(1.0)
end program test

Marco, I can reproduce your results. I don't know at this time why the traceback is not produced when using the ifort version 13.1.3.192. There may have been a previous report of this that is fixed in the ifort 14.0 compiler. I can check about that and post again after I know more.

Kevin, thank you for checking. So, apart from specific issues with some compiler version, am I correct assuming that:

call abort  +  -g -traceback  ->  backtrace

stop  /  error stop  ->  no backtrace

?

Thank you, Marco

Leave a Comment

Please sign in to add a comment. Not a member? Join today