summaryrefslogtreecommitdiff
path: root/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp')
-rw-r--r--source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp107
1 files changed, 26 insertions, 81 deletions
diff --git a/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp b/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
index affe4b85bdab..26301566a8e1 100644
--- a/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
+++ b/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
@@ -1,9 +1,8 @@
//===-- DWARFDebugAbbrev.cpp ------------------------------------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// 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
//
//===----------------------------------------------------------------------===//
@@ -15,50 +14,41 @@ using namespace lldb;
using namespace lldb_private;
using namespace std;
-//----------------------------------------------------------------------
// DWARFAbbreviationDeclarationSet::Clear()
-//----------------------------------------------------------------------
void DWARFAbbreviationDeclarationSet::Clear() {
m_idx_offset = 0;
m_decls.clear();
}
-//----------------------------------------------------------------------
// DWARFAbbreviationDeclarationSet::Extract()
-//----------------------------------------------------------------------
-bool DWARFAbbreviationDeclarationSet::Extract(const DWARFDataExtractor &data,
- lldb::offset_t *offset_ptr) {
+llvm::Error
+DWARFAbbreviationDeclarationSet::extract(const DWARFDataExtractor &data,
+ lldb::offset_t *offset_ptr) {
const lldb::offset_t begin_offset = *offset_ptr;
m_offset = begin_offset;
Clear();
DWARFAbbreviationDeclaration abbrevDeclaration;
dw_uleb128_t prev_abbr_code = 0;
- while (abbrevDeclaration.Extract(data, offset_ptr)) {
+ while (true) {
+ llvm::Expected<DWARFEnumState> es =
+ abbrevDeclaration.extract(data, offset_ptr);
+ if (!es)
+ return es.takeError();
+ if (*es == DWARFEnumState::Complete)
+ break;
m_decls.push_back(abbrevDeclaration);
if (m_idx_offset == 0)
m_idx_offset = abbrevDeclaration.Code();
- else {
- if (prev_abbr_code + 1 != abbrevDeclaration.Code())
- m_idx_offset =
- UINT32_MAX; // Out of order indexes, we can't do O(1) lookups...
+ else if (prev_abbr_code + 1 != abbrevDeclaration.Code()) {
+ // Out of order indexes, we can't do O(1) lookups...
+ m_idx_offset = UINT32_MAX;
}
prev_abbr_code = abbrevDeclaration.Code();
}
- return begin_offset != *offset_ptr;
+ return llvm::ErrorSuccess();
}
-//----------------------------------------------------------------------
-// DWARFAbbreviationDeclarationSet::Dump()
-//----------------------------------------------------------------------
-void DWARFAbbreviationDeclarationSet::Dump(Stream *s) const {
- std::for_each(
- m_decls.begin(), m_decls.end(),
- bind2nd(std::mem_fun_ref(&DWARFAbbreviationDeclaration::Dump), s));
-}
-
-//----------------------------------------------------------------------
// DWARFAbbreviationDeclarationSet::GetAbbreviationDeclaration()
-//----------------------------------------------------------------------
const DWARFAbbreviationDeclaration *
DWARFAbbreviationDeclarationSet::GetAbbreviationDeclaration(
dw_uleb128_t abbrCode) const {
@@ -74,32 +64,11 @@ DWARFAbbreviationDeclarationSet::GetAbbreviationDeclaration(
if (idx < m_decls.size())
return &m_decls[idx];
}
- return NULL;
+ return nullptr;
}
-//----------------------------------------------------------------------
-// DWARFAbbreviationDeclarationSet::AppendAbbrevDeclSequential()
-//
-// Append an abbreviation declaration with a sequential code for O(n) lookups.
-// Handy when creating an DWARFAbbreviationDeclarationSet.
-//----------------------------------------------------------------------
-dw_uleb128_t DWARFAbbreviationDeclarationSet::AppendAbbrevDeclSequential(
- const DWARFAbbreviationDeclaration &abbrevDecl) {
- // Get the next abbreviation code based on our current array size
- dw_uleb128_t code = m_decls.size() + 1;
-
- // Push the new declaration on the back
- m_decls.push_back(abbrevDecl);
-
- // Update the code for this new declaration
- m_decls.back().SetCode(code);
-
- return code; // return the new abbreviation code!
-}
-//----------------------------------------------------------------------
// DWARFAbbreviationDeclarationSet::GetUnsupportedForms()
-//----------------------------------------------------------------------
void DWARFAbbreviationDeclarationSet::GetUnsupportedForms(
std::set<dw_form_t> &invalid_forms) const {
for (const auto &abbr_decl : m_decls) {
@@ -112,13 +81,11 @@ void DWARFAbbreviationDeclarationSet::GetUnsupportedForms(
}
}
-//----------------------------------------------------------------------
// Encode
//
// Encode the abbreviation table onto the end of the buffer provided into a
// byte representation as would be found in a ".debug_abbrev" debug information
// section.
-//----------------------------------------------------------------------
// void
// DWARFAbbreviationDeclarationSet::Encode(BinaryStreamBuf& debug_abbrev_buf)
// const
@@ -130,49 +97,29 @@ void DWARFAbbreviationDeclarationSet::GetUnsupportedForms(
// debug_abbrev_buf.Append8(0);
//}
-//----------------------------------------------------------------------
// DWARFDebugAbbrev constructor
-//----------------------------------------------------------------------
DWARFDebugAbbrev::DWARFDebugAbbrev()
: m_abbrevCollMap(), m_prev_abbr_offset_pos(m_abbrevCollMap.end()) {}
-//----------------------------------------------------------------------
// DWARFDebugAbbrev::Parse()
-//----------------------------------------------------------------------
-void DWARFDebugAbbrev::Parse(const DWARFDataExtractor &data) {
+llvm::Error DWARFDebugAbbrev::parse(const DWARFDataExtractor &data) {
lldb::offset_t offset = 0;
while (data.ValidOffset(offset)) {
uint32_t initial_cu_offset = offset;
DWARFAbbreviationDeclarationSet abbrevDeclSet;
- if (abbrevDeclSet.Extract(data, &offset))
- m_abbrevCollMap[initial_cu_offset] = abbrevDeclSet;
- else
- break;
- }
- m_prev_abbr_offset_pos = m_abbrevCollMap.end();
-}
+ llvm::Error error = abbrevDeclSet.extract(data, &offset);
+ if (error)
+ return error;
-//----------------------------------------------------------------------
-// DWARFDebugAbbrev::Dump()
-//----------------------------------------------------------------------
-void DWARFDebugAbbrev::Dump(Stream *s) const {
- if (m_abbrevCollMap.empty()) {
- s->PutCString("< EMPTY >\n");
- return;
- }
-
- DWARFAbbreviationDeclarationCollMapConstIter pos;
- for (pos = m_abbrevCollMap.begin(); pos != m_abbrevCollMap.end(); ++pos) {
- s->Printf("Abbrev table for offset: 0x%8.8x\n", pos->first);
- pos->second.Dump(s);
+ 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 {
@@ -188,12 +135,10 @@ DWARFDebugAbbrev::GetAbbreviationDeclarationSet(
if (pos != m_abbrevCollMap.end())
return &(pos->second);
- return NULL;
+ return nullptr;
}
-//----------------------------------------------------------------------
// DWARFDebugAbbrev::GetUnsupportedForms()
-//----------------------------------------------------------------------
void DWARFDebugAbbrev::GetUnsupportedForms(
std::set<dw_form_t> &invalid_forms) const {
for (const auto &pair : m_abbrevCollMap)