GDB:如何调试期间使用修改后的参数调用函数



考虑以下微不足道的fortran程序,该程序通过子例程添加两个整数并打印结果:

      PROGRAM MAIN
      INTEGER I, J, SUM
      I = 1
      J = 1
      CALL ADD(I, J, SUM)
      WRITE(*,*) SUM
      END
      SUBROUTINE ADD(I, J, SUM)
      INTEGER I, J, SUM
      SUM = I + J
      END

通过gfortran -g -O0 gdb-mwe.f -o gdb-mwe编译并在GNU调试器中运行,我想从调试器调用ADD,并在写入输出之前使用修改后的输入参数。这是发生的事情:

Reading symbols from gdb-mwe...done.
(gdb) break 10
Breakpoint 1 at 0x4007dd: file gdb-mwe.f, line 10.
(gdb) r
Starting program: /home/username/Documents/Fortran/gdb-mwe 
Breakpoint 1, MAIN__ () at gdb-mwe.f:10
10        WRITE(*,*) SUM
(gdb) p j = j+1
$2 = 2
(gdb) call add(i,j,sum)
Program received signal SIGSEGV, Segmentation fault.
0x000000000040079a in add (
i=<error reading variable: Cannot access memory at address 0x1>, 
j=<error reading variable: Cannot access memory at address 0x2>, 
sum=<error reading variable: Cannot access memory at address 0x2>)
at gdb-mwe.f:18
18        SUM = I + J
The program being debugged was signaled while in a function called from GDB.
GDB remains in the frame where the signal was received.
To change this behavior use "set unwindonsignal on".
Evaluation of the expression containing the function
(add) will be abandoned.
When the function is done executing, GDB will silently stop.

我如何正确吗?

正如评论中指出的那样,GDB中的open错误可防止此操作。

可能的解决方法是调试代码的32位版本。这会导致一些差异,但是对于简单的调试任务,这可能就足够了。

对于Intel Fortran编译器,这仅需要添加-M32标志(已安装了32位库)。

对于GFORTRAN,似乎首先安装Multilib软件包是必要的,如此问题所示。

相关内容

  • 没有找到相关文章