llvm-dwarfdump: Don't print even an empty string when a type is unprintable
authorDavid Blaikie <dblaikie@gmail.com>
Mon, 20 Sep 2021 00:03:10 +0000 (17:03 -0700)
committerDavid Blaikie <dblaikie@gmail.com>
Mon, 20 Sep 2021 00:03:10 +0000 (17:03 -0700)
llvm/lib/DebugInfo/DWARF/DWARFDie.cpp
llvm/test/tools/llvm-dwarfdump/X86/verify_debug_info.s

index fe7377b..1f16158 100644 (file)
@@ -374,15 +374,11 @@ struct DWARFTypePrinter {
   }
 
   /// Recursively append the DIE type name when applicable.
-  void appendUnqualifiedName(const DWARFDie &D,
-                                 bool SkipFirstParamIfArtificial = false) {
-    if (!D.isValid() || D.isNULL())
-      return;
-
+  void appendUnqualifiedName(const DWARFDie &D) {
     // FIXME: We should have pretty printers per language. Currently we print
     // everything as if it was C++ and fall back to the TAG type name.
     DWARFDie Inner = appendUnqualifiedNameBefore(D);
-    appendUnqualifiedNameAfter(D, Inner, SkipFirstParamIfArtificial);
+    appendUnqualifiedNameAfter(D, Inner);
   }
 
   void appendSubroutineNameAfter(DWARFDie D, DWARFDie Inner,
@@ -546,10 +542,12 @@ static void dumpAttribute(raw_ostream &OS, const DWARFDie &Die,
                 DINameKind::LinkageName))
       OS << Space << "\"" << Name << '\"';
   } else if (Attr == DW_AT_type) {
-    OS << Space << "\"";
-    DWARFTypePrinter(OS).appendQualifiedName(
-        Die.getAttributeValueAsReferencedDie(FormValue));
-    OS << '"';
+    DWARFDie D = Die.getAttributeValueAsReferencedDie(FormValue);
+    if (D && !D.isNULL()) {
+      OS << Space << "\"";
+      DWARFTypePrinter(OS).appendQualifiedName(D);
+      OS << '"';
+    }
   } else if (Attr == DW_AT_APPLE_property_attribute) {
     if (Optional<uint64_t> OptVal = FormValue.getAsUnsignedConstant())
       dumpApplePropertyAttribute(OS, *OptVal);
index 1536c45..b3e5c77 100644 (file)
@@ -20,7 +20,7 @@
 # CHECK-NEXT: DW_AT_decl_file [DW_FORM_data1]  (0x01)
 # CHECK-NEXT: DW_AT_decl_line [DW_FORM_data1]  (1)
 # CHECK-NEXT: DW_AT_prototyped [DW_FORM_flag_present]  (true)
-# CHECK-NEXT: DW_AT_type [DW_FORM_ref4]        (cu + 0x0052 => {0x00000052} "")
+# CHECK-NEXT: DW_AT_type [DW_FORM_ref4]        (cu + 0x0052 => {0x00000052})
 # CHECK-NEXT: DW_AT_external [DW_FORM_flag_present]    (true){{[[:space:]]}}
 # CHECK-NEXT: error: DIE has DW_AT_type with incompatible tag DW_TAG_null{{[[:space:]]}}
 # CHECK-NEXT: 0x0000002b: DW_TAG_subprogram [2] *
@@ -31,7 +31,7 @@
 # CHECK-NEXT: DW_AT_decl_file [DW_FORM_data1]   (0x01)
 # CHECK-NEXT: DW_AT_decl_line [DW_FORM_data1]   (1)
 # CHECK-NEXT: DW_AT_prototyped [DW_FORM_flag_present]   (true)
-# CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x0052 => {0x00000052} "")
+# CHECK-NEXT: DW_AT_type [DW_FORM_ref4] (cu + 0x0052 => {0x00000052})
 # CHECK-NEXT: DW_AT_external [DW_FORM_flag_present]     (true){{[[:space:]]}}
 # CHECK-NEXT: error: DIE has DW_AT_decl_file that references a file with index 1 and the compile unit has no line table{{[[:space:]]}}
 # CHECK-NEXT: 0x00000044: DW_TAG_variable [3]