Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Fortran 90 uses descriptors to represent the dimensions (the shape) of its arrays and to pass assumed-shape array arguments. Also pointers in Fortran are special - they can only point to qualified targets. This allows much better debugger introspection in Fortran than in C/C++. Just use <code>print arr(index)</code> or one of the <code>info</code> commands - no need for fancy stuff.</p> <p>Sample code:</p> <pre><code>program arr real, dimension(40) :: stack_array real, allocatable, dimension(:), target :: heap_array real, dimension(:), pointer :: ptr_array integer :: i ! Interface required because of the assumed-shape array argument interface subroutine foo(bar, baz, qux, ptr) real, dimension(:) :: bar real, dimension(40) :: baz real, dimension(*) :: qux real, dimension(:), pointer :: ptr end subroutine foo end interface allocate(heap_array(40)) forall(i = 1:40) stack_array(i) = i heap_array = stack_array + 2 ptr_array =&gt; heap_array print *, stack_array(1) call foo(stack_array, stack_array, stack_array, ptr_array) deallocate(heap_array) end program arr subroutine foo(bar, baz, qux, ptr) real, dimension(:) :: bar real, dimension(40) :: baz real, dimension(*) :: qux real, dimension(:), pointer :: ptr print *, bar(1), baz(1), qux(1), ptr(1) end subroutine foo </code></pre> <p>Compile with debug information and run with <code>gdb</code>:</p> <pre><code>$ gfortran -g -o arr.x arr.f90 &amp;&amp; gdb ./arr.x ... (gdb) info locals heap_array = (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ... ptr_array = (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ... stack_array = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ... (gdb) print heap_array $1 = (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... (gdb) print ptr_array(3:7) $2 = (5, 6, 7, 8, 9) ... (gdb) info args bar = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ... baz = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, ... qux = () ptr = (3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, ... </code></pre> <p>It cannot show the content of assumed-size array arguments for obvious reasons but you can print each element individually:</p> <pre><code>(gdb) print qux(1) $5 = 1 (gdb) print qux(2) $6 = 2 (gdb) print qux(15) $7 = 15 </code></pre> <p>Note that printing array sections doesn't work on assumed-size array arguments as they are not passed by descriptor and <code>gdb</code> runs into trouble:</p> <pre><code>(gdb) print qux(1:8) $8 = (0, 0, 0, 0, 0, 0, 2.25609053e-43, 0) (gdb) print qux(2:9) $9 = (0, 0, 0, 0, 0, 0, 2.25609053e-43, 0) </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload