aboutsummaryrefslogtreecommitdiffstats
path: root/lib/DebugInfo
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2013-10-31 17:20:14 +0000
committerAlexey Samsonov <samsonov@google.com>2013-10-31 17:20:14 +0000
commitbc5e25ddef214e8bebf04bd7abeffade2f21dc4e (patch)
treed737372ed9ad96f214c8740ef50d44c0d292acf5 /lib/DebugInfo
parent2343e3b228c02896f4779962a91aaa659356fe2a (diff)
downloadexternal_llvm-bc5e25ddef214e8bebf04bd7abeffade2f21dc4e.zip
external_llvm-bc5e25ddef214e8bebf04bd7abeffade2f21dc4e.tar.gz
external_llvm-bc5e25ddef214e8bebf04bd7abeffade2f21dc4e.tar.bz2
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
Diffstat (limited to 'lib/DebugInfo')
-rw-r--r--lib/DebugInfo/DWARFAbbreviationDeclaration.cpp76
-rw-r--r--lib/DebugInfo/DWARFAbbreviationDeclaration.h29
-rw-r--r--lib/DebugInfo/DWARFAttribute.h30
3 files changed, 60 insertions, 75 deletions
diff --git a/lib/DebugInfo/DWARFAbbreviationDeclaration.cpp b/lib/DebugInfo/DWARFAbbreviationDeclaration.cpp
index 2de62ab..f46fd58 100644
--- a/lib/DebugInfo/DWARFAbbreviationDeclaration.cpp
+++ b/lib/DebugInfo/DWARFAbbreviationDeclaration.cpp
@@ -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();
}
-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::DWARFAbbreviationDeclaration() {
+ clear();
+}
- while (data.isValidOffset(*offset_ptr)) {
- uint16_t attr = data.getULEB128(offset_ptr);
- uint16_t form = data.getULEB128(offset_ptr);
+bool
+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);
- 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;
diff --git a/lib/DebugInfo/DWARFAbbreviationDeclaration.h b/lib/DebugInfo/DWARFAbbreviationDeclaration.h
index 9a3fcd8..e9b072e 100644
--- a/lib/DebugInfo/DWARFAbbreviationDeclaration.h
+++ b/lib/DebugInfo/DWARFAbbreviationDeclaration.h
@@ -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();
};
}
diff --git a/lib/DebugInfo/DWARFAttribute.h b/lib/DebugInfo/DWARFAttribute.h
deleted file mode 100644
index 6f49b63..0000000
--- a/lib/DebugInfo/DWARFAttribute.h
+++ /dev/null
@@ -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