gdb crashes on printing allocatable array in Fortran derived type

Bug #1886836 reported by Manuel Engel
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
gdb (Ubuntu)
New
Undecided
Unassigned

Bug Description

Package: gdb (8.1-0ubuntu3.2 Ubuntu:18.04/bionic-updates [amd64])
Ubuntu Release: Ubuntu 18.04.4 LTS

Bug occurs when trying to print allocatable or pointer component of a Fortran derived-type structure in gdb.

Expected behavior:
gdb prints the contents of array BUFFER%ALPHA in the MWE below.

Observed behavior:

See upstream report https://sourceware.org/bugzilla/show_bug.cgi?id=23051

When trying to print BUFFER%ALPHA, gdb crashes. The MWE copied form the above link is:

  1 PROGRAM allocate_array
  2
  3 TYPE L_BUFFER
  4 REAL, DIMENSION(:), POINTER :: ALPHA
  5 END TYPE L_BUFFER
  6 TYPE(L_BUFFER), POINTER :: BUFFER
  7
  8 ALLOCATE(BUFFER)
  9
 10 ALLOCATE(BUFFER%ALPHA(5))
 11
 12 BUFFER%ALPHA(5)=0.0078
 13 print *, buffer%alpha
 14
 15 END PROGRAM allocate_array

And the gdb output reads:

Breakpoint 1, allocate_array () at allocate_array.F90:13
13 print *, buffer%alpha
(gdb) i lo
buffer = 0x603f80
(gdb) p *buffer
$1 = (
value.c:3116: internal-error: value* value_primitive_field(value*, LONGEST, int, type*): Assertion `PROP_CONST == TYPE_DATA_LOCATION_KIND (type)' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) n

The same error can be observed from inside a type-bound procedure when trying to print THIS%ALPHA (where this is the instance variable).

The assertion fails since TYPE_DATA_LOCATION_KIND (type) is PROP_LOCEXPR. A standalone allocatable array has the property type PROP_CONST, as expected.

This bug renders debugging of Fortran code with visual tools (vscode, eclipse, etc.) very difficult as the components are parsed automatically, leading to a crash.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.