Skip to content

[lldb] Modify the DWARFDebugAbbrev interface to be closer to LLVM's #67190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 25, 2023

Conversation

bulbazord
Copy link
Member

I want to work towards unifying the implementations. It would be a lot easier to do if LLDB's DWARFDebugAbbrev looked more similar to LLVM's implementation, so this change moves in that direction.

I want to work towards unifying the implementations. It would be a lot
easier to do if LLDB's DWARFDebugAbbrev looked more similar to LLVM's
implementation, so this change moves in that direction.
@llvmbot
Copy link
Member

llvmbot commented Sep 22, 2023

@llvm/pr-subscribers-lldb

Changes

I want to work towards unifying the implementations. It would be a lot easier to do if LLDB's DWARFDebugAbbrev looked more similar to LLVM's implementation, so this change moves in that direction.


Full diff: https://github.com/llvm/llvm-project/pull/67190.diff

3 Files Affected:

  • (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp (+13-7)
  • (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h (+3-2)
  • (modified) lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp (+2-2)
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
index 0cd53463ee65e08..bcebba6abd3ee5c 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
@@ -15,24 +15,30 @@ using namespace lldb;
 using namespace lldb_private;
 
 // DWARFDebugAbbrev constructor
-DWARFDebugAbbrev::DWARFDebugAbbrev()
-    : m_abbrevCollMap(), m_prev_abbr_offset_pos(m_abbrevCollMap.end()) {}
+DWARFDebugAbbrev::DWARFDebugAbbrev(const DWARFDataExtractor &data)
+    : m_abbrevCollMap(), m_prev_abbr_offset_pos(m_abbrevCollMap.end()),
+      m_data(data.GetAsLLVM()) {}
 
 // DWARFDebugAbbrev::Parse()
-llvm::Error DWARFDebugAbbrev::parse(const DWARFDataExtractor &data) {
-  llvm::DataExtractor llvm_data = data.GetAsLLVM();
+llvm::Error DWARFDebugAbbrev::parse() {
+  if (!m_data)
+    return llvm::Error::success();
+
   lldb::offset_t offset = 0;
 
-  while (llvm_data.isValidOffset(offset)) {
+  while (m_data->isValidOffset(offset)) {
     uint32_t initial_cu_offset = offset;
     DWARFAbbreviationDeclarationSet abbrevDeclSet;
 
-    llvm::Error error = abbrevDeclSet.extract(llvm_data, &offset);
-    if (error)
+    llvm::Error error = abbrevDeclSet.extract(*m_data, &offset);
+    if (error) {
+      m_data = std::nullopt;
       return error;
+    }
 
     m_abbrevCollMap[initial_cu_offset] = abbrevDeclSet;
   }
+  m_data = std::nullopt;
   m_prev_abbr_offset_pos = m_abbrevCollMap.end();
   return llvm::ErrorSuccess();
 }
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
index 0a579e34b001337..6d0616deeb91038 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
@@ -29,18 +29,19 @@ typedef DWARFAbbreviationDeclarationCollMap::const_iterator
 
 class DWARFDebugAbbrev {
 public:
-  DWARFDebugAbbrev();
+  DWARFDebugAbbrev(const lldb_private::DWARFDataExtractor &data);
   const DWARFAbbreviationDeclarationSet *
   GetAbbreviationDeclarationSet(dw_offset_t cu_abbr_offset) const;
   /// Extract all abbreviations for a particular compile unit.  Returns
   /// llvm::ErrorSuccess() on success, and an appropriate llvm::Error object
   /// otherwise.
-  llvm::Error parse(const lldb_private::DWARFDataExtractor &data);
+  llvm::Error parse();
   void GetUnsupportedForms(std::set<dw_form_t> &invalid_forms) const;
 
 protected:
   DWARFAbbreviationDeclarationCollMap m_abbrevCollMap;
   mutable DWARFAbbreviationDeclarationCollMapConstIter m_prev_abbr_offset_pos;
+  mutable std::optional<llvm::DataExtractor> m_data;
 };
 
 #endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGABBREV_H
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 04c729e333a9854..9832c324a2c0e55 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -622,8 +622,8 @@ DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() {
   if (debug_abbrev_data.GetByteSize() == 0)
     return nullptr;
 
-  auto abbr = std::make_unique<DWARFDebugAbbrev>();
-  llvm::Error error = abbr->parse(debug_abbrev_data);
+  auto abbr = std::make_unique<DWARFDebugAbbrev>(debug_abbrev_data);
+  llvm::Error error = abbr->parse();
   if (error) {
     Log *log = GetLog(DWARFLog::DebugInfo);
     LLDB_LOG_ERROR(log, std::move(error),

@bulbazord bulbazord merged commit d3505c2 into llvm:main Sep 25, 2023
@bulbazord bulbazord deleted the lldb-dwarf-debug-abbrev branch September 25, 2023 20:11
adrian-prantl pushed a commit to adrian-prantl/llvm-project that referenced this pull request Oct 25, 2023
…lvm#67190)

I want to work towards unifying the implementations. It would be a lot
easier to do if LLDB's DWARFDebugAbbrev looked more similar to LLVM's
implementation, so this change moves in that direction.

(cherry picked from commit d3505c2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants