https://github.com/bulbazord created 
https://github.com/llvm/llvm-project/pull/67579

The LLVM implementation of DWARFDebugAbbrev does not have a way of listing all 
the DW_FORM values that have been parsed but are unsupported or otherwise 
unknown. AFAICT this functionality does not exist in LLVM at all. Since my 
primary goal is to unify the implementations and not judge the usefulness or 
completeness of this functionality, I decided to move it out of LLDB's 
implementation of DWARFDebugAbbrev for the time being.

>From 40507690a8f7ec584a580d6b2be1a8f90598d708 Mon Sep 17 00:00:00 2001
From: Alex Langford <alangf...@apple.com>
Date: Wed, 27 Sep 2023 10:29:41 -0700
Subject: [PATCH] [lldb][NFCI] Move functionality for getting unsupported
 DW_FORM values

The LLVM implementation of DWARFDebugAbbrev does not have a way of
listing all the DW_FORM values that have been parsed but are unsupported
or otherwise unknown. AFAICT this functionality does not exist in LLVM
at all. Since my primary goal is to unify the implementations and not
judge the usefulness or completeness of this functionality, I decided to
move it out of LLDB's implementation of DWARFDebugAbbrev for the time
being.
---
 .../SymbolFile/DWARF/DWARFDebugAbbrev.cpp     | 10 ------
 .../SymbolFile/DWARF/DWARFDebugAbbrev.h       | 10 +++++-
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp      | 36 ++++++++++++-------
 3 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
index bcebba6abd3ee5c..f3c2755c5a527cc 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
@@ -61,13 +61,3 @@ DWARFDebugAbbrev::GetAbbreviationDeclarationSet(
     return &(pos->second);
   return nullptr;
 }
-
-// DWARFDebugAbbrev::GetUnsupportedForms()
-void DWARFDebugAbbrev::GetUnsupportedForms(
-    std::set<dw_form_t> &invalid_forms) const {
-  for (const auto &pair : m_abbrevCollMap)
-    for (const auto &decl : pair.second)
-      for (const auto &attr : decl.attributes())
-        if (!DWARFFormValue::FormIsSupported(attr.Form))
-          invalid_forms.insert(attr.Form);
-}
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
index 6d0616deeb91038..d2fade0934c8a88 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
@@ -36,7 +36,15 @@ class DWARFDebugAbbrev {
   /// llvm::ErrorSuccess() on success, and an appropriate llvm::Error object
   /// otherwise.
   llvm::Error parse();
-  void GetUnsupportedForms(std::set<dw_form_t> &invalid_forms) const;
+
+  DWARFAbbreviationDeclarationCollMapConstIter begin() const {
+    assert(!m_data && "Must call parse before iterating over 
DWARFDebugAbbrev");
+    return m_abbrevCollMap.begin();
+  }
+
+  DWARFAbbreviationDeclarationCollMapConstIter end() const {
+    return m_abbrevCollMap.end();
+  }
 
 protected:
   DWARFAbbreviationDeclarationCollMap m_abbrevCollMap;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 9832c324a2c0e55..aae481e2ae74177 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -511,6 +511,20 @@ bool SymbolFileDWARF::SupportedVersion(uint16_t version) {
   return version >= 2 && version <= 5;
 }
 
+static std::set<dw_form_t> GetUnsupportedForms(DWARFDebugAbbrev *debug_abbrev) 
{
+  if (!debug_abbrev)
+    return {};
+
+  std::set<dw_form_t> unsupported_forms;
+  for (const auto &[_, decl_set] : *debug_abbrev)
+    for (const auto &decl : decl_set)
+      for (const auto &attr : decl.attributes())
+        if (!DWARFFormValue::FormIsSupported(attr.Form))
+          unsupported_forms.insert(attr.Form);
+
+  return unsupported_forms;
+}
+
 uint32_t SymbolFileDWARF::CalculateAbilities() {
   uint32_t abilities = 0;
   if (m_objfile_sp != nullptr) {
@@ -540,19 +554,15 @@ uint32_t SymbolFileDWARF::CalculateAbilities() {
         debug_abbrev_file_size = section->GetFileSize();
 
       DWARFDebugAbbrev *abbrev = DebugAbbrev();
-      if (abbrev) {
-        std::set<dw_form_t> invalid_forms;
-        abbrev->GetUnsupportedForms(invalid_forms);
-        if (!invalid_forms.empty()) {
-          StreamString error;
-          error.Printf("unsupported DW_FORM value%s:",
-                       invalid_forms.size() > 1 ? "s" : "");
-          for (auto form : invalid_forms)
-            error.Printf(" %#x", form);
-          m_objfile_sp->GetModule()->ReportWarning(
-              "{0}", error.GetString().str().c_str());
-          return 0;
-        }
+      std::set<dw_form_t> unsupported_forms = GetUnsupportedForms(abbrev);
+      if (!unsupported_forms.empty()) {
+        StreamString error;
+        error.Printf("unsupported DW_FORM value%s:",
+                     unsupported_forms.size() > 1 ? "s" : "");
+        for (auto form : unsupported_forms)
+          error.Printf(" %#x", form);
+        m_objfile_sp->GetModule()->ReportWarning("{0}", error.GetString());
+        return 0;
       }
 
       section =

_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to