How to print a human-readable backtrace with `nvfortran` when an exception occurs?

How to print a human-readable backtrace with nvfortran when an exception occurs?

Here is a minimal example.

! test.f90                                                                                                                     
program test                                                                                                                         
implicit none                                                                                                                        
                                                                                                                                     
real :: a                                                                                                                            
                                                                                                                                     
a = tiny(a)                                                                                                                          
                                                                                                                                     
write (*, *) 1.0 / (a**2)                                                                                                                                                                                    
                                                                                                                                     
end program test                                                                                                                     

According to the nvfortran manual, I do the following.

$ uname -a && nvfortran --version 

Linux 5.15.0-52-generic #58-Ubuntu SMP Thu Oct 13 08:03:55 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

nvfortran 22.11-0 64-bit target on x86-64 Linux -tp zen2 
NVIDIA Compilers and Tools
Copyright (c) 2022, NVIDIA CORPORATION & AFFILIATES.  All rights reserved.

$ export NVCOMPILER_TERM=trace && nvfortran -g -Kieee -Ktrap=divz test.f90 && ./a.out 

Error: floating point exception, floating point divide by zero
   rax 0x0000000000000000, rbx 0x00007fff3100e178, rcx 0x0000000000000000
   rdx 0x0000000000000000, rsp 0x00007fff3100e030, rbp 0x00007fff3100e040
   rsi 0x00007fb93c4fbf50, rdi 0x0000000000000006, r8  0x0000000000004240
   r9  0x0000000000004100, r10 0x00007fb93be156d0, r11 0x00007fb93bee3640
   r12 0x00007fff3100e178, r13 0x0000000000401200, r14 0x0000000000403d98
   r15 0x00007fb93c573040
  /usr/lib/x86_64-linux-gnu/libc.so.6(+0x42520) [0x7fb93a41a520]
  ./a.out() [0x401233]
  /usr/lib/x86_64-linux-gnu/libc.so.6(+0x29d90) [0x7fb93a401d90]
  /usr/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0x80) [0x7fb93a401e40]
  ./a.out() [0x401125]

Am I supposed to read and understand the above-printed backtrace or did I overlook something?

Thanks.

It’s correctly printing out the state of the registers and the back trace. Granted you have no subroutine calls so the back trace is effectively empty.

If you’re wanting to know the line number where the exception is occurring, you’ll want to use a debugger, such as gdb.

% gdb a.out
... cut header info ...
Reading symbols from a.out...
(gdb) run
Starting program: a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGFPE, Arithmetic exception.
0x0000000000401308 in test () at test.f90:9
9       write (*, *) 1.0 / (a**2)

Alternatively, set NVCOMPILER_TERM to “debug”, and the program will open in the debugger. Then type “where” to see the line number of the error.

Hope this helps,
Mat

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.