Oracle Solaris Studio 12.2:使用 dbx 调试程序

定位异常

有许多原因可导致程序异常。一种定位故障的方法是在源程序中找到发生异常的行号,然后在该处寻找线索。

编译时使用 -ftrap=common 可强制捕获所有常见异常。

查找异常发生位置:


demo% cat wh.f
                 call joe(r, s)
                 print *, r/s
                 end
                 subroutine joe(r,s)
                 r = 12.
                 s = 0.
                 return
                 end
demo% f95 -g -o wh -ftrap=common wh.f
demo% dbx wh
Reading symbolic information for wh
(dbx) catch FPE
(dbx) run
Running: wh
(process id 17970)
signal FPE (floating point divide by zero) in MAIN at line 2 in file “wh.f”
   2                     print *, r/s
(dbx)