From d04723665f9391c6cb9db453ccb8e6eba3d5adfd Mon Sep 17 00:00:00 2001 From: mgschossmann <109181247+mgschossmann@users.noreply.github.com> Date: Thu, 23 May 2024 10:54:00 +0200 Subject: [PATCH 1/4] [llvm-dwarfdump] Add a null-check in `prettyPrintBaseTypeRef`. Fixes #93104 Prevent a crash by only printing DWARFUnit-unaware information in cases in which `DWARFUnit* U` is `nullptr`. --- llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp | 24 ++++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp index 87a4fc78ceb19..0c28701360b3c 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp @@ -240,17 +240,21 @@ static void prettyPrintBaseTypeRef(DWARFUnit *U, raw_ostream &OS, ArrayRef Operands, unsigned Operand) { assert(Operand < Operands.size() && "operand out of bounds"); - auto Die = U->getDIEForOffset(U->getOffset() + Operands[Operand]); - if (Die && Die.getTag() == dwarf::DW_TAG_base_type) { - OS << " ("; - if (DumpOpts.Verbose) - OS << format("0x%08" PRIx64 " -> ", Operands[Operand]); - OS << format("0x%08" PRIx64 ")", U->getOffset() + Operands[Operand]); - if (auto Name = dwarf::toString(Die.find(dwarf::DW_AT_name))) - OS << " \"" << *Name << "\""; + if (U) { + auto Die = U->getDIEForOffset(U->getOffset() + Operands[Operand]); + if (Die && Die.getTag() == dwarf::DW_TAG_base_type) { + OS << " ("; + if (DumpOpts.Verbose) + OS << format("0x%08" PRIx64 " -> ", Operands[Operand]); + OS << format("0x%08" PRIx64 ")", U->getOffset() + Operands[Operand]); + if (auto Name = dwarf::toString(Die.find(dwarf::DW_AT_name))) + OS << " \"" << *Name << "\""; + } else { + OS << format(" ", + Operands[Operand]); + } } else { - OS << format(" ", - Operands[Operand]); + OS << format(" ", Operands[Operand]); } } From a0d8a4a2c6fd35d4645a0c0064cafbc507915ef3 Mon Sep 17 00:00:00 2001 From: mgschossmann <109181247+mgschossmann@users.noreply.github.com> Date: Thu, 23 May 2024 22:37:43 +0200 Subject: [PATCH 2/4] added test --- .../dwarfdump-loclist-basetyperef.elf-x86-64 | Bin 0 -> 3552 bytes .../dwarfdump-loclist-basetyperef.test | 17 +++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 llvm/test/DebugInfo/Inputs/dwarfdump-loclist-basetyperef.elf-x86-64 create mode 100644 llvm/test/DebugInfo/dwarfdump-loclist-basetyperef.test diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-loclist-basetyperef.elf-x86-64 b/llvm/test/DebugInfo/Inputs/dwarfdump-loclist-basetyperef.elf-x86-64 new file mode 100644 index 0000000000000000000000000000000000000000..ef5d6387d95cdb56c229ae4340e9bf0786743401 GIT binary patch literal 3552 zcmbtV&2Jl35P#2WI}UD~I4O-ofNT(fHe#1Jl#nL0SdB^=s3>X`i4Tc%ZLdGT-i>zG zG^s=@R7C<#J#s)TC?J);0JtC|E*!XU=EAWj5OAYNWoCEAUcVYef{}J-<~Q?uZ{EDO zZ?By>_hLdy!6L;e(eoG;LeKQwetIbT$+c!Er_BZx|z&R%8SX#LULbj-V#p%9CkNG##C+-+HrXU z9Gqw#w3PC0ZUhxJ4IVIN!u}=XOky+|HYBI!#BkR=oR+Cn`g&>vbXFvi@@7iDtS2PU zEw5e_Rku@a*<$^bO?|ESoL+p!ESd|t(GEI}eX?#lw%4qHYk8H%$(`jTW9hhV)OF)L zJT=STbt(admdpmj^lzC8Gtgo%D=tnop z9Vh5e8;s>n=oYUoE}9F+j}eSb#`8Z0PYNFB9q#IPh-vVk9FCNbS1t&-GbX1G4P|b? zZaoY*J}BX?pUI6~Ph80L4pS6U-?-69@%ud$M_(Iw10aso-7lKxeq?kQu4<3N$?|YGOUl9xMEXwD~ z5yx&EB7B@Q;><|To>mPT|7nx=3}4d z$j2KJh4J~w?du!nzeM;dX?1*^aNLvlz6jIbZNnV}I`AUhV9T>xmKoSPfiSC9UwBY}#bl_tzc|Uo$5*hs6GLE@%nFa^H zvr-%cyMTuab)>@k5xM-0F^=aC@%R}+%4_%hesIkH%3lJmIwnrb^WR1%CTcEz z--Fh_KB z_<9$K4DKJpKY@W`s{Gr;U*<&8D*s2o2kqZcEDD703EV&Y_b{LF uL31PT7n(mq3w{u=LFW&#L9M!jMS&cPRQIj+FAtGH{1VmwbC($zD*qqN5+%X_ literal 0 HcmV?d00001 diff --git a/llvm/test/DebugInfo/dwarfdump-loclist-basetyperef.test b/llvm/test/DebugInfo/dwarfdump-loclist-basetyperef.test new file mode 100644 index 0000000000000..448f94b0f03db --- /dev/null +++ b/llvm/test/DebugInfo/dwarfdump-loclist-basetyperef.test @@ -0,0 +1,17 @@ +#RUN: llvm-dwarfdump %p/Inputs/dwarfdump-loclist-basetyperef.elf-x86-64 --debug-loclists | FileCheck %s + +// The .debug-loclists section of the binary contains a base type reference as an argument +// to DW_OP_regval_type that cannot be resolved when only dumping the .debug-loclists +// section. prettyPrintBaseTypeRef must handle this case without crashing by printing reduced information. +// +// The binary was compiled using following command: +// gcc-13 dwarfdump-loclist-basetyperef.c -c -g -Og -o dwarfdump-loclist-basetyperef.elf-x86-64 +// +// Contents of dwarfdump-loclist-basetyperef.c: +// extern double foo(); +// +// void bar(double arg1, double *arg2) { +// *arg2 = foo(arg1); +// } + +#CHECK: (0x0000000000000011, 0x0000000000000018): DW_OP_entry_value(DW_OP_regval_type XMM0 ), DW_OP_stack_value From b9796d63120c62a9f3688c4ef28f97d2e2b6712b Mon Sep 17 00:00:00 2001 From: mgschossmann <109181247+mgschossmann@users.noreply.github.com> Date: Tue, 28 May 2024 13:17:23 +0200 Subject: [PATCH 3/4] changed to early return, removed whitespace in test, clang-format --- llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp | 27 +++++++++---------- .../dwarfdump-loclist-basetyperef.test | 4 +-- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp index 0c28701360b3c..d4979024cb57b 100644 --- a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp +++ b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp @@ -240,21 +240,20 @@ static void prettyPrintBaseTypeRef(DWARFUnit *U, raw_ostream &OS, ArrayRef Operands, unsigned Operand) { assert(Operand < Operands.size() && "operand out of bounds"); - if (U) { - auto Die = U->getDIEForOffset(U->getOffset() + Operands[Operand]); - if (Die && Die.getTag() == dwarf::DW_TAG_base_type) { - OS << " ("; - if (DumpOpts.Verbose) - OS << format("0x%08" PRIx64 " -> ", Operands[Operand]); - OS << format("0x%08" PRIx64 ")", U->getOffset() + Operands[Operand]); - if (auto Name = dwarf::toString(Die.find(dwarf::DW_AT_name))) - OS << " \"" << *Name << "\""; - } else { - OS << format(" ", - Operands[Operand]); - } - } else { + if (!U) { OS << format(" ", Operands[Operand]); + return; + } + auto Die = U->getDIEForOffset(U->getOffset() + Operands[Operand]); + if (Die && Die.getTag() == dwarf::DW_TAG_base_type) { + OS << " ("; + if (DumpOpts.Verbose) + OS << format("0x%08" PRIx64 " -> ", Operands[Operand]); + OS << format("0x%08" PRIx64 ")", U->getOffset() + Operands[Operand]); + if (auto Name = dwarf::toString(Die.find(dwarf::DW_AT_name))) + OS << " \"" << *Name << "\""; + } else { + OS << format(" ", Operands[Operand]); } } diff --git a/llvm/test/DebugInfo/dwarfdump-loclist-basetyperef.test b/llvm/test/DebugInfo/dwarfdump-loclist-basetyperef.test index 448f94b0f03db..59b85e293d30c 100644 --- a/llvm/test/DebugInfo/dwarfdump-loclist-basetyperef.test +++ b/llvm/test/DebugInfo/dwarfdump-loclist-basetyperef.test @@ -3,13 +3,13 @@ // The .debug-loclists section of the binary contains a base type reference as an argument // to DW_OP_regval_type that cannot be resolved when only dumping the .debug-loclists // section. prettyPrintBaseTypeRef must handle this case without crashing by printing reduced information. -// +// // The binary was compiled using following command: // gcc-13 dwarfdump-loclist-basetyperef.c -c -g -Og -o dwarfdump-loclist-basetyperef.elf-x86-64 // // Contents of dwarfdump-loclist-basetyperef.c: // extern double foo(); -// +// // void bar(double arg1, double *arg2) { // *arg2 = foo(arg1); // } From c7b1a0aca99433787d128959b7017dc750c6961c Mon Sep 17 00:00:00 2001 From: mgschossmann <109181247+mgschossmann@users.noreply.github.com> Date: Fri, 7 Jun 2024 16:52:19 +0200 Subject: [PATCH 4/4] replaced test binary with hand-written .debug_loclists section --- .../dwarfdump-loclist-basetyperef.elf-x86-64 | Bin 3552 -> 0 bytes .../dwarfdump-loclist-basetyperef.test | 54 ++++++++++++------ 2 files changed, 37 insertions(+), 17 deletions(-) delete mode 100644 llvm/test/DebugInfo/Inputs/dwarfdump-loclist-basetyperef.elf-x86-64 diff --git a/llvm/test/DebugInfo/Inputs/dwarfdump-loclist-basetyperef.elf-x86-64 b/llvm/test/DebugInfo/Inputs/dwarfdump-loclist-basetyperef.elf-x86-64 deleted file mode 100644 index ef5d6387d95cdb56c229ae4340e9bf0786743401..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3552 zcmbtV&2Jl35P#2WI}UD~I4O-ofNT(fHe#1Jl#nL0SdB^=s3>X`i4Tc%ZLdGT-i>zG zG^s=@R7C<#J#s)TC?J);0JtC|E*!XU=EAWj5OAYNWoCEAUcVYef{}J-<~Q?uZ{EDO zZ?By>_hLdy!6L;e(eoG;LeKQwetIbT$+c!Er_BZx|z&R%8SX#LULbj-V#p%9CkNG##C+-+HrXU z9Gqw#w3PC0ZUhxJ4IVIN!u}=XOky+|HYBI!#BkR=oR+Cn`g&>vbXFvi@@7iDtS2PU zEw5e_Rku@a*<$^bO?|ESoL+p!ESd|t(GEI}eX?#lw%4qHYk8H%$(`jTW9hhV)OF)L zJT=STbt(admdpmj^lzC8Gtgo%D=tnop z9Vh5e8;s>n=oYUoE}9F+j}eSb#`8Z0PYNFB9q#IPh-vVk9FCNbS1t&-GbX1G4P|b? zZaoY*J}BX?pUI6~Ph80L4pS6U-?-69@%ud$M_(Iw10aso-7lKxeq?kQu4<3N$?|YGOUl9xMEXwD~ z5yx&EB7B@Q;><|To>mPT|7nx=3}4d z$j2KJh4J~w?du!nzeM;dX?1*^aNLvlz6jIbZNnV}I`AUhV9T>xmKoSPfiSC9UwBY}#bl_tzc|Uo$5*hs6GLE@%nFa^H zvr-%cyMTuab)>@k5xM-0F^=aC@%R}+%4_%hesIkH%3lJmIwnrb^WR1%CTcEz z--Fh_KB z_<9$K4DKJpKY@W`s{Gr;U*<&8D*s2o2kqZcEDD703EV&Y_b{LF uL31PT7n(mq3w{u=LFW&#L9M!jMS&cPRQIj+FAtGH{1VmwbC($zD*qqN5+%X_ diff --git a/llvm/test/DebugInfo/dwarfdump-loclist-basetyperef.test b/llvm/test/DebugInfo/dwarfdump-loclist-basetyperef.test index 59b85e293d30c..1c647920a3cf2 100644 --- a/llvm/test/DebugInfo/dwarfdump-loclist-basetyperef.test +++ b/llvm/test/DebugInfo/dwarfdump-loclist-basetyperef.test @@ -1,17 +1,37 @@ -#RUN: llvm-dwarfdump %p/Inputs/dwarfdump-loclist-basetyperef.elf-x86-64 --debug-loclists | FileCheck %s - -// The .debug-loclists section of the binary contains a base type reference as an argument -// to DW_OP_regval_type that cannot be resolved when only dumping the .debug-loclists -// section. prettyPrintBaseTypeRef must handle this case without crashing by printing reduced information. -// -// The binary was compiled using following command: -// gcc-13 dwarfdump-loclist-basetyperef.c -c -g -Og -o dwarfdump-loclist-basetyperef.elf-x86-64 -// -// Contents of dwarfdump-loclist-basetyperef.c: -// extern double foo(); -// -// void bar(double arg1, double *arg2) { -// *arg2 = foo(arg1); -// } - -#CHECK: (0x0000000000000011, 0x0000000000000018): DW_OP_entry_value(DW_OP_regval_type XMM0 ), DW_OP_stack_value +# REQUIRES: x86-registered-target + + +# This test checks whether llvm-dwarfdump correctly handles base type +# references when dumping the .debug_loclists section. + +# When dumping the .debug_loclists section, the corresponding compile unit +# for a base type reference is not known and therefore it cannot be resolved. + +# prettyPrintBaseTypeRef must handle this case by printing only reduced +# information without crashing. + + +# RUN: llvm-mc %s -filetype=obj -triple=x86_64 -o %t +# RUN: llvm-dwarfdump %t --debug-loclists | FileCheck %s + +# CHECK: 0x0000000c: +# CHECK-NEXT: : DW_OP_regval_type XMM0 , DW_OP_stack_value + + + .section .debug_loclists,"",@progbits + .long .Ldebug_loc1-.Ldebug_loc0 # Length +.Ldebug_loc0: + .value 0x5 # Version + .byte 0x8 # Address size + .byte 0 # Segmen selector size + .long 0 # Offset entry count + + .byte 0x5 # DW_LLE_default_location + .uleb128 0x4 # Loc expr size + .byte 0xa5 # DW_OP_regval_type + .uleb128 0x11 # XMM0 + .uleb128 0x2a # + .byte 0x9f # DW_OP_stack_value + + .byte 0 # DW_LLE_end_of_list +.Ldebug_loc1: