Print the command line and ABI in stack dumps like debuggerd.

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

(cherry picked from commit 09865b8aa2d85f2824fbdac8034cab01629e8adc)

Change-Id: I52d55660276092ed73b61d5e0708460ec39f1a4a
diff --git a/runtime/signal_catcher.cc b/runtime/signal_catcher.cc
index c13776d..11e06fe 100644
--- a/runtime/signal_catcher.cc
+++ b/runtime/signal_catcher.cc
@@ -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 @@
 #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 @@
 
   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);