jankratochvil updated this revision to Diff 242936.
This revision is now accepted and ready to land.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73787/new/

https://reviews.llvm.org/D73787

Files:
  lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
  lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
  lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h

Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -308,8 +308,7 @@
   static lldb_private::CompilerDeclContext
   GetContainingDeclContext(const DWARFDIE &die);
 
-  static void GetDWARFDeclContext(const DWARFDIE &die,
-                                  DWARFDeclContext &dwarf_decl_ctx);
+  static DWARFDeclContext GetDWARFDeclContext(const DWARFDIE &die);
 
   static lldb::LanguageType LanguageTypeFromDWARF(uint64_t val);
 
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2959,8 +2959,8 @@
             }
 
             if (try_resolving_type) {
-              DWARFDeclContext type_dwarf_decl_ctx;
-              GetDWARFDeclContext(type_die, type_dwarf_decl_ctx);
+              DWARFDeclContext type_dwarf_decl_ctx =
+                  GetDWARFDeclContext(type_die);
 
               if (log) {
                 GetObjectFile()->GetModule()->LogMessage(
@@ -3377,12 +3377,10 @@
         // declaration context.
         if ((parent_tag == DW_TAG_compile_unit ||
              parent_tag == DW_TAG_partial_unit) &&
-            Language::LanguageIsCPlusPlus(GetLanguage(*die.GetCU()))) {
-          DWARFDeclContext decl_ctx;
-
-          GetDWARFDeclContext(die, decl_ctx);
-          mangled = decl_ctx.GetQualifiedNameAsConstString().GetCString();
-        }
+            Language::LanguageIsCPlusPlus(GetLanguage(*die.GetCU())))
+          mangled = GetDWARFDeclContext(die)
+                        .GetQualifiedNameAsConstString()
+                        .GetCString();
       }
 
       if (tag == DW_TAG_formal_parameter)
@@ -3984,14 +3982,13 @@
   return CompilerDeclContext();
 }
 
-void SymbolFileDWARF::GetDWARFDeclContext(const DWARFDIE &die,
-                                          DWARFDeclContext &dwarf_decl_ctx) {
-  if (!die.IsValid()) {
-    dwarf_decl_ctx.Clear();
-    return;
-  }
+DWARFDeclContext SymbolFileDWARF::GetDWARFDeclContext(const DWARFDIE &die) {
+  if (!die.IsValid())
+    return {};
+  DWARFDeclContext dwarf_decl_ctx =
+      die.GetDIE()->GetDWARFDeclContext(die.GetCU());
   dwarf_decl_ctx.SetLanguage(GetLanguage(*die.GetCU()));
-  die.GetDIE()->GetDWARFDeclContext(die.GetCU(), dwarf_decl_ctx);
+  return dwarf_decl_ctx;
 }
 
 LanguageType SymbolFileDWARF::LanguageTypeFromDWARF(uint64_t val) {
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
@@ -158,8 +158,7 @@
     return HasChildren() ? this + 1 : nullptr;
   }
 
-  void GetDWARFDeclContext(DWARFUnit *cu,
-                           DWARFDeclContext &dwarf_decl_ctx) const;
+  DWARFDeclContext GetDWARFDeclContext(DWARFUnit *cu) const;
 
   DWARFDIE GetParentDeclContextDIE(DWARFUnit *cu) const;
   DWARFDIE GetParentDeclContextDIE(DWARFUnit *cu,
@@ -169,6 +168,9 @@
   void SetParentIndex(uint32_t idx) { m_parent_idx = idx; }
 
 protected:
+  static DWARFDeclContext
+  GetDWARFDeclContextStatic(const DWARFDebugInfoEntry *die, DWARFUnit *cu);
+
   dw_offset_t m_offset; // Offset within the .debug_info/.debug_types
   uint32_t m_parent_idx; // How many to subtract from "this" to get the parent.
                          // If zero this die has no parent
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -868,21 +868,30 @@
   }
 }
 
-void DWARFDebugInfoEntry::GetDWARFDeclContext(
-    DWARFUnit *cu, DWARFDeclContext &dwarf_decl_ctx) const {
-  const dw_tag_t tag = Tag();
-  if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
-    return;
-  dwarf_decl_ctx.AppendDeclContext(tag, GetName(cu));
-  DWARFDIE parent_decl_ctx_die = GetParentDeclContextDIE(cu);
-  if (parent_decl_ctx_die && parent_decl_ctx_die.GetDIE() != this) {
-    if (parent_decl_ctx_die.Tag() != DW_TAG_compile_unit &&
-        parent_decl_ctx_die.Tag() != DW_TAG_partial_unit)
-      parent_decl_ctx_die.GetDIE()->GetDWARFDeclContext(
-          parent_decl_ctx_die.GetCU(), dwarf_decl_ctx);
+DWARFDeclContext
+DWARFDebugInfoEntry::GetDWARFDeclContextStatic(const DWARFDebugInfoEntry *die,
+                                               DWARFUnit *cu) {
+  DWARFDeclContext dwarf_decl_ctx;
+  for (;;) {
+    const dw_tag_t tag = die->Tag();
+    if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
+      return dwarf_decl_ctx;
+    dwarf_decl_ctx.AppendDeclContext(tag, die->GetName(cu));
+    DWARFDIE parent_decl_ctx_die = die->GetParentDeclContextDIE(cu);
+    if (!parent_decl_ctx_die || parent_decl_ctx_die.GetDIE() == die)
+      return dwarf_decl_ctx;
+    if (parent_decl_ctx_die.Tag() == DW_TAG_compile_unit ||
+        parent_decl_ctx_die.Tag() == DW_TAG_partial_unit)
+      return dwarf_decl_ctx;
+    die = parent_decl_ctx_die.GetDIE();
+    cu = parent_decl_ctx_die.GetCU();
   }
 }
 
+DWARFDeclContext DWARFDebugInfoEntry::GetDWARFDeclContext(DWARFUnit *cu) const {
+  return GetDWARFDeclContextStatic(this, cu);
+}
+
 DWARFDIE
 DWARFDebugInfoEntry::GetParentDeclContextDIE(DWARFUnit *cu) const {
   DWARFAttributes attributes;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -726,8 +726,7 @@
     if (type_sp)
       return type_sp;
 
-    DWARFDeclContext die_decl_ctx;
-    SymbolFileDWARF::GetDWARFDeclContext(die, die_decl_ctx);
+    DWARFDeclContext die_decl_ctx = SymbolFileDWARF::GetDWARFDeclContext(die);
 
     type_sp = dwarf->FindDefinitionTypeForDWARFDeclContext(die_decl_ctx);
 
@@ -1515,8 +1514,7 @@
     if (type_sp)
       return type_sp;
 
-    DWARFDeclContext die_decl_ctx;
-    SymbolFileDWARF::GetDWARFDeclContext(die, die_decl_ctx);
+    DWARFDeclContext die_decl_ctx = SymbolFileDWARF::GetDWARFDeclContext(die);
 
     // type_sp = FindDefinitionTypeForDIE (dwarf_cu, die,
     // type_name_const_str);
@@ -2323,10 +2321,9 @@
         unsigned type_quals = 0;
         std::vector<CompilerType> param_types;
         std::vector<clang::ParmVarDecl *> param_decls;
-        DWARFDeclContext decl_ctx;
         StreamString sstr;
 
-        SymbolFileDWARF::GetDWARFDeclContext(die, decl_ctx);
+        DWARFDeclContext decl_ctx = SymbolFileDWARF::GetDWARFDeclContext(die);
         sstr << decl_ctx.GetQualifiedName();
 
         clang::DeclContext *containing_decl_ctx =
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to