This patch emits DW_TAG_namelist and DW_TAG_namelist_item for fortran namelist variables. Namelist in fortran is basically group of variables. Already Metadata is created for each of the namelist items or variables, we just need to create MDList of these items and use the DICompositeType (with TAG: DW_TAG_namelist). Gfortran supports this fortran feature already. Flang is enhanced to support this feature and GDB also enhanced to support this. Both flang and GDB changes will up streamed soon.
Sample fortran program, IR, dwarf info are shared below.
Sample program :
program main
integer :: a, b namelist /nml/ a, b a = 10 b = 20 Write(*,nml)
end program main
LLVM IR:
!20 = !DILocalVariable(scope: !15, name: "a", file: !3, line: 6, type: !19)
. . .
!22 = !DILocalVariable(scope: !15, name: "b", file: !3, line: 7, type: !19)
. . .
!24 = !{ !20, !22 }
!25 = !DICompositeType(tag: DW_TAG_namelist, file: !3, scope: !15, name: "nml", elements: !24)
dwarfdump :
. . .
0x000000b4: DW_TAG_variable [10]
DW_AT_name [DW_FORM_string] ("a") DW_AT_decl_file [DW_FORM_data1] ("/dir/namelist.f90") DW_AT_decl_line [DW_FORM_data1] (20) DW_AT_type [DW_FORM_ref4] (cu + 0x006d => {0x0000006d} "integer(kind=4)") DW_AT_declaration [DW_FORM_flag_present] (true) DW_AT_location [DW_FORM_exprloc] (DW_OP_fbreg -20)
0x000000c0: DW_TAG_variable [10]
DW_AT_name [DW_FORM_string] ("b") DW_AT_decl_file [DW_FORM_data1] ("/dir/namelist.f90") DW_AT_decl_line [DW_FORM_data1] (20) DW_AT_type [DW_FORM_ref4] (cu + 0x006d => {0x0000006d} "integer(kind=4)") DW_AT_declaration [DW_FORM_flag_present] (true) DW_AT_location [DW_FORM_exprloc] (DW_OP_fbreg -24)
. . .
0x000000dd: DW_TAG_namelist [12] *
DW_AT_name [DW_FORM_string] ("nml")
0x000000e2: DW_TAG_namelist_item [9]
DW_AT_namelist_item [DW_FORM_ref4] (cu + 0x00b4 => {0x000000b4})
0x000000e7: DW_TAG_namelist_item [9]
DW_AT_namelist_item [DW_FORM_ref4] (cu + 0x00c0 => {0x000000c0})
0x000000ec: NULL