forked from OSchip/llvm-project
DWARFAbbreviationDeclaration: remove dead code, refactor parsing code and make it more robust. No functionality change.
llvm-svn: 193770
This commit is contained in:
parent
74f4c749cf
commit
d5cc93c3ae
|
@ -14,37 +14,51 @@
|
|||
using namespace llvm;
|
||||
using namespace dwarf;
|
||||
|
||||
bool
|
||||
DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr){
|
||||
return extract(data, offset_ptr, data.getULEB128(offset_ptr));
|
||||
void DWARFAbbreviationDeclaration::clear() {
|
||||
Code = 0;
|
||||
Tag = 0;
|
||||
HasChildren = false;
|
||||
Attributes.clear();
|
||||
}
|
||||
|
||||
DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration() {
|
||||
clear();
|
||||
}
|
||||
|
||||
bool
|
||||
DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr,
|
||||
uint32_t code) {
|
||||
Code = code;
|
||||
Attribute.clear();
|
||||
if (Code) {
|
||||
Tag = data.getULEB128(offset_ptr);
|
||||
HasChildren = data.getU8(offset_ptr);
|
||||
DWARFAbbreviationDeclaration::extract(DataExtractor Data, uint32_t* OffsetPtr) {
|
||||
clear();
|
||||
Code = Data.getULEB128(OffsetPtr);
|
||||
if (Code == 0) {
|
||||
return false;
|
||||
}
|
||||
Tag = Data.getULEB128(OffsetPtr);
|
||||
uint8_t ChildrenByte = Data.getU8(OffsetPtr);
|
||||
HasChildren = (ChildrenByte == DW_CHILDREN_yes);
|
||||
|
||||
while (data.isValidOffset(*offset_ptr)) {
|
||||
uint16_t attr = data.getULEB128(offset_ptr);
|
||||
uint16_t form = data.getULEB128(offset_ptr);
|
||||
|
||||
if (attr && form)
|
||||
Attribute.push_back(DWARFAttribute(attr, form));
|
||||
else
|
||||
break;
|
||||
while (true) {
|
||||
uint32_t CurOffset = *OffsetPtr;
|
||||
uint16_t Attr = Data.getULEB128(OffsetPtr);
|
||||
if (CurOffset == *OffsetPtr) {
|
||||
clear();
|
||||
return false;
|
||||
}
|
||||
|
||||
return Tag != 0;
|
||||
} else {
|
||||
Tag = 0;
|
||||
HasChildren = false;
|
||||
CurOffset = *OffsetPtr;
|
||||
uint16_t Form = Data.getULEB128(OffsetPtr);
|
||||
if (CurOffset == *OffsetPtr) {
|
||||
clear();
|
||||
return false;
|
||||
}
|
||||
if (Attr == 0 && Form == 0)
|
||||
break;
|
||||
Attributes.push_back(AttributeSpec(Attr, Form));
|
||||
}
|
||||
|
||||
return false;
|
||||
if (Tag == 0) {
|
||||
clear();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
|
||||
|
@ -55,19 +69,19 @@ void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
|
|||
else
|
||||
OS << format("DW_TAG_Unknown_%x", getTag());
|
||||
OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n';
|
||||
for (unsigned i = 0, e = Attribute.size(); i != e; ++i) {
|
||||
for (unsigned i = 0, e = Attributes.size(); i != e; ++i) {
|
||||
OS << '\t';
|
||||
const char *attrString = AttributeString(Attribute[i].getAttribute());
|
||||
const char *attrString = AttributeString(Attributes[i].Attr);
|
||||
if (attrString)
|
||||
OS << attrString;
|
||||
else
|
||||
OS << format("DW_AT_Unknown_%x", Attribute[i].getAttribute());
|
||||
OS << format("DW_AT_Unknown_%x", Attributes[i].Attr);
|
||||
OS << '\t';
|
||||
const char *formString = FormEncodingString(Attribute[i].getForm());
|
||||
const char *formString = FormEncodingString(Attributes[i].Form);
|
||||
if (formString)
|
||||
OS << formString;
|
||||
else
|
||||
OS << format("DW_FORM_Unknown_%x", Attribute[i].getForm());
|
||||
OS << format("DW_FORM_Unknown_%x", Attributes[i].Form);
|
||||
OS << '\n';
|
||||
}
|
||||
OS << '\n';
|
||||
|
@ -75,8 +89,8 @@ void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
|
|||
|
||||
uint32_t
|
||||
DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const {
|
||||
for (uint32_t i = 0, e = Attribute.size(); i != e; ++i) {
|
||||
if (Attribute[i].getAttribute() == attr)
|
||||
for (uint32_t i = 0, e = Attributes.size(); i != e; ++i) {
|
||||
if (Attributes[i].Attr == attr)
|
||||
return i;
|
||||
}
|
||||
return -1U;
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
#ifndef LLVM_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
|
||||
#define LLVM_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
|
||||
|
||||
#include "DWARFAttribute.h"
|
||||
#include "llvm/ADT/SmallVector.h"
|
||||
#include "llvm/Support/DataExtractor.h"
|
||||
|
||||
|
@ -22,31 +21,33 @@ class DWARFAbbreviationDeclaration {
|
|||
uint32_t Code;
|
||||
uint32_t Tag;
|
||||
bool HasChildren;
|
||||
SmallVector<DWARFAttribute, 8> Attribute;
|
||||
|
||||
struct AttributeSpec {
|
||||
AttributeSpec(uint16_t Attr, uint16_t Form) : Attr(Attr), Form(Form) {}
|
||||
uint16_t Attr;
|
||||
uint16_t Form;
|
||||
};
|
||||
SmallVector<AttributeSpec, 8> Attributes;
|
||||
public:
|
||||
enum { InvalidCode = 0 };
|
||||
DWARFAbbreviationDeclaration()
|
||||
: Code(InvalidCode), Tag(0), HasChildren(0) {}
|
||||
DWARFAbbreviationDeclaration();
|
||||
|
||||
uint32_t getCode() const { return Code; }
|
||||
uint32_t getTag() const { return Tag; }
|
||||
bool hasChildren() const { return HasChildren; }
|
||||
uint32_t getNumAttributes() const { return Attribute.size(); }
|
||||
uint32_t getNumAttributes() const { return Attributes.size(); }
|
||||
uint16_t getAttrByIndex(uint32_t idx) const {
|
||||
return Attribute.size() > idx ? Attribute[idx].getAttribute() : 0;
|
||||
return idx < Attributes.size() ? Attributes[idx].Attr : 0;
|
||||
}
|
||||
uint16_t getFormByIndex(uint32_t idx) const {
|
||||
return Attribute.size() > idx ? Attribute[idx].getForm() : 0;
|
||||
return idx < Attributes.size() ? Attributes[idx].Form : 0;
|
||||
}
|
||||
|
||||
uint32_t findAttributeIndex(uint16_t attr) const;
|
||||
bool extract(DataExtractor data, uint32_t* offset_ptr);
|
||||
bool extract(DataExtractor data, uint32_t* offset_ptr, uint32_t code);
|
||||
bool isValid() const { return Code != 0 && Tag != 0; }
|
||||
bool extract(DataExtractor Data, uint32_t* OffsetPtr);
|
||||
void dump(raw_ostream &OS) const;
|
||||
const SmallVectorImpl<DWARFAttribute> &getAttributes() const {
|
||||
return Attribute;
|
||||
}
|
||||
|
||||
private:
|
||||
void clear();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
//===-- DWARFAttribute.h ----------------------------------------*- C++ -*-===//
|
||||
//
|
||||
// The LLVM Compiler Infrastructure
|
||||
//
|
||||
// This file is distributed under the University of Illinois Open Source
|
||||
// License. See LICENSE.TXT for details.
|
||||
//
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#ifndef LLVM_DEBUGINFO_DWARFATTRIBUTE_H
|
||||
#define LLVM_DEBUGINFO_DWARFATTRIBUTE_H
|
||||
|
||||
#include "llvm/Support/DataTypes.h"
|
||||
|
||||
namespace llvm {
|
||||
|
||||
class DWARFAttribute {
|
||||
uint16_t Attribute;
|
||||
uint16_t Form;
|
||||
public:
|
||||
DWARFAttribute(uint16_t attr, uint16_t form)
|
||||
: Attribute(attr), Form(form) {}
|
||||
|
||||
uint16_t getAttribute() const { return Attribute; }
|
||||
uint16_t getForm() const { return Form; }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue