[llvm] c6e9371 - [llvm-dwarfdump] Add a null-check in `prettyPrintBaseTypeRef`. (#93156)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 7 12:59:13 PDT 2024


Author: mgschossmann
Date: 2024-06-07T12:59:10-07:00
New Revision: c6e9371cbd23a9f2d03fee9b406065dbd0b7cf6a

URL: https://github.com/llvm/llvm-project/commit/c6e9371cbd23a9f2d03fee9b406065dbd0b7cf6a
DIFF: https://github.com/llvm/llvm-project/commit/c6e9371cbd23a9f2d03fee9b406065dbd0b7cf6a.diff

LOG: [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`.

Added: 
    llvm/test/DebugInfo/dwarfdump-loclist-basetyperef.test

Modified: 
    llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
index 87a4fc78ceb19..d4979024cb57b 100644
--- a/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
+++ b/llvm/lib/DebugInfo/DWARF/DWARFExpression.cpp
@@ -240,6 +240,10 @@ static void prettyPrintBaseTypeRef(DWARFUnit *U, raw_ostream &OS,
                                    ArrayRef<uint64_t> Operands,
                                    unsigned Operand) {
   assert(Operand < Operands.size() && "operand out of bounds");
+  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 << " (";
@@ -249,8 +253,7 @@ static void prettyPrintBaseTypeRef(DWARFUnit *U, raw_ostream &OS,
     if (auto Name = dwarf::toString(Die.find(dwarf::DW_AT_name)))
       OS << " \"" << *Name << "\"";
   } else {
-    OS << format(" <invalid base_type ref: 0x%" PRIx64 ">",
-                 Operands[Operand]);
+    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
new file mode 100644
index 0000000000000..1c647920a3cf2
--- /dev/null
+++ b/llvm/test/DebugInfo/dwarfdump-loclist-basetyperef.test
@@ -0,0 +1,37 @@
+# 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: <default>: DW_OP_regval_type XMM0 <base_type ref: 0x2a>, DW_OP_stack_value
+
+
+	.section	.debug_loclists,"", at 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                       #   <base_type ref: 0x2a>
+	.byte	0x9f                        # DW_OP_stack_value
+
+	.byte	0                           # DW_LLE_end_of_list
+.Ldebug_loc1:


        


More information about the llvm-commits mailing list