OSDN Git Service

Print the command line and ABI in stack dumps like debuggerd.
authorJeff Brown <jeffbrown@google.com>
Thu, 11 Sep 2014 01:41:18 +0000 (18:41 -0700)
committerBrian Carlstrom <bdc@google.com>
Thu, 11 Sep 2014 23:04:55 +0000 (16:04 -0700)
Ensure the heading is "Cmd line:" just like debuggerd and
as it used to be in Dalvik.
Fix a missing newline.
Trim all training nulls from the command line.
Don't bother printing the original command line if unset.
Add the ABI to the dump to help the native stack symbol tool.

Bug: 17474152
Change-Id: Ie1da1bd4f38c92b13ea08c7122f4573d8ec8fc73

runtime/signal_catcher.cc

index c13776d..11e06fe 100644 (file)
@@ -28,6 +28,7 @@
 #include "base/unix_file/fd_file.h"
 #include "class_linker.h"
 #include "gc/heap.h"
+#include "instruction_set.h"
 #include "os.h"
 #include "runtime.h"
 #include "scoped_thread_state_change.h"
@@ -42,20 +43,21 @@ static void DumpCmdLine(std::ostream& os) {
 #if defined(__linux__)
   // Show the original command line, and the current command line too if it's changed.
   // On Android, /proc/self/cmdline will have been rewritten to something like "system_server".
+  // Note: The string "Cmd line:" is chosen to match the format used by debuggerd.
   std::string current_cmd_line;
   if (ReadFileToString("/proc/self/cmdline", &current_cmd_line)) {
-    current_cmd_line.resize(current_cmd_line.size() - 1);  // Lose the trailing '\0'.
+    current_cmd_line.resize(current_cmd_line.find_last_not_of('\0') + 1);  // trim trailing '\0's
     std::replace(current_cmd_line.begin(), current_cmd_line.end(), '\0', ' ');
 
-    os << "Cmdline: " << current_cmd_line;
+    os << "Cmd line: " << current_cmd_line << "\n";
     const char* stashed_cmd_line = GetCmdLine();
-    if (stashed_cmd_line != NULL && current_cmd_line != stashed_cmd_line) {
-      os << "Original command line: " << stashed_cmd_line;
+    if (stashed_cmd_line != NULL && current_cmd_line != stashed_cmd_line
+            && strcmp(stashed_cmd_line, "<unset>") != 0) {
+      os << "Original command line: " << stashed_cmd_line << "\n";
     }
   }
-  os << "\n";
 #else
-  os << "Cmdline: " << GetCmdLine() << "\n";
+  os << "Cmd line: " << GetCmdLine() << "\n";
 #endif
 }
 
@@ -133,6 +135,9 @@ void SignalCatcher::HandleSigQuit() {
 
   DumpCmdLine(os);
 
+  // Note: The string "ABI:" is chosen to match the format used by debuggerd.
+  os << "ABI: " << GetInstructionSetString(runtime->GetInstructionSet()) << "\n";
+
   os << "Build type: " << (kIsDebugBuild ? "debug" : "optimized") << "\n";
 
   runtime->DumpForSigQuit(os);