[PATCH] Fixed gdb to print arrays with very high indexes

Sharma, Alok Kumar AlokKumar.Sharma@amd.com
Wed Jan 29 11:31:00 GMT 2020


Hi all,

Problem description:

Due to a bug GDB is not able to print arrays with very high indexes (lower/upper bounds). As explained below.

A) gdb crashes while printing arrays with very high positive index
program main
      integer(4) :: arr(4294967296_8:4294967297_8)
      integer(8) :: lb, ub
      arr = 99
      lb = lbound (arr, dim = 1, kind = 8)
      ub = ubound (arr, dim = 1, kind = 8)
      print *, 'bounds of arr - ', lb, ':', ub
end

Actual output: it crashes while printing array
GNU gdb (GDB) 10.0.50.20200127-git
(gdb) p arr
Aborted (core dumped)
Expected output
(gdb) p arr
$1 = (99, 99)

B) gdb is not able to print arrays with very high negative indexes
program main
      integer(4) :: arr(-4294967297_8:-4294967296_8)
      integer(8) :: lb, ub
      arr = 99
      lb = lbound (arr, dim = 1, kind = 8)
      ub = ubound (arr, dim = 1, kind = 8)
      print *, 'bounds of arr - ', lb, ':', ub
end

Actual output: it displays empty array.
(gdb) p arr
$1 = ()

Expected output
(gdb) p arr
$1 = (99, 99)

Root cause:

     In the function f77_print_array_1, the variable 'i' which holds the
    index is of datatype 'int', while bounds are of datatype LONGEST. Due
    to size of int being smaller than LONGEST, the variable 'i' stores
    incorrect values for high indexes (higher than max limit of int).
     Due to this issue in sources, two abnormal behaviors are seen while
    printing arrays with high indexes (please check array-bounds-high.f90)
     For high indexes with negative sign, gdb prints empty array even if
    the array has elements,
    (gdb) p arr
    $1 = ()
     For high indexes with positive sign, gdb crashes.

Resolution:

     We have now changed the datatype of 'i' to LONGEST which is same as
    datatype of bounds.

Testing:

- New test-case (gdb.fortran/array-bounds-high.exp) is added to test (+/-) high indexed array printing
- There was no regression seen

Please let me know your comments.

Regards,
Alok


-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Fixed-gdb-to-print-arrays-with-very-high-indexes.patch
Type: application/octet-stream
Size: 4879 bytes
Desc:  0001-Fixed-gdb-to-print-arrays-with-very-high-indexes.patch
URL: <http://sourceware.org/pipermail/gdb-patches/attachments/20200129/698a3ba6/attachment.obj>


More information about the Gdb-patches mailing list