OSDN Git Service

Simpleperf: warn if it can't read kernel symbols addresses.
authorYabin Cui <yabinc@google.com>
Thu, 1 Oct 2015 18:32:44 +0000 (11:32 -0700)
committerYabin Cui <yabinc@google.com>
Thu, 1 Oct 2015 18:35:21 +0000 (11:35 -0700)
And a little format adjustment.

Bug: 24404256
Change-Id: Ie8dcd37138a693df18101d415e6e3243f4963582

simpleperf/cmd_help.cpp
simpleperf/darwin_support/darwin_support.cpp
simpleperf/dso.cpp
simpleperf/dwarf_unwind.cpp
simpleperf/dwarf_unwind.h
simpleperf/main.cpp

index cc66376..72a4236 100644 (file)
@@ -60,7 +60,7 @@ void HelpCommand::PrintShortHelp() {
       "common options:\n"
       "    -h/--help     Print this help information.\n"
       "    --log <severity> Set the minimum severity of logging. Possible severities\n"
-      "                     include debug, warning, error, fatal. Default is error.\n"
+      "                     include debug, warning, error, fatal. Default is warning.\n"
       "subcommands:\n");
   for (auto& cmd_name : GetAllCommandNames()) {
     std::unique_ptr<Command> cmd = CreateCommandInstance(cmd_name);
index 0b27a8f..cdfcdb1 100644 (file)
@@ -20,8 +20,7 @@
 #include "dwarf_unwind.h"
 #include "environment.h"
 
-std::vector<uint64_t> UnwindCallChain(const ThreadEntry&, const RegSet&,
-                                      const std::vector<char>&) {
+std::vector<uint64_t> UnwindCallChain(const ThreadEntry&, const RegSet&, const std::vector<char>&) {
   return std::vector<uint64_t>();
 }
 
index 69cbcc3..13f2bfe 100644 (file)
@@ -150,7 +150,6 @@ struct SymbolComparator {
   }
 };
 
-
 std::string Dso::GetAccessiblePath() const {
   return symfs_dir_ + path_;
 }
@@ -228,8 +227,22 @@ bool Dso::LoadKernel() {
         return false;
       }
     }
+
     ProcessKernelSymbols("/proc/kallsyms",
                          std::bind(&KernelSymbolCallback, std::placeholders::_1, this));
+    bool allZero = true;
+    for (auto& symbol : symbols_) {
+      if (symbol.addr != 0) {
+        allZero = false;
+        break;
+      }
+    }
+    if (allZero) {
+      LOG(WARNING) << "Symbol addresses in /proc/kallsyms are all zero. Check "
+                      "/proc/sys/kernel/kptr_restrict if possible.";
+      symbols_.clear();
+      return false;
+    }
   }
   return true;
 }
index cd51a13..1d0f7ae 100644 (file)
 
 #include "thread_tree.h"
 
-#define SetUContextReg(dst, perf_regno) \
-  do { \
-    uint64_t value; \
+#define SetUContextReg(dst, perf_regno)          \
+  do {                                           \
+    uint64_t value;                              \
     if (GetRegValue(regs, perf_regno, &value)) { \
-      dst = value; \
-    } \
+      dst = value;                               \
+    }                                            \
   } while (0)
 
 static ucontext_t BuildUContextFromRegs(const RegSet& regs __attribute__((unused))) {
@@ -94,8 +94,7 @@ static ucontext_t BuildUContextFromRegs(const RegSet& regs __attribute__((unused
   return ucontext;
 }
 
-std::vector<uint64_t> UnwindCallChain(const ThreadEntry& thread,
-                                      const RegSet& regs,
+std::vector<uint64_t> UnwindCallChain(const ThreadEntry& thread, const RegSet& regs,
                                       const std::vector<char>& stack) {
   std::vector<uint64_t> result;
   if (GetCurrentArch() != GetBuildArch()) {
index f6a58a1..671013e 100644 (file)
@@ -24,6 +24,6 @@
 struct ThreadEntry;
 
 std::vector<uint64_t> UnwindCallChain(const ThreadEntry& thread, const RegSet& regs,
-                            const std::vector<char>& stack);
+                                      const std::vector<char>& stack);
 
 #endif  // SIMPLE_PERF_DWARF_UNWIND_H_
index 7cc04b8..6b204ec 100644 (file)
@@ -33,7 +33,7 @@ static std::map<std::string, android::base::LogSeverity> log_severity_map = {
 int main(int argc, char** argv) {
   InitLogging(argv, android::base::StderrLogger);
   std::vector<std::string> args;
-  android::base::LogSeverity log_severity = android::base::ERROR;
+  android::base::LogSeverity log_severity = android::base::WARNING;
 
   if (argc == 1) {
     args.push_back("help");