summaryrefslogtreecommitdiff
path: root/simpleperf/read_apk.cpp
diff options
context:
space:
mode:
authorChristopher Ferris <cferris@google.com>2017-12-14 15:53:37 -0800
committerChristopher Ferris <cferris@google.com>2018-01-29 16:25:48 -0800
commit11017687d6deef1bf510d3000933351a75ddf28c (patch)
treee32a7456d475f93222d5b91986269041f5ad9927 /simpleperf/read_apk.cpp
parent74ffa03189676d35ebd95abded8ea926d83466f5 (diff)
downloadextras-11017687d6deef1bf510d3000933351a75ddf28c.tar.gz
Change to new libbacktrace offline functions.
Changes: - Removes references to libunwind. - Add enabling of global Elf cache. - Add new ApkInspector function to get the offset from an apk by name. - When a map name contains a '!' convert back to a name and offset. - Initialize global elf cache in OfflineUnwinder constructor. Bug: 65682279 Test: All unit tests pass. Change-Id: I303b4beab8270ed2097cd17d91253c321cdc97f1
Diffstat (limited to 'simpleperf/read_apk.cpp')
-rw-r--r--simpleperf/read_apk.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/simpleperf/read_apk.cpp b/simpleperf/read_apk.cpp
index 6a6b55f5..994edfb2 100644
--- a/simpleperf/read_apk.cpp
+++ b/simpleperf/read_apk.cpp
@@ -110,33 +110,46 @@ std::unique_ptr<EmbeddedElf> ApkInspector::FindElfInApkByOffsetWithoutCache(cons
zentry.uncompressed_length));
}
-std::unique_ptr<EmbeddedElf> ApkInspector::FindElfInApkByName(const std::string& apk_path,
- const std::string& elf_filename) {
+bool ApkInspector::FindOffsetInApkByName(const std::string& apk_path,
+ const std::string& elf_filename, off64_t* offset,
+ uint32_t* uncompressed_length) {
if (!IsValidApkPath(apk_path)) {
- return nullptr;
+ return false;
}
FileHelper fhelper = FileHelper::OpenReadOnly(apk_path);
if (!fhelper) {
- return nullptr;
+ return false;
}
ArchiveHelper ahelper(fhelper.fd(), apk_path);
if (!ahelper) {
- return nullptr;
+ return false;
}
ZipArchiveHandle& handle = ahelper.archive_handle();
ZipEntry zentry;
int32_t rc = FindEntry(handle, ZipString(elf_filename.c_str()), &zentry);
- if (rc != 0) {
+ if (rc != false) {
LOG(ERROR) << "failed to find " << elf_filename << " in " << apk_path
<< ": " << ErrorCodeString(rc);
- return nullptr;
+ return false;
}
if (zentry.method != kCompressStored || zentry.compressed_length != zentry.uncompressed_length) {
LOG(ERROR) << "shared library " << elf_filename << " in " << apk_path << " is compressed";
+ return false;
+ }
+ *offset = zentry.offset;
+ *uncompressed_length = zentry.uncompressed_length;
+ return true;
+}
+
+std::unique_ptr<EmbeddedElf> ApkInspector::FindElfInApkByName(const std::string& apk_path,
+ const std::string& elf_filename) {
+ off64_t offset;
+ uint32_t uncompressed_length;
+ if (!FindOffsetInApkByName(apk_path, elf_filename, &offset, &uncompressed_length)) {
return nullptr;
}
- return std::unique_ptr<EmbeddedElf>(new EmbeddedElf(apk_path, elf_filename, zentry.offset,
- zentry.uncompressed_length));
+ return std::unique_ptr<EmbeddedElf>(new EmbeddedElf(apk_path, elf_filename, offset,
+ uncompressed_length));
}
bool IsValidApkPath(const std::string& apk_path) {