[llvm] [llvm-dwarfdump] Add a null-check in `prettyPrintBaseTypeRef`. (PR #93156)
via llvm-commits
llvm-commits at lists.llvm.org
Tue May 28 04:35:51 PDT 2024
https://github.com/mgschossmann updated https://github.com/llvm/llvm-project/pull/93156
>From d04723665f9391c6cb9db453ccb8e6eba3d5adfd Mon Sep 17 00:00:00 2001
From: mgschossmann <109181247+mgschossmann at users.noreply.github.com>
Date: Thu, 23 May 2024 10:54:00 +0200
Subject: [PATCH 1/3] [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<uint64_t> 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(" <invalid base_type ref: 0x%" PRIx64 ">",
+ Operands[Operand]);
+ }
} else {
- OS << format(" <invalid base_type ref: 0x%" PRIx64 ">",
- Operands[Operand]);
+ OS << format(" <base_type ref: 0x%" PRIx64 ">", Operands[Operand]);
}
}
>From a0d8a4a2c6fd35d4645a0c0064cafbc507915ef3 Mon Sep 17 00:00:00 2001
From: mgschossmann <109181247+mgschossmann at users.noreply.github.com>
Date: Thu, 23 May 2024 22:37:43 +0200
Subject: [PATCH 2/3] 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;LeKQ<QfQXMq&On}9DVe!i)TN)`!$m8VBn9 at y!PhzpM#YW
zGGrwXegt1}Da0HtlSD6Bb6p|js0sEuJSmYbTb__w8lxyolAnAAURY=zvspr924gHk
zY&;7_Mp~(T?F*y~XF{G#2`#rWD_3W=6WNW4#N=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K<jT10sjvOsp~%tm^vmvU2rdSdM`Ei)m~~Z39LOzJkf`ChwY*^Sn8M<{FcCl
zZf0btxt9PQwEmCjKrtWJKMaq${$0S-F#!_468IK6F;Q~^hz*+m2b%v9adCe9tEuy2
ze{oE%6U<P~(Iv9a0BN3|^$oxW at qZ)!+XwJJ{TKf0bfEcu<Y9PT)?X5z<E;184}t>B
z<GgRc!2bi4%dq%>_<9$K4DKJpKY at 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 <base_type ref: 0x2e>), DW_OP_stack_value
>From b9796d63120c62a9f3688c4ef28f97d2e2b6712b Mon Sep 17 00:00:00 2001
From: mgschossmann <109181247+mgschossmann at users.noreply.github.com>
Date: Tue, 28 May 2024 13:17:23 +0200
Subject: [PATCH 3/3] 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<uint64_t> 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(" <invalid base_type ref: 0x%" PRIx64 ">",
- Operands[Operand]);
- }
- } else {
+ if (!U) {
OS << format(" <base_type ref: 0x%" PRIx64 ">", 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(" <invalid base_type ref: 0x%" PRIx64 ">", 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);
// }
More information about the llvm-commits
mailing list