diff options
author | Marco Nelissen <marcone@google.com> | 2012-03-07 09:04:18 -0800 |
---|---|---|
committer | Marco Nelissen <marcone@google.com> | 2012-03-07 12:32:15 -0800 |
commit | 3df3e672f51580525452c2eeb4d35633d4dba873 (patch) | |
tree | 86d8417655599f1c44f416865488237826fe88c0 | |
parent | 45976873353d05b44f23fa53cbcd793b22927820 (diff) | |
download | android_bionic-3df3e672f51580525452c2eeb4d35633d4dba873.tar.gz android_bionic-3df3e672f51580525452c2eeb4d35633d4dba873.tar.bz2 android_bionic-3df3e672f51580525452c2eeb4d35633d4dba873.zip |
Log the thread id and name for fatal signals.
This adds the thread id and name to the "Fatal signal" logging,
making it easier to track down where in process it actually crashed.
Change-Id: I17a365042b2f10b161debe98bc2e7070af055dfb
-rw-r--r-- | linker/debugger.c | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/linker/debugger.c b/linker/debugger.c index ef8286cd9..40411b11a 100644 --- a/linker/debugger.c +++ b/linker/debugger.c @@ -32,6 +32,7 @@ #include <ctype.h> #include <signal.h> #include <sys/mman.h> +#include <sys/prctl.h> #include <errno.h> #include "linker.h" @@ -46,6 +47,8 @@ void notify_gdb_of_libraries(); ret = (cond); \ } while (ret < 0 && errno == EINTR) +// see man(2) prctl, specifically the section about PR_GET_NAME +#define MAX_TASK_NAME_LEN (16) static int socket_abstract_client(const char *name, int type) { @@ -100,6 +103,7 @@ static int socket_abstract_client(const char *name, int type) static void logSignalSummary(int signum, const siginfo_t* info) { char buffer[128]; + char threadname[MAX_TASK_NAME_LEN + 1]; // one more for termination char* signame; switch (signum) { @@ -113,9 +117,16 @@ static void logSignalSummary(int signum, const siginfo_t* info) default: signame = "???"; break; } + if (prctl(PR_GET_NAME, (unsigned long)threadname, 0, 0, 0) != 0) { + strcpy(threadname, "<name unknown>"); + } else { + // short names are null terminated by prctl, but the manpage + // implies that 16 byte names are not. + threadname[MAX_TASK_NAME_LEN] = 0; + } format_buffer(buffer, sizeof(buffer), - "Fatal signal %d (%s) at 0x%08x (code=%d)", - signum, signame, info->si_addr, info->si_code); + "Fatal signal %d (%s) at 0x%08x (code=%d), thread %d (%s)", + signum, signame, info->si_addr, info->si_code, gettid(), threadname); __libc_android_log_write(ANDROID_LOG_FATAL, "libc", buffer); } |