diff options
author | Greg Clayton <gclayton@apple.com> | 2016-11-11 16:21:37 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2016-11-11 16:21:37 +0000 |
commit | 82f12b149f431e629d845c6efa590e756fceac00 (patch) | |
tree | 37544250edce41a8f9c3d8298d82d005e9cc0474 /llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp | |
parent | 2efc3cb968f088c1eb2c480d7e460e3f09cdab32 (diff) | |
download | bcm5719-llvm-82f12b149f431e629d845c6efa590e756fceac00.tar.gz bcm5719-llvm-82f12b149f431e629d845c6efa590e756fceac00.zip |
Clean up DWARFFormValue by reducing duplicated code and removing DWARFFormValue::getFixedFormSizes()
In preparation for a follow on patch that improves DWARF parsing speed, clean up DWARFFormValue so that we have can get the fixed byte size of a form value given a DWARFUnit or given the version, address byte size and dwarf32/64.
This patch cleans up code so that everyone is using one of the new DWARFFormValue functions:
static Optional<uint8_t> DWARFFormValue::getFixedByteSize(dwarf::Form Form, const DWARFUnit *U = nullptr);
static Optional<uint8_t> DWARFFormValue::getFixedByteSize(dwarf::Form Form, uint16_t Version, uint8_t AddrSize, bool Dwarf32);
This patch changes DWARFFormValue::skipValue() to rely on the output of DWARFFormValue::getFixedByteSize(...) instead of duplicating the code in each function. This will reduce the number of changes we need to make to DWARF to fewer places in DWARFFormValue when we add support for new form.
This patch also starts to support DWARF64 so that we can get correct byte sizes for forms that vary according the DWARF 32/64.
To reduce the code duplication a new FormSizeHelper pure virtual class was created that can be created as a FormSizeHelperDWARFUnit when you have a DWARFUnit, or FormSizeHelperManual where you manually specify the DWARF version, address byte size and DWARF32/DWARF64. There is now a single implementation of a function that gets the fixed byte size (instead of two where one took a DWARFUnit and one took the DWARF version, address byte size and DWARFFormat enum) and one function to skip the form values.
https://reviews.llvm.org/D26526
llvm-svn: 286597
Diffstat (limited to 'llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp')
-rw-r--r-- | llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp index c751bffb35e..028a03595de 100644 --- a/llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DWARFFormValueTest.cpp @@ -21,16 +21,47 @@ using namespace dwarf; namespace { TEST(DWARFFormValue, FixedFormSizes) { - // Size of DW_FORM_addr and DW_FORM_ref_addr are equal in DWARF2, - // DW_FORM_ref_addr is always 4 bytes in DWARF32 starting from DWARF3. - ArrayRef<uint8_t> sizes = DWARFFormValue::getFixedFormSizes(4, 2); - EXPECT_EQ(sizes[DW_FORM_addr], sizes[DW_FORM_ref_addr]); - sizes = DWARFFormValue::getFixedFormSizes(8, 2); - EXPECT_EQ(sizes[DW_FORM_addr], sizes[DW_FORM_ref_addr]); - sizes = DWARFFormValue::getFixedFormSizes(8, 3); - EXPECT_EQ(4, sizes[DW_FORM_ref_addr]); - // Check that we don't have fixed form sizes for weird address sizes. - EXPECT_EQ(0U, DWARFFormValue::getFixedFormSizes(16, 2).size()); + Optional<uint8_t> RefSize; + Optional<uint8_t> AddrSize; + // Test 32 bit DWARF version 2 with 4 byte addresses. + RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, 2, 4, DWARF32); + AddrSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, 2, 4, DWARF32); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_TRUE(AddrSize.hasValue()); + EXPECT_EQ(*RefSize, *AddrSize); + + // Test 32 bit DWARF version 2 with 8 byte addresses. + RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, 2, 8, DWARF32); + AddrSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, 2, 8, DWARF32); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_TRUE(AddrSize.hasValue()); + EXPECT_EQ(*RefSize, *AddrSize); + + // DW_FORM_ref_addr is 4 bytes in DWARF 32 in DWARF version 3 and beyond. + RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, 3, 4, DWARF32); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_EQ(*RefSize, 4); + + RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, 4, 4, DWARF32); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_EQ(*RefSize, 4); + + RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, 5, 4, DWARF32); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_EQ(*RefSize, 4); + + // DW_FORM_ref_addr is 8 bytes in DWARF 64 in DWARF version 3 and beyond. + RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, 3, 8, DWARF64); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_EQ(*RefSize, 8); + + RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, 4, 8, DWARF64); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_EQ(*RefSize, 8); + + RefSize = DWARFFormValue::getFixedByteSize(DW_FORM_ref_addr, 5, 8, DWARF64); + EXPECT_TRUE(RefSize.hasValue()); + EXPECT_EQ(*RefSize, 8); } bool isFormClass(dwarf::Form Form, DWARFFormValue::FormClass FC) { |