bulbazord updated this revision to Diff 523500.
bulbazord marked 2 inline comments as done.
bulbazord added a comment.
Redo include order in DWARFDebugAbbrev.h to match project guidelines
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D150716/new/
https://reviews.llvm.org/D150716
Files:
lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
Index: lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
===================================================================
--- lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
+++ lldb/unittests/SymbolFile/DWARF/SymbolFileDWARFTests.cpp
@@ -15,7 +15,6 @@
#include "llvm/Support/Path.h"
#include "Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h"
-#include "Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h"
#include "Plugins/SymbolFile/DWARF/DWARFDataExtractor.h"
#include "Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h"
#include "Plugins/SymbolFile/DWARF/DWARFDebugArangeSet.h"
@@ -105,13 +104,13 @@
EXPECT_EQ(abbrev_set.GetIndexOffset(), 1u);
auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(1);
- EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
- EXPECT_TRUE(abbrev1->HasChildren());
- EXPECT_EQ(abbrev1->NumAttributes(), 1u);
+ EXPECT_EQ(abbrev1->getTag(), DW_TAG_compile_unit);
+ EXPECT_TRUE(abbrev1->hasChildren());
+ EXPECT_EQ(abbrev1->getNumAttributes(), 1u);
auto abbrev2 = abbrev_set.GetAbbreviationDeclaration(2);
- EXPECT_EQ(abbrev2->Tag(), DW_TAG_subprogram);
- EXPECT_FALSE(abbrev2->HasChildren());
- EXPECT_EQ(abbrev2->NumAttributes(), 1u);
+ EXPECT_EQ(abbrev2->getTag(), DW_TAG_subprogram);
+ EXPECT_FALSE(abbrev2->hasChildren());
+ EXPECT_EQ(abbrev2->getNumAttributes(), 1u);
}
TEST_F(SymbolFileDWARFTests, TestAbbrevOrder1Start5) {
@@ -150,13 +149,13 @@
EXPECT_EQ(abbrev_set.GetIndexOffset(), 5u);
auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(5);
- EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
- EXPECT_TRUE(abbrev1->HasChildren());
- EXPECT_EQ(abbrev1->NumAttributes(), 1u);
+ EXPECT_EQ(abbrev1->getTag(), DW_TAG_compile_unit);
+ EXPECT_TRUE(abbrev1->hasChildren());
+ EXPECT_EQ(abbrev1->getNumAttributes(), 1u);
auto abbrev2 = abbrev_set.GetAbbreviationDeclaration(6);
- EXPECT_EQ(abbrev2->Tag(), DW_TAG_subprogram);
- EXPECT_FALSE(abbrev2->HasChildren());
- EXPECT_EQ(abbrev2->NumAttributes(), 1u);
+ EXPECT_EQ(abbrev2->getTag(), DW_TAG_subprogram);
+ EXPECT_FALSE(abbrev2->hasChildren());
+ EXPECT_EQ(abbrev2->getNumAttributes(), 1u);
}
TEST_F(SymbolFileDWARFTests, TestAbbrevOutOfOrder) {
@@ -195,13 +194,13 @@
EXPECT_EQ(abbrev_set.GetIndexOffset(), UINT32_MAX);
auto abbrev1 = abbrev_set.GetAbbreviationDeclaration(2);
- EXPECT_EQ(abbrev1->Tag(), DW_TAG_compile_unit);
- EXPECT_TRUE(abbrev1->HasChildren());
- EXPECT_EQ(abbrev1->NumAttributes(), 1u);
+ EXPECT_EQ(abbrev1->getTag(), DW_TAG_compile_unit);
+ EXPECT_TRUE(abbrev1->hasChildren());
+ EXPECT_EQ(abbrev1->getNumAttributes(), 1u);
auto abbrev2 = abbrev_set.GetAbbreviationDeclaration(1);
- EXPECT_EQ(abbrev2->Tag(), DW_TAG_subprogram);
- EXPECT_FALSE(abbrev2->HasChildren());
- EXPECT_EQ(abbrev2->NumAttributes(), 1u);
+ EXPECT_EQ(abbrev2->getTag(), DW_TAG_subprogram);
+ EXPECT_FALSE(abbrev2->hasChildren());
+ EXPECT_EQ(abbrev2->getNumAttributes(), 1u);
}
TEST_F(SymbolFileDWARFTests, TestAbbrevInvalidNULLTag) {
@@ -226,9 +225,8 @@
llvm::Error error = abbrev_set.extract(data, &data_offset);
// Verify we get an error
EXPECT_TRUE(bool(error));
- EXPECT_EQ("abbrev decl requires non-null tag.",
+ EXPECT_EQ("abbreviation declaration requires a non-null tag",
llvm::toString(std::move(error)));
-
}
TEST_F(SymbolFileDWARFTests, TestAbbrevNullAttrValidForm) {
@@ -255,7 +253,8 @@
llvm::Error error = abbrev_set.extract(data, &data_offset);
// Verify we get an error
EXPECT_TRUE(bool(error));
- EXPECT_EQ("malformed abbreviation declaration attribute",
+ EXPECT_EQ("malformed abbreviation declaration attribute. Either the "
+ "attribute or the form is zero while the other is not",
llvm::toString(std::move(error)));
}
@@ -283,7 +282,8 @@
llvm::Error error = abbrev_set.extract(data, &data_offset);
// Verify we get an error
EXPECT_TRUE(bool(error));
- EXPECT_EQ("malformed abbreviation declaration attribute",
+ EXPECT_EQ("malformed abbreviation declaration attribute. Either the "
+ "attribute or the form is zero while the other is not",
llvm::toString(std::move(error)));
}
@@ -309,8 +309,9 @@
llvm::Error error = abbrev_set.extract(data, &data_offset);
// Verify we get an error
EXPECT_TRUE(bool(error));
- EXPECT_EQ("abbreviation declaration attribute list not terminated with a "
- "null entry", llvm::toString(std::move(error)));
+ EXPECT_EQ("abbreviation declaration attribute list was not terminated with a "
+ "null entry",
+ llvm::toString(std::move(error)));
}
TEST_F(SymbolFileDWARFTests, ParseArangesNonzeroSegmentSize) {
Index: lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
+++ lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.h
@@ -40,7 +40,6 @@
// Forward Declarations for this DWARF plugin
class DebugMapModule;
-class DWARFAbbreviationDeclaration;
class DWARFAbbreviationDeclarationSet;
class DWARFCompileUnit;
class DWARFDebugAbbrev;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDefines.h
@@ -14,8 +14,6 @@
namespace lldb_private {
-enum class DWARFEnumState { MoreItems, Complete };
-
typedef uint32_t DRC_class; // Holds DRC_* class bitfields
const char *DW_TAG_value_to_name(uint32_t val);
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.h
@@ -12,7 +12,7 @@
#include "SymbolFileDWARF.h"
#include "llvm/ADT/SmallVector.h"
-#include "DWARFAbbreviationDeclaration.h"
+#include "DWARFAttribute.h"
#include "DWARFBaseDIE.h"
#include "DWARFDebugAbbrev.h"
#include "DWARFDebugRanges.h"
@@ -21,6 +21,8 @@
#include <set>
#include <vector>
+#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
+
class DWARFDeclContext;
#define DIE_SIBLING_IDX_BITSIZE 31
@@ -111,7 +113,7 @@
std::optional<int> &call_column,
lldb_private::DWARFExpressionList *frame_base = nullptr) const;
- const DWARFAbbreviationDeclaration *
+ const llvm::DWARFAbbreviationDeclaration *
GetAbbreviationDeclarationPtr(const DWARFUnit *cu) const;
lldb::offset_t GetFirstAttributeOffset() const;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugInfoEntry.cpp
@@ -69,14 +69,12 @@
*offset_ptr = UINT32_MAX;
return false;
}
- m_tag = abbrevDecl->Tag();
- m_has_children = abbrevDecl->HasChildren();
+ m_tag = abbrevDecl->getTag();
+ m_has_children = abbrevDecl->hasChildren();
// Skip all data in the .debug_info or .debug_types for the attributes
- const uint32_t numAttributes = abbrevDecl->NumAttributes();
- uint32_t i;
dw_form_t form;
- for (i = 0; i < numAttributes; ++i) {
- form = abbrevDecl->GetFormByIndexUnchecked(i);
+ for (const auto &attribute : abbrevDecl->attributes()) {
+ form = attribute.Form;
std::optional<uint8_t> fixed_skip_size =
DWARFFormValue::GetFixedSize(form, cu);
if (fixed_skip_size)
@@ -228,6 +226,15 @@
return DWARFRangeList();
}
+static void ExtractAttrAndFormValue(
+ const llvm::DWARFAbbreviationDeclaration::AttributeSpec &attr_spec,
+ dw_attr_t &attr, DWARFFormValue &form_value) {
+ attr = attr_spec.Attr;
+ form_value.FormRef() = attr_spec.Form;
+ if (attr_spec.isImplicitConst())
+ form_value.SetSigned(attr_spec.getImplicitConstValue());
+}
+
// GetDIENamesAndRanges
//
// Gets the valid address ranges for a given DIE by looking for a
@@ -243,25 +250,22 @@
std::vector<DWARFDIE> dies;
bool set_frame_base_loclist_addr = false;
- const auto *abbrevDecl = GetAbbreviationDeclarationPtr(cu);
-
SymbolFileDWARF &dwarf = cu->GetSymbolFileDWARF();
lldb::ModuleSP module = dwarf.GetObjectFile()->GetModule();
- if (abbrevDecl) {
+ if (const auto *abbrevDecl = GetAbbreviationDeclarationPtr(cu)) {
const DWARFDataExtractor &data = cu->GetData();
lldb::offset_t offset = GetFirstAttributeOffset();
if (!data.ValidOffset(offset))
return false;
- const uint32_t numAttributes = abbrevDecl->NumAttributes();
bool do_offset = false;
- for (uint32_t i = 0; i < numAttributes; ++i) {
+ for (const auto &attribute : abbrevDecl->attributes()) {
DWARFFormValue form_value(cu);
dw_attr_t attr;
- abbrevDecl->GetAttrAndFormValueByIndex(i, attr, form_value);
+ ExtractAttrAndFormValue(attribute, attr, form_value);
if (form_value.ExtractValue(data, &offset)) {
switch (attr) {
@@ -415,54 +419,54 @@
Recurse recurse,
uint32_t curr_depth) const {
const auto *abbrevDecl = GetAbbreviationDeclarationPtr(cu);
- if (abbrevDecl) {
- const DWARFDataExtractor &data = cu->GetData();
- lldb::offset_t offset = GetFirstAttributeOffset();
-
- const uint32_t num_attributes = abbrevDecl->NumAttributes();
- for (uint32_t i = 0; i < num_attributes; ++i) {
- DWARFFormValue form_value(cu);
- dw_attr_t attr;
- abbrevDecl->GetAttrAndFormValueByIndex(i, attr, form_value);
- const dw_form_t form = form_value.Form();
+ if (!abbrevDecl) {
+ attributes.Clear();
+ return;
+ }
- // If we are tracking down DW_AT_specification or DW_AT_abstract_origin
- // attributes, the depth will be non-zero. We need to omit certain
- // attributes that don't make sense.
- switch (attr) {
- case DW_AT_sibling:
- case DW_AT_declaration:
- if (curr_depth > 0) {
- // This attribute doesn't make sense when combined with the DIE that
- // references this DIE. We know a DIE is referencing this DIE because
- // curr_depth is not zero
- break;
- }
- [[fallthrough]];
- default:
- attributes.Append(form_value, offset, attr);
+ const DWARFDataExtractor &data = cu->GetData();
+ lldb::offset_t offset = GetFirstAttributeOffset();
+
+ for (const auto &attribute : abbrevDecl->attributes()) {
+ DWARFFormValue form_value(cu);
+ dw_attr_t attr;
+ ExtractAttrAndFormValue(attribute, attr, form_value);
+
+ // If we are tracking down DW_AT_specification or DW_AT_abstract_origin
+ // attributes, the depth will be non-zero. We need to omit certain
+ // attributes that don't make sense.
+ switch (attr) {
+ case DW_AT_sibling:
+ case DW_AT_declaration:
+ if (curr_depth > 0) {
+ // This attribute doesn't make sense when combined with the DIE that
+ // references this DIE. We know a DIE is referencing this DIE because
+ // curr_depth is not zero
break;
}
+ [[fallthrough]];
+ default:
+ attributes.Append(form_value, offset, attr);
+ break;
+ }
- if (recurse == Recurse::yes &&
- ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin))) {
- if (form_value.ExtractValue(data, &offset)) {
- DWARFDIE spec_die = form_value.Reference();
- if (spec_die)
- spec_die.GetDIE()->GetAttributes(spec_die.GetCU(), attributes,
- recurse, curr_depth + 1);
- }
- } else {
- std::optional<uint8_t> fixed_skip_size =
- DWARFFormValue::GetFixedSize(form, cu);
- if (fixed_skip_size)
- offset += *fixed_skip_size;
- else
- DWARFFormValue::SkipValue(form, data, &offset, cu);
+ if (recurse == Recurse::yes &&
+ ((attr == DW_AT_specification) || (attr == DW_AT_abstract_origin))) {
+ if (form_value.ExtractValue(data, &offset)) {
+ DWARFDIE spec_die = form_value.Reference();
+ if (spec_die)
+ spec_die.GetDIE()->GetAttributes(spec_die.GetCU(), attributes,
+ recurse, curr_depth + 1);
}
+ } else {
+ const dw_form_t form = form_value.Form();
+ std::optional<uint8_t> fixed_skip_size =
+ DWARFFormValue::GetFixedSize(form, cu);
+ if (fixed_skip_size)
+ offset += *fixed_skip_size;
+ else
+ DWARFFormValue::SkipValue(form, data, &offset, cu);
}
- } else {
- attributes.Clear();
}
}
@@ -477,20 +481,20 @@
dw_offset_t *end_attr_offset_ptr,
bool check_specification_or_abstract_origin) const {
if (const auto *abbrevDecl = GetAbbreviationDeclarationPtr(cu)) {
- uint32_t attr_idx = abbrevDecl->FindAttributeIndex(attr);
+ std::optional<uint32_t> attr_idx = abbrevDecl->findAttributeIndex(attr);
- if (attr_idx != DW_INVALID_INDEX) {
+ if (attr_idx) {
const DWARFDataExtractor &data = cu->GetData();
lldb::offset_t offset = GetFirstAttributeOffset();
uint32_t idx = 0;
- while (idx < attr_idx)
- DWARFFormValue::SkipValue(abbrevDecl->GetFormByIndex(idx++),
- data, &offset, cu);
+ while (idx < *attr_idx)
+ DWARFFormValue::SkipValue(abbrevDecl->getFormByIndex(idx++), data,
+ &offset, cu);
const dw_offset_t attr_offset = offset;
form_value.SetUnit(cu);
- form_value.SetForm(abbrevDecl->GetFormByIndex(idx));
+ form_value.SetForm(abbrevDecl->getFormByIndex(idx));
if (form_value.ExtractValue(data, &offset)) {
if (end_attr_offset_ptr)
*end_attr_offset_ptr = offset;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.h
@@ -9,13 +9,14 @@
#ifndef LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGABBREV_H
#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFDEBUGABBREV_H
-#include <list>
-#include <map>
-
+#include "DWARFDefines.h"
#include "lldb/lldb-private.h"
-#include "DWARFAbbreviationDeclaration.h"
-#include "DWARFDefines.h"
+#include "llvm/DebugInfo/DWARF/DWARFAbbreviationDeclaration.h"
+
+#include <map>
+
+using DWARFAbbreviationDeclaration = llvm::DWARFAbbreviationDeclaration;
typedef std::vector<DWARFAbbreviationDeclaration>
DWARFAbbreviationDeclarationColl;
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
+++ lldb/source/Plugins/SymbolFile/DWARF/DWARFDebugAbbrev.cpp
@@ -8,6 +8,7 @@
#include "DWARFDebugAbbrev.h"
#include "DWARFDataExtractor.h"
+#include "DWARFFormValue.h"
#include "lldb/Utility/Stream.h"
using namespace lldb;
@@ -23,26 +24,26 @@
llvm::Error
DWARFAbbreviationDeclarationSet::extract(const DWARFDataExtractor &data,
lldb::offset_t *offset_ptr) {
+ llvm::DataExtractor llvm_data = data.GetAsLLVM();
const lldb::offset_t begin_offset = *offset_ptr;
m_offset = begin_offset;
Clear();
DWARFAbbreviationDeclaration abbrevDeclaration;
uint32_t prev_abbr_code = 0;
while (true) {
- llvm::Expected<DWARFEnumState> es =
- abbrevDeclaration.extract(data, offset_ptr);
+ llvm::Expected<llvm::DWARFAbbreviationDeclaration::ExtractState> es =
+ abbrevDeclaration.extract(llvm_data, offset_ptr);
if (!es)
return es.takeError();
- if (*es == DWARFEnumState::Complete)
+ if (*es == llvm::DWARFAbbreviationDeclaration::ExtractState::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()) {
- // Out of order indexes, we can't do O(1) lookups...
+ m_idx_offset = abbrevDeclaration.getCode();
+ else if (prev_abbr_code + 1 != abbrevDeclaration.getCode())
m_idx_offset = UINT32_MAX;
- }
- prev_abbr_code = abbrevDeclaration.Code();
+
+ prev_abbr_code = abbrevDeclaration.getCode();
+ m_decls.push_back(abbrevDeclaration);
}
return llvm::ErrorSuccess();
}
@@ -52,29 +53,24 @@
DWARFAbbreviationDeclarationSet::GetAbbreviationDeclaration(
uint32_t abbrCode) const {
if (m_idx_offset == UINT32_MAX) {
- DWARFAbbreviationDeclarationCollConstIter pos;
- DWARFAbbreviationDeclarationCollConstIter end = m_decls.end();
- for (pos = m_decls.begin(); pos != end; ++pos) {
- if (pos->Code() == abbrCode)
- return &(*pos);
+ for (const auto &decl : m_decls) {
+ if (decl.getCode() == abbrCode)
+ return &decl;
}
- } else {
- uint32_t idx = abbrCode - m_idx_offset;
- if (idx < m_decls.size())
- return &m_decls[idx];
+ return nullptr;
}
- return nullptr;
+ if (abbrCode < m_idx_offset || abbrCode >= m_idx_offset + m_decls.size())
+ return nullptr;
+ return &m_decls[abbrCode - m_idx_offset];
}
// DWARFAbbreviationDeclarationSet::GetUnsupportedForms()
void DWARFAbbreviationDeclarationSet::GetUnsupportedForms(
std::set<dw_form_t> &invalid_forms) const {
- for (const auto &abbr_decl : m_decls) {
- const size_t num_attrs = abbr_decl.NumAttributes();
- for (size_t i=0; i<num_attrs; ++i) {
- dw_form_t form = abbr_decl.GetFormByIndex(i);
- if (!DWARFFormValue::FormIsSupported(form))
- invalid_forms.insert(form);
+ for (const auto &decl : m_decls) {
+ for (const auto &attr : decl.attributes()) {
+ if (!DWARFFormValue::FormIsSupported(attr.Form))
+ invalid_forms.insert(attr.Form);
}
}
}
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.h
+++ /dev/null
@@ -1,92 +0,0 @@
-//===-- DWARFAbbreviationDeclaration.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_DWARFABBREVIATIONDECLARATION_H
-#define LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFABBREVIATIONDECLARATION_H
-
-#include "DWARFAttribute.h"
-#include "DWARFDefines.h"
-#include "SymbolFileDWARF.h"
-#include "llvm/Support/Error.h"
-
-class DWARFAbbreviationDeclaration {
-public:
- struct AttributeSpec {
- AttributeSpec(dw_attr_t attr, dw_form_t form, int64_t value)
- : m_attr(attr), m_form(form), m_value(value) {}
-
- AttributeSpec(dw_attr_t attr, dw_form_t form)
- : m_attr(attr), m_form(form), m_value(0) {}
-
- bool IsImplicitConst() const {
- return m_form == lldb_private::dwarf::DW_FORM_implicit_const;
- }
-
- int64_t GetImplicitConstValue() const { return m_value; }
-
- dw_attr_t GetAttribute() const { return m_attr; }
-
- dw_form_t GetForm() const { return m_form; }
-
- private:
- dw_attr_t m_attr;
- dw_form_t m_form;
- int64_t m_value;
- };
-
- enum { InvalidCode = 0 };
- DWARFAbbreviationDeclaration();
-
- // For hand crafting an abbreviation declaration
- DWARFAbbreviationDeclaration(dw_tag_t tag, uint8_t has_children);
-
- uint32_t Code() const { return m_code; }
- void SetCode(uint32_t code) { m_code = code; }
- dw_tag_t Tag() const { return m_tag; }
- bool HasChildren() const { return m_has_children; }
- size_t NumAttributes() const { return m_attributes.size(); }
- dw_form_t GetFormByIndex(uint32_t idx) const {
- return m_attributes.size() > idx ? m_attributes[idx].GetForm()
- : dw_form_t(0);
- }
-
- // idx is assumed to be valid when calling GetAttrAndFormByIndex()
- void GetAttrAndFormValueByIndex(uint32_t idx, dw_attr_t &attr,
- DWARFFormValue &form_value) const {
- const AttributeSpec &spec = m_attributes[idx];
- attr = spec.GetAttribute();
- form_value.FormRef() = spec.GetForm();
- if (spec.IsImplicitConst())
- form_value.SetSigned(spec.GetImplicitConstValue());
- }
- dw_form_t GetFormByIndexUnchecked(uint32_t idx) const {
- return m_attributes[idx].GetForm();
- }
- uint32_t FindAttributeIndex(dw_attr_t attr) const;
-
- /// Extract one abbreviation declaration and all of its associated attributes.
- /// Possible return values:
- /// DWARFEnumState::Complete - the extraction completed successfully. This
- /// was the last abbrev decl in a sequence, and the user should not call
- /// this function again.
- /// DWARFEnumState::MoreItems - the extraction completed successfully. The
- /// user should call this function again to retrieve the next decl.
- /// llvm::Error - A parsing error occurred. The debug info is malformed.
- llvm::Expected<lldb_private::DWARFEnumState>
- extract(const lldb_private::DWARFDataExtractor &data,
- lldb::offset_t *offset_ptr);
- bool IsValid();
-
-protected:
- uint32_t m_code = InvalidCode;
- dw_tag_t m_tag = llvm::dwarf::DW_TAG_null;
- uint8_t m_has_children = 0;
- llvm::SmallVector<AttributeSpec, 4> m_attributes;
-};
-
-#endif // LLDB_SOURCE_PLUGINS_SYMBOLFILE_DWARF_DWARFABBREVIATIONDECLARATION_H
Index: lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/DWARFAbbreviationDeclaration.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-//===-- DWARFAbbreviationDeclaration.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 "DWARFAbbreviationDeclaration.h"
-
-#include "lldb/Core/dwarf.h"
-#include "lldb/Utility/Stream.h"
-
-#include "llvm/Object/Error.h"
-
-#include "DWARFFormValue.h"
-
-using namespace lldb_private;
-using namespace lldb_private::dwarf;
-
-DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration() : m_attributes() {}
-
-DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration(dw_tag_t tag,
- uint8_t has_children)
- : m_tag(tag), m_has_children(has_children), m_attributes() {}
-
-llvm::Expected<DWARFEnumState>
-DWARFAbbreviationDeclaration::extract(const DWARFDataExtractor &data,
- lldb::offset_t *offset_ptr) {
- m_code = data.GetULEB128(offset_ptr);
- if (m_code == 0)
- return DWARFEnumState::Complete;
-
- m_attributes.clear();
- m_tag = static_cast<dw_tag_t>(data.GetULEB128(offset_ptr));
- if (m_tag == DW_TAG_null)
- return llvm::make_error<llvm::object::GenericBinaryError>(
- "abbrev decl requires non-null tag.");
-
- m_has_children = data.GetU8(offset_ptr);
-
- while (data.ValidOffset(*offset_ptr)) {
- auto attr = static_cast<dw_attr_t>(data.GetULEB128(offset_ptr));
- auto form = static_cast<dw_form_t>(data.GetULEB128(offset_ptr));
-
- // This is the last attribute for this abbrev decl, but there may still be
- // more abbrev decls, so return MoreItems to indicate to the caller that
- // they should call this function again.
- if (!attr && !form)
- return DWARFEnumState::MoreItems;
-
- if (!attr || !form)
- return llvm::make_error<llvm::object::GenericBinaryError>(
- "malformed abbreviation declaration attribute");
-
- if (form == DW_FORM_implicit_const) {
- int64_t value = data.GetSLEB128(offset_ptr);
- m_attributes.emplace_back(attr, form, value);
- continue;
- }
-
- m_attributes.emplace_back(attr, form);
- }
-
- return llvm::make_error<llvm::object::GenericBinaryError>(
- "abbreviation declaration attribute list not terminated with a null "
- "entry");
-}
-
-bool DWARFAbbreviationDeclaration::IsValid() {
- return m_code != 0 && m_tag != llvm::dwarf::DW_TAG_null;
-}
-
-uint32_t
-DWARFAbbreviationDeclaration::FindAttributeIndex(dw_attr_t attr) const {
- for (size_t i = 0; i < m_attributes.size(); ++i) {
- if (m_attributes[i].GetAttribute() == attr)
- return i;
- }
- return DW_INVALID_INDEX;
-}
Index: lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
===================================================================
--- lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
+++ lldb/source/Plugins/SymbolFile/DWARF/CMakeLists.txt
@@ -10,7 +10,6 @@
AppleDWARFIndex.cpp
DebugNamesDWARFIndex.cpp
DIERef.cpp
- DWARFAbbreviationDeclaration.cpp
DWARFASTParser.cpp
DWARFASTParserClang.cpp
DWARFAttribute.cpp
_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits