summaryrefslogtreecommitdiff
path: root/simpleperf
diff options
context:
space:
mode:
authorDavid Srbecky <dsrbecky@google.com>2021-04-15 20:52:22 +0100
committerDavid Srbecky <dsrbecky@google.com>2021-04-15 21:59:20 +0100
commit6a296b61e8ed81eedad6736cbfa2f1710511c671 (patch)
tree8f5c02be704cf1f845a2b3504a60e1a171431b59 /simpleperf
parentb3d800c52c894064c49f2f506ee1541dd4b42361 (diff)
downloadextras-6a296b61e8ed81eedad6736cbfa2f1710511c671.tar.gz
Adjust to libdexfile API changes
Test: simpleperf_unit_test --gtest_filter=*dex* Change-Id: I837c1e1669bd7f602da6d86051b2fb666044b1ac
Diffstat (limited to 'simpleperf')
-rw-r--r--simpleperf/dso.cpp5
-rw-r--r--simpleperf/read_dex_file.cpp50
-rw-r--r--simpleperf/read_dex_file.h12
-rw-r--r--simpleperf/read_dex_file_test.cpp3
4 files changed, 32 insertions, 38 deletions
diff --git a/simpleperf/dso.cpp b/simpleperf/dso.cpp
index 76751d20..73e21ef8 100644
--- a/simpleperf/dso.cpp
+++ b/simpleperf/dso.cpp
@@ -469,9 +469,8 @@ class DexFileDso : public Dso {
std::vector<Symbol> symbols;
auto tuple = SplitUrlInApk(debug_file_path_);
bool status = false;
- auto symbol_callback = [&](DexFileSymbol* dex_symbol) {
- symbols.emplace_back(std::string_view(dex_symbol->name, dex_symbol->name_size),
- dex_symbol->addr, dex_symbol->size);
+ auto symbol_callback = [&](DexFileSymbol* symbol) {
+ symbols.emplace_back(symbol->name, symbol->addr, symbol->size);
};
if (std::get<0>(tuple)) {
std::unique_ptr<ArchiveHelper> ahelper = ArchiveHelper::CreateInstance(std::get<1>(tuple));
diff --git a/simpleperf/read_dex_file.cpp b/simpleperf/read_dex_file.cpp
index d4d50e07..13ca403f 100644
--- a/simpleperf/read_dex_file.cpp
+++ b/simpleperf/read_dex_file.cpp
@@ -25,26 +25,32 @@
#include <vector>
#include <android-base/logging.h>
+#include <android-base/mapped_file.h>
#include <android-base/unique_fd.h>
#include <art_api/dex_file_support.h>
+#include "utils.h"
+
namespace simpleperf {
static bool ReadSymbols(
const std::vector<uint64_t>& dex_file_offsets,
const std::function<std::unique_ptr<art_api::dex::DexFile>(uint64_t offset)>& open_file_cb,
const std::function<void(DexFileSymbol*)>& symbol_cb) {
- for (uint64_t offset : dex_file_offsets) {
- std::unique_ptr<art_api::dex::DexFile> dex_file = open_file_cb(offset);
+ for (uint64_t dex_offset : dex_file_offsets) {
+ std::unique_ptr<art_api::dex::DexFile> dex_file = open_file_cb(dex_offset);
if (dex_file == nullptr) {
return false;
}
- auto callback = [&](DexFileSymbol* symbol) {
- symbol->addr += offset;
- symbol_cb(symbol);
+ auto callback = [&](const art_api::dex::DexFile::Method& method) {
+ size_t name_size, code_size;
+ const char* name = method.GetQualifiedName(/*with_params=*/false, &name_size);
+ size_t offset = method.GetCodeOffset(&code_size);
+ DexFileSymbol symbol{std::string_view(name, name_size), dex_offset + offset, code_size};
+ symbol_cb(&symbol);
};
- dex_file->GetAllMethodInfos(callback);
+ dex_file->ForEachMethod(callback);
}
return true;
@@ -61,11 +67,11 @@ bool ReadSymbolsFromDexFileInMemory(void* addr, uint64_t size,
return nullptr;
}
uint8_t* file_addr = static_cast<uint8_t*>(addr) + offset;
- std::string error_msg;
- std::unique_ptr<art_api::dex::DexFile> dex_file =
- art_api::dex::DexFile::OpenFromMemory(file_addr, &max_file_size, "", &error_msg);
+ std::unique_ptr<art_api::dex::DexFile> dex_file;
+ art_api::dex::DexFile::Error error_msg =
+ art_api::dex::DexFile::Create(file_addr, max_file_size, nullptr, "", &dex_file);
if (dex_file == nullptr) {
- LOG(WARNING) << "Failed to read dex file symbols: " << error_msg;
+ LOG(WARNING) << "Failed to read dex file symbols: " << error_msg.ToString();
return nullptr;
}
return dex_file;
@@ -80,20 +86,16 @@ bool ReadSymbolsFromDexFile(const std::string& file_path,
if (fd == -1) {
return false;
}
- return ReadSymbols(
- dex_file_offsets,
- [&](uint64_t offset) -> std::unique_ptr<art_api::dex::DexFile> {
- std::string error_msg;
- std::unique_ptr<art_api::dex::DexFile> dex_file =
- art_api::dex::DexFile::OpenFromFd(fd, offset, file_path, &error_msg);
- if (dex_file == nullptr) {
- LOG(WARNING) << "Failed to read dex file symbols from '" << file_path
- << "': " << error_msg;
- return nullptr;
- }
- return dex_file;
- },
- symbol_callback);
+ size_t file_size = GetFileSize(file_path);
+ if (file_size == 0) {
+ return false;
+ }
+ std::unique_ptr<android::base::MappedFile> map;
+ map = android::base::MappedFile::FromFd(fd, 0, file_size, PROT_READ);
+ if (map == nullptr) {
+ return false;
+ }
+ return ReadSymbolsFromDexFileInMemory(map->data(), file_size, dex_file_offsets, symbol_callback);
}
} // namespace simpleperf
diff --git a/simpleperf/read_dex_file.h b/simpleperf/read_dex_file.h
index e5b97904..b4298fab 100644
--- a/simpleperf/read_dex_file.h
+++ b/simpleperf/read_dex_file.h
@@ -28,17 +28,11 @@
namespace simpleperf {
-#ifdef NO_LIBDEXFILE_SUPPORT
struct DexFileSymbol {
- size_t sizeof_struct;
- uint32_t addr;
- uint32_t size;
- const char* name;
- size_t name_size;
+ std::string_view name;
+ uint64_t addr;
+ uint64_t size;
};
-#else
-using DexFileSymbol = ExtDexFileMethodInfo;
-#endif
bool ReadSymbolsFromDexFileInMemory(void* addr, uint64_t size,
const std::vector<uint64_t>& dex_file_offsets,
diff --git a/simpleperf/read_dex_file_test.cpp b/simpleperf/read_dex_file_test.cpp
index 5d71bc35..843a964c 100644
--- a/simpleperf/read_dex_file_test.cpp
+++ b/simpleperf/read_dex_file_test.cpp
@@ -30,8 +30,7 @@ using namespace simpleperf;
TEST(read_dex_file, smoke) {
std::vector<Symbol> symbols;
auto symbol_callback = [&](DexFileSymbol* symbol) {
- symbols.emplace_back(std::string_view(symbol->name, symbol->name_size), symbol->addr,
- symbol->size);
+ symbols.emplace_back(symbol->name, symbol->addr, symbol->size);
};
ASSERT_TRUE(ReadSymbolsFromDexFile(GetTestData("base.vdex"), {0x28}, symbol_callback));
ASSERT_EQ(12435u, symbols.size());