summaryrefslogtreecommitdiff
path: root/simpleperf/dso.cpp
diff options
context:
space:
mode:
authorThiƩbaud Weksteen <tweek@google.com>2020-11-19 15:07:46 +0100
committerThiƩbaud Weksteen <tweek@google.com>2020-12-01 15:22:07 +0100
commite7e750e5060f69d7a9dcc71abefc5c6e9d999e89 (patch)
tree47f203a978e6d1d8c53b3f7fb15afcb34d7f7064 /simpleperf/dso.cpp
parentcae896b243eeb852b57c778e95b7ef5fae65d403 (diff)
downloadextras-e7e750e5060f69d7a9dcc71abefc5c6e9d999e89.tar.gz
Refactor loading of /proc/kallsyms
Moves related functions to a new source file (kallsyms.cpp). Adds support for the security.lower_kptr_restrict system property. The implementation of ScopedKptrUnrestrict is based on Perfetto (see aosp/1454882). Test: lunch aosp_crosshatch-userdebug; atest CtsSimpleperfTestCases Change-Id: Ie6ba7aab93d68be915583ad4f8551c627b35f292
Diffstat (limited to 'simpleperf/dso.cpp')
-rw-r--r--simpleperf/dso.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/simpleperf/dso.cpp b/simpleperf/dso.cpp
index 1fe8a0d1..f034997b 100644
--- a/simpleperf/dso.cpp
+++ b/simpleperf/dso.cpp
@@ -32,6 +32,7 @@
#include "JITDebugReader.h"
#include "environment.h"
+#include "kallsyms.h"
#include "read_apk.h"
#include "read_dex_file.h"
#include "read_elf.h"
@@ -234,7 +235,6 @@ static bool CompareAddrToSymbol(uint64_t addr, const Symbol& s) {
bool Dso::demangle_ = true;
std::string Dso::vmlinux_;
std::string Dso::kallsyms_;
-bool Dso::read_kernel_symbols_from_proc_;
std::unordered_map<std::string, BuildId> Dso::build_id_map_;
size_t Dso::dso_count_;
uint32_t Dso::g_dump_id_;
@@ -332,7 +332,6 @@ Dso::~Dso() {
demangle_ = true;
vmlinux_.clear();
kallsyms_.clear();
- read_kernel_symbols_from_proc_ = false;
build_id_map_.clear();
g_dump_id_ = 0;
debug_elf_file_finder_.Reset();
@@ -642,12 +641,15 @@ class KernelDso : public Dso {
if (has_debug_file_) {
ReadSymbolsFromDebugFile(&symbols);
}
+
+#if defined(__linux__)
if (symbols.empty() && !kallsyms_.empty()) {
ReadSymbolsFromKallsyms(kallsyms_, &symbols);
}
if (symbols.empty()) {
ReadSymbolsFromProc(&symbols);
}
+#endif // defined(__linux__)
SortAndFixSymbols(symbols);
if (!symbols.empty()) {
symbols.back().len = std::numeric_limits<uint64_t>::max() - symbols.back().addr;
@@ -680,6 +682,7 @@ class KernelDso : public Dso {
ReportReadElfSymbolResult(status, path_, debug_file_path_);
}
+#if defined(__linux__)
void ReadSymbolsFromKallsyms(std::string& kallsyms, std::vector<Symbol>* symbols) {
auto symbol_callback = [&](const KernelSymbol& symbol) {
if (strchr("TtWw", symbol.type) && symbol.addr != 0u) {
@@ -701,7 +704,7 @@ class KernelDso : public Dso {
void ReadSymbolsFromProc(std::vector<Symbol>* symbols) {
BuildId build_id = GetExpectedBuildId();
- if (read_kernel_symbols_from_proc_ || !build_id.IsEmpty()) {
+ if (!build_id.IsEmpty()) {
// Try /proc/kallsyms only when asked to do so, or when build id matches.
// Otherwise, it is likely to use /proc/kallsyms on host for perf.data recorded on device.
bool can_read_kallsyms = true;
@@ -714,14 +717,13 @@ class KernelDso : public Dso {
}
if (can_read_kallsyms) {
std::string kallsyms;
- if (!android::base::ReadFileToString("/proc/kallsyms", &kallsyms)) {
- LOG(DEBUG) << "failed to read /proc/kallsyms";
- } else {
+ if (LoadKernelSymbols(&kallsyms)) {
ReadSymbolsFromKallsyms(kallsyms, symbols);
}
}
}
}
+#endif // defined(__linux__)
uint64_t GetKernelStartAddr() {
if (!kernel_start_addr_) {