[lldb] Replace lldb's DWARFDebugAbbrev implementation with llvm's (#67841)
The implementations are now close enough that replacing it is trivial.
This commit is contained in:
@@ -17,7 +17,6 @@ add_lldb_library(lldbPluginSymbolFileDWARF PLUGIN
|
||||
DWARFCompileUnit.cpp
|
||||
DWARFContext.cpp
|
||||
DWARFDataExtractor.cpp
|
||||
DWARFDebugAbbrev.cpp
|
||||
DWARFDebugAranges.cpp
|
||||
DWARFDebugArangeSet.cpp
|
||||
DWARFDebugInfo.cpp
|
||||
|
||||
@@ -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 @@ public:
|
||||
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) {}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
#include "DWARFAttribute.h"
|
||||
#include "DWARFBaseDIE.h"
|
||||
#include "DWARFDebugAbbrev.h"
|
||||
#include "DWARFDebugRanges.h"
|
||||
#include <map>
|
||||
#include <optional>
|
||||
|
||||
@@ -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 @@ public:
|
||||
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) {}
|
||||
|
||||
|
||||
@@ -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.");
|
||||
|
||||
@@ -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 @@ public:
|
||||
// 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 @@ public:
|
||||
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 @@ protected:
|
||||
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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 @@ public:
|
||||
// PluginInterface protocol
|
||||
llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
|
||||
|
||||
DWARFDebugAbbrev *DebugAbbrev();
|
||||
llvm::DWARFDebugAbbrev *DebugAbbrev();
|
||||
|
||||
DWARFDebugInfo &DebugInfo();
|
||||
|
||||
@@ -536,7 +539,7 @@ protected:
|
||||
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>
|
||||
|
||||
Reference in New Issue
Block a user