Files
clang-p2996/lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
Alex Langford f09cca4c6f [lldb] Remove lldb's DWARFAbbreviationDeclarationSet in favor of llvm's
lldb's and llvm's implementations of DWARFAbbreviationDeclarationSet are
now close enough (almost the same, actually) to replace lldb's with
llvm's wholesale. llvm's is also tested against the same kinds of
scenarios that lldb's is tested against so we can remove lldb's tests
here. (see: llvm/unittests/DebugInfo/DWARF/DWARFDebugAbbrevTest.cpp).

Differential Revision: https://reviews.llvm.org/D152476
2023-06-12 14:53:44 -07:00

68 lines
2.2 KiB
C++

//===-- 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()
: m_abbrevCollMap(), m_prev_abbr_offset_pos(m_abbrevCollMap.end()) {}
// DWARFDebugAbbrev::Parse()
llvm::Error DWARFDebugAbbrev::parse(const DWARFDataExtractor &data) {
llvm::DataExtractor llvm_data = data.GetAsLLVM();
lldb::offset_t offset = 0;
while (llvm_data.isValidOffset(offset)) {
uint32_t initial_cu_offset = offset;
DWARFAbbreviationDeclarationSet abbrevDeclSet;
llvm::Error error = abbrevDeclSet.extract(llvm_data, &offset);
if (error)
return error;
m_abbrevCollMap[initial_cu_offset] = abbrevDeclSet;
}
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;
}
// 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);
}