llvm.org GIT mirror llvm / 636a5cb
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 Alexey Samsonov 5 years ago
2 changed file(s) with 43 addition(s) and 44 deletion(s). Raw diff Collapse all Expand all
2020 using namespace dwarf;
2121
2222 namespace {
23 template struct FixedFormSizes {
24 // FIXME: do we need a template here? Will a stack-allocated struct with
25 // an initializer in getFixedFormSizes() work just fine?
26 static const uint8_t sizes[27];
27 };
28 }
29
30 template
31 const uint8_t FixedFormSizes::sizes[] = {
32 0, // 0x00 unused
33 AddrSize, // 0x01 DW_FORM_addr
34 0, // 0x02 unused
35 0, // 0x03 DW_FORM_block2
36 0, // 0x04 DW_FORM_block4
37 2, // 0x05 DW_FORM_data2
38 4, // 0x06 DW_FORM_data4
39 8, // 0x07 DW_FORM_data8
40 0, // 0x08 DW_FORM_string
41 0, // 0x09 DW_FORM_block
42 0, // 0x0a DW_FORM_block1
43 1, // 0x0b DW_FORM_data1
44 1, // 0x0c DW_FORM_flag
45 0, // 0x0d DW_FORM_sdata
46 4, // 0x0e DW_FORM_strp
47 0, // 0x0f DW_FORM_udata
48 RefAddrSize, // 0x10 DW_FORM_ref_addr
49 1, // 0x11 DW_FORM_ref1
50 2, // 0x12 DW_FORM_ref2
51 4, // 0x13 DW_FORM_ref4
52 8, // 0x14 DW_FORM_ref8
53 0, // 0x15 DW_FORM_ref_udata
54 0, // 0x16 DW_FORM_indirect
55 4, // 0x17 DW_FORM_sec_offset
56 0, // 0x18 DW_FORM_exprloc
57 0, // 0x19 DW_FORM_flag_present
58 8, // 0x20 DW_FORM_ref_sig8
59 };
60
61 static uint8_t getRefAddrSize(uint8_t AddrSize, uint16_t Version) {
23 uint8_t getRefAddrSize(uint8_t AddrSize, uint16_t Version) {
6224 // FIXME: Support DWARF64.
6325 return (Version == 2) ? AddrSize : 4;
26 }
27
28 template
29 ArrayRef makeFixedFormSizesArrayRef() {
30 static const uint8_t sizes[] = {
31 0, // 0x00 unused
32 AddrSize, // 0x01 DW_FORM_addr
33 0, // 0x02 unused
34 0, // 0x03 DW_FORM_block2
35 0, // 0x04 DW_FORM_block4
36 2, // 0x05 DW_FORM_data2
37 4, // 0x06 DW_FORM_data4
38 8, // 0x07 DW_FORM_data8
39 0, // 0x08 DW_FORM_string
40 0, // 0x09 DW_FORM_block
41 0, // 0x0a DW_FORM_block1
42 1, // 0x0b DW_FORM_data1
43 1, // 0x0c DW_FORM_flag
44 0, // 0x0d DW_FORM_sdata
45 4, // 0x0e DW_FORM_strp
46 0, // 0x0f DW_FORM_udata
47 RefAddrSize, // 0x10 DW_FORM_ref_addr
48 1, // 0x11 DW_FORM_ref1
49 2, // 0x12 DW_FORM_ref2
50 4, // 0x13 DW_FORM_ref4
51 8, // 0x14 DW_FORM_ref8
52 0, // 0x15 DW_FORM_ref_udata
53 0, // 0x16 DW_FORM_indirect
54 4, // 0x17 DW_FORM_sec_offset
55 0, // 0x18 DW_FORM_exprloc
56 0, // 0x19 DW_FORM_flag_present
57 };
58 return makeArrayRef(sizes);
59 }
6460 }
6561
6662 ArrayRef DWARFFormValue::getFixedFormSizes(uint8_t AddrSize,
6763 uint16_t Version) {
6864 uint8_t RefAddrSize = getRefAddrSize(AddrSize, Version);
6965 if (AddrSize == 4 && RefAddrSize == 4)
70 return makeArrayRef(FixedFormSizes<4, 4>::sizes);
66 return makeFixedFormSizesArrayRef<4, 4>();
7167 if (AddrSize == 4 && RefAddrSize == 8)
72 return makeArrayRef(FixedFormSizes<4, 8>::sizes);
68 return makeFixedFormSizesArrayRef<4, 8>();
7369 if (AddrSize == 8 && RefAddrSize == 4)
74 return makeArrayRef(FixedFormSizes<8, 4>::sizes);
70 return makeFixedFormSizesArrayRef<8, 4>();
7571 if (AddrSize == 8 && RefAddrSize == 8)
76 return makeArrayRef(FixedFormSizes<8, 8>::sizes);
72 return makeFixedFormSizesArrayRef<8, 8>();
7773 return None;
7874 }
7975
106102 DWARFFormValue::FC_SectionOffset, // 0x17 DW_FORM_sec_offset
107103 DWARFFormValue::FC_Exprloc, // 0x18 DW_FORM_exprloc
108104 DWARFFormValue::FC_Flag, // 0x19 DW_FORM_flag_present
109 DWARFFormValue::FC_Reference, // 0x20 DW_FORM_ref_sig8
110105 };
111106
112107 bool DWARFFormValue::isFormClass(DWARFFormValue::FormClass FC) const {
114109 if (Form < ArrayRef(DWARF4FormClasses).size() &&
115110 DWARF4FormClasses[Form] == FC)
116111 return true;
112 // Check DW_FORM_ref_sig8 from DWARF4.
113 if (Form == DW_FORM_ref_sig8)
114 return (FC == FC_Reference);
117115 // Check for some DWARF5 forms.
118116 if (Form == DW_FORM_GNU_addr_index)
119117 return (FC == FC_Address);
4242 EXPECT_TRUE(isFormClass(DW_FORM_GNU_addr_index, DWARFFormValue::FC_Address));
4343 EXPECT_FALSE(isFormClass(DW_FORM_ref_addr, DWARFFormValue::FC_Address));
4444 EXPECT_TRUE(isFormClass(DW_FORM_ref_addr, DWARFFormValue::FC_Reference));
45 EXPECT_TRUE(isFormClass(DW_FORM_ref_sig8, DWARFFormValue::FC_Reference));
4546 }
4647
4748 } // end anonymous namespace