Refactor the DwarfSection classes.
Modify the code for the no header sections because it turns out that
it is not okay to assume that the fdes are non-overlapping. It's necessary
to read the fdes in order and match as you go.
Modify the code so that it only reads until it finds the given pc rather than
reading all of the cie/fde entries at once.
Rewrote the tests to verify the new behavior.
Bug: 68998033
Bug: 110235461
Test: Ran libbacktrace/libunwindstack unit tests.
Test: Unwind the mediaserver process on a walleye and verify it
Test: unwinds properly.
Change-Id: I7bb59d1db72c13fa34caa9735ec34c1a60e20ed2
diff --git a/libunwindstack/tests/ElfInterfaceTest.cpp b/libunwindstack/tests/ElfInterfaceTest.cpp
index 487d39c..aa6df84 100644
--- a/libunwindstack/tests/ElfInterfaceTest.cpp
+++ b/libunwindstack/tests/ElfInterfaceTest.cpp
@@ -656,8 +656,7 @@
memory_.SetData32(0x5000, 0xfc);
memory_.SetData32(0x5004, 0xffffffff);
- memory_.SetData8(0x5008, 1);
- memory_.SetData8(0x5009, '\0');
+ memory_.SetMemory(0x5008, std::vector<uint8_t>{1, '\0', 4, 8, 2});
memory_.SetData32(0x5100, 0xfc);
memory_.SetData32(0x5104, 0);
@@ -678,56 +677,6 @@
InitHeadersDebugFrame<ElfInterface64Fake>();
}
-template <typename ElfType>
-void ElfInterfaceTest::InitHeadersEhFrameFail() {
- ElfType elf(&memory_);
-
- elf.FakeSetEhFrameOffset(0x1000);
- elf.FakeSetEhFrameSize(0x100);
- elf.FakeSetDebugFrameOffset(0);
- elf.FakeSetDebugFrameSize(0);
-
- elf.InitHeaders(0);
-
- EXPECT_TRUE(elf.eh_frame() == nullptr);
- EXPECT_EQ(0U, elf.eh_frame_offset());
- EXPECT_EQ(static_cast<uint64_t>(-1), elf.eh_frame_size());
- EXPECT_TRUE(elf.debug_frame() == nullptr);
-}
-
-TEST_F(ElfInterfaceTest, init_headers_eh_frame32_fail) {
- InitHeadersEhFrameFail<ElfInterface32Fake>();
-}
-
-TEST_F(ElfInterfaceTest, init_headers_eh_frame64_fail) {
- InitHeadersEhFrameFail<ElfInterface64Fake>();
-}
-
-template <typename ElfType>
-void ElfInterfaceTest::InitHeadersDebugFrameFail() {
- ElfType elf(&memory_);
-
- elf.FakeSetEhFrameOffset(0);
- elf.FakeSetEhFrameSize(0);
- elf.FakeSetDebugFrameOffset(0x1000);
- elf.FakeSetDebugFrameSize(0x100);
-
- elf.InitHeaders(0);
-
- EXPECT_TRUE(elf.eh_frame() == nullptr);
- EXPECT_TRUE(elf.debug_frame() == nullptr);
- EXPECT_EQ(0U, elf.debug_frame_offset());
- EXPECT_EQ(static_cast<uint64_t>(-1), elf.debug_frame_size());
-}
-
-TEST_F(ElfInterfaceTest, init_headers_debug_frame32_fail) {
- InitHeadersDebugFrameFail<ElfInterface32Fake>();
-}
-
-TEST_F(ElfInterfaceTest, init_headers_debug_frame64_fail) {
- InitHeadersDebugFrameFail<ElfInterface64Fake>();
-}
-
template <typename Ehdr, typename Shdr, typename ElfInterfaceType>
void ElfInterfaceTest::InitSectionHeadersMalformed() {
std::unique_ptr<ElfInterfaceType> elf(new ElfInterfaceType(&memory_));
@@ -1024,11 +973,7 @@
// CIE 32.
memory_.SetData32(0x600, 0xfc);
memory_.SetData32(0x604, 0xffffffff);
- memory_.SetData8(0x608, 1);
- memory_.SetData8(0x609, '\0');
- memory_.SetData8(0x60a, 0x4);
- memory_.SetData8(0x60b, 0x4);
- memory_.SetData8(0x60c, 0x1);
+ memory_.SetMemory(0x608, std::vector<uint8_t>{1, '\0', 4, 4, 1});
// FDE 32.
memory_.SetData32(0x700, 0xfc);
@@ -1085,11 +1030,7 @@
// CIE 32.
memory_.SetData32(0x600, 0xfc);
memory_.SetData32(0x604, 0);
- memory_.SetData8(0x608, 1);
- memory_.SetData8(0x609, '\0');
- memory_.SetData8(0x60a, 0x4);
- memory_.SetData8(0x60b, 0x4);
- memory_.SetData8(0x60c, 0x1);
+ memory_.SetMemory(0x608, std::vector<uint8_t>{1, '\0', 4, 4, 1});
// FDE 32.
memory_.SetData32(0x700, 0xfc);