[lldb] [llvm] [DWARF] Fix DWARTTypePrinter unable to print qualified name for DW_TAG_typedef DIE (PR #117239)

Zequan Wu via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 21 13:03:03 PST 2024


https://github.com/ZequanWu created https://github.com/llvm/llvm-project/pull/117239

Fix a bug introduced in https://github.com/llvm/llvm-project/pull/117071.

Ideally the DWARTTypePrinter test should go to `llvm/unittests/DebugInfo/DWARF/DWARTTypePrinterTest.cpp`.

>From 5ecdcda44c179d32e64fae33a03aa5086255ae22 Mon Sep 17 00:00:00 2001
From: Zequan Wu <zequanwu at google.com>
Date: Thu, 21 Nov 2024 12:59:54 -0800
Subject: [PATCH] [DWARF] Fix DWARTTypePrinter unable to print qualified name
 for DW_TAG_typedef DIE

---
 .../SymbolFile/DWARF/DWARFDIETest.cpp         | 48 ++++++++++++++-----
 .../llvm/DebugInfo/DWARF/DWARFTypePrinter.h   |  1 +
 2 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp b/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
index ae63e286cc1551..3a03ed283a98d4 100644
--- a/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
+++ b/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
@@ -23,6 +23,26 @@ using namespace lldb_private;
 using namespace lldb_private::plugin::dwarf;
 using namespace lldb_private::dwarf;
 
+namespace {
+void Test_appendAndTerminateTemplateParameters(const DWARFDIE &die,
+                                               const std::string &expected) {
+  std::string template_name;
+  llvm::raw_string_ostream template_name_os(template_name);
+  llvm::DWARFTypePrinter<DWARFDIE> template_name_printer(template_name_os);
+  template_name_printer.appendAndTerminateTemplateParameters(die);
+  EXPECT_THAT(template_name, expected);
+}
+
+void Test_appendQualifiedName(const DWARFDIE &die,
+                              const std::string &expected) {
+  std::string qualified_name;
+  llvm::raw_string_ostream template_name_os(qualified_name);
+  llvm::DWARFTypePrinter<DWARFDIE> template_name_printer(template_name_os);
+  template_name_printer.appendQualifiedName(die);
+  EXPECT_THAT(qualified_name, expected);
+}
+} // namespace
+
 TEST(DWARFDIETest, ChildIteration) {
   // Tests DWARFDIE::child_iterator.
 
@@ -466,6 +486,14 @@ TEST(DWARFDIETest, TestDWARFTypePrinter) {
           Attributes:
             - Attribute:       DW_AT_type
               Form:            DW_FORM_ref4
+        - Code:            0x8
+          Tag:             DW_TAG_typedef
+          Children:        DW_CHILDREN_no
+          Attributes:
+            - Attribute:       DW_AT_type
+              Form:            DW_FORM_ref4
+            - Attribute:       DW_AT_name
+              Form:            DW_FORM_string
   debug_info:
     - Version:         4
       AddrSize:        8
@@ -494,6 +522,10 @@ TEST(DWARFDIETest, TestDWARFTypePrinter) {
         - AbbrCode:        0x7
           Values:
             - Value:            0x0000000c # update
+        - AbbrCode:        0x8
+          Values:
+            - Value:            0x0000000c
+            - CStr:            my_int
         - AbbrCode:        0x0
         - AbbrCode:        0x0)";
   YAMLModuleTester t(yamldata);
@@ -505,17 +537,7 @@ TEST(DWARFDIETest, TestDWARFTypePrinter) {
   unit->Dump(&debug_os);
   ASSERT_TRUE(unit);
 
-  DWARFDIE t1_die = unit->GetDIE(0x11);
-  std::string template_name;
-  llvm::raw_string_ostream template_name_os(template_name);
-  llvm::DWARFTypePrinter<DWARFDIE> template_name_printer(template_name_os);
-  template_name_printer.appendAndTerminateTemplateParameters(t1_die);
-  EXPECT_THAT(template_name, "<t3<int> >");
-
-  DWARFDIE t2_die = unit->GetDIE(0x1a);
-  std::string qualified_name;
-  llvm::raw_string_ostream qualified_name_os(qualified_name);
-  llvm::DWARFTypePrinter<DWARFDIE> qualified_name_printer(qualified_name_os);
-  qualified_name_printer.appendQualifiedName(t2_die);
-  EXPECT_THAT(qualified_name, "t1<t3<int> >::t2");
+  Test_appendAndTerminateTemplateParameters(unit->GetDIE(0x11), "<t3<int> >");
+  Test_appendQualifiedName(unit->GetDIE(0x1a), "t1<t3<int> >::t2");
+  Test_appendQualifiedName(unit->GetDIE(0x28), "t3<int>::my_int");
 }
diff --git a/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h b/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
index 962462b8278259..3c936b93865045 100644
--- a/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
+++ b/llvm/include/llvm/DebugInfo/DWARF/DWARFTypePrinter.h
@@ -70,6 +70,7 @@ template <typename DieType> struct DWARFTypePrinter {
     case dwarf::DW_TAG_union_type:
     case dwarf::DW_TAG_namespace:
     case dwarf::DW_TAG_enumeration_type:
+    case dwarf::DW_TAG_typedef:
       return true;
     default:
       break;



More information about the llvm-commits mailing list