https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78212
John DelSignore <jdelsignore at perforce dot com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jdelsignore at perforce dot com --- Comment #2 from John DelSignore <jdelsignore at perforce dot com> --- A user recently reported that TotalView could not print the value of Fortran variable length character strings in user defined types. Here is the test program they submitted, which is similar to the one contained in this bug report: program test implicit none type my_type character(:), allocatable :: str end type my_type type (my_type) a character(:), allocatable :: t allocate (character(10):: t) t = 'abc' a%str = 'xyz' print *, 't="', t, '", a%str="', a%str, '"' end program test The DWARF for "t" is OK, but the DWARF for field "str" in "my_type" is not. The GNU Fortran (gfortran) compiler does not generate a DWARF string length attribute for the string type. Dumping the DWARF for gfortran 10.2.0, we see: <1><2e>: Abbrev Number: 2 (DW_TAG_structure_type) <2f> DW_AT_name : (indirect string, offset: 0x0): my_type <33> DW_AT_byte_size : 16 <34> DW_AT_decl_file : 1 <35> DW_AT_decl_line : 4 <36> DW_AT_sibling : <0x55> <2><3a>: Abbrev Number: 3 (DW_TAG_member) <3b> DW_AT_name : str <3f> DW_AT_decl_file : 1 <40> DW_AT_decl_line : 7 <41> DW_AT_decl_column : 37 <42> DW_AT_type : <0x57> <46> DW_AT_data_member_location: 0 <2><47>: Abbrev Number: 4 (DW_TAG_member) <48> DW_AT_name : (indirect string, offset: 0x188): _str_length <4c> DW_AT_decl_file : 1 <4d> DW_AT_decl_line : 4 <4e> DW_AT_decl_column : 12 <4f> DW_AT_type : <0x5d> <53> DW_AT_data_member_location: 8 <1><57>: Abbrev Number: 6 (DW_TAG_pointer_type) <58> DW_AT_byte_size : 8 <59> DW_AT_type : <0x55> <1><55>: Abbrev Number: 5 (DW_TAG_string_type) Member "str" is at offset 0 in the structure and has a type that references DIE <57>. DIE <57> is a pointer type, which isn't the correct way of handling Fortran, but TotalView is smart enough to automatically dereference pointer types in Fortran codes. The target of the pointer type is a reference to DIE <55>. DIE <55> is a string type, but it does not contain an attribute that provides the string length, which I think is a compiler bug. The compiler DOES generate the correct DWARF string type DIE for "t", which is: <2><f9>: Abbrev Number: 12 (DW_TAG_variable) <fa> DW_AT_name : t <fc> DW_AT_decl_file : 1 <fd> DW_AT_decl_line : 10 <fe> DW_AT_decl_column : 32 <ff> DW_AT_type : <0x10e> <103> DW_AT_location : 2 byte block: 91 68 (DW_OP_fbreg: -24) <1><10e>: Abbrev Number: 6 (DW_TAG_pointer_type) <10f> DW_AT_byte_size : 8 <110> DW_AT_type : <0x107> <1><107>: Abbrev Number: 14 (DW_TAG_string_type) <108> DW_AT_string_length: 5 byte block: 99 ee 0 0 0 (DW_OP_call4: <0xee>) <2><ee>: Abbrev Number: 13 (DW_TAG_variable) <ef> DW_AT_name : .t <f2> DW_AT_type : <0x5d> <f6> DW_AT_artificial : 1 <f6> DW_AT_location : 2 byte block: 91 60 (DW_OP_fbreg: -32) Notice that the compiler generates a string type with a string length attribute, which is a reference to an artificial variable that holds the length of the string. I think that DWARF 5 can support this by generating an string length attribute that is an exprloc containing an operation that pushes the object address and adds the offset to the length field.