summaryrefslogtreecommitdiffstats
path: root/libunwindstack/tests/DwarfSectionTest.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2018-06-21 10:44:02 -0700
committerChristopher Ferris <cferris@google.com>2018-06-27 14:52:21 -0700
commit92acaac8c713c3e1828948064ebca055dc00a723 (patch)
treed50cf188a4df626b8e9718469575e7ff17671dd7 /libunwindstack/tests/DwarfSectionTest.cpp
parentfc1cf90741e59d5615a7dcea1813f38bfa3a2eec (diff)
downloadsystem_core-92acaac8c713c3e1828948064ebca055dc00a723.tar.gz
system_core-92acaac8c713c3e1828948064ebca055dc00a723.tar.bz2
system_core-92acaac8c713c3e1828948064ebca055dc00a723.zip
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
Diffstat (limited to 'libunwindstack/tests/DwarfSectionTest.cpp')
-rw-r--r--libunwindstack/tests/DwarfSectionTest.cpp135
1 files changed, 33 insertions, 102 deletions
diff --git a/libunwindstack/tests/DwarfSectionTest.cpp b/libunwindstack/tests/DwarfSectionTest.cpp
index 2c6c8790a..d754fcc50 100644
--- a/libunwindstack/tests/DwarfSectionTest.cpp
+++ b/libunwindstack/tests/DwarfSectionTest.cpp
@@ -30,23 +30,17 @@ class MockDwarfSection : public DwarfSection {
MockDwarfSection(Memory* memory) : DwarfSection(memory) {}
virtual ~MockDwarfSection() = default;
- MOCK_METHOD3(Log, bool(uint8_t, uint64_t, const DwarfFde*));
-
- MOCK_METHOD5(Eval, bool(const DwarfCie*, Memory*, const dwarf_loc_regs_t&, Regs*, bool*));
-
- MOCK_METHOD3(GetCfaLocationInfo, bool(uint64_t, const DwarfFde*, dwarf_loc_regs_t*));
-
MOCK_METHOD3(Init, bool(uint64_t, uint64_t, uint64_t));
- MOCK_METHOD2(GetFdeOffsetFromPc, bool(uint64_t, uint64_t*));
+ MOCK_METHOD5(Eval, bool(const DwarfCie*, Memory*, const dwarf_loc_regs_t&, Regs*, bool*));
- MOCK_METHOD1(GetFdeFromOffset, const DwarfFde*(uint64_t));
+ MOCK_METHOD3(Log, bool(uint8_t, uint64_t, const DwarfFde*));
- MOCK_METHOD1(GetFdeFromIndex, const DwarfFde*(size_t));
+ MOCK_METHOD1(GetFdes, void(std::vector<const DwarfFde*>*));
- MOCK_METHOD1(IsCie32, bool(uint32_t));
+ MOCK_METHOD1(GetFdeFromPc, const DwarfFde*(uint64_t));
- MOCK_METHOD1(IsCie64, bool(uint64_t));
+ MOCK_METHOD3(GetCfaLocationInfo, bool(uint64_t, const DwarfFde*, dwarf_loc_regs_t*));
MOCK_METHOD1(GetCieOffsetFromFde32, uint64_t(uint32_t));
@@ -57,112 +51,60 @@ class MockDwarfSection : public DwarfSection {
class DwarfSectionTest : public ::testing::Test {
protected:
+ void SetUp() override { section_.reset(new MockDwarfSection(&memory_)); }
+
MemoryFake memory_;
+ std::unique_ptr<MockDwarfSection> section_;
};
-TEST_F(DwarfSectionTest, GetFdeOffsetFromPc_fail_from_pc) {
- MockDwarfSection mock_section(&memory_);
-
- EXPECT_CALL(mock_section, GetFdeOffsetFromPc(0x1000, ::testing::_))
- .WillOnce(::testing::Return(false));
-
- // Verify nullptr when GetFdeOffsetFromPc fails.
- ASSERT_TRUE(mock_section.GetFdeFromPc(0x1000) == nullptr);
-}
-
-TEST_F(DwarfSectionTest, GetFdeOffsetFromPc_fail_fde_pc_end) {
- MockDwarfSection mock_section(&memory_);
-
- DwarfFde fde{};
- fde.pc_end = 0x500;
-
- EXPECT_CALL(mock_section, GetFdeOffsetFromPc(0x1000, ::testing::_))
- .WillOnce(::testing::Return(true));
- EXPECT_CALL(mock_section, GetFdeFromOffset(::testing::_)).WillOnce(::testing::Return(&fde));
-
- // Verify nullptr when GetFdeOffsetFromPc fails.
- ASSERT_TRUE(mock_section.GetFdeFromPc(0x1000) == nullptr);
-}
-
-TEST_F(DwarfSectionTest, GetFdeOffsetFromPc_pass) {
- MockDwarfSection mock_section(&memory_);
-
- DwarfFde fde{};
- fde.pc_end = 0x2000;
-
- EXPECT_CALL(mock_section, GetFdeOffsetFromPc(0x1000, ::testing::_))
- .WillOnce(::testing::Return(true));
- EXPECT_CALL(mock_section, GetFdeFromOffset(::testing::_)).WillOnce(::testing::Return(&fde));
-
- // Verify nullptr when GetFdeOffsetFromPc fails.
- ASSERT_EQ(&fde, mock_section.GetFdeFromPc(0x1000));
-}
-
TEST_F(DwarfSectionTest, Step_fail_fde) {
- MockDwarfSection mock_section(&memory_);
-
- EXPECT_CALL(mock_section, GetFdeOffsetFromPc(0x1000, ::testing::_))
- .WillOnce(::testing::Return(false));
+ EXPECT_CALL(*section_, GetFdeFromPc(0x1000)).WillOnce(::testing::Return(nullptr));
bool finished;
- ASSERT_FALSE(mock_section.Step(0x1000, nullptr, nullptr, &finished));
+ ASSERT_FALSE(section_->Step(0x1000, nullptr, nullptr, &finished));
}
TEST_F(DwarfSectionTest, Step_fail_cie_null) {
- MockDwarfSection mock_section(&memory_);
-
DwarfFde fde{};
fde.pc_end = 0x2000;
fde.cie = nullptr;
- EXPECT_CALL(mock_section, GetFdeOffsetFromPc(0x1000, ::testing::_))
- .WillOnce(::testing::Return(true));
- EXPECT_CALL(mock_section, GetFdeFromOffset(::testing::_)).WillOnce(::testing::Return(&fde));
+ EXPECT_CALL(*section_, GetFdeFromPc(0x1000)).WillOnce(::testing::Return(&fde));
bool finished;
- ASSERT_FALSE(mock_section.Step(0x1000, nullptr, nullptr, &finished));
+ ASSERT_FALSE(section_->Step(0x1000, nullptr, nullptr, &finished));
}
TEST_F(DwarfSectionTest, Step_fail_cfa_location) {
- MockDwarfSection mock_section(&memory_);
-
DwarfCie cie{};
DwarfFde fde{};
fde.pc_end = 0x2000;
fde.cie = &cie;
- EXPECT_CALL(mock_section, GetFdeOffsetFromPc(0x1000, ::testing::_))
- .WillOnce(::testing::Return(true));
- EXPECT_CALL(mock_section, GetFdeFromOffset(::testing::_)).WillOnce(::testing::Return(&fde));
-
- EXPECT_CALL(mock_section, GetCfaLocationInfo(0x1000, &fde, ::testing::_))
+ EXPECT_CALL(*section_, GetFdeFromPc(0x1000)).WillOnce(::testing::Return(&fde));
+ EXPECT_CALL(*section_, GetCfaLocationInfo(0x1000, &fde, ::testing::_))
.WillOnce(::testing::Return(false));
bool finished;
- ASSERT_FALSE(mock_section.Step(0x1000, nullptr, nullptr, &finished));
+ ASSERT_FALSE(section_->Step(0x1000, nullptr, nullptr, &finished));
}
TEST_F(DwarfSectionTest, Step_pass) {
- MockDwarfSection mock_section(&memory_);
-
DwarfCie cie{};
DwarfFde fde{};
fde.pc_end = 0x2000;
fde.cie = &cie;
- EXPECT_CALL(mock_section, GetFdeOffsetFromPc(0x1000, ::testing::_))
- .WillOnce(::testing::Return(true));
- EXPECT_CALL(mock_section, GetFdeFromOffset(::testing::_)).WillOnce(::testing::Return(&fde));
-
- EXPECT_CALL(mock_section, GetCfaLocationInfo(0x1000, &fde, ::testing::_))
+ EXPECT_CALL(*section_, GetFdeFromPc(0x1000)).WillOnce(::testing::Return(&fde));
+ EXPECT_CALL(*section_, GetCfaLocationInfo(0x1000, &fde, ::testing::_))
.WillOnce(::testing::Return(true));
MemoryFake process;
- EXPECT_CALL(mock_section, Eval(&cie, &process, ::testing::_, nullptr, ::testing::_))
+ EXPECT_CALL(*section_, Eval(&cie, &process, ::testing::_, nullptr, ::testing::_))
.WillOnce(::testing::Return(true));
bool finished;
- ASSERT_TRUE(mock_section.Step(0x1000, nullptr, &process, &finished));
+ ASSERT_TRUE(section_->Step(0x1000, nullptr, &process, &finished));
}
static bool MockGetCfaLocationInfo(::testing::Unused, const DwarfFde* fde,
@@ -173,64 +115,53 @@ static bool MockGetCfaLocationInfo(::testing::Unused, const DwarfFde* fde,
}
TEST_F(DwarfSectionTest, Step_cache) {
- MockDwarfSection mock_section(&memory_);
-
DwarfCie cie{};
DwarfFde fde{};
fde.pc_start = 0x500;
fde.pc_end = 0x2000;
fde.cie = &cie;
- EXPECT_CALL(mock_section, GetFdeOffsetFromPc(0x1000, ::testing::_))
- .WillOnce(::testing::Return(true));
- EXPECT_CALL(mock_section, GetFdeFromOffset(::testing::_)).WillOnce(::testing::Return(&fde));
-
- EXPECT_CALL(mock_section, GetCfaLocationInfo(0x1000, &fde, ::testing::_))
+ EXPECT_CALL(*section_, GetFdeFromPc(0x1000)).WillOnce(::testing::Return(&fde));
+ EXPECT_CALL(*section_, GetCfaLocationInfo(0x1000, &fde, ::testing::_))
.WillOnce(::testing::Invoke(MockGetCfaLocationInfo));
MemoryFake process;
- EXPECT_CALL(mock_section, Eval(&cie, &process, ::testing::_, nullptr, ::testing::_))
+ EXPECT_CALL(*section_, Eval(&cie, &process, ::testing::_, nullptr, ::testing::_))
.WillRepeatedly(::testing::Return(true));
bool finished;
- ASSERT_TRUE(mock_section.Step(0x1000, nullptr, &process, &finished));
- ASSERT_TRUE(mock_section.Step(0x1000, nullptr, &process, &finished));
- ASSERT_TRUE(mock_section.Step(0x1500, nullptr, &process, &finished));
+ ASSERT_TRUE(section_->Step(0x1000, nullptr, &process, &finished));
+ ASSERT_TRUE(section_->Step(0x1000, nullptr, &process, &finished));
+ ASSERT_TRUE(section_->Step(0x1500, nullptr, &process, &finished));
}
TEST_F(DwarfSectionTest, Step_cache_not_in_pc) {
- MockDwarfSection mock_section(&memory_);
-
DwarfCie cie{};
DwarfFde fde0{};
fde0.pc_start = 0x1000;
fde0.pc_end = 0x2000;
fde0.cie = &cie;
- EXPECT_CALL(mock_section, GetFdeOffsetFromPc(0x1000, ::testing::_))
- .WillOnce(::testing::Return(true));
- EXPECT_CALL(mock_section, GetFdeFromOffset(::testing::_)).WillOnce(::testing::Return(&fde0));
- EXPECT_CALL(mock_section, GetCfaLocationInfo(0x1000, &fde0, ::testing::_))
+ EXPECT_CALL(*section_, GetFdeFromPc(0x1000)).WillOnce(::testing::Return(&fde0));
+ EXPECT_CALL(*section_, GetCfaLocationInfo(0x1000, &fde0, ::testing::_))
.WillOnce(::testing::Invoke(MockGetCfaLocationInfo));
MemoryFake process;
- EXPECT_CALL(mock_section, Eval(&cie, &process, ::testing::_, nullptr, ::testing::_))
+ EXPECT_CALL(*section_, Eval(&cie, &process, ::testing::_, nullptr, ::testing::_))
.WillRepeatedly(::testing::Return(true));
bool finished;
- ASSERT_TRUE(mock_section.Step(0x1000, nullptr, &process, &finished));
+ ASSERT_TRUE(section_->Step(0x1000, nullptr, &process, &finished));
DwarfFde fde1{};
fde1.pc_start = 0x500;
fde1.pc_end = 0x800;
fde1.cie = &cie;
- EXPECT_CALL(mock_section, GetFdeOffsetFromPc(0x600, ::testing::_))
- .WillOnce(::testing::Return(true));
- EXPECT_CALL(mock_section, GetFdeFromOffset(::testing::_)).WillOnce(::testing::Return(&fde1));
- EXPECT_CALL(mock_section, GetCfaLocationInfo(0x600, &fde1, ::testing::_))
+ EXPECT_CALL(*section_, GetFdeFromPc(0x600)).WillOnce(::testing::Return(&fde1));
+ EXPECT_CALL(*section_, GetCfaLocationInfo(0x600, &fde1, ::testing::_))
.WillOnce(::testing::Invoke(MockGetCfaLocationInfo));
- ASSERT_TRUE(mock_section.Step(0x600, nullptr, &process, &finished));
- ASSERT_TRUE(mock_section.Step(0x700, nullptr, &process, &finished));
+ ASSERT_TRUE(section_->Step(0x600, nullptr, &process, &finished));
+ ASSERT_TRUE(section_->Step(0x700, nullptr, &process, &finished));
}
} // namespace unwindstack