From 02a6c448c32c37aae834bc25e92db97bfac32524 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Mon, 11 Mar 2019 14:43:33 -0700 Subject: Add support for displaying soname in an apk. Changes: - Change GetSoname to always returns a std::string. - Added new unit tests for the soname printing. - Modify the GetElf() function to save the same elf when we see rosegment linkers that split the read-only and read-write across a map. This avoids creating multiple elf objects for each map. - Fixed a few offline unwind tests. Bug: 29218999 Test: Unit tests pass. Change-Id: Iad7c38b5c2957a8c5fd4ba94ebec335bafcad57d --- libunwindstack/tests/MapInfoGetElfTest.cpp | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'libunwindstack/tests/MapInfoGetElfTest.cpp') diff --git a/libunwindstack/tests/MapInfoGetElfTest.cpp b/libunwindstack/tests/MapInfoGetElfTest.cpp index d7b848544..d60b8b1af 100644 --- a/libunwindstack/tests/MapInfoGetElfTest.cpp +++ b/libunwindstack/tests/MapInfoGetElfTest.cpp @@ -371,4 +371,35 @@ TEST_F(MapInfoGetElfTest, multiple_thread_get_elf) { } } +// Verify that previous maps don't automatically get the same elf object. +TEST_F(MapInfoGetElfTest, prev_map_elf_not_set) { + MapInfo info1(nullptr, 0x1000, 0x2000, 0, PROT_READ, "/not/present"); + MapInfo info2(&info1, 0x2000, 0x3000, 0, PROT_READ, elf_.path); + + Elf32_Ehdr ehdr; + TestInitEhdr(&ehdr, ELFCLASS32, EM_ARM); + memory_->SetMemory(0x2000, &ehdr, sizeof(ehdr)); + Elf* elf = info2.GetElf(process_memory_, ARCH_ARM); + ASSERT_TRUE(elf != nullptr); + ASSERT_TRUE(elf->valid()); + + ASSERT_NE(elf, info1.GetElf(process_memory_, ARCH_ARM)); +} + +// Verify that a read-only map followed by a read-execute map will result +// in the same elf object in both maps. +TEST_F(MapInfoGetElfTest, read_only_followed_by_read_exec_share_elf) { + MapInfo r_info(nullptr, 0x1000, 0x2000, 0, PROT_READ, elf_.path); + MapInfo rw_info(&r_info, 0x2000, 0x3000, 0x1000, PROT_READ | PROT_EXEC, elf_.path); + + Elf32_Ehdr ehdr; + TestInitEhdr(&ehdr, ELFCLASS32, EM_ARM); + memory_->SetMemory(0x1000, &ehdr, sizeof(ehdr)); + Elf* elf = rw_info.GetElf(process_memory_, ARCH_ARM); + ASSERT_TRUE(elf != nullptr); + ASSERT_TRUE(elf->valid()); + + ASSERT_EQ(elf, r_info.GetElf(process_memory_, ARCH_ARM)); +} + } // namespace unwindstack -- cgit v1.2.3