summaryrefslogtreecommitdiffstats
path: root/llvm/lib/DebugInfo/DWARFDebugInfoEntry.cpp
diff options
context:
space:
mode:
authorAlexey Samsonov <samsonov@google.com>2013-10-28 23:01:48 +0000
committerAlexey Samsonov <samsonov@google.com>2013-10-28 23:01:48 +0000
commit48cbda5850264671e982ecdd834c1587b1732c15 (patch)
treefceb336b9978d09dbaa90b78b3ee5028c40e6b19 /llvm/lib/DebugInfo/DWARFDebugInfoEntry.cpp
parent0a09ebf445339748b549d7c8743fcb7e435d3527 (diff)
downloadbcm5719-llvm-48cbda5850264671e982ecdd834c1587b1732c15.tar.gz
bcm5719-llvm-48cbda5850264671e982ecdd834c1587b1732c15.zip
DebugInfo: Introduce the notion of "form classes"
Summary: Use DWARF4 table of form classes to fetch attributes from DIE in a more consistent way. This shouldn't change the functionality and serves as a refactoring for upcoming change: DW_AT_high_pc has different semantics depending on its form class. Reviewers: dblaikie, echristo Reviewed By: echristo CC: echristo, llvm-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1961 llvm-svn: 193553
Diffstat (limited to 'llvm/lib/DebugInfo/DWARFDebugInfoEntry.cpp')
-rw-r--r--llvm/lib/DebugInfo/DWARFDebugInfoEntry.cpp55
1 files changed, 36 insertions, 19 deletions
diff --git a/llvm/lib/DebugInfo/DWARFDebugInfoEntry.cpp b/llvm/lib/DebugInfo/DWARFDebugInfoEntry.cpp
index 9bb49df5d13..e8b8748a9d7 100644
--- a/llvm/lib/DebugInfo/DWARFDebugInfoEntry.cpp
+++ b/llvm/lib/DebugInfo/DWARFDebugInfoEntry.cpp
@@ -160,8 +160,11 @@ bool DWARFDebugInfoEntryMinimal::extract(const DWARFUnit *U,
((Attr == DW_AT_entry_pc) || (Attr == DW_AT_low_pc))) {
DWARFFormValue FormValue(Form);
if (FormValue.extractValue(DebugInfoData, OffsetPtr, U)) {
- if (Attr == DW_AT_low_pc || Attr == DW_AT_entry_pc)
- const_cast<DWARFUnit *>(U)->setBaseAddress(FormValue.getUnsigned());
+ if (Attr == DW_AT_low_pc || Attr == DW_AT_entry_pc) {
+ Optional<uint64_t> BaseAddr = FormValue.getAsAddress(U);
+ if (BaseAddr.hasValue())
+ const_cast<DWARFUnit *>(U)->setBaseAddress(BaseAddr.getValue());
+ }
}
} else if (!DWARFFormValue::skipValue(Form, DebugInfoData, OffsetPtr, U)) {
// Restore the original offset.
@@ -210,33 +213,46 @@ bool DWARFDebugInfoEntryMinimal::getAttributeValue(
const char *DWARFDebugInfoEntryMinimal::getAttributeValueAsString(
const DWARFUnit *U, const uint16_t Attr, const char *FailValue) const {
DWARFFormValue FormValue;
- if (getAttributeValue(U, Attr, FormValue))
- return FormValue.getAsCString(U);
- return FailValue;
+ if (!getAttributeValue(U, Attr, FormValue))
+ return FailValue;
+ Optional<const char *> Result = FormValue.getAsCString(U);
+ return Result.hasValue() ? Result.getValue() : FailValue;
}
uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsAddress(
const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
DWARFFormValue FormValue;
- if (getAttributeValue(U, Attr, FormValue))
- return FormValue.getAsAddress(U);
- return FailValue;
+ if (!getAttributeValue(U, Attr, FormValue))
+ return FailValue;
+ Optional<uint64_t> Result = FormValue.getAsAddress(U);
+ return Result.hasValue() ? Result.getValue() : FailValue;
}
-uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsUnsigned(
+uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsUnsignedConstant(
const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
DWARFFormValue FormValue;
- if (getAttributeValue(U, Attr, FormValue))
- return FormValue.getUnsigned();
- return FailValue;
+ if (!getAttributeValue(U, Attr, FormValue))
+ return FailValue;
+ Optional<uint64_t> Result = FormValue.getAsUnsignedConstant();
+ return Result.hasValue() ? Result.getValue() : FailValue;
}
uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsReference(
const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
DWARFFormValue FormValue;
- if (getAttributeValue(U, Attr, FormValue))
- return FormValue.getReference(U);
- return FailValue;
+ if (!getAttributeValue(U, Attr, FormValue))
+ return FailValue;
+ Optional<uint64_t> Result = FormValue.getAsReference(U);
+ return Result.hasValue() ? Result.getValue() : FailValue;
+}
+
+uint64_t DWARFDebugInfoEntryMinimal::getAttributeValueAsSectionOffset(
+ const DWARFUnit *U, const uint16_t Attr, uint64_t FailValue) const {
+ DWARFFormValue FormValue;
+ if (!getAttributeValue(U, Attr, FormValue))
+ return FailValue;
+ Optional<uint64_t> Result = FormValue.getAsSectionOffset();
+ return Result.hasValue() ? Result.getValue() : FailValue;
}
bool DWARFDebugInfoEntryMinimal::getLowAndHighPC(const DWARFUnit *U,
@@ -277,7 +293,8 @@ bool DWARFDebugInfoEntryMinimal::addressRangeContainsAddress(
if (getLowAndHighPC(U, LowPC, HighPC))
return (LowPC <= Address && Address <= HighPC);
// Try to get address ranges from .debug_ranges section.
- uint32_t RangesOffset = getAttributeValueAsReference(U, DW_AT_ranges, -1U);
+ uint32_t RangesOffset =
+ getAttributeValueAsSectionOffset(U, DW_AT_ranges, -1U);
if (RangesOffset != -1U) {
DWARFDebugRangeList RangeList;
if (U->extractRangeList(RangesOffset, RangeList))
@@ -325,9 +342,9 @@ void DWARFDebugInfoEntryMinimal::getCallerFrame(const DWARFUnit *U,
uint32_t &CallFile,
uint32_t &CallLine,
uint32_t &CallColumn) const {
- CallFile = getAttributeValueAsUnsigned(U, DW_AT_call_file, 0);
- CallLine = getAttributeValueAsUnsigned(U, DW_AT_call_line, 0);
- CallColumn = getAttributeValueAsUnsigned(U, DW_AT_call_column, 0);
+ CallFile = getAttributeValueAsUnsignedConstant(U, DW_AT_call_file, 0);
+ CallLine = getAttributeValueAsUnsignedConstant(U, DW_AT_call_line, 0);
+ CallColumn = getAttributeValueAsUnsignedConstant(U, DW_AT_call_column, 0);
}
DWARFDebugInfoEntryInlinedChain
OpenPOWER on IntegriCloud