diff options
author | Yabin Cui <yabinc@google.com> | 2018-05-09 17:27:27 -0700 |
---|---|---|
committer | Yabin Cui <yabinc@google.com> | 2018-05-09 17:47:08 -0700 |
commit | 8422f3437188ae3e4d4b8ee5f65804cc23d9fda4 (patch) | |
tree | f987549465c839100723ffab08ac9a30a19f28a6 /simpleperf/dso.cpp | |
parent | dc0191161cb4557535e89d45c8cfdd2305dcef4e (diff) | |
download | extras-8422f3437188ae3e4d4b8ee5f65804cc23d9fda4.tar.gz |
simpleperf: change interface of read_apk.h.
1. Remove GetBuildIdFromApkFile and ParseSymbolsFromApkFile, because
their function can be supported using ApkInspector::FindElfInApkByName
and read_elf.h.
2. Remove ApkInspector::FindOffsetInApkByName, instead the caller can
use ApkInspector::FindElfInApkByName directly.
3. In ApkInspector::embedded_elf_cache_, add map for entry_name. So
the EmbeddedElfs added by cmd_record.cpp can be used by OfflineUnwinder.
Also support reading min executable virtual address from embedded elfs
in ElfDso.
Also avoid segfault reading build id of elf files with broken section
table, and add test.
Bug: none.
Test: run simpleperf_unit_test.
Change-Id: I2e4f51a5e348138cbf7445ec6dd42dbd6ae1b03d
Diffstat (limited to 'simpleperf/dso.cpp')
-rw-r--r-- | simpleperf/dso.cpp | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/simpleperf/dso.cpp b/simpleperf/dso.cpp index cdc21049..04342744 100644 --- a/simpleperf/dso.cpp +++ b/simpleperf/dso.cpp @@ -374,8 +374,20 @@ class ElfDso : public Dso { BuildId build_id = GetExpectedBuildId(); uint64_t addr; - ElfStatus result = ReadMinExecutableVirtualAddressFromElfFile( - GetDebugFilePath(), build_id, &addr); + ElfStatus result; + auto tuple = SplitUrlInApk(debug_file_path_); + if (std::get<0>(tuple)) { + EmbeddedElf* elf = ApkInspector::FindElfInApkByName(std::get<1>(tuple), + std::get<2>(tuple)); + if (elf == nullptr) { + result = ElfStatus::FILE_NOT_FOUND; + } else { + result = ReadMinExecutableVirtualAddressFromEmbeddedElfFile( + elf->filepath(), elf->entry_offset(), elf->entry_size(), build_id, &addr); + } + } else { + result = ReadMinExecutableVirtualAddressFromElfFile(debug_file_path_, build_id, &addr); + } if (result != ElfStatus::NO_ERROR) { LOG(WARNING) << "failed to read min virtual address of " << GetDebugFilePath() << ": " << result; @@ -423,8 +435,13 @@ class ElfDso : public Dso { ElfStatus status; std::tuple<bool, std::string, std::string> tuple = SplitUrlInApk(debug_file_path_); if (std::get<0>(tuple)) { - status = ParseSymbolsFromApkFile(std::get<1>(tuple), std::get<2>(tuple), build_id, - symbol_callback); + EmbeddedElf* elf = ApkInspector::FindElfInApkByName(std::get<1>(tuple), std::get<2>(tuple)); + if (elf == nullptr) { + status = ElfStatus::FILE_NOT_FOUND; + } else { + status = ParseSymbolsFromEmbeddedElfFile(elf->filepath(), elf->entry_offset(), + elf->entry_size(), build_id, symbol_callback); + } } else { status = ParseSymbolsFromElfFile(debug_file_path_, build_id, symbol_callback); } @@ -576,7 +593,13 @@ bool GetBuildIdFromDsoPath(const std::string& dso_path, BuildId* build_id) { auto tuple = SplitUrlInApk(dso_path); ElfStatus result; if (std::get<0>(tuple)) { - result = GetBuildIdFromApkFile(std::get<1>(tuple), std::get<2>(tuple), build_id); + EmbeddedElf* elf = ApkInspector::FindElfInApkByName(std::get<1>(tuple), std::get<2>(tuple)); + if (elf == nullptr) { + result = ElfStatus::FILE_NOT_FOUND; + } else { + result = GetBuildIdFromEmbeddedElfFile(elf->filepath(), elf->entry_offset(), + elf->entry_size(), build_id); + } } else { result = GetBuildIdFromElfFile(dso_path, build_id); } |