diff options
author | Yabin Cui <yabinc@google.com> | 2022-11-14 11:52:18 -0800 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2022-11-15 13:35:28 -0800 |
commit | 2315ff61f1172e7a3aa5db481c1ff51785407129 (patch) | |
tree | aeb3362774fac503ed8568fbfe024bfb51fab27c | |
parent | f6c4be2195899f3dd281a81a0a6d37173a96a30d (diff) | |
download | extras-2315ff61f1172e7a3aa5db481c1ff51785407129.tar.gz |
simpleperf: suppress read symbol warning for not-ELF files.
Bug: 195561085
Test: run simpleperf_unit_test
Change-Id: I79ea304a9c7743a18e69548598167aec7577272f
-rw-r--r-- | simpleperf/dso.cpp | 13 | ||||
-rw-r--r-- | simpleperf/dso_test.cpp | 40 |
2 files changed, 51 insertions, 2 deletions
diff --git a/simpleperf/dso.cpp b/simpleperf/dso.cpp index 7167c02d..71d40c38 100644 --- a/simpleperf/dso.cpp +++ b/simpleperf/dso.cpp @@ -617,8 +617,17 @@ class ElfDso : public Dso { if (elf) { status = elf->ParseSymbols(symbol_callback); } - ReportReadElfSymbolResult(status, path_, GetDebugFilePath(), - symbols_.empty() ? android::base::WARNING : android::base::DEBUG); + android::base::LogSeverity log_level = android::base::WARNING; + if (!symbols_.empty()) { + // We already have some symbols when recording. + log_level = android::base::DEBUG; + } + if ((status == ElfStatus::FILE_NOT_FOUND || status == ElfStatus::FILE_MALFORMED) && + build_id.IsEmpty()) { + // This is likely to be a file wongly thought of as an ELF file, maybe due to stack unwinding. + log_level = android::base::DEBUG; + } + ReportReadElfSymbolResult(status, path_, GetDebugFilePath(), log_level); SortAndFixSymbols(symbols); return symbols; } diff --git a/simpleperf/dso_test.cpp b/simpleperf/dso_test.cpp index d8ab3f8b..a1a37d34 100644 --- a/simpleperf/dso_test.cpp +++ b/simpleperf/dso_test.cpp @@ -331,3 +331,43 @@ TEST(dso, search_debug_file_only_when_needed) { ASSERT_NE(capture.str().find("build id mismatch"), std::string::npos); capture.Stop(); } + +TEST(dso, read_symbol_warning) { + { + // Don't warn when the file may not be an ELF file. + auto dso = Dso::CreateDso(DSO_ELF_FILE, GetTestData("not_exist_file")); + CapturedStderr capture; + dso->LoadSymbols(); + ASSERT_EQ(capture.str().find("failed to read symbols"), std::string::npos); + } + { + // Don't warn when the file may not be an ELF file. + auto dso = Dso::CreateDso(DSO_ELF_FILE, GetTestData("base.vdex")); + CapturedStderr capture; + dso->LoadSymbols(); + ASSERT_EQ(capture.str().find("failed to read symbols"), std::string::npos); + } + { + // Warn when the file is an ELF file (having a build id). + std::string file_path = GetTestData("not_exist_file"); + Dso::SetBuildIds( + {std::make_pair(file_path, BuildId("1b12a384a9f4a3f3659b7171ca615dbec3a81f71"))}); + auto dso = Dso::CreateDso(DSO_ELF_FILE, file_path); + CapturedStderr capture; + dso->LoadSymbols(); + ASSERT_NE(capture.str().find("failed to read symbols"), std::string::npos); + } + { + // Don't warn when we already have symbols. + std::string file_path = GetTestData("not_exist_file"); + Dso::SetBuildIds( + {std::make_pair(file_path, BuildId("1b12a384a9f4a3f3659b7171ca615dbec3a81f71"))}); + auto dso = Dso::CreateDso(DSO_ELF_FILE, file_path); + std::vector<Symbol> symbols; + symbols.emplace_back("fake_symbol", 0x1234, 0x60); + dso->SetSymbols(&symbols); + CapturedStderr capture; + dso->LoadSymbols(); + ASSERT_EQ(capture.str().find("failed to read symbols"), std::string::npos); + } +} |