Author: Alex Langford Date: 2023-10-02T10:46:16-07:00 New Revision: cdd3e964f229aac5366433a549466d18ed696660
URL: https://github.com/llvm/llvm-project/commit/cdd3e964f229aac5366433a549466d18ed696660 DIFF: https://github.com/llvm/llvm-project/commit/cdd3e964f229aac5366433a549466d18ed696660.diff LOG: [lldb] Replace lldb's DWARFDebugAbbrev implementation with llvm's (#67841) The implementations are now close enough that replacing it is trivial. Added: Modified: lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h lldb/source/Plugins/SymbolFile/DWARF/DWARFTypeUnit.h lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h Removed: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h ################################################################################ diff --git a/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt b/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt index dad206040068716..0e4fd5b995d1ba9 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt +++ b/lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt @@ -17,7 +17,6 @@ add_lldb_library(lldbPluginSymbolFileDWARF PLUGIN DWARFCompileUnit.cpp DWARFContext.cpp DWARFDataExtractor.cpp - DWARFDebugAbbrev.cpp DWARFDebugAranges.cpp DWARFDebugArangeSet.cpp DWARFDebugInfo.cpp diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h index ab3017ba0ffcbca..65debac4c7d9265 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFCompileUnit.h @@ -12,6 +12,10 @@ #include "DWARFUnit.h" #include "llvm/Support/Error.h" +namespace llvm { +class DWARFAbbreviationDeclarationSet; +} + class DWARFCompileUnit : public DWARFUnit { public: void BuildAddressRangeTable(DWARFDebugAranges *debug_aranges) override; @@ -27,7 +31,7 @@ class DWARFCompileUnit : public DWARFUnit { private: DWARFCompileUnit(SymbolFileDWARF &dwarf, lldb::user_id_t uid, const DWARFUnitHeader &header, - const DWARFAbbreviationDeclarationSet &abbrevs, + const llvm::DWARFAbbreviationDeclarationSet &abbrevs, DIERef::Section section, bool is_dwo) : DWARFUnit(dwarf, uid, header, abbrevs, section, is_dwo) {} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp deleted file mode 100644 index f3c2755c5a527cc..000000000000000 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp +++ /dev/null @@ -1,63 +0,0 @@ -//===-- DWARFDebugAbbrev.cpp ----------------------------------------------===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "DWARFDebugAbbrev.h" -#include "DWARFDataExtractor.h" -#include "DWARFFormValue.h" -#include "lldb/Utility/Stream.h" - -using namespace lldb; -using namespace lldb_private; - -// DWARFDebugAbbrev constructor -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() { - if (!m_data) - return llvm::Error::success(); - - lldb::offset_t offset = 0; - - while (m_data->isValidOffset(offset)) { - uint32_t initial_cu_offset = offset; - DWARFAbbreviationDeclarationSet abbrevDeclSet; - - 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(); -} - -// DWARFDebugAbbrev::GetAbbreviationDeclarationSet() -const DWARFAbbreviationDeclarationSet * -DWARFDebugAbbrev::GetAbbreviationDeclarationSet( - dw_offset_t cu_abbr_offset) const { - DWARFAbbreviationDeclarationCollMapConstIter end = m_abbrevCollMap.end(); - DWARFAbbreviationDeclarationCollMapConstIter pos; - if (m_prev_abbr_offset_pos != end && - m_prev_abbr_offset_pos->first == cu_abbr_offset) - return &(m_prev_abbr_offset_pos->second); - else { - pos = m_abbrevCollMap.find(cu_abbr_offset); - m_prev_abbr_offset_pos = pos; - } - - if (pos != m_abbrevCollMap.end()) - return &(pos->second); - return nullptr; -} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h deleted file mode 100644 index d2fade0934c8a88..000000000000000 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h +++ /dev/null @@ -1,55 +0,0 @@ -//===-- DWARFDebugAbbrev.h --------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGABBREV_H -#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGABBREV_H - -#include "DWARFDefines.h" -#include "lldb/lldb-private.h" - -#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h" -#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h" - -#include <map> - -using DWARFAbbreviationDeclaration = llvm::DWARFAbbreviationDeclaration; -using DWARFAbbreviationDeclarationSet = llvm::DWARFAbbreviationDeclarationSet; - -typedef std::map<dw_offset_t, DWARFAbbreviationDeclarationSet> - DWARFAbbreviationDeclarationCollMap; -typedef DWARFAbbreviationDeclarationCollMap::iterator - DWARFAbbreviationDeclarationCollMapIter; -typedef DWARFAbbreviationDeclarationCollMap::const_iterator - DWARFAbbreviationDeclarationCollMapConstIter; - -class DWARFDebugAbbrev { -public: - 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(); - - 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; - 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/DWARFDebugInfoEntry.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp index a08637aef066978..a6ab83700904cb9 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp @@ -22,7 +22,6 @@ #include "lldb/Utility/StreamString.h" #include "DWARFCompileUnit.h" -#include "DWARFDebugAbbrev.h" #include "DWARFDebugAranges.h" #include "DWARFDebugInfo.h" #include "DWARFDebugRanges.h" @@ -32,6 +31,8 @@ #include "SymbolFileDWARF.h" #include "SymbolFileDWARFDwo.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h" + using namespace lldb_private; using namespace lldb_private::dwarf; extern int g_verbose; @@ -810,12 +811,13 @@ lldb::offset_t DWARFDebugInfoEntry::GetFirstAttributeOffset() const { return GetOffset() + llvm::getULEB128Size(m_abbr_idx); } -const DWARFAbbreviationDeclaration * +const llvm::DWARFAbbreviationDeclaration * DWARFDebugInfoEntry::GetAbbreviationDeclarationPtr(const DWARFUnit *cu) const { if (!cu) return nullptr; - const DWARFAbbreviationDeclarationSet *abbrev_set = cu->GetAbbreviations(); + const llvm::DWARFAbbreviationDeclarationSet *abbrev_set = + cu->GetAbbreviations(); if (!abbrev_set) return nullptr; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h index c2ea40065232e72..29db44a16bb1281 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h @@ -14,7 +14,6 @@ #include "DWARFAttribute.h" #include "DWARFBaseDIE.h" -#include "DWARFDebugAbbrev.h" #include "DWARFDebugRanges.h" #include <map> #include <optional> diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFTypeUnit.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFTypeUnit.h index 5e4d48ab285a9d6..5d939582a312e98 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFTypeUnit.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFTypeUnit.h @@ -12,6 +12,10 @@ #include "DWARFUnit.h" #include "llvm/Support/Error.h" +namespace llvm { +class DWARFAbbreviationDeclarationSet; +} + class DWARFTypeUnit : public DWARFUnit { public: void BuildAddressRangeTable(DWARFDebugAranges *debug_aranges) override {} @@ -27,7 +31,7 @@ class DWARFTypeUnit : public DWARFUnit { private: DWARFTypeUnit(SymbolFileDWARF &dwarf, lldb::user_id_t uid, const DWARFUnitHeader &header, - const DWARFAbbreviationDeclarationSet &abbrevs, + const llvm::DWARFAbbreviationDeclarationSet &abbrevs, DIERef::Section section, bool is_dwo) : DWARFUnit(dwarf, uid, header, abbrevs, section, is_dwo) {} diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp index 749ffcb094ecfd9..45e37b42f5e9566 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.cpp @@ -13,6 +13,7 @@ #include "lldb/Utility/LLDBAssert.h" #include "lldb/Utility/StreamString.h" #include "lldb/Utility/Timer.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h" #include "llvm/DebugInfo/DWARF/DWARFDebugLoc.h" #include "llvm/Object/Error.h" @@ -32,7 +33,7 @@ extern int g_verbose; DWARFUnit::DWARFUnit(SymbolFileDWARF &dwarf, lldb::user_id_t uid, const DWARFUnitHeader &header, - const DWARFAbbreviationDeclarationSet &abbrevs, + const llvm::DWARFAbbreviationDeclarationSet &abbrevs, DIERef::Section section, bool is_dwo) : UserID(uid), m_dwarf(dwarf), m_header(header), m_abbrevs(&abbrevs), m_cancel_scopes(false), m_section(section), m_is_dwo(is_dwo), @@ -435,7 +436,8 @@ size_t DWARFUnit::GetDebugInfoSize() const { return GetLengthByteSize() + GetLength() - GetHeaderByteSize(); } -const DWARFAbbreviationDeclarationSet *DWARFUnit::GetAbbreviations() const { +const llvm::DWARFAbbreviationDeclarationSet * +DWARFUnit::GetAbbreviations() const { return m_abbrevs; } @@ -973,7 +975,7 @@ DWARFUnit::extract(SymbolFileDWARF &dwarf, user_id_t uid, if (!expected_header) return expected_header.takeError(); - const DWARFDebugAbbrev *abbr = dwarf.DebugAbbrev(); + const llvm::DWARFDebugAbbrev *abbr = dwarf.DebugAbbrev(); if (!abbr) return llvm::make_error<llvm::object::GenericBinaryError>( "No debug_abbrev data"); @@ -985,8 +987,12 @@ DWARFUnit::extract(SymbolFileDWARF &dwarf, user_id_t uid, return llvm::make_error<llvm::object::GenericBinaryError>( "Abbreviation offset for unit is not valid"); - const DWARFAbbreviationDeclarationSet *abbrevs = - abbr->GetAbbreviationDeclarationSet(expected_header->GetAbbrOffset()); + llvm::Expected<const llvm::DWARFAbbreviationDeclarationSet *> abbrevs_or_err = + abbr->getAbbreviationDeclarationSet(expected_header->GetAbbrOffset()); + if (!abbrevs_or_err) + return abbrevs_or_err.takeError(); + + const llvm::DWARFAbbreviationDeclarationSet *abbrevs = *abbrevs_or_err; if (!abbrevs) return llvm::make_error<llvm::object::GenericBinaryError>( "No abbrev exists at the specified offset."); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h index bc55b093e894edd..004c01a37bb05e3 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFUnit.h @@ -13,6 +13,7 @@ #include "DWARFDebugInfoEntry.h" #include "lldb/Utility/XcodeSDK.h" #include "lldb/lldb-enumerations.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h" #include "llvm/DebugInfo/DWARF/DWARFDebugRnglists.h" #include "llvm/Support/RWMutex.h" #include <atomic> @@ -153,7 +154,7 @@ class DWARFUnit : public lldb_private::UserID { // Size of the CU data incl. header but without initial length. uint32_t GetLength() const { return m_header.GetLength(); } uint16_t GetVersion() const { return m_header.GetVersion(); } - const DWARFAbbreviationDeclarationSet *GetAbbreviations() const; + const llvm::DWARFAbbreviationDeclarationSet *GetAbbreviations() const; dw_offset_t GetAbbrevOffset() const; uint8_t GetAddressByteSize() const { return m_header.GetAddressByteSize(); } dw_addr_t GetAddrBase() const { return m_addr_base.value_or(0); } @@ -291,7 +292,7 @@ class DWARFUnit : public lldb_private::UserID { protected: DWARFUnit(SymbolFileDWARF &dwarf, lldb::user_id_t uid, const DWARFUnitHeader &header, - const DWARFAbbreviationDeclarationSet &abbrevs, + const llvm::DWARFAbbreviationDeclarationSet &abbrevs, DIERef::Section section, bool is_dwo); llvm::Error ExtractHeader(SymbolFileDWARF &dwarf, @@ -323,7 +324,7 @@ class DWARFUnit : public lldb_private::UserID { SymbolFileDWARF &m_dwarf; std::shared_ptr<DWARFUnit> m_dwo; DWARFUnitHeader m_header; - const DWARFAbbreviationDeclarationSet *m_abbrevs = nullptr; + const llvm::DWARFAbbreviationDeclarationSet *m_abbrevs = nullptr; void *m_user_data = nullptr; // The compile unit debug information entry item DWARFDebugInfoEntry::collection m_die_array; diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp index aae481e2ae74177..e472074545a6f07 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp @@ -58,7 +58,6 @@ #include "DWARFASTParser.h" #include "DWARFASTParserClang.h" #include "DWARFCompileUnit.h" -#include "DWARFDebugAbbrev.h" #include "DWARFDebugAranges.h" #include "DWARFDebugInfo.h" #include "DWARFDebugMacro.h" @@ -74,6 +73,7 @@ #include "SymbolFileDWARFDwo.h" #include "llvm/DebugInfo/DWARF/DWARFContext.h" +#include "llvm/DebugInfo/DWARF/DWARFDebugAbbrev.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/FormatVariadic.h" @@ -511,7 +511,8 @@ bool SymbolFileDWARF::SupportedVersion(uint16_t version) { return version >= 2 && version <= 5; } -static std::set<dw_form_t> GetUnsupportedForms(DWARFDebugAbbrev *debug_abbrev) { +static std::set<dw_form_t> +GetUnsupportedForms(llvm::DWARFDebugAbbrev *debug_abbrev) { if (!debug_abbrev) return {}; @@ -553,7 +554,7 @@ uint32_t SymbolFileDWARF::CalculateAbilities() { if (section) debug_abbrev_file_size = section->GetFileSize(); - DWARFDebugAbbrev *abbrev = DebugAbbrev(); + llvm::DWARFDebugAbbrev *abbrev = DebugAbbrev(); std::set<dw_form_t> unsupported_forms = GetUnsupportedForms(abbrev); if (!unsupported_forms.empty()) { StreamString error; @@ -624,7 +625,7 @@ void SymbolFileDWARF::LoadSectionData(lldb::SectionType sect_type, m_objfile_sp->ReadSectionData(section_sp.get(), data); } -DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() { +llvm::DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() { if (m_abbr) return m_abbr.get(); @@ -632,7 +633,8 @@ DWARFDebugAbbrev *SymbolFileDWARF::DebugAbbrev() { if (debug_abbrev_data.GetByteSize() == 0) return nullptr; - auto abbr = std::make_unique<DWARFDebugAbbrev>(debug_abbrev_data); + auto abbr = + std::make_unique<llvm::DWARFDebugAbbrev>(debug_abbrev_data.GetAsLLVM()); llvm::Error error = abbr->parse(); if (error) { Log *log = GetLog(DWARFLog::DebugInfo); diff --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h index 191a5abcf265abd..5aaf8bd270ef7b1 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h +++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h @@ -41,7 +41,6 @@ // Forward Declarations for this DWARF plugin class DebugMapModule; class DWARFCompileUnit; -class DWARFDebugAbbrev; class DWARFDebugAranges; class DWARFDebugInfo; class DWARFDebugInfoEntry; @@ -55,6 +54,10 @@ class SymbolFileDWARFDwo; class SymbolFileDWARFDwp; class UserID; +namespace llvm { +class DWARFDebugAbbrev; +} + #define DIE_IS_BEING_PARSED ((lldb_private::Type *)1) class SymbolFileDWARF : public lldb_private::SymbolFileCommon { @@ -224,7 +227,7 @@ class SymbolFileDWARF : public lldb_private::SymbolFileCommon { // PluginInterface protocol llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); } - DWARFDebugAbbrev *DebugAbbrev(); + llvm::DWARFDebugAbbrev *DebugAbbrev(); DWARFDebugInfo &DebugInfo(); @@ -536,7 +539,7 @@ class SymbolFileDWARF : public lldb_private::SymbolFileCommon { llvm::once_flag m_info_once_flag; std::unique_ptr<DWARFDebugInfo> m_info; - std::unique_ptr<DWARFDebugAbbrev> m_abbr; + std::unique_ptr<llvm::DWARFDebugAbbrev> m_abbr; std::unique_ptr<GlobalVariableMap> m_global_aranges_up; typedef std::unordered_map<lldb::offset_t, lldb_private::DebugMacrosSP> _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits