[Lldb-commits] [lldb] [lldb][DWARF] Fix adding children to clang type that hasn't started definition. (PR #93839)

Zequan Wu via lldb-commits lldb-commits at lists.llvm.org
Thu May 30 09:33:12 PDT 2024


https://github.com/ZequanWu updated https://github.com/llvm/llvm-project/pull/93839

>From 90cbcf8a97fb2e7c5131ac2cb601b95fe7a331c6 Mon Sep 17 00:00:00 2001
From: Zequan Wu <zequanwu at google.com>
Date: Thu, 30 May 2024 11:36:10 -0400
Subject: [PATCH 1/3] [lldb][DWARF] Do not differentiate DW_TAG_class_type and
 DW_TAG_struct_type in UniqueDWARFASTTypeList.

---
 .../Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp |  5 +++++
 .../Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp  | 12 ++++++++++--
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index e0b1b430b266f..78969d4752f80 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2232,6 +2232,11 @@ bool DWARFASTParserClang::CompleteRecordType(const DWARFDIE &die,
       // For objective C we don't start the definition when the class is
       // created.
       TypeSystemClang::StartTagDeclarationDefinition(clang_type);
+    } else if (!clang_type.IsBeingDefined()) {
+      // In case of some weired DWARF causing we don't start definition on this
+      // definition DIE because we failed to find existing clang_type from
+      // UniqueDWARFASTTypeMap due to overstrict checking.
+      TypeSystemClang::StartTagDeclarationDefinition(clang_type);
     }
 
     AccessType default_accessibility = eAccessNone;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp b/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
index 4762356034cab..3d201e96f92c3 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
@@ -13,12 +13,18 @@
 using namespace lldb_private::dwarf;
 using namespace lldb_private::plugin::dwarf;
 
+static bool IsStructOrClassTag(llvm::dwarf::Tag Tag) {
+  return Tag == llvm::dwarf::Tag::DW_TAG_class_type ||
+         Tag == llvm::dwarf::Tag::DW_TAG_structure_type;
+}
+
 UniqueDWARFASTType *UniqueDWARFASTTypeList::Find(
     const DWARFDIE &die, const lldb_private::Declaration &decl,
     const int32_t byte_size, bool is_forward_declaration) {
   for (UniqueDWARFASTType &udt : m_collection) {
     // Make sure the tags match
-    if (udt.m_die.Tag() == die.Tag()) {
+    if (udt.m_die.Tag() == die.Tag() || (IsStructOrClassTag(udt.m_die.Tag()) &&
+                                         IsStructOrClassTag(die.Tag()))) {
       // If they are not both definition DIEs or both declaration DIEs, then
       // don't check for byte size and declaration location, because declaration
       // DIEs usually don't have those info.
@@ -39,7 +45,9 @@ UniqueDWARFASTType *UniqueDWARFASTTypeList::Find(
       while (!done && match && parent_arg_die && parent_pos_die) {
         const dw_tag_t parent_arg_tag = parent_arg_die.Tag();
         const dw_tag_t parent_pos_tag = parent_pos_die.Tag();
-        if (parent_arg_tag == parent_pos_tag) {
+        if (parent_arg_tag == parent_pos_tag ||
+            (IsStructOrClassTag(parent_arg_tag) &&
+             IsStructOrClassTag(parent_pos_tag))) {
           switch (parent_arg_tag) {
           case DW_TAG_class_type:
           case DW_TAG_structure_type:

>From d78b4d1394643c3cb4a558d91d907bad30e3b4e6 Mon Sep 17 00:00:00 2001
From: Zequan Wu <zequanwu at google.com>
Date: Thu, 30 May 2024 12:29:03 -0400
Subject: [PATCH 2/3] Just assert if c/c++ clang_type is not being defined in
 DWARFASTParserClang::CompleteRecordType.

---
 .../Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp     | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 78969d4752f80..09325404d6092 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2232,11 +2232,10 @@ bool DWARFASTParserClang::CompleteRecordType(const DWARFDIE &die,
       // For objective C we don't start the definition when the class is
       // created.
       TypeSystemClang::StartTagDeclarationDefinition(clang_type);
-    } else if (!clang_type.IsBeingDefined()) {
-      // In case of some weired DWARF causing we don't start definition on this
-      // definition DIE because we failed to find existing clang_type from
-      // UniqueDWARFASTTypeMap due to overstrict checking.
-      TypeSystemClang::StartTagDeclarationDefinition(clang_type);
+    } else {
+      assert(
+          clang_type.IsBeingDefined() &&
+          "The clang type should already start its definition at this point.");
     }
 
     AccessType default_accessibility = eAccessNone;

>From e7fc16ec5f31693191188b3b95728c4320465923 Mon Sep 17 00:00:00 2001
From: Zequan Wu <zequanwu at google.com>
Date: Thu, 30 May 2024 12:33:05 -0400
Subject: [PATCH 3/3] Apply suggestions from code review

Update assertion message.

Co-authored-by: Michael Buch <michaelbuch12 at gmail.com>
---
 lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 09325404d6092..74bc5ac93aada 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -2235,7 +2235,7 @@ bool DWARFASTParserClang::CompleteRecordType(const DWARFDIE &die,
     } else {
       assert(
           clang_type.IsBeingDefined() &&
-          "The clang type should already start its definition at this point.");
+          "Trying to complete a definition without a prior call to StartTagDeclarationDefinition.");
     }
 
     AccessType default_accessibility = eAccessNone;



More information about the lldb-commits mailing list