diff options
author | Christopher Ferris <cferris@google.com> | 2022-03-15 23:19:56 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-03-15 23:19:56 +0000 |
commit | e99edcb1158f41891f321d8db5089dd70d54bebb (patch) | |
tree | 6b6a8104bce13ab8356f4c056be223003334a10f | |
parent | 312a6a714f5691d063bb997ce95518f207127d89 (diff) | |
parent | ae901bf107756ea3c3ad53e4845b423996a5ab34 (diff) | |
download | unwinding-e99edcb1158f41891f321d8db5089dd70d54bebb.tar.gz |
Remove elf_from_memory_not_file from unwinder. am: 4ed20b59e9 am: ae901bf107
Original change: https://android-review.googlesource.com/c/platform/system/unwinding/+/2025803
Change-Id: Icd5608ce8b40d5b9d7cc3c72733f27f78558d99e
-rw-r--r-- | libunwindstack/MapInfo.cpp | 8 | ||||
-rw-r--r-- | libunwindstack/Unwinder.cpp | 9 | ||||
-rw-r--r-- | libunwindstack/include/unwindstack/MapInfo.h | 4 | ||||
-rw-r--r-- | libunwindstack/include/unwindstack/Unwinder.h | 5 | ||||
-rw-r--r-- | libunwindstack/tests/MapInfoTest.cpp | 18 | ||||
-rw-r--r-- | libunwindstack/tests/UnwinderTest.cpp | 32 |
6 files changed, 32 insertions, 44 deletions
diff --git a/libunwindstack/MapInfo.cpp b/libunwindstack/MapInfo.cpp index f19c6b7..6db1183 100644 --- a/libunwindstack/MapInfo.cpp +++ b/libunwindstack/MapInfo.cpp @@ -23,6 +23,8 @@ #include <mutex> #include <string> +#include <android-base/strings.h> + #include <unwindstack/Elf.h> #include <unwindstack/MapInfo.h> #include <unwindstack/Maps.h> @@ -32,6 +34,12 @@ namespace unwindstack { +bool MapInfo::ElfFileNotReadable() { + const std::string& map_name = name(); + return memory_backed_elf() && !map_name.empty() && map_name[0] != '[' && + !android::base::StartsWith(map_name, "/memfd:"); +} + std::shared_ptr<MapInfo> MapInfo::GetPrevRealMap() { if (name().empty()) { return nullptr; diff --git a/libunwindstack/Unwinder.cpp b/libunwindstack/Unwinder.cpp index 2312652..f6def23 100644 --- a/libunwindstack/Unwinder.cpp +++ b/libunwindstack/Unwinder.cpp @@ -28,7 +28,6 @@ #include <android-base/file.h> #include <android-base/stringprintf.h> -#include <android-base/strings.h> #include <unwindstack/DexFiles.h> #include <unwindstack/Elf.h> @@ -127,7 +126,6 @@ void Unwinder::Unwind(const std::vector<std::string>* initial_map_names_to_skip, ClearErrors(); frames_.clear(); - elf_from_memory_not_file_ = false; // Clear any cached data from previous unwinds. process_memory_->Clear(); @@ -161,13 +159,6 @@ void Unwinder::Unwind(const std::vector<std::string>* initial_map_names_to_skip, break; } elf = map_info->GetElf(process_memory_, arch_); - // If this elf is memory backed, and there is a valid file, then set - // an indicator that we couldn't open the file. - const std::string& map_name = map_info->name(); - if (!elf_from_memory_not_file_ && map_info->memory_backed_elf() && !map_name.empty() && - map_name[0] != '[' && !android::base::StartsWith(map_name, "/memfd:")) { - elf_from_memory_not_file_ = true; - } step_pc = regs_->pc(); rel_pc = elf->GetRelPc(step_pc, map_info.get()); // Everyone except elf data in gdb jit debug maps uses the relative pc. diff --git a/libunwindstack/include/unwindstack/MapInfo.h b/libunwindstack/include/unwindstack/MapInfo.h index 41aeaf3..ce4dbea 100644 --- a/libunwindstack/include/unwindstack/MapInfo.h +++ b/libunwindstack/include/unwindstack/MapInfo.h @@ -102,6 +102,10 @@ class MapInfo { std::mutex elf_mutex_; }; + // True if the file named by this map is not actually readable and the + // elf is using the data in memory. + bool ElfFileNotReadable(); + // This is the previous map with the same name that is not empty and with // a 0 offset. For example, this set of maps: // 1000-2000 r--p 000000 00:00 0 libc.so diff --git a/libunwindstack/include/unwindstack/Unwinder.h b/libunwindstack/include/unwindstack/Unwinder.h index e21e91d..de3438f 100644 --- a/libunwindstack/include/unwindstack/Unwinder.h +++ b/libunwindstack/include/unwindstack/Unwinder.h @@ -102,8 +102,6 @@ class Unwinder { void SetDexFiles(DexFiles* dex_files); - bool elf_from_memory_not_file() { return elf_from_memory_not_file_; } - ErrorCode LastErrorCode() { return last_error_.code; } const char* LastErrorCodeString() { return GetErrorCodeString(last_error_.code); } uint64_t LastErrorAddress() { return last_error_.address; } @@ -142,9 +140,6 @@ class Unwinder { DexFiles* dex_files_ = nullptr; bool resolve_names_ = true; bool display_build_id_ = false; - // True if at least one elf file is coming from memory and not the related - // file. This is only true if there is an actual file backing up the elf. - bool elf_from_memory_not_file_ = false; ErrorData last_error_; uint64_t warnings_; ArchEnum arch_ = ARCH_UNKNOWN; diff --git a/libunwindstack/tests/MapInfoTest.cpp b/libunwindstack/tests/MapInfoTest.cpp index 16b4747..9cfbb44 100644 --- a/libunwindstack/tests/MapInfoTest.cpp +++ b/libunwindstack/tests/MapInfoTest.cpp @@ -174,4 +174,22 @@ TEST(MapInfoTest, multiple_thread_get_elf_fields) { } } +TEST(MapInfoTest, elf_file_not_readable) { + auto map_info_readable = MapInfo::Create(0, 0x1000, 0, PROT_READ, "fake.so"); + map_info_readable->set_memory_backed_elf(true); + ASSERT_TRUE(map_info_readable->ElfFileNotReadable()); + + auto map_info_no_name = MapInfo::Create(0, 0x1000, 0, PROT_READ, ""); + map_info_no_name->set_memory_backed_elf(true); + ASSERT_FALSE(map_info_no_name->ElfFileNotReadable()); + + auto map_info_bracket = MapInfo::Create(0, 0x2000, 0, PROT_READ, "[vdso]"); + map_info_bracket->set_memory_backed_elf(true); + ASSERT_FALSE(map_info_bracket->ElfFileNotReadable()); + + auto map_info_memfd = MapInfo::Create(0, 0x3000, 0, PROT_READ, "/memfd:jit-cache"); + map_info_memfd->set_memory_backed_elf(true); + ASSERT_FALSE(map_info_memfd->ElfFileNotReadable()); +} + } // namespace unwindstack diff --git a/libunwindstack/tests/UnwinderTest.cpp b/libunwindstack/tests/UnwinderTest.cpp index 8e43fe4..74bc516 100644 --- a/libunwindstack/tests/UnwinderTest.cpp +++ b/libunwindstack/tests/UnwinderTest.cpp @@ -206,7 +206,6 @@ TEST_F(UnwinderTest, multiple_frames) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(3U, unwinder.NumFrames()); @@ -278,7 +277,6 @@ TEST_F(UnwinderTest, multiple_frames_dont_resolve_names) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(3U, unwinder.NumFrames()); @@ -345,7 +343,6 @@ TEST_F(UnwinderTest, non_zero_load_bias) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(1U, unwinder.NumFrames()); @@ -378,7 +375,6 @@ TEST_F(UnwinderTest, non_zero_elf_offset) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(1U, unwinder.NumFrames()); @@ -411,7 +407,6 @@ TEST_F(UnwinderTest, non_zero_map_offset) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(1U, unwinder.NumFrames()); @@ -451,7 +446,6 @@ TEST_F(UnwinderTest, no_frames_after_finished) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(1U, unwinder.NumFrames()); @@ -487,7 +481,6 @@ TEST_F(UnwinderTest, max_frames) { unwinder.Unwind(); EXPECT_EQ(ERROR_MAX_FRAMES_EXCEEDED, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(20U, unwinder.NumFrames()); @@ -534,7 +527,6 @@ TEST_F(UnwinderTest, verify_frames_skipped) { unwinder.Unwind(&skip_libs); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(3U, unwinder.NumFrames()); @@ -603,7 +595,6 @@ TEST_F(UnwinderTest, sp_not_in_map) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(2U, unwinder.NumFrames()); @@ -656,7 +647,6 @@ TEST_F(UnwinderTest, pc_in_device_stops_unwind) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(1U, unwinder.NumFrames()); } @@ -677,7 +667,6 @@ TEST_F(UnwinderTest, sp_in_device_stops_unwind) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(1U, unwinder.NumFrames()); } @@ -693,7 +682,6 @@ TEST_F(UnwinderTest, pc_without_map) { unwinder.Unwind(); EXPECT_EQ(ERROR_INVALID_MAP, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(1U, unwinder.NumFrames()); @@ -725,7 +713,6 @@ TEST_F(UnwinderTest, speculative_frame) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(3U, unwinder.NumFrames()); @@ -790,7 +777,6 @@ TEST_F(UnwinderTest, speculative_frame_removed) { unwinder.Unwind(); EXPECT_EQ(ERROR_INVALID_MAP, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(2U, unwinder.NumFrames()); @@ -837,7 +823,6 @@ TEST_F(UnwinderTest, speculative_frame_not_removed_pc_bad) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(2U, unwinder.NumFrames()); @@ -882,7 +867,6 @@ TEST_F(UnwinderTest, speculative_frame_check_with_no_frames) { unwinder.Unwind(&skip_names); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(0U, unwinder.NumFrames()); } @@ -899,7 +883,6 @@ TEST_F(UnwinderTest, speculative_frame_to_invalid_map_not_hide_prev_error) { unwinder.Unwind(); EXPECT_EQ(ERROR_INVALID_ELF, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(1U, unwinder.NumFrames()); @@ -932,7 +915,6 @@ TEST_F(UnwinderTest, map_ignore_suffixes) { unwinder.Unwind(nullptr, &suffixes); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(2U, unwinder.NumFrames()); // Make sure the elf was not initialized. @@ -996,7 +978,6 @@ TEST_F(UnwinderTest, sp_pc_do_not_change) { unwinder.Unwind(); EXPECT_EQ(ERROR_REPEATED_FRAME, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(3U, unwinder.NumFrames()); @@ -1062,7 +1043,6 @@ TEST_F(UnwinderTest, dex_pc_in_map) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(2U, unwinder.NumFrames()); @@ -1111,7 +1091,6 @@ TEST_F(UnwinderTest, dex_pc_in_map_non_zero_offset) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(2U, unwinder.NumFrames()); @@ -1160,7 +1139,6 @@ TEST_F(UnwinderTest, dex_pc_not_in_map) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_DEX_PC_NOT_IN_MAP, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(2U, unwinder.NumFrames()); @@ -1203,7 +1181,6 @@ TEST_F(UnwinderTest, dex_pc_not_in_map_valid_dex_files) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_DEX_PC_NOT_IN_MAP, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(2U, unwinder.NumFrames()); @@ -1247,7 +1224,6 @@ TEST_F(UnwinderTest, dex_pc_multiple_frames) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(3U, unwinder.NumFrames()); @@ -1312,7 +1288,6 @@ TEST_F(UnwinderTest, dex_pc_max_frames) { unwinder.Unwind(); EXPECT_EQ(ERROR_MAX_FRAMES_EXCEEDED, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(1U, unwinder.NumFrames()); @@ -1334,7 +1309,7 @@ TEST_F(UnwinderTest, dex_pc_max_frames) { EXPECT_EQ(PROT_READ | PROT_WRITE | PROT_EXEC, frame->map_info->flags()); } -TEST_F(UnwinderTest, elf_from_memory_not_file) { +TEST_F(UnwinderTest, elf_file_not_readable) { ElfInterfaceFake::FakePushFunctionData(FunctionData("Frame0", 0)); regs_.set_pc(0xc0050); @@ -1345,7 +1320,6 @@ TEST_F(UnwinderTest, elf_from_memory_not_file) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_TRUE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(1U, unwinder.NumFrames()); @@ -1357,6 +1331,7 @@ TEST_F(UnwinderTest, elf_from_memory_not_file) { EXPECT_EQ("Frame0", frame->function_name); EXPECT_EQ(0U, frame->function_offset); ASSERT_TRUE(frame->map_info != nullptr); + EXPECT_TRUE(frame->map_info->ElfFileNotReadable()); EXPECT_EQ("/fake/unreadable.so", frame->map_info->name()); EXPECT_EQ("/fake/unreadable.so", frame->map_info->GetFullName()); EXPECT_EQ(0U, frame->map_info->elf_start_offset()); @@ -1378,7 +1353,6 @@ TEST_F(UnwinderTest, elf_from_memory_but_no_valid_file_with_bracket) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(1U, unwinder.NumFrames()); @@ -1411,7 +1385,6 @@ TEST_F(UnwinderTest, elf_from_memory_but_empty_filename) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(1U, unwinder.NumFrames()); @@ -1444,7 +1417,6 @@ TEST_F(UnwinderTest, elf_from_memory_but_from_memfd) { unwinder.Unwind(); EXPECT_EQ(ERROR_NONE, unwinder.LastErrorCode()); EXPECT_EQ(WARNING_NONE, unwinder.warnings()); - EXPECT_FALSE(unwinder.elf_from_memory_not_file()); ASSERT_EQ(1U, unwinder.NumFrames()); |