llvm.org GIT mirror llvm / bc5e25d
DWARFAbbreviationDeclaration: remove dead code, refactor parsing code and make it more robust. No functionality change. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193770 91177308-0d34-0410-b5e6-96231b3b80d8 Alexey Samsonov 5 years ago
3 changed file(s) with 60 addition(s) and 75 deletion(s). Raw diff Collapse all Expand all
1313 using namespace llvm;
1414 using namespace dwarf;
1515
16 bool
17 DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr){
18 return extract(data, offset_ptr, data.getULEB128(offset_ptr));
16 void DWARFAbbreviationDeclaration::clear() {
17 Code = 0;
18 Tag = 0;
19 HasChildren = false;
20 Attributes.clear();
21 }
22
23 DWARFAbbreviationDeclaration::DWARFAbbreviationDeclaration() {
24 clear();
1925 }
2026
2127 bool
22 DWARFAbbreviationDeclaration::extract(DataExtractor data, uint32_t* offset_ptr,
23 uint32_t code) {
24 Code = code;
25 Attribute.clear();
26 if (Code) {
27 Tag = data.getULEB128(offset_ptr);
28 HasChildren = data.getU8(offset_ptr);
28 DWARFAbbreviationDeclaration::extract(DataExtractor Data, uint32_t* OffsetPtr) {
29 clear();
30 Code = Data.getULEB128(OffsetPtr);
31 if (Code == 0) {
32 return false;
33 }
34 Tag = Data.getULEB128(OffsetPtr);
35 uint8_t ChildrenByte = Data.getU8(OffsetPtr);
36 HasChildren = (ChildrenByte == DW_CHILDREN_yes);
2937
30 while (data.isValidOffset(*offset_ptr)) {
31 uint16_t attr = data.getULEB128(offset_ptr);
32 uint16_t form = data.getULEB128(offset_ptr);
33
34 if (attr && form)
35 Attribute.push_back(DWARFAttribute(attr, form));
36 else
37 break;
38 while (true) {
39 uint32_t CurOffset = *OffsetPtr;
40 uint16_t Attr = Data.getULEB128(OffsetPtr);
41 if (CurOffset == *OffsetPtr) {
42 clear();
43 return false;
3844 }
39
40 return Tag != 0;
41 } else {
42 Tag = 0;
43 HasChildren = false;
45 CurOffset = *OffsetPtr;
46 uint16_t Form = Data.getULEB128(OffsetPtr);
47 if (CurOffset == *OffsetPtr) {
48 clear();
49 return false;
50 }
51 if (Attr == 0 && Form == 0)
52 break;
53 Attributes.push_back(AttributeSpec(Attr, Form));
4454 }
4555
46 return false;
56 if (Tag == 0) {
57 clear();
58 return false;
59 }
60 return true;
4761 }
4862
4963 void DWARFAbbreviationDeclaration::dump(raw_ostream &OS) const {
5468 else
5569 OS << format("DW_TAG_Unknown_%x", getTag());
5670 OS << "\tDW_CHILDREN_" << (hasChildren() ? "yes" : "no") << '\n';
57 for (unsigned i = 0, e = Attribute.size(); i != e; ++i) {
71 for (unsigned i = 0, e = Attributes.size(); i != e; ++i) {
5872 OS << '\t';
59 const char *attrString = AttributeString(Attribute[i].getAttribute());
73 const char *attrString = AttributeString(Attributes[i].Attr);
6074 if (attrString)
6175 OS << attrString;
6276 else
63 OS << format("DW_AT_Unknown_%x", Attribute[i].getAttribute());
77 OS << format("DW_AT_Unknown_%x", Attributes[i].Attr);
6478 OS << '\t';
65 const char *formString = FormEncodingString(Attribute[i].getForm());
79 const char *formString = FormEncodingString(Attributes[i].Form);
6680 if (formString)
6781 OS << formString;
6882 else
69 OS << format("DW_FORM_Unknown_%x", Attribute[i].getForm());
83 OS << format("DW_FORM_Unknown_%x", Attributes[i].Form);
7084 OS << '\n';
7185 }
7286 OS << '\n';
7488
7589 uint32_t
7690 DWARFAbbreviationDeclaration::findAttributeIndex(uint16_t attr) const {
77 for (uint32_t i = 0, e = Attribute.size(); i != e; ++i) {
78 if (Attribute[i].getAttribute() == attr)
91 for (uint32_t i = 0, e = Attributes.size(); i != e; ++i) {
92 if (Attributes[i].Attr == attr)
7993 return i;
8094 }
8195 return -1U;
99 #ifndef LLVM_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
1010 #define LLVM_DEBUGINFO_DWARFABBREVIATIONDECLARATION_H
1111
12 #include "DWARFAttribute.h"
1312 #include "llvm/ADT/SmallVector.h"
1413 #include "llvm/Support/DataExtractor.h"
1514
2120 uint32_t Code;
2221 uint32_t Tag;
2322 bool HasChildren;
24 SmallVector Attribute;
23
24 struct AttributeSpec {
25 AttributeSpec(uint16_t Attr, uint16_t Form) : Attr(Attr), Form(Form) {}
26 uint16_t Attr;
27 uint16_t Form;
28 };
29 SmallVector Attributes;
2530 public:
26 enum { InvalidCode = 0 };
27 DWARFAbbreviationDeclaration()
28 : Code(InvalidCode), Tag(0), HasChildren(0) {}
31 DWARFAbbreviationDeclaration();
2932
3033 uint32_t getCode() const { return Code; }
3134 uint32_t getTag() const { return Tag; }
3235 bool hasChildren() const { return HasChildren; }
33 uint32_t getNumAttributes() const { return Attribute.size(); }
36 uint32_t getNumAttributes() const { return Attributes.size(); }
3437 uint16_t getAttrByIndex(uint32_t idx) const {
35 return Attribute.size() > idx ? Attribute[idx].getAttribute() : 0;
38 return idx < Attributes.size() ? Attributes[idx].Attr : 0;
3639 }
3740 uint16_t getFormByIndex(uint32_t idx) const {
38 return Attribute.size() > idx ? Attribute[idx].getForm() : 0;
41 return idx < Attributes.size() ? Attributes[idx].Form : 0;
3942 }
4043
4144 uint32_t findAttributeIndex(uint16_t attr) const;
42 bool extract(DataExtractor data, uint32_t* offset_ptr);
43 bool extract(DataExtractor data, uint32_t* offset_ptr, uint32_t code);
44 bool isValid() const { return Code != 0 && Tag != 0; }
45 bool extract(DataExtractor Data, uint32_t* OffsetPtr);
4546 void dump(raw_ostream &OS) const;
46 const SmallVectorImpl &getAttributes() const {
47 return Attribute;
48 }
47
48 private:
49 void clear();
4950 };
5051
5152 }
+0
-30
lib/DebugInfo/DWARFAttribute.h less more
None //===-- DWARFAttribute.h ----------------------------------------*- C++ -*-===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8
9 #ifndef LLVM_DEBUGINFO_DWARFATTRIBUTE_H
10 #define LLVM_DEBUGINFO_DWARFATTRIBUTE_H
11
12 #include "llvm/Support/DataTypes.h"
13
14 namespace llvm {
15
16 class DWARFAttribute {
17 uint16_t Attribute;
18 uint16_t Form;
19 public:
20 DWARFAttribute(uint16_t attr, uint16_t form)
21 : Attribute(attr), Form(form) {}
22
23 uint16_t getAttribute() const { return Attribute; }
24 uint16_t getForm() const { return Form; }
25 };
26
27 }
28
29 #endif