summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/DebugInfo/DWARFCompileUnit.cpp2
-rw-r--r--lib/DebugInfo/DWARFFormValue.cpp76
-rw-r--r--lib/DebugInfo/DWARFFormValue.h2
3 files changed, 35 insertions, 45 deletions
diff --git a/lib/DebugInfo/DWARFCompileUnit.cpp b/lib/DebugInfo/DWARFCompileUnit.cpp
index e3e4ccd7d9..1f2b40fbbe 100644
--- a/lib/DebugInfo/DWARFCompileUnit.cpp
+++ b/lib/DebugInfo/DWARFCompileUnit.cpp
@@ -165,7 +165,7 @@ size_t DWARFCompileUnit::extractDIEsIfNeeded(bool cu_die_only) {
// we were told to parse
const uint8_t *fixed_form_sizes =
- DWARFFormValue::getFixedFormSizesForAddressSize(getAddressByteSize());
+ DWARFFormValue::getFixedFormSizes(getAddressByteSize(), getVersion());
while (offset < next_cu_offset &&
die.extractFast(this, fixed_form_sizes, &offset)) {
diff --git a/lib/DebugInfo/DWARFFormValue.cpp b/lib/DebugInfo/DWARFFormValue.cpp
index d29af3595f..2e16db9bab 100644
--- a/lib/DebugInfo/DWARFFormValue.cpp
+++ b/lib/DebugInfo/DWARFFormValue.cpp
@@ -18,39 +18,15 @@
using namespace llvm;
using namespace dwarf;
-static const uint8_t form_sizes_addr4[] = {
- 0, // 0x00 unused
- 4, // 0x01 DW_FORM_addr
- 0, // 0x02 unused
- 0, // 0x03 DW_FORM_block2
- 0, // 0x04 DW_FORM_block4
- 2, // 0x05 DW_FORM_data2
- 4, // 0x06 DW_FORM_data4
- 8, // 0x07 DW_FORM_data8
- 0, // 0x08 DW_FORM_string
- 0, // 0x09 DW_FORM_block
- 0, // 0x0a DW_FORM_block1
- 1, // 0x0b DW_FORM_data1
- 1, // 0x0c DW_FORM_flag
- 0, // 0x0d DW_FORM_sdata
- 4, // 0x0e DW_FORM_strp
- 0, // 0x0f DW_FORM_udata
- 4, // 0x10 DW_FORM_ref_addr
- 1, // 0x11 DW_FORM_ref1
- 2, // 0x12 DW_FORM_ref2
- 4, // 0x13 DW_FORM_ref4
- 8, // 0x14 DW_FORM_ref8
- 0, // 0x15 DW_FORM_ref_udata
- 0, // 0x16 DW_FORM_indirect
- 4, // 0x17 DW_FORM_sec_offset
- 0, // 0x18 DW_FORM_exprloc
- 0, // 0x19 DW_FORM_flag_present
- 8, // 0x20 DW_FORM_ref_sig8
+template <uint8_t AddrSize, uint8_t RefAddrSize>
+struct FixedFormSizes {
+ static const uint8_t sizes[];
};
-static const uint8_t form_sizes_addr8[] = {
+template <uint8_t AddrSize, uint8_t RefAddrSize>
+const uint8_t FixedFormSizes<AddrSize, RefAddrSize>::sizes[] = {
0, // 0x00 unused
- 8, // 0x01 DW_FORM_addr
+ AddrSize, // 0x01 DW_FORM_addr
0, // 0x02 unused
0, // 0x03 DW_FORM_block2
0, // 0x04 DW_FORM_block4
@@ -65,7 +41,7 @@ static const uint8_t form_sizes_addr8[] = {
0, // 0x0d DW_FORM_sdata
4, // 0x0e DW_FORM_strp
0, // 0x0f DW_FORM_udata
- 8, // 0x10 DW_FORM_ref_addr
+ RefAddrSize, // 0x10 DW_FORM_ref_addr
1, // 0x11 DW_FORM_ref1
2, // 0x12 DW_FORM_ref2
4, // 0x13 DW_FORM_ref4
@@ -78,13 +54,23 @@ static const uint8_t form_sizes_addr8[] = {
8, // 0x20 DW_FORM_ref_sig8
};
+static uint8_t getRefAddrSize(uint8_t AddrSize, uint16_t Version) {
+ // FIXME: Support DWARF64.
+ return (Version == 2) ? AddrSize : 4;
+}
+
const uint8_t *
-DWARFFormValue::getFixedFormSizesForAddressSize(uint8_t addr_size) {
- switch (addr_size) {
- case 4: return form_sizes_addr4;
- case 8: return form_sizes_addr8;
- }
- return NULL;
+DWARFFormValue::getFixedFormSizes(uint8_t AddrSize, uint16_t Version) {
+ uint8_t RefAddrSize = getRefAddrSize(AddrSize, Version);
+ if (AddrSize == 4 && RefAddrSize == 4)
+ return FixedFormSizes<4, 4>::sizes;
+ if (AddrSize == 4 && RefAddrSize == 8)
+ return FixedFormSizes<4, 8>::sizes;
+ if (AddrSize == 8 && RefAddrSize == 4)
+ return FixedFormSizes<8, 4>::sizes;
+ if (AddrSize == 8 && RefAddrSize == 8)
+ return FixedFormSizes<8, 8>::sizes;
+ return 0;
}
bool
@@ -100,14 +86,16 @@ DWARFFormValue::extractValue(DataExtractor data, uint32_t *offset_ptr,
switch (Form) {
case DW_FORM_addr:
case DW_FORM_ref_addr: {
- RelocAddrMap::const_iterator AI
- = cu->getRelocMap()->find(*offset_ptr);
+ uint16_t AddrSize =
+ (Form == DW_FORM_addr)
+ ? cu->getAddressByteSize()
+ : getRefAddrSize(cu->getAddressByteSize(), cu->getVersion());
+ RelocAddrMap::const_iterator AI = cu->getRelocMap()->find(*offset_ptr);
if (AI != cu->getRelocMap()->end()) {
const std::pair<uint8_t, int64_t> &R = AI->second;
- Value.uval = data.getUnsigned(offset_ptr, cu->getAddressByteSize()) +
- R.second;
+ Value.uval = data.getUnsigned(offset_ptr, AddrSize) + R.second;
} else
- Value.uval = data.getUnsigned(offset_ptr, cu->getAddressByteSize());
+ Value.uval = data.getUnsigned(offset_ptr, AddrSize);
break;
}
case DW_FORM_exprloc:
@@ -256,9 +244,11 @@ DWARFFormValue::skipValue(uint16_t form, DataExtractor debug_info_data,
// Compile unit address sized values
case DW_FORM_addr:
- case DW_FORM_ref_addr:
*offset_ptr += cu->getAddressByteSize();
return true;
+ case DW_FORM_ref_addr:
+ *offset_ptr += getRefAddrSize(cu->getAddressByteSize(), cu->getVersion());
+ return true;
// 0 byte values - implied from the form.
case DW_FORM_flag_present:
diff --git a/lib/DebugInfo/DWARFFormValue.h b/lib/DebugInfo/DWARFFormValue.h
index b863001e4a..eaaccfb4f3 100644
--- a/lib/DebugInfo/DWARFFormValue.h
+++ b/lib/DebugInfo/DWARFFormValue.h
@@ -74,7 +74,7 @@ public:
uint32_t *offset_ptr, const DWARFCompileUnit *cu);
static bool isBlockForm(uint16_t form);
static bool isDataForm(uint16_t form);
- static const uint8_t *getFixedFormSizesForAddressSize(uint8_t addr_size);
+ static const uint8_t *getFixedFormSizes(uint8_t AddrSize, uint16_t Version);
};
}