Skip to content

Commit c6e9371

Browse files
authored
[llvm-dwarfdump] Add a null-check in prettyPrintBaseTypeRef. (#93156)
Fixes #93104 Prevent a crash by only printing DWARFUnit-unaware information in cases in which `DWARFUnit* U` is `nullptr`.
1 parent 28dd55b commit c6e9371

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,10 @@ static void prettyPrintBaseTypeRef(DWARFUnit *U, raw_ostream &OS,
240240
ArrayRef<uint64_t> Operands,
241241
unsigned Operand) {
242242
assert(Operand < Operands.size() && "operand out of bounds");
243+
if (!U) {
244+
OS << format(" <base_type ref: 0x%" PRIx64 ">", Operands[Operand]);
245+
return;
246+
}
243247
auto Die = U->getDIEForOffset(U->getOffset() + Operands[Operand]);
244248
if (Die && Die.getTag() == dwarf::DW_TAG_base_type) {
245249
OS << " (";
@@ -249,8 +253,7 @@ static void prettyPrintBaseTypeRef(DWARFUnit *U, raw_ostream &OS,
249253
if (auto Name = dwarf::toString(Die.find(dwarf::DW_AT_name)))
250254
OS << " \"" << *Name << "\"";
251255
} else {
252-
OS << format(" <invalid base_type ref: 0x%" PRIx64 ">",
253-
Operands[Operand]);
256+
OS << format(" <invalid base_type ref: 0x%" PRIx64 ">", Operands[Operand]);
254257
}
255258
}
256259

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# REQUIRES: x86-registered-target
2+
3+
4+
# This test checks whether llvm-dwarfdump correctly handles base type
5+
# references when dumping the .debug_loclists section.
6+
7+
# When dumping the .debug_loclists section, the corresponding compile unit
8+
# for a base type reference is not known and therefore it cannot be resolved.
9+
10+
# prettyPrintBaseTypeRef must handle this case by printing only reduced
11+
# information without crashing.
12+
13+
14+
# RUN: llvm-mc %s -filetype=obj -triple=x86_64 -o %t
15+
# RUN: llvm-dwarfdump %t --debug-loclists | FileCheck %s
16+
17+
# CHECK: 0x0000000c:
18+
# CHECK-NEXT: <default>: DW_OP_regval_type XMM0 <base_type ref: 0x2a>, DW_OP_stack_value
19+
20+
21+
.section .debug_loclists,"",@progbits
22+
.long .Ldebug_loc1-.Ldebug_loc0 # Length
23+
.Ldebug_loc0:
24+
.value 0x5 # Version
25+
.byte 0x8 # Address size
26+
.byte 0 # Segmen selector size
27+
.long 0 # Offset entry count
28+
29+
.byte 0x5 # DW_LLE_default_location
30+
.uleb128 0x4 # Loc expr size
31+
.byte 0xa5 # DW_OP_regval_type
32+
.uleb128 0x11 # XMM0
33+
.uleb128 0x2a # <base_type ref: 0x2a>
34+
.byte 0x9f # DW_OP_stack_value
35+
36+
.byte 0 # DW_LLE_end_of_list
37+
.Ldebug_loc1:

0 commit comments

Comments
 (0)