mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 04:32:44 +01:00
Switch all DWARF variables for tags, attributes and forms over to use the llvm::dwarf enumerations instead of using raw uint16_t values. This allows easier debugging as users can see the values of the enumerations in the variables view that will show the enumeration string instead of just a number.
https://reviews.llvm.org/D26013 llvm-svn: 285309
This commit is contained in:
parent
ecb41605f5
commit
c59e887dd6
@ -12,6 +12,7 @@
|
||||
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/Support/DataExtractor.h"
|
||||
#include "llvm/Support/Dwarf.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
@ -20,16 +21,16 @@ class raw_ostream;
|
||||
class DWARFAbbreviationDeclaration {
|
||||
public:
|
||||
struct AttributeSpec {
|
||||
AttributeSpec(uint16_t Attr, uint16_t Form) : Attr(Attr), Form(Form) {}
|
||||
uint16_t Attr;
|
||||
uint16_t Form;
|
||||
AttributeSpec(dwarf::Attribute A, dwarf::Form F) : Attr(A), Form(F) {}
|
||||
dwarf::Attribute Attr;
|
||||
dwarf::Form Form;
|
||||
};
|
||||
typedef SmallVector<AttributeSpec, 8> AttributeSpecVector;
|
||||
|
||||
DWARFAbbreviationDeclaration();
|
||||
|
||||
uint32_t getCode() const { return Code; }
|
||||
uint32_t getTag() const { return Tag; }
|
||||
dwarf::Tag getTag() const { return Tag; }
|
||||
bool hasChildren() const { return HasChildren; }
|
||||
|
||||
typedef iterator_range<AttributeSpecVector::const_iterator>
|
||||
@ -39,11 +40,13 @@ public:
|
||||
return attr_iterator_range(AttributeSpecs.begin(), AttributeSpecs.end());
|
||||
}
|
||||
|
||||
uint16_t getFormByIndex(uint32_t idx) const {
|
||||
return idx < AttributeSpecs.size() ? AttributeSpecs[idx].Form : 0;
|
||||
dwarf::Form getFormByIndex(uint32_t idx) const {
|
||||
if (idx < AttributeSpecs.size())
|
||||
return AttributeSpecs[idx].Form;
|
||||
return dwarf::Form(0);
|
||||
}
|
||||
|
||||
uint32_t findAttributeIndex(uint16_t attr) const;
|
||||
uint32_t findAttributeIndex(dwarf::Attribute attr) const;
|
||||
bool extract(DataExtractor Data, uint32_t* OffsetPtr);
|
||||
void dump(raw_ostream &OS) const;
|
||||
|
||||
@ -51,7 +54,7 @@ private:
|
||||
void clear();
|
||||
|
||||
uint32_t Code;
|
||||
uint32_t Tag;
|
||||
dwarf::Tag Tag;
|
||||
bool HasChildren;
|
||||
|
||||
AttributeSpecVector AttributeSpecs;
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/DebugInfo/DWARF/DWARFFormValue.h"
|
||||
#include "llvm/DebugInfo/DWARF/DWARFRelocMap.h"
|
||||
#include "llvm/Support/Dwarf.h"
|
||||
#include <cstdint>
|
||||
|
||||
namespace llvm {
|
||||
@ -30,7 +31,7 @@ class DWARFAcceleratorTable {
|
||||
|
||||
struct HeaderData {
|
||||
typedef uint16_t AtomType;
|
||||
typedef uint16_t Form;
|
||||
typedef dwarf::Form Form;
|
||||
uint32_t DIEOffsetBase;
|
||||
SmallVector<std::pair<AtomType, Form>, 3> Atoms;
|
||||
};
|
||||
|
@ -41,7 +41,8 @@ public:
|
||||
void dump(raw_ostream &OS, DWARFUnit *u, unsigned recurseDepth,
|
||||
unsigned indent = 0) const;
|
||||
void dumpAttribute(raw_ostream &OS, DWARFUnit *u, uint32_t *offset_ptr,
|
||||
uint16_t attr, uint16_t form, unsigned indent = 0) const;
|
||||
dwarf::Attribute attr, dwarf::Form form,
|
||||
unsigned indent = 0) const;
|
||||
|
||||
/// Extracts a debug info entry, which is a child of a given unit,
|
||||
/// starting at a given offset. If DIE can't be extracted, returns false and
|
||||
@ -86,24 +87,27 @@ public:
|
||||
return AbbrevDecl;
|
||||
}
|
||||
|
||||
bool getAttributeValue(const DWARFUnit *U, const uint16_t Attr,
|
||||
bool getAttributeValue(const DWARFUnit *U, dwarf::Attribute Attr,
|
||||
DWARFFormValue &FormValue) const;
|
||||
|
||||
const char *getAttributeValueAsString(const DWARFUnit *U, const uint16_t Attr,
|
||||
const char *getAttributeValueAsString(const DWARFUnit *U,
|
||||
dwarf::Attribute Attr,
|
||||
const char *FailValue) const;
|
||||
|
||||
uint64_t getAttributeValueAsAddress(const DWARFUnit *U, const uint16_t Attr,
|
||||
uint64_t getAttributeValueAsAddress(const DWARFUnit *U,
|
||||
dwarf::Attribute Attr,
|
||||
uint64_t FailValue) const;
|
||||
|
||||
uint64_t getAttributeValueAsUnsignedConstant(const DWARFUnit *U,
|
||||
const uint16_t Attr,
|
||||
dwarf::Attribute Attr,
|
||||
uint64_t FailValue) const;
|
||||
|
||||
uint64_t getAttributeValueAsReference(const DWARFUnit *U, const uint16_t Attr,
|
||||
uint64_t getAttributeValueAsReference(const DWARFUnit *U,
|
||||
dwarf::Attribute Attr,
|
||||
uint64_t FailValue) const;
|
||||
|
||||
uint64_t getAttributeValueAsSectionOffset(const DWARFUnit *U,
|
||||
const uint16_t Attr,
|
||||
dwarf::Attribute Attr,
|
||||
uint64_t FailValue) const;
|
||||
|
||||
uint64_t getRangesBaseAttribute(const DWARFUnit *U, uint64_t FailValue) const;
|
||||
|
@ -12,6 +12,7 @@
|
||||
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include "llvm/Support/DataExtractor.h"
|
||||
#include "llvm/Support/Dwarf.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
@ -48,12 +49,12 @@ private:
|
||||
const uint8_t* data;
|
||||
};
|
||||
|
||||
uint16_t Form; // Form for this value.
|
||||
dwarf::Form Form; // Form for this value.
|
||||
ValueType Value; // Contains all data for the form.
|
||||
|
||||
public:
|
||||
DWARFFormValue(uint16_t Form = 0) : Form(Form) {}
|
||||
uint16_t getForm() const { return Form; }
|
||||
DWARFFormValue(dwarf::Form F = dwarf::Form(0)) : Form(F) {}
|
||||
dwarf::Form getForm() const { return Form; }
|
||||
bool isFormClass(FormClass FC) const;
|
||||
|
||||
void dump(raw_ostream &OS, const DWARFUnit *U) const;
|
||||
@ -82,9 +83,9 @@ public:
|
||||
|
||||
bool skipValue(DataExtractor debug_info_data, uint32_t *offset_ptr,
|
||||
const DWARFUnit *u) const;
|
||||
static bool skipValue(uint16_t form, DataExtractor debug_info_data,
|
||||
static bool skipValue(dwarf::Form form, DataExtractor debug_info_data,
|
||||
uint32_t *offset_ptr, const DWARFUnit *u);
|
||||
static bool skipValue(uint16_t form, DataExtractor debug_info_data,
|
||||
static bool skipValue(dwarf::Form form, DataExtractor debug_info_data,
|
||||
uint32_t *offset_ptr, uint16_t Version,
|
||||
uint8_t AddrSize);
|
||||
|
||||
|
@ -42,7 +42,7 @@
|
||||
#define HANDLE_DW_CC(ID, NAME)
|
||||
#endif
|
||||
|
||||
|
||||
HANDLE_DW_TAG(0x0000, null)
|
||||
HANDLE_DW_TAG(0x0001, array_type)
|
||||
HANDLE_DW_TAG(0x0002, class_type)
|
||||
HANDLE_DW_TAG(0x0003, entry_point)
|
||||
|
@ -312,7 +312,8 @@ enum Form : uint16_t {
|
||||
DW_FORM_exprloc = 0x18,
|
||||
DW_FORM_flag_present = 0x19,
|
||||
DW_FORM_ref_sig8 = 0x20,
|
||||
|
||||
|
||||
DW_FORM_lo_user = 0x1f00,
|
||||
// Extensions for Fission proposal
|
||||
DW_FORM_GNU_addr_index = 0x1f01,
|
||||
DW_FORM_GNU_str_index = 0x1f02,
|
||||
|
@ -16,7 +16,7 @@ using namespace dwarf;
|
||||
|
||||
void DWARFAbbreviationDeclaration::clear() {
|
||||
Code = 0;
|
||||
Tag = 0;
|
||||
Tag = DW_TAG_null;
|
||||
HasChildren = false;
|
||||
AttributeSpecs.clear();
|
||||
}
|
||||
@ -26,37 +26,38 @@ DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration() {
|
||||
}
|
||||
|
||||
bool
|
||||
DWARFAbbreviationDeclaration::extract(DataExtractor Data, uint32_t* OffsetPtr) {
|
||||
DWARFAbbreviationDeclaration::extract(DataExtractor Data,
|
||||
uint32_t* OffsetPtr) {
|
||||
clear();
|
||||
Code = Data.getULEB128(OffsetPtr);
|
||||
if (Code == 0) {
|
||||
return false;
|
||||
}
|
||||
Tag = Data.getULEB128(OffsetPtr);
|
||||
Tag = static_cast<llvm::dwarf::Tag>(Data.getULEB128(OffsetPtr));
|
||||
if (Tag == DW_TAG_null) {
|
||||
clear();
|
||||
return false;
|
||||
}
|
||||
uint8_t ChildrenByte = Data.getU8(OffsetPtr);
|
||||
HasChildren = (ChildrenByte == DW_CHILDREN_yes);
|
||||
|
||||
while (true) {
|
||||
uint32_t CurOffset = *OffsetPtr;
|
||||
uint16_t Attr = Data.getULEB128(OffsetPtr);
|
||||
if (CurOffset == *OffsetPtr) {
|
||||
clear();
|
||||
return false;
|
||||
}
|
||||
CurOffset = *OffsetPtr;
|
||||
uint16_t Form = Data.getULEB128(OffsetPtr);
|
||||
if (CurOffset == *OffsetPtr) {
|
||||
clear();
|
||||
return false;
|
||||
}
|
||||
if (Attr == 0 && Form == 0)
|
||||
auto A = static_cast<Attribute>(Data.getULEB128(OffsetPtr));
|
||||
auto F = static_cast<Form>(Data.getULEB128(OffsetPtr));
|
||||
if (A && F) {
|
||||
AttributeSpecs.push_back(AttributeSpec(A, F));
|
||||
} else if (A == 0 && F == 0) {
|
||||
// We successfully reached the end of this abbreviation declaration
|
||||
// since both attribute and form are zero.
|
||||
break;
|
||||
AttributeSpecs.push_back(AttributeSpec(Attr, Form));
|
||||
}
|
||||
|
||||
if (Tag == 0) {
|
||||
clear();
|
||||
return false;
|
||||
} else {
|
||||
// Attribute and form pairs must either both be non-zero, in which case
|
||||
// they are added to the abbreviation declaration, or both be zero to
|
||||
// terminate the abbrevation declaration. In this case only one was
|
||||
// zero which is an error.
|
||||
clear();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -88,7 +89,7 @@ void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
|
||||
}
|
||||
|
||||
uint32_t
|
||||
DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const {
|
||||
DWARFAbbreviationDeclaration::findAttributeIndex(dwarf::Attribute attr) const {
|
||||
for (uint32_t i = 0, e = AttributeSpecs.size(); i != e; ++i) {
|
||||
if (AttributeSpecs[i].Attr == attr)
|
||||
return i;
|
||||
|
@ -39,7 +39,7 @@ bool DWARFAcceleratorTable::extract() {
|
||||
|
||||
for (unsigned i = 0; i < NumAtoms; ++i) {
|
||||
uint16_t AtomType = AccelSection.getU16(&Offset);
|
||||
uint16_t AtomForm = AccelSection.getU16(&Offset);
|
||||
auto AtomForm = static_cast<dwarf::Form>(AccelSection.getU16(&Offset));
|
||||
HdrData.Atoms.push_back(std::make_pair(AtomType, AtomForm));
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,8 @@ static void dumpRanges(raw_ostream &OS, const DWARFAddressRangesVector& Ranges,
|
||||
void DWARFDebugInfoEntryMinimal::dumpAttribute(raw_ostream &OS,
|
||||
DWARFUnit *u,
|
||||
uint32_t *offset_ptr,
|
||||
uint16_t attr, uint16_t form,
|
||||
dwarf::Attribute attr,
|
||||
dwarf::Form form,
|
||||
unsigned indent) const {
|
||||
const char BaseIndent[] = " ";
|
||||
OS << BaseIndent;
|
||||
@ -207,7 +208,7 @@ bool DWARFDebugInfoEntryMinimal::extractFast(const DWARFUnit *U,
|
||||
|
||||
// Skip all data in the .debug_info for the attributes
|
||||
for (const auto &AttrSpec : AbbrevDecl->attributes()) {
|
||||
uint16_t Form = AttrSpec.Form;
|
||||
auto Form = AttrSpec.Form;
|
||||
|
||||
uint8_t FixedFormSize =
|
||||
(Form < FixedFormSizes.size()) ? FixedFormSizes[Form] : 0;
|
||||
@ -232,8 +233,8 @@ bool DWARFDebugInfoEntryMinimal::isSubroutineDIE() const {
|
||||
Tag == DW_TAG_inlined_subroutine;
|
||||
}
|
||||
|
||||
bool DWARFDebugInfoEntryMinimal::getAttributeValue(
|
||||
const DWARFUnit *U, const uint16_t Attr, DWARFFormValue &FormValue) const {
|
||||
bool DWARFDebugInfoEntryMinimal::getAttributeValue(const DWARFUnit *U,
|
||||
dwarf::Attribute Attr, DWARFFormValue &FormValue) const {
|
||||
if (!AbbrevDecl)
|
||||
return false;
|
||||
|
||||
@ -258,7 +259,8 @@ bool DWARFDebugInfoEntryMinimal::getAttributeValue(
|
||||
}
|
||||
|
||||
const char *DWARFDebugInfoEntryMinimal::getAttributeValueAsString(
|
||||
const DWARFUnit *U, const uint16_t Attr, const char *FailValue) const {
|
||||
const DWARFUnit *U, dwarf::Attribute Attr,
|
||||
const char *FailValue) const {
|
||||
DWARFFormValue FormValue;
|
||||
if (!getAttributeValue(U, Attr, FormValue))
|
||||
return FailValue;
|
||||
@ -267,7 +269,8 @@ const char *DWARFDebugInfoEntryMinimal::getAttributeValueAsString(
|
||||
}
|
||||
|
||||
uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsAddress(
|
||||
const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
|
||||
const DWARFUnit *U, dwarf::Attribute Attr,
|
||||
uint64_t FailValue) const {
|
||||
DWARFFormValue FormValue;
|
||||
if (!getAttributeValue(U, Attr, FormValue))
|
||||
return FailValue;
|
||||
@ -276,7 +279,8 @@ uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsAddress(
|
||||
}
|
||||
|
||||
uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsUnsignedConstant(
|
||||
const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
|
||||
const DWARFUnit *U, dwarf::Attribute Attr,
|
||||
uint64_t FailValue) const {
|
||||
DWARFFormValue FormValue;
|
||||
if (!getAttributeValue(U, Attr, FormValue))
|
||||
return FailValue;
|
||||
@ -285,7 +289,8 @@ uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsUnsignedConstant(
|
||||
}
|
||||
|
||||
uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsReference(
|
||||
const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
|
||||
const DWARFUnit *U, dwarf::Attribute Attr,
|
||||
uint64_t FailValue) const {
|
||||
DWARFFormValue FormValue;
|
||||
if (!getAttributeValue(U, Attr, FormValue))
|
||||
return FailValue;
|
||||
@ -294,7 +299,8 @@ uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsReference(
|
||||
}
|
||||
|
||||
uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsSectionOffset(
|
||||
const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
|
||||
const DWARFUnit *U, dwarf::Attribute Attr,
|
||||
uint64_t FailValue) const {
|
||||
DWARFFormValue FormValue;
|
||||
if (!getAttributeValue(U, Attr, FormValue))
|
||||
return FailValue;
|
||||
|
@ -123,6 +123,8 @@ bool DWARFFormValue::isFormClass(DWARFFormValue::FormClass FC) const {
|
||||
case DW_FORM_GNU_str_index:
|
||||
case DW_FORM_GNU_strp_alt:
|
||||
return (FC == FC_String);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// In DWARF3 DW_FORM_data4 and DW_FORM_data8 served also as a section offset.
|
||||
// Don't check for DWARF version here, as some producers may still do this
|
||||
@ -208,7 +210,7 @@ bool DWARFFormValue::extractValue(DataExtractor data, uint32_t *offset_ptr,
|
||||
Value.cstr = data.getCStr(offset_ptr);
|
||||
break;
|
||||
case DW_FORM_indirect:
|
||||
Form = data.getULEB128(offset_ptr);
|
||||
Form = static_cast<dwarf::Form>(data.getULEB128(offset_ptr));
|
||||
indirect = true;
|
||||
break;
|
||||
case DW_FORM_sec_offset:
|
||||
@ -259,14 +261,15 @@ DWARFFormValue::skipValue(DataExtractor debug_info_data, uint32_t* offset_ptr,
|
||||
}
|
||||
|
||||
bool
|
||||
DWARFFormValue::skipValue(uint16_t form, DataExtractor debug_info_data,
|
||||
DWARFFormValue::skipValue(dwarf::Form form, DataExtractor debug_info_data,
|
||||
uint32_t *offset_ptr, const DWARFUnit *cu) {
|
||||
return skipValue(form, debug_info_data, offset_ptr, cu->getVersion(),
|
||||
cu->getAddressByteSize());
|
||||
}
|
||||
bool DWARFFormValue::skipValue(uint16_t form, DataExtractor debug_info_data,
|
||||
uint32_t *offset_ptr, uint16_t Version,
|
||||
uint8_t AddrSize) {
|
||||
bool
|
||||
DWARFFormValue::skipValue(dwarf::Form form, DataExtractor debug_info_data,
|
||||
uint32_t *offset_ptr, uint16_t Version,
|
||||
uint8_t AddrSize) {
|
||||
bool indirect = false;
|
||||
do {
|
||||
switch (form) {
|
||||
@ -349,7 +352,7 @@ bool DWARFFormValue::skipValue(uint16_t form, DataExtractor debug_info_data,
|
||||
|
||||
case DW_FORM_indirect:
|
||||
indirect = true;
|
||||
form = debug_info_data.getULEB128(offset_ptr);
|
||||
form = static_cast<dwarf::Form>(debug_info_data.getULEB128(offset_ptr));
|
||||
break;
|
||||
|
||||
// FIXME: 4 for DWARF32, 8 for DWARF64.
|
||||
|
@ -112,8 +112,8 @@ struct CompileUnitIdentifiers {
|
||||
};
|
||||
|
||||
static Expected<const char *>
|
||||
getIndexedString(uint32_t Form, DataExtractor InfoData, uint32_t &InfoOffset,
|
||||
StringRef StrOffsets, StringRef Str) {
|
||||
getIndexedString(dwarf::Form Form, DataExtractor InfoData,
|
||||
uint32_t &InfoOffset, StringRef StrOffsets, StringRef Str) {
|
||||
if (Form == dwarf::DW_FORM_string)
|
||||
return InfoData.getCStr(&InfoOffset);
|
||||
if (Form != dwarf::DW_FORM_GNU_str_index)
|
||||
@ -142,16 +142,16 @@ static Expected<CompileUnitIdentifiers> getCUIdentifiers(StringRef Abbrev,
|
||||
|
||||
DataExtractor AbbrevData(Abbrev, true, 0);
|
||||
uint32_t AbbrevOffset = getCUAbbrev(Abbrev, AbbrCode);
|
||||
uint64_t Tag = AbbrevData.getULEB128(&AbbrevOffset);
|
||||
auto Tag = static_cast<dwarf::Tag>(AbbrevData.getULEB128(&AbbrevOffset));
|
||||
if (Tag != dwarf::DW_TAG_compile_unit)
|
||||
return make_error<DWPError>("top level DIE is not a compile unit");
|
||||
// DW_CHILDREN
|
||||
AbbrevData.getU8(&AbbrevOffset);
|
||||
uint32_t Name;
|
||||
uint32_t Form;
|
||||
dwarf::Form Form;
|
||||
CompileUnitIdentifiers ID;
|
||||
while ((Name = AbbrevData.getULEB128(&AbbrevOffset)) |
|
||||
(Form = AbbrevData.getULEB128(&AbbrevOffset)) &&
|
||||
(Form = static_cast<dwarf::Form>(AbbrevData.getULEB128(&AbbrevOffset))) &&
|
||||
(Name != 0 || Form != 0)) {
|
||||
switch (Name) {
|
||||
case dwarf::DW_AT_name: {
|
||||
|
@ -33,7 +33,7 @@ TEST(DWARFFormValue, FixedFormSizes) {
|
||||
EXPECT_EQ(0U, DWARFFormValue::getFixedFormSizes(16, 2).size());
|
||||
}
|
||||
|
||||
bool isFormClass(uint16_t Form, DWARFFormValue::FormClass FC) {
|
||||
bool isFormClass(dwarf::Form Form, DWARFFormValue::FormClass FC) {
|
||||
return DWARFFormValue(Form).isFormClass(FC);
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ TEST(DWARFFormValue, FormClass) {
|
||||
}
|
||||
|
||||
template<typename RawTypeT>
|
||||
DWARFFormValue createDataXFormValue(uint16_t Form, RawTypeT Value) {
|
||||
DWARFFormValue createDataXFormValue(dwarf::Form Form, RawTypeT Value) {
|
||||
char Raw[sizeof(RawTypeT)];
|
||||
memcpy(Raw, &Value, sizeof(RawTypeT));
|
||||
uint32_t Offset = 0;
|
||||
|
Loading…
Reference in New Issue
Block a user