Alex Langford 36a518317f
[lldb][NFCI] Move functionality for getting unsupported DW_FORM values (#67579)
The LLVM implementation of DWARFDebugAbbrev does not have a way of
listing all the DW_FORM values that have been parsed but are unsupported
or otherwise unknown. AFAICT this functionality does not exist in LLVM
at all. Since my primary goal is to unify the implementations and not
judge the usefulness or completeness of this functionality, I decided to
move it out of LLDB's implementation of DWARFDebugAbbrev for the time
being.
2023-09-28 12:18:08 -07:00

64 lines
1.9 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(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;
}