From 09865b8aa2d85f2824fbdac8034cab01629e8adc Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Wed, 10 Sep 2014 18:41:18 -0700 Subject: [PATCH] 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 Change-Id: Ie1da1bd4f38c92b13ea08c7122f4573d8ec8fc73 --- runtime/signal_catcher.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/runtime/signal_catcher.cc b/runtime/signal_catcher.cc index c13776d57..11e06fe88 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 @@ 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", ¤t_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, "") != 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); -- 2.11.0