[Lldb-commits] [lldb] [lldb] Modify the DWARFDebugAbbrev interface to be closer to LLVM's (PR #67190)

Alex Langford via lldb-commits lldb-commits at lists.llvm.org
Fri Sep 22 13:00:52 PDT 2023


https://github.com/bulbazord created https://github.com/llvm/llvm-project/pull/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.

>From 16e6a1f7db9be3fb58e650f6e17bb52ada51d40d Mon Sep 17 00:00:00 2001
From: Alex Langford <alangford at apple.com>
Date: Fri, 22 Sep 2023 12:48:40 -0700
Subject: [PATCH] [lldb] Modify the DWARFDebugAbbrev interface to be closer to
 LLVM's

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.
---
 .../SymbolFile/DWARF/DWARFDebugAbbrev.cpp     | 20 ++++++++++++-------
 .../SymbolFile/DWARF/DWARFDebugAbbrev.h       |  5 +++--
 .../SymbolFile/DWARF/SymbolFileDWARF.cpp      |  4 ++--
 3 files changed, 18 insertions(+), 11 deletions(-)

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),



More information about the lldb-commits mailing list