[Lldb-commits] [lldb] 1d11d5f - [lldb] [NFC] Refactor GetDWARFDeclContext to return DWARFDeclContext

Jan Kratochvil via lldb-commits lldb-commits at lists.llvm.org
Thu Feb 6 11:06:45 PST 2020


Author: Jan Kratochvil
Date: 2020-02-06T20:06:28+01:00
New Revision: 1d11d5f6242206f4d0dbc11623f73cdf2173a087

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

LOG: [lldb] [NFC] Refactor GetDWARFDeclContext to return DWARFDeclContext

Suggested by Pavel Labath.

Differential Revision: https://reviews.llvm.org/D73787

Added: 
    

Modified: 
    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

Removed: 
    


################################################################################
diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 0d640819ff28..5b3ea8838786 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -726,8 +726,7 @@ TypeSP DWARFASTParserClang::ParseEnum(const SymbolContext &sc,
     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 @@ DWARFASTParserClang::ParseStructureLikeDIE(const SymbolContext &sc,
     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 @@ Function *DWARFASTParserClang::ParseFunctionFromDWARF(CompileUnit &comp_unit,
         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 =

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
index 5d22e3d607ac..746be69a3e12 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -868,21 +868,30 @@ void DWARFDebugInfoEntry::BuildFunctionAddressRangeTable(
   }
 }
 
-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;

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
index 2bb69e738a2f..ef00d09cf71e 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
@@ -158,8 +158,7 @@ class DWARFDebugInfoEntry {
     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 @@ class DWARFDebugInfoEntry {
   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

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 02fb37f65da0..bc79a9d06ad1 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -2959,8 +2959,8 @@ TypeSP SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(
             }
 
             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 @@ VariableSP SymbolFileDWARF::ParseVariableDIE(const SymbolContext &sc,
         // 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 @@ SymbolFileDWARF::GetContainingDeclContext(const DWARFDIE &die) {
   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) {

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
index 9e533829bd9a..23df3a2762a5 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -308,8 +308,7 @@ class SymbolFileDWARF : public lldb_private::SymbolFile,
   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);
 


        


More information about the lldb-commits mailing list