DWARF parser: propery handle DW_FORM_ref_sig8 and fix Windows build.

Based on D2050 by Timur Iskhodzhanov.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193619 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Alexey Samsonov 2013-10-29 16:32:19 +00:00
parent a300b1cc29
commit 636a5cb8de
2 changed files with 42 additions and 43 deletions

View File

@ -21,60 +21,56 @@ using namespace llvm;
using namespace dwarf; using namespace dwarf;
namespace { namespace {
template <uint8_t AddrSize, uint8_t RefAddrSize> struct FixedFormSizes { uint8_t getRefAddrSize(uint8_t AddrSize, uint16_t Version) {
// FIXME: do we need a template here? Will a stack-allocated struct with // FIXME: Support DWARF64.
// an initializer in getFixedFormSizes() work just fine? return (Version == 2) ? AddrSize : 4;
static const uint8_t sizes[27];
};
} }
template <uint8_t AddrSize, uint8_t RefAddrSize> template <uint8_t AddrSize, uint8_t RefAddrSize>
const uint8_t FixedFormSizes<AddrSize, RefAddrSize>::sizes[] = { ArrayRef<uint8_t> makeFixedFormSizesArrayRef() {
0, // 0x00 unused static const uint8_t sizes[] = {
AddrSize, // 0x01 DW_FORM_addr 0, // 0x00 unused
0, // 0x02 unused AddrSize, // 0x01 DW_FORM_addr
0, // 0x03 DW_FORM_block2 0, // 0x02 unused
0, // 0x04 DW_FORM_block4 0, // 0x03 DW_FORM_block2
2, // 0x05 DW_FORM_data2 0, // 0x04 DW_FORM_block4
4, // 0x06 DW_FORM_data4 2, // 0x05 DW_FORM_data2
8, // 0x07 DW_FORM_data8 4, // 0x06 DW_FORM_data4
0, // 0x08 DW_FORM_string 8, // 0x07 DW_FORM_data8
0, // 0x09 DW_FORM_block 0, // 0x08 DW_FORM_string
0, // 0x0a DW_FORM_block1 0, // 0x09 DW_FORM_block
1, // 0x0b DW_FORM_data1 0, // 0x0a DW_FORM_block1
1, // 0x0c DW_FORM_flag 1, // 0x0b DW_FORM_data1
0, // 0x0d DW_FORM_sdata 1, // 0x0c DW_FORM_flag
4, // 0x0e DW_FORM_strp 0, // 0x0d DW_FORM_sdata
0, // 0x0f DW_FORM_udata 4, // 0x0e DW_FORM_strp
RefAddrSize, // 0x10 DW_FORM_ref_addr 0, // 0x0f DW_FORM_udata
1, // 0x11 DW_FORM_ref1 RefAddrSize, // 0x10 DW_FORM_ref_addr
2, // 0x12 DW_FORM_ref2 1, // 0x11 DW_FORM_ref1
4, // 0x13 DW_FORM_ref4 2, // 0x12 DW_FORM_ref2
8, // 0x14 DW_FORM_ref8 4, // 0x13 DW_FORM_ref4
0, // 0x15 DW_FORM_ref_udata 8, // 0x14 DW_FORM_ref8
0, // 0x16 DW_FORM_indirect 0, // 0x15 DW_FORM_ref_udata
4, // 0x17 DW_FORM_sec_offset 0, // 0x16 DW_FORM_indirect
0, // 0x18 DW_FORM_exprloc 4, // 0x17 DW_FORM_sec_offset
0, // 0x19 DW_FORM_flag_present 0, // 0x18 DW_FORM_exprloc
8, // 0x20 DW_FORM_ref_sig8 0, // 0x19 DW_FORM_flag_present
}; };
return makeArrayRef(sizes);
static uint8_t getRefAddrSize(uint8_t AddrSize, uint16_t Version) { }
// FIXME: Support DWARF64.
return (Version == 2) ? AddrSize : 4;
} }
ArrayRef<uint8_t> DWARFFormValue::getFixedFormSizes(uint8_t AddrSize, ArrayRef<uint8_t> DWARFFormValue::getFixedFormSizes(uint8_t AddrSize,
uint16_t Version) { uint16_t Version) {
uint8_t RefAddrSize = getRefAddrSize(AddrSize, Version); uint8_t RefAddrSize = getRefAddrSize(AddrSize, Version);
if (AddrSize == 4 && RefAddrSize == 4) if (AddrSize == 4 && RefAddrSize == 4)
return makeArrayRef(FixedFormSizes<4, 4>::sizes); return makeFixedFormSizesArrayRef<4, 4>();
if (AddrSize == 4 && RefAddrSize == 8) if (AddrSize == 4 && RefAddrSize == 8)
return makeArrayRef(FixedFormSizes<4, 8>::sizes); return makeFixedFormSizesArrayRef<4, 8>();
if (AddrSize == 8 && RefAddrSize == 4) if (AddrSize == 8 && RefAddrSize == 4)
return makeArrayRef(FixedFormSizes<8, 4>::sizes); return makeFixedFormSizesArrayRef<8, 4>();
if (AddrSize == 8 && RefAddrSize == 8) if (AddrSize == 8 && RefAddrSize == 8)
return makeArrayRef(FixedFormSizes<8, 8>::sizes); return makeFixedFormSizesArrayRef<8, 8>();
return None; return None;
} }
@ -107,7 +103,6 @@ static const DWARFFormValue::FormClass DWARF4FormClasses[] = {
DWARFFormValue::FC_SectionOffset, // 0x17 DW_FORM_sec_offset DWARFFormValue::FC_SectionOffset, // 0x17 DW_FORM_sec_offset
DWARFFormValue::FC_Exprloc, // 0x18 DW_FORM_exprloc DWARFFormValue::FC_Exprloc, // 0x18 DW_FORM_exprloc
DWARFFormValue::FC_Flag, // 0x19 DW_FORM_flag_present DWARFFormValue::FC_Flag, // 0x19 DW_FORM_flag_present
DWARFFormValue::FC_Reference, // 0x20 DW_FORM_ref_sig8
}; };
bool DWARFFormValue::isFormClass(DWARFFormValue::FormClass FC) const { bool DWARFFormValue::isFormClass(DWARFFormValue::FormClass FC) const {
@ -115,6 +110,9 @@ bool DWARFFormValue::isFormClass(DWARFFormValue::FormClass FC) const {
if (Form < ArrayRef<FormClass>(DWARF4FormClasses).size() && if (Form < ArrayRef<FormClass>(DWARF4FormClasses).size() &&
DWARF4FormClasses[Form] == FC) DWARF4FormClasses[Form] == FC)
return true; return true;
// Check DW_FORM_ref_sig8 from DWARF4.
if (Form == DW_FORM_ref_sig8)
return (FC == FC_Reference);
// Check for some DWARF5 forms. // Check for some DWARF5 forms.
if (Form == DW_FORM_GNU_addr_index) if (Form == DW_FORM_GNU_addr_index)
return (FC == FC_Address); return (FC == FC_Address);

View File

@ -43,6 +43,7 @@ TEST(DWARFFormValue, FormClass) {
EXPECT_TRUE(isFormClass(DW_FORM_GNU_addr_index, DWARFFormValue::FC_Address)); EXPECT_TRUE(isFormClass(DW_FORM_GNU_addr_index, DWARFFormValue::FC_Address));
EXPECT_FALSE(isFormClass(DW_FORM_ref_addr, DWARFFormValue::FC_Address)); EXPECT_FALSE(isFormClass(DW_FORM_ref_addr, DWARFFormValue::FC_Address));
EXPECT_TRUE(isFormClass(DW_FORM_ref_addr, DWARFFormValue::FC_Reference)); EXPECT_TRUE(isFormClass(DW_FORM_ref_addr, DWARFFormValue::FC_Reference));
EXPECT_TRUE(isFormClass(DW_FORM_ref_sig8, DWARFFormValue::FC_Reference));
} }
} // end anonymous namespace } // end anonymous namespace