diff options
author | Benjamin Maxwell <benjamin.maxwell@arm.com> | 2023-02-01 13:35:31 +0000 |
---|---|---|
committer | Benjamin Maxwell <benjamin.maxwell@arm.com> | 2023-02-06 17:15:54 +0000 |
commit | 121452aa50afe99f56bffc1086016f3ceedd20e6 (patch) | |
tree | e88bb8bb9952c73becd64c360432009e1d5d07ed /llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp | |
parent | f8563a2545416df90e41b4345ccb81f9ca9b7835 (diff) | |
download | llvm-121452aa50afe99f56bffc1086016f3ceedd20e6.zip llvm-121452aa50afe99f56bffc1086016f3ceedd20e6.tar.gz llvm-121452aa50afe99f56bffc1086016f3ceedd20e6.tar.bz2 |
[DebugInfo] Handle fixed-width DW_FORM_addrx variants in DWARFFormValue::getAsSectionedAddress()
Previously this would incorrectly return the raw offset into the .debug_addr section for the
DW_FORM_addrx1/2/3/4 forms rather than the actual address.
Note that this was handled correctly in the dump() function so this issue only occurs for users
of this API and not in tools such as llvm-dwarfdump. The dump() method has now been updated
to use this method to increase coverage.
This also now adds a few unit tests for indexed addresses to DWARFDebugInfoTest.
Differential Revision: https://reviews.llvm.org/D143073
Diffstat (limited to 'llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp')
-rw-r--r-- | llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp | 41 |
1 files changed, 40 insertions, 1 deletions
diff --git a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp index edda022..e1bb6ab 100644 --- a/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp +++ b/llvm/unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp @@ -48,6 +48,11 @@ void TestAllForms() { // Test that we can decode all DW_FORM values correctly. const AddrType AddrValue = (AddrType)0x0123456789abcdefULL; + const AddrType AddrxValue = (AddrType)0x4231abcd4231abcdULL; + const AddrType Addrx1Value = (AddrType)0x0000aaaabbbbccccULL; + const AddrType Addrx2Value = (AddrType)0xf00123f00456f000ULL; + const AddrType Addrx4Value = (AddrType)0xa1b2c3d4e5f6e5d4ULL; + const uint8_t BlockData[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0}; const uint32_t BlockSize = sizeof(BlockData); const RefAddrType RefAddr = 0x12345678; @@ -79,8 +84,10 @@ void TestAllForms() { dwarfgen::CompileUnit &CU = DG->addCompileUnit(); dwarfgen::DIE CUDie = CU.getUnitDIE(); - if (Version >= 5) + if (Version >= 5) { CUDie.addStrOffsetsBaseAttribute(); + CUDie.addAddrBaseAttribute(); + } uint16_t Attr = DW_AT_lo_user; @@ -90,6 +97,20 @@ void TestAllForms() { const auto Attr_DW_FORM_addr = static_cast<dwarf::Attribute>(Attr++); CUDie.addAttribute(Attr_DW_FORM_addr, DW_FORM_addr, AddrValue); + const auto Attr_DW_FORM_addrx = static_cast<dwarf::Attribute>(Attr++); + const auto Attr_DW_FORM_addrx1 = static_cast<dwarf::Attribute>(Attr++); + const auto Attr_DW_FORM_addrx2 = static_cast<dwarf::Attribute>(Attr++); + // TODO: Add Attr_DW_FORM_addrx3 test (this form type is currently + // unsupported) + const auto Attr_DW_FORM_addrx4 = static_cast<dwarf::Attribute>(Attr++); + + if (Version >= 5) { + CUDie.addAttribute(Attr_DW_FORM_addrx, DW_FORM_addrx, AddrxValue); + CUDie.addAttribute(Attr_DW_FORM_addrx1, DW_FORM_addrx1, Addrx1Value); + CUDie.addAttribute(Attr_DW_FORM_addrx2, DW_FORM_addrx2, Addrx2Value); + CUDie.addAttribute(Attr_DW_FORM_addrx4, DW_FORM_addrx4, Addrx4Value); + } + //---------------------------------------------------------------------- // Test block forms //---------------------------------------------------------------------- @@ -241,6 +262,24 @@ void TestAllForms() { //---------------------------------------------------------------------- EXPECT_EQ(AddrValue, toAddress(DieDG.find(Attr_DW_FORM_addr), 0)); + if (Version >= 5) { + auto ExtractedAddrxValue = toAddress(DieDG.find(Attr_DW_FORM_addrx)); + EXPECT_TRUE(ExtractedAddrxValue.has_value()); + EXPECT_EQ(AddrxValue, *ExtractedAddrxValue); + + auto ExtractedAddrx1Value = toAddress(DieDG.find(Attr_DW_FORM_addrx1)); + EXPECT_TRUE(ExtractedAddrx1Value.has_value()); + EXPECT_EQ(Addrx1Value, *ExtractedAddrx1Value); + + auto ExtractedAddrx2Value = toAddress(DieDG.find(Attr_DW_FORM_addrx2)); + EXPECT_TRUE(ExtractedAddrx2Value.has_value()); + EXPECT_EQ(Addrx2Value, *ExtractedAddrx2Value); + + auto ExtractedAddrx4Value = toAddress(DieDG.find(Attr_DW_FORM_addrx4)); + EXPECT_TRUE(ExtractedAddrx1Value.has_value()); + EXPECT_EQ(Addrx4Value, *ExtractedAddrx4Value); + } + //---------------------------------------------------------------------- // Test block forms //---------------------------------------------------------------------- |