Skip to content

Commit

Permalink
Fix DW_AT_decl_{file,line} forms in gdb.rocm/{lane-pc-vega20,aspace-w…
Browse files Browse the repository at this point in the history
…atchpoint-src-vega20}.exp

Running current llvm-dwarfdump on the kernel .so produced by
gdb.rocm/lane-pc-vega20.exp hits an assertion, like:

 /opt/rocm/llvm/bin/llvm-dwarfdump ./testsuite/outputs/gdb.rocm/lane-pc-vega20/lane-pc-vega20-kernel.so

 (... snip ...)
 0x000000b4:   DW_TAG_structure_type
		 DW_AT_name      ("test_struct")
		 DW_AT_byte_size (136)
		 DW_AT_decl_file (llvm-dwarfdump: (... snip ...)/llvm/include/llvm/ADT/Optional.h:197: T& llvm::optional_detail::OptionalStorage<T, true>::getValue() & [with T = long unsigned int]: Assertion `hasVal' failed.
 PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
 Stack dump:
 0.      Program arguments: /opt/rocm/llvm/bin/llvm-dwarfdump ./testsuite/outputs/gdb.rocm/lane-pc-vega20/lane-pc-vega20-kernel.so
  #0 0x000055cc8e78315f PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
  #1 0x000055cc8e780d3d SignalHandler(int) Signals.cpp:0:0
  #2 0x00007f8f2cae8420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
  #3 0x00007f8f2c58d00b raise /build/glibc-SzIz7B/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
  #4 0x00007f8f2c56c859 abort /build/glibc-SzIz7B/glibc-2.31/stdlib/abort.c:81:7
  #5 0x00007f8f2c56c729 get_sysdep_segment_value /build/glibc-SzIz7B/glibc-2.31/intl/loadmsgcat.c:509:8
  #6 0x00007f8f2c56c729 _nl_load_domain /build/glibc-SzIz7B/glibc-2.31/intl/loadmsgcat.c:970:34
  #7 0x00007f8f2c57dfd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
  #8 0x000055cc8e58ceb9 llvm::DWARFDie::dump(llvm::raw_ostream&, unsigned int, llvm::DIDumpOptions) const (/opt/rocm/llvm/bin/llvm-dwarfdump+0x2e0eb9)
  #9 0x000055cc8e58bec3 llvm::DWARFDie::dump(llvm::raw_ostream&, unsigned int, llvm::DIDumpOptions) const (/opt/rocm/llvm/bin/llvm-dwarfdump+0x2dfec3)
 #10 0x000055cc8e5b28a3 llvm::DWARFCompileUnit::dump(llvm::raw_ostream&, llvm::DIDumpOptions) (.part.21) DWARFCompileUnit.cpp:0:0

The issue here is invalid DWARF that the tool isn't expecting,
particularly, the use of a signed data format for the file index:

 [31] DW_TAG_subprogram  DW_CHILDREN_yes
	 DW_AT_name      DW_FORM_string
	 DW_AT_low_pc    DW_FORM_addr
	 DW_AT_high_pc   DW_FORM_addr
	 DW_AT_decl_file DW_FORM_sdata   << signed
	 DW_AT_decl_line DW_FORM_sdata   << signed

The DWARF spec says:

 Any debugging information entry representing the declaration of an object,
 module, subprogram or type may have DW_AT_decl_file, DW_AT_decl_line and
 DW_AT_decl_column attributes, each of whose value is an unsigned integer
                                                         ^^^^^^^^
 constant.

llvm-dwarfdump should be fixed to error out or warn on invalid input
instead of asserting, but still, we should fix the DWARF.  That's what
this commit does, by using DW_FORM_udata instead of DW_FORM_sdata, for
both DW_AT_decl_file and DW_AT_decl_line.

"git grep "decl_file.*FORM_sdata" shows that
gdb.rocm/aspace-watchpoint-src-vega20.exp has the same issue, so fix
it too.

llvm-dwarfdump is able to parse the lane-pc-vega20-kernel.so file
without crashing after this fix, and the gdb.rocm/lane-pc-vega20.exp
and gdb.rocm/aspace-watchpoint-src-vega20.exp testcases still pass
cleanly.

Change-Id: Ifa14331bbaa7c6ebbac03d534d59268e63663af4
(cherry picked from commit 42cbe2e)
  • Loading branch information
palves authored and lmoriche committed Jul 13, 2022
1 parent 37aa5a1 commit f04867f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 76 deletions.
24 changes: 12 additions & 12 deletions gdb/testsuite/gdb.rocm/aspace-watchpoint-src-vega20.exp
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,28 @@ Dwarf::assemble $asmfile_dwarf {
struct_label: structure_type {
{DW_AT_name test_struct}
{DW_AT_byte_size 0x88 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 19 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 19 DW_FORM_udata}
} {
member {
{DW_AT_name int_elem}
{DW_AT_type :$int_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 21 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 21 DW_FORM_udata}
{DW_AT_data_member_location 0 DW_FORM_sdata}
}
member {
{DW_AT_name char_elem}
{DW_AT_type :$char_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 22 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 22 DW_FORM_udata}
{DW_AT_data_member_location 4 DW_FORM_sdata}
}
member {
{DW_AT_name array_elem}
{DW_AT_type :$array_int_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 23 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 23 DW_FORM_udata}
{DW_AT_data_member_location 0x8 DW_FORM_sdata}
}
}
Expand All @@ -135,14 +135,14 @@ Dwarf::assemble $asmfile_dwarf {
{DW_AT_name AddrClassTest}
{DW_AT_low_pc "AddrClassTest" addr}
{DW_AT_high_pc "Lfunc_end6" addr}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 96 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 96 DW_FORM_udata}
} {
DW_TAG_variable {
{DW_AT_name local_struct}
{DW_AT_type :$struct_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 98 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 98 DW_FORM_udata}
{DW_AT_location {
DW_OP_constu 0x0
DW_OP_constu 0x3
Expand Down
128 changes: 64 additions & 64 deletions gdb/testsuite/gdb.rocm/lane-pc-vega20.exp
Original file line number Diff line number Diff line change
Expand Up @@ -259,28 +259,28 @@ Dwarf::assemble $asmfile_dwarf {
struct_label: structure_type {
{DW_AT_name test_struct}
{DW_AT_byte_size 0x88 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 19 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 19 DW_FORM_udata}
} {
member {
{DW_AT_name int_elem}
{DW_AT_type :$int_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 21 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 21 DW_FORM_udata}
{DW_AT_data_member_location 0 DW_FORM_sdata}
}
member {
{DW_AT_name char_elem}
{DW_AT_type :$char_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 22 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 22 DW_FORM_udata}
{DW_AT_data_member_location 4 DW_FORM_sdata}
}
member {
{DW_AT_name array_elem}
{DW_AT_type :$array_32_int_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 23 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 23 DW_FORM_udata}
{DW_AT_data_member_location 0x8 DW_FORM_sdata}
}
}
Expand All @@ -296,28 +296,28 @@ Dwarf::assemble $asmfile_dwarf {
local_struct_label: structure_type {
{DW_AT_name test_struct}
{DW_AT_byte_size 0x88 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 19 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 19 DW_FORM_udata}
} {
member {
{DW_AT_name int_elem}
{DW_AT_type :$int_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 21 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 21 DW_FORM_udata}
{DW_AT_data_member_location 0 DW_FORM_sdata}
}
member {
{DW_AT_name char_elem}
{DW_AT_type :$char_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 22 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 22 DW_FORM_udata}
{DW_AT_data_member_location 4 DW_FORM_sdata}
}
member {
{DW_AT_name array_elem}
{DW_AT_type :$array_32_int_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 23 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 23 DW_FORM_udata}
{DW_AT_data_member_location 0x8 DW_FORM_sdata}
}
}
Expand Down Expand Up @@ -381,16 +381,16 @@ Dwarf::assemble $asmfile_dwarf {
DW_TAG_variable {
{DW_AT_type :$array_64_int_label}
{DW_AT_name "_lane_pc"}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 37 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 37 DW_FORM_udata}
{DW_AT_location 8 DW_FORM_loclistx}
}

DW_TAG_variable {
{DW_AT_name const_struct}
{DW_AT_type :$struct_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 26 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 26 DW_FORM_udata}
{DW_AT_location {
DW_OP_addr $const_struct_src
} SPECIAL_expr}
Expand All @@ -400,8 +400,8 @@ Dwarf::assemble $asmfile_dwarf {
DW_TAG_variable {
{DW_AT_name const_array}
{DW_AT_type :$array_32_int_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 29 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 29 DW_FORM_udata}
{DW_AT_location {
DW_OP_addr $const_array_src
} SPECIAL_expr}
Expand All @@ -412,31 +412,31 @@ Dwarf::assemble $asmfile_dwarf {
{DW_AT_name AddrClassTest}
{DW_AT_low_pc "AddrClassTest" addr}
{DW_AT_high_pc "Lfunc_end6" addr}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 96 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 96 DW_FORM_udata}
{DW_AT_LLVM_lane_pc 2 DW_FORM_loclistx}
} {
DW_TAG_formal_parameter {
{DW_AT_type :$pointer_int_label}
{DW_AT_name in}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 96 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 96 DW_FORM_udata}
{DW_AT_location 6 DW_FORM_loclistx}
}

DW_TAG_formal_parameter {
{DW_AT_type :$pointer_struct_label}
{DW_AT_name out}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 96 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 96 DW_FORM_udata}
{DW_AT_location 7 DW_FORM_loclistx}
}

DW_TAG_variable {
{DW_AT_name gid}
{DW_AT_type :$unsigned_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 97 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 97 DW_FORM_udata}
{DW_AT_location {
DW_OP_regx $vgpr41_num
DW_OP_LLVM_push_lane
Expand All @@ -450,8 +450,8 @@ Dwarf::assemble $asmfile_dwarf {
DW_TAG_variable {
{DW_AT_name local_struct}
{DW_AT_type :$struct_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 98 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 98 DW_FORM_udata}
{DW_AT_location {
DW_OP_constu 0x0
DW_OP_constu 0x3
Expand All @@ -465,15 +465,15 @@ Dwarf::assemble $asmfile_dwarf {
{DW_AT_name GenValue}
{DW_AT_low_pc "GenValue" addr}
{DW_AT_high_pc "Lfunc_end2" addr}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 35 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 35 DW_FORM_udata}
{DW_AT_LLVM_lane_pc 3 DW_FORM_loclistx}
} {
DW_TAG_variable {
{DW_AT_type :$array_32_int_label}
{DW_AT_name array}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 38 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 38 DW_FORM_udata}
{DW_AT_location {
DW_OP_bregx $sgpr33_num 0
DW_OP_constu $wave_size
Expand All @@ -486,8 +486,8 @@ Dwarf::assemble $asmfile_dwarf {
DW_TAG_variable {
{DW_AT_name gid}
{DW_AT_type :$unsigned_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 39 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 39 DW_FORM_udata}
{DW_AT_location {
DW_OP_regx $vgpr0_num
DW_OP_LLVM_push_lane
Expand All @@ -501,8 +501,8 @@ Dwarf::assemble $asmfile_dwarf {
DW_TAG_variable {
{DW_AT_type :$pointer_int_label}
{DW_AT_name pconst_array_elem1}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 40 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 40 DW_FORM_udata}
{DW_AT_location {
DW_OP_regx $vgpr1_num
DW_OP_LLVM_push_lane
Expand All @@ -522,8 +522,8 @@ Dwarf::assemble $asmfile_dwarf {
DW_TAG_variable {
{DW_AT_type :$pointer_int_label}
{DW_AT_name pconst_array_elem2}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 40 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 40 DW_FORM_udata}
{DW_AT_location {
DW_OP_regx $vgpr3_num
DW_OP_LLVM_push_lane
Expand All @@ -546,23 +546,23 @@ Dwarf::assemble $asmfile_dwarf {
{DW_AT_name ChangeLocalContent}
{DW_AT_low_pc "ChangeLocalContent" addr}
{DW_AT_high_pc "Lfunc_end3" addr}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 55 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 55 DW_FORM_udata}
{DW_AT_LLVM_lane_pc 5 DW_FORM_loclistx}
} {
DW_TAG_formal_parameter {
{DW_AT_type :$local_pointer_int_label}
{DW_AT_name plocal_content}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 55 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 55 DW_FORM_udata}
{DW_AT_location 0 DW_FORM_loclistx}
}

DW_TAG_variable {
{DW_AT_type :$array_32_int_label}
{DW_AT_name array}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 58 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 58 DW_FORM_udata}
{DW_AT_location {
DW_OP_bregx $sgpr33_num 0
DW_OP_constu $wave_size
Expand All @@ -577,8 +577,8 @@ Dwarf::assemble $asmfile_dwarf {
DW_TAG_variable {
{DW_AT_name gid}
{DW_AT_type :$unsigned_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 59 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 59 DW_FORM_udata}
{DW_AT_location {
DW_OP_regx $vgpr40_num
DW_OP_LLVM_push_lane
Expand All @@ -590,14 +590,14 @@ Dwarf::assemble $asmfile_dwarf {
}

DW_TAG_lexical_block {
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 62 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 62 DW_FORM_udata}
} {
DW_TAG_variable {
{DW_AT_name pconst_array_elem}
{DW_AT_type :$pointer_int_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 63 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 63 DW_FORM_udata}
{DW_AT_location {
DW_OP_regx $vgpr0_num
DW_OP_LLVM_push_lane
Expand All @@ -618,8 +618,8 @@ Dwarf::assemble $asmfile_dwarf {
DW_TAG_variable {
{DW_AT_name temp}
{DW_AT_type :$int_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 64 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 64 DW_FORM_udata}
{DW_AT_location {
DW_OP_regx $vgpr2_num
DW_OP_LLVM_push_lane
Expand All @@ -636,15 +636,15 @@ Dwarf::assemble $asmfile_dwarf {
{DW_AT_name SendResults}
{DW_AT_low_pc "SendResults" addr}
{DW_AT_high_pc "Lfunc_end4" addr}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 82 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 82 DW_FORM_udata}
{DW_AT_LLVM_lane_pc 4 DW_FORM_loclistx}
} {
DW_TAG_formal_parameter {
{DW_AT_type :$local_pointer_struct_label}
{DW_AT_name plocal_struct}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 82 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 82 DW_FORM_udata}
{DW_AT_location {
DW_OP_regx $vgpr42_num
DW_OP_LLVM_push_lane
Expand All @@ -657,16 +657,16 @@ Dwarf::assemble $asmfile_dwarf {
DW_TAG_formal_parameter {
{DW_AT_type :$pointer_struct_label}
{DW_AT_name out}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 82 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 82 DW_FORM_udata}
{DW_AT_location 1 DW_FORM_loclistx}
}

DW_TAG_variable {
{DW_AT_name gid}
{DW_AT_type :$unsigned_label}
{DW_AT_decl_file 1 DW_FORM_sdata}
{DW_AT_decl_line 84 DW_FORM_sdata}
{DW_AT_decl_file 1 DW_FORM_udata}
{DW_AT_decl_line 84 DW_FORM_udata}
{DW_AT_location {
DW_OP_regx $vgpr0_num
DW_OP_LLVM_push_lane
Expand Down

0 comments on commit f04867f

Please sign in to comment.