Given the program below, I get the following error when trying to print the base type of "bar": (gdb) p bar%my_type A syntax error in expression, near `my_type'. (gdb) p bar%my_int There is no member named my_int. (gdb) p bar%my_type%my_int A syntax error in expression, near `my_type%my_int'. (gdb) p bar $1 = ( my_type = ( my_int = 1 ) ) Note that all of the expressions I'm trying to print are valid Fortran expressions, and that `p foo%my_int` works MVCE: program mvce implicit none type :: my_type integer :: my_int end type my_type type, extends(my_type) :: extended_type end type extended_type type(my_type) :: foo type(extended_type) :: bar foo%my_int = 0 bar%my_int = 1 print*, foo, bar end program mvce
I can confirm that this was a bug in GDB but now actually only is one in gfortran. I recently pushed 87e10e9c288c2f6c933f235b623522c8d9a2d727 and 110aae55a8b7e19fa5f04998851968e48822605f which fixed this problem on GDB's side. The problem with gfortran is, that it is not emitting the correct DWARF OOP Fortran tags. This is a known issue here: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=49475 Compiling the example with the ifort or ifx compiler I can get the following out of gdb (breaking at line 17): ================================================================= (gdb) p foo $1 = ( my_int = 0 ) (gdb) p bar $2 = ( my_type = ( my_int = 1 ) ) (gdb) ptype foo type = Type my_type INTEGER*4 :: my_int End Type my_type (gdb) ptype bar type = Type, extends(my_type) :: extended_type Type my_type :: my_type End Type extended_type (gdb) p bar%my_type $3 = ( my_int = 1 ) (gdb) p bar%my_int $4 = 1 (gdb) p bar%my_type%my_int $5 = 1 (gdb) ================================================================= The types emitted by gfortran (GNU Fortran (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0) do not provide any inheritance information: ================================================================= <1><53>: Abbrev Number: 2 (DW_TAG_structure_type) <54> DW_AT_name : (indirect string, offset: 0x8): extended_type <58> DW_AT_byte_size : 4 <59> DW_AT_decl_file : 1 <5a> DW_AT_decl_line : 1 <5b> DW_AT_sibling : <0x6c> <2><5f>: Abbrev Number: 3 (DW_TAG_member) <60> DW_AT_name : (indirect string, offset: 0x0): my_type <64> DW_AT_decl_file : 1 <65> DW_AT_decl_line : 8 <66> DW_AT_type : <0x2e> <6a> DW_AT_data_member_location: 0 <2><6b>: Abbrev Number: 0 ================================================================= while ifx/ifort emit ================================================================= <2><5c>: Abbrev Number: 4 (DW_TAG_structure_type) <5d> DW_AT_name : (indirect string, offset: 0x3b): extended_type <61> DW_AT_byte_size : 4 <62> DW_AT_decl_file : 1 <63> DW_AT_decl_line : 8 <3><64>: Abbrev Number: 5 (DW_TAG_inheritance) <65> DW_AT_type : <0x83> <3><69>: Abbrev Number: 0 ... <2><83>: Abbrev Number: 4 (DW_TAG_structure_type) <84> DW_AT_name : (indirect string, offset: 0x68): my_type <88> DW_AT_byte_size : 4 <89> DW_AT_decl_file : 1 <8a> DW_AT_decl_line : 4 <3><8b>: Abbrev Number: 6 (DW_TAG_member) <8c> DW_AT_name : (indirect string, offset: 0x57): my_int <90> DW_AT_type : <0x9a> <94> DW_AT_decl_file : 1 <95> DW_AT_decl_line : 4 <96> DW_AT_data_member_location: 0 <97> DW_AT_accessibility: 1 (public) <3><98>: Abbrev Number: 0 =================================================================
I forgot to mention that also for gfortran the bugfix did something: I can now do ================================================================= Breakpoint 1, mvce () at ./f.f90:17 17 print*, foo, bar (gdb) p foo $1 = ( my_int = 0 ) (gdb) p bar $2 = ( my_type = ( my_int = 1 ) ) (gdb) p bar%my_int There is no member named my_int. (gdb) p bar%my_type $3 = ( my_int = 1 ) (gdb) p bar%my_type%my_int $4 = 1 (gdb) ================================================================= Note, that since the inheritance info is missing GDB has no way of knowing that "p bar%my_int" is legal and one has to go the way via accessing the member variable first.
Since the gdb side of this is fixed, I'm closing this.