Merge "Clean up debuggerd-related logging."

This commit is contained in:
Elliott Hughes
2013-01-22 22:37:27 +00:00
committed by Gerrit Code Review

View File

@@ -109,43 +109,40 @@ static int socket_abstract_client(const char* name, int type) {
* could allocate memory or hold a lock. * could allocate memory or hold a lock.
*/ */
static void logSignalSummary(int signum, const siginfo_t* info) { static void logSignalSummary(int signum, const siginfo_t* info) {
const char* signame; const char* signal_name;
switch (signum) { switch (signum) {
case SIGILL: signame = "SIGILL"; break; case SIGILL: signal_name = "SIGILL"; break;
case SIGABRT: signame = "SIGABRT"; break; case SIGABRT: signal_name = "SIGABRT"; break;
case SIGBUS: signame = "SIGBUS"; break; case SIGBUS: signal_name = "SIGBUS"; break;
case SIGFPE: signame = "SIGFPE"; break; case SIGFPE: signal_name = "SIGFPE"; break;
case SIGSEGV: signame = "SIGSEGV"; break; case SIGSEGV: signal_name = "SIGSEGV"; break;
#if defined(SIGSTKFLT) #if defined(SIGSTKFLT)
case SIGSTKFLT: signame = "SIGSTKFLT"; break; case SIGSTKFLT: signal_name = "SIGSTKFLT"; break;
#endif #endif
case SIGPIPE: signame = "SIGPIPE"; break; case SIGPIPE: signal_name = "SIGPIPE"; break;
default: signame = "???"; break; default: signal_name = "???"; break;
} }
char threadname[MAX_TASK_NAME_LEN + 1]; // one more for termination char thread_name[MAX_TASK_NAME_LEN + 1]; // one more for termination
if (prctl(PR_GET_NAME, (unsigned long)threadname, 0, 0, 0) != 0) { if (prctl(PR_GET_NAME, (unsigned long)thread_name, 0, 0, 0) != 0) {
strcpy(threadname, "<name unknown>"); strcpy(thread_name, "<name unknown>");
} else { } else {
// short names are null terminated by prctl, but the manpage // short names are null terminated by prctl, but the man page
// implies that 16 byte names are not. // implies that 16 byte names are not.
threadname[MAX_TASK_NAME_LEN] = 0; thread_name[MAX_TASK_NAME_LEN] = 0;
} }
char buffer[128];
// "info" will be NULL if the siginfo_t information was not available. // "info" will be NULL if the siginfo_t information was not available.
if (info != NULL) { if (info != NULL) {
__libc_format_buffer(buffer, sizeof(buffer), __libc_format_log(ANDROID_LOG_FATAL, "libc",
"Fatal signal %d (%s) at 0x%08x (code=%d), thread %d (%s)", "Fatal signal %d (%s) at 0x%08x (code=%d), thread %d (%s)",
signum, signame, reinterpret_cast<uintptr_t>(info->si_addr), signum, signal_name, reinterpret_cast<uintptr_t>(info->si_addr),
info->si_code, gettid(), threadname); info->si_code, gettid(), thread_name);
} else { } else {
__libc_format_buffer(buffer, sizeof(buffer), __libc_format_log(ANDROID_LOG_FATAL, "libc",
"Fatal signal %d (%s), thread %d (%s)", "Fatal signal %d (%s), thread %d (%s)",
signum, signame, gettid(), threadname); signum, signal_name, gettid(), thread_name);
} }
__libc_android_log_write(ANDROID_LOG_FATAL, "libc", buffer);
} }
/* /*
@@ -178,8 +175,6 @@ static bool haveSiginfo(int signum) {
* we crash. * we crash.
*/ */
void debugger_signal_handler(int n, siginfo_t* info, void*) { void debugger_signal_handler(int n, siginfo_t* info, void*) {
char msgbuf[128];
/* /*
* It's possible somebody cleared the SA_SIGINFO flag, which would mean * It's possible somebody cleared the SA_SIGINFO flag, which would mean
* our "info" arg holds an undefined value. * our "info" arg holds an undefined value.
@@ -215,17 +210,15 @@ void debugger_signal_handler(int n, siginfo_t* info, void*) {
if (ret < 0) { if (ret < 0) {
/* read or write failed -- broken connection? */ /* read or write failed -- broken connection? */
__libc_format_buffer(msgbuf, sizeof(msgbuf), __libc_format_log(ANDROID_LOG_FATAL, "libc", "Failed while talking to debuggerd: %s",
"Failed while talking to debuggerd: %s", strerror(errno)); strerror(errno));
__libc_android_log_write(ANDROID_LOG_FATAL, "libc", msgbuf);
} }
close(s); close(s);
} else { } else {
/* socket failed; maybe process ran out of fds */ /* socket failed; maybe process ran out of fds */
__libc_format_buffer(msgbuf, sizeof(msgbuf), __libc_format_log(ANDROID_LOG_FATAL, "libc", "Unable to open connection to debuggerd: %s",
"Unable to open connection to debuggerd: %s", strerror(errno)); strerror(errno));
__libc_android_log_write(ANDROID_LOG_FATAL, "libc", msgbuf);
} }
/* remove our net so we fault for real when we return */ /* remove our net so we fault for real when we return */