title: GDB: how to call functions with modified parameters during debugging
body: <p>Consider the following trivial Fortran program that adds two integers via a subroutine and prints the result:</p>
  
  <pre><code>      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
  </code></pre>
  
  <p>Compiling via <code>gfortran -g -O0 gdb-mwe.f -o gdb-mwe</code> and running in the GNU Debugger, I want to call <code>ADD</code> from the debugger with modified input arguments right before the write output. Here's what happens:</p>
  
  <pre><code>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=&lt;error reading variable: Cannot access memory at address 0x1&gt;, 
  j=&lt;error reading variable: Cannot access memory at address 0x2&gt;, 
  sum=&lt;error reading variable: Cannot access memory at address 0x2&gt;)
  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.
  </code></pre>
  
  <p>How do I get this right?</p>