Include the crashing thread's name in crash dumps.
Change-Id: I7fd821e3f390fde3a7280689292373d413218893
diff --git a/src/runtime_linux.cc b/src/runtime_linux.cc
index d68e4bd..5856f06 100644
--- a/src/runtime_linux.cc
+++ b/src/runtime_linux.cc
@@ -235,8 +235,10 @@
OS os_info;
const char* cmd_line = GetCmdLine();
if (cmd_line == NULL) {
- cmd_line = "<unset>"; // Because we're in a unit test, say.
+ cmd_line = "<unset>"; // Because no-one called InitLogging.
}
+ pid_t tid = GetTid();
+ std::string thread_name(GetThreadName(tid));
UContext thread_context(raw_context);
Backtrace thread_backtrace;
@@ -248,14 +250,17 @@
<< (has_address ? StringPrintf(" fault addr %p", info->si_addr) : "") << "\n"
<< "OS: " << Dumpable<OS>(os_info) << "\n"
<< "Cmdline: " << cmd_line << "\n"
+ << "Thread: " << tid << " \"" << thread_name << "\"\n"
<< "Registers:\n" << Dumpable<UContext>(thread_context) << "\n"
<< "Backtrace:\n" << Dumpable<Backtrace>(thread_backtrace);
// TODO: instead, get debuggerd running on the host, try to connect, and hang around on success.
if (getenv("debug_db_uid") != NULL) {
LOG(INTERNAL_FATAL) << "********************************************************\n"
- << "* Process " << getpid() << " thread " << GetTid() << " has been suspended while crashing. Attach gdb:\n"
- << "* gdb -p " << GetTid() << "\n"
+ << "* Process " << getpid() << " thread " << tid << " \"" << thread_name << "\""
+ << " has been suspended while crashing.\n"
+ << "* Attach gdb:\n"
+ << "* gdb -p " << tid << "\n"
<< "********************************************************\n";
// Wait for debugger to attach.
while (true) {
diff --git a/src/thread.cc b/src/thread.cc
index b263039..b177cf8 100644
--- a/src/thread.cc
+++ b/src/thread.cc
@@ -465,13 +465,7 @@
<< " tid=" << thread->GetThinLockId()
<< " " << thread->GetState() << "\n";
} else {
- std::string thread_name;
- if (ReadFileToString(StringPrintf("/proc/self/task/%d/comm", tid), &thread_name)) {
- thread_name.resize(thread_name.size() - 1); // Lose the trailing '\n'.
- } else {
- thread_name = "<unknown>";
- }
- os << '"' << thread_name << '"'
+ os << '"' << ::art::GetThreadName(tid) << '"'
<< " prio=" << priority
<< " (not attached)\n";
}
diff --git a/src/utils.cc b/src/utils.cc
index 084456d..d45568e 100644
--- a/src/utils.cc
+++ b/src/utils.cc
@@ -69,6 +69,16 @@
#endif
}
+std::string GetThreadName(pid_t tid) {
+ std::string result;
+ if (ReadFileToString(StringPrintf("/proc/self/task/%d/comm", tid), &result)) {
+ result.resize(result.size() - 1); // Lose the trailing '\n'.
+ } else {
+ result = "<unknown>";
+ }
+ return result;
+}
+
void GetThreadStack(void*& stack_base, size_t& stack_size) {
#if defined(__APPLE__)
stack_size = pthread_get_stacksize_np(pthread_self());
diff --git a/src/utils.h b/src/utils.h
index e1c00ac..a31588b 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -267,6 +267,9 @@
// Returns the calling thread's tid. (The C libraries don't expose this.)
pid_t GetTid();
+// Returns the given thread's name.
+std::string GetThreadName(pid_t tid);
+
// Returns details of the calling thread's stack.
void GetThreadStack(void*& stack_base, size_t& stack_size);