Loading debuggerd/crasher.c +21 −12 Original line number Diff line number Diff line Loading @@ -126,7 +126,7 @@ static int do_action(const char* arg) return ctest(); } else if (!strcmp(arg, "exit")) { exit(1); } else if (!strcmp(arg, "crash")) { } else if (!strcmp(arg, "crash") || !strcmp(arg, "SIGSEGV")) { return crash(42); } else if (!strcmp(arg, "abort")) { maybe_abort(); Loading @@ -138,6 +138,12 @@ static int do_action(const char* arg) LOG_ALWAYS_FATAL("hello %s", "world"); } else if (!strcmp(arg, "LOG_ALWAYS_FATAL_IF")) { LOG_ALWAYS_FATAL_IF(true, "hello %s", "world"); } else if (!strcmp(arg, "SIGPIPE")) { int pipe_fds[2]; pipe(pipe_fds); close(pipe_fds[0]); write(pipe_fds[1], "oops", 4); return EXIT_SUCCESS; } else if (!strcmp(arg, "heap-usage")) { abuse_heap(); } Loading @@ -151,10 +157,13 @@ static int do_action(const char* arg) fprintf(stderr, " nostack crash with a NULL stack pointer\n"); fprintf(stderr, " ctest (obsoleted by thread-crash?)\n"); fprintf(stderr, " exit call exit(1)\n"); fprintf(stderr, " crash cause a SIGSEGV\n"); fprintf(stderr, " abort call abort()\n"); fprintf(stderr, " assert call assert() without a function\n"); fprintf(stderr, " assert2 call assert() with a function\n"); fprintf(stderr, " LOG_ALWAYS_FATAL call LOG_ALWAYS_FATAL\n"); fprintf(stderr, " LOG_ALWAYS_FATAL_IF call LOG_ALWAYS_FATAL\n"); fprintf(stderr, " SIGPIPE cause a SIGPIPE\n"); fprintf(stderr, " SIGSEGV cause a SIGSEGV (synonym: crash)\n"); fprintf(stderr, "prefix any of the above with 'thread-' to not run\n"); fprintf(stderr, "on the process' main thread.\n"); return EXIT_SUCCESS; Loading debuggerd/debuggerd.cpp +10 −6 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ struct debugger_request_t { pid_t pid, tid; uid_t uid, gid; uintptr_t abort_msg_address; int32_t original_si_code; }; static int write_string(const char* file, const char* string) { Loading Loading @@ -218,6 +219,7 @@ static int read_request(int fd, debugger_request_t* out_request) { out_request->uid = cr.uid; out_request->gid = cr.gid; out_request->abort_msg_address = msg.abort_msg_address; out_request->original_si_code = msg.original_si_code; if (msg.action == DEBUGGER_ACTION_CRASH) { // Ensure that the tid reported by the crashing process is valid. Loading Loading @@ -302,8 +304,9 @@ static void handle_request(int fd) { case SIGSTOP: if (request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) { XLOG("stopped -- dumping to tombstone\n"); tombstone_path = engrave_tombstone( request.pid, request.tid, signal, request.abort_msg_address, true, true, tombstone_path = engrave_tombstone(request.pid, request.tid, signal, request.original_si_code, request.abort_msg_address, true, true, &detach_failed, &total_sleep_time_usec); } else if (request.action == DEBUGGER_ACTION_DUMP_BACKTRACE) { XLOG("stopped -- dumping to fd\n"); Loading Loading @@ -336,9 +339,10 @@ static void handle_request(int fd) { kill(request.pid, SIGSTOP); // don't dump sibling threads when attaching to GDB because it // makes the process less reliable, apparently... tombstone_path = engrave_tombstone( request.pid, request.tid, signal, request.abort_msg_address, !attach_gdb, false, &detach_failed, &total_sleep_time_usec); tombstone_path = engrave_tombstone(request.pid, request.tid, signal, request.original_si_code, request.abort_msg_address, !attach_gdb, false, &detach_failed, &total_sleep_time_usec); break; default: Loading debuggerd/tombstone.cpp +27 −20 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ // Must match the path defined in NativeCrashListener.java #define NCRASH_SOCKET_PATH "/data/system/ndebugsocket" static bool signal_has_address(int sig) { static bool signal_has_si_addr(int sig) { switch (sig) { case SIGILL: case SIGFPE: Loading @@ -75,7 +75,7 @@ static const char* get_signame(int sig) { case SIGFPE: return "SIGFPE"; case SIGSEGV: return "SIGSEGV"; case SIGPIPE: return "SIGPIPE"; #ifdef SIGSTKFLT #if defined(SIGSTKFLT) case SIGSTKFLT: return "SIGSTKFLT"; #endif case SIGSTOP: return "SIGSTOP"; Loading Loading @@ -171,20 +171,26 @@ static void dump_build_info(log_t* log) { _LOG(log, SCOPE_AT_FAULT, "Build fingerprint: '%s'\n", fingerprint); } static void dump_fault_addr(log_t* log, pid_t tid, int sig) { static void dump_signal_info(log_t* log, pid_t tid, int signal, int si_code) { siginfo_t si; memset(&si, 0, sizeof(si)); if (ptrace(PTRACE_GETSIGINFO, tid, 0, &si)){ if (ptrace(PTRACE_GETSIGINFO, tid, 0, &si) == -1) { _LOG(log, SCOPE_AT_FAULT, "cannot get siginfo: %s\n", strerror(errno)); } else if (signal_has_address(sig)) { _LOG(log, SCOPE_AT_FAULT, "signal %d (%s), code %d (%s), fault addr %" PRIPTR "\n", sig, get_signame(sig), si.si_code, get_sigcode(sig, si.si_code), reinterpret_cast<uintptr_t>(si.si_addr)); return; } // bionic has to re-raise some signals, which overwrites the si_code with SI_TKILL. si.si_code = si_code; char addr_desc[32]; // ", fault addr 0x1234" if (signal_has_si_addr(signal)) { snprintf(addr_desc, sizeof(addr_desc), "%p", si.si_addr); } else { _LOG(log, SCOPE_AT_FAULT, "signal %d (%s), code %d (%s), fault addr --------\n", sig, get_signame(sig), si.si_code, get_sigcode(sig, si.si_code)); snprintf(addr_desc, sizeof(addr_desc), "--------"); } _LOG(log, SCOPE_AT_FAULT, "signal %d (%s), code %d (%s), fault addr %s\n", signal, get_signame(signal), si.si_code, get_sigcode(signal, si.si_code), addr_desc); } static void dump_thread_info(log_t* log, pid_t pid, pid_t tid, int scope_flags) { Loading Loading @@ -349,7 +355,7 @@ static void dump_nearby_maps(BacktraceMap* map, log_t* log, pid_t tid, int scope _LOG(log, scope_flags, "cannot get siginfo for %d: %s\n", tid, strerror(errno)); return; } if (!signal_has_address(si.si_signo)) { if (!signal_has_si_addr(si.si_signo)) { return; } Loading Loading @@ -588,8 +594,9 @@ static void dump_abort_message(Backtrace* backtrace, log_t* log, uintptr_t addre } // Dumps all information about the specified pid to the tombstone. static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, uintptr_t abort_msg_address, bool dump_sibling_threads, int* total_sleep_time_usec) { static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, int si_code, uintptr_t abort_msg_address, bool dump_sibling_threads, int* total_sleep_time_usec) { // don't copy log messages to tombstone unless this is a dev device char value[PROPERTY_VALUE_MAX]; property_get("ro.debuggable", value, "0"); Loading @@ -611,7 +618,7 @@ static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, uintptr_t a dump_revision_info(log); dump_thread_info(log, pid, tid, SCOPE_AT_FAULT); if (signal) { dump_fault_addr(log, tid, signal); dump_signal_info(log, tid, signal, si_code); } UniquePtr<BacktraceMap> map(BacktraceMap::Create(pid)); Loading Loading @@ -725,9 +732,9 @@ static int activity_manager_connect() { return amfd; } char* engrave_tombstone( pid_t pid, pid_t tid, int signal, uintptr_t abort_msg_address, bool dump_sibling_threads, bool quiet, bool* detach_failed, int* total_sleep_time_usec) { char* engrave_tombstone(pid_t pid, pid_t tid, int signal, int original_si_code, uintptr_t abort_msg_address, bool dump_sibling_threads, bool quiet, bool* detach_failed, int* total_sleep_time_usec) { if ((mkdir(TOMBSTONE_DIR, 0755) == -1) && (errno != EEXIST)) { LOG("failed to create %s: %s\n", TOMBSTONE_DIR, strerror(errno)); } Loading @@ -752,8 +759,8 @@ char* engrave_tombstone( log.tfd = fd; log.amfd = activity_manager_connect(); log.quiet = quiet; *detach_failed = dump_crash( &log, pid, tid, signal, abort_msg_address, dump_sibling_threads, total_sleep_time_usec); *detach_failed = dump_crash(&log, pid, tid, signal, original_si_code, abort_msg_address, dump_sibling_threads, total_sleep_time_usec); close(log.amfd); close(fd); Loading debuggerd/tombstone.h +4 −2 Original line number Diff line number Diff line Loading @@ -23,7 +23,9 @@ /* Creates a tombstone file and writes the crash dump to it. * Returns the path of the tombstone, which must be freed using free(). */ char* engrave_tombstone(pid_t pid, pid_t tid, int signal, uintptr_t abort_msg_address, bool dump_sibling_threads, bool quiet, bool* detach_failed, int* total_sleep_time_usec); char* engrave_tombstone(pid_t pid, pid_t tid, int signal, int original_si_code, uintptr_t abort_msg_address, bool dump_sibling_threads, bool quiet, bool* detach_failed, int* total_sleep_time_usec); #endif // _DEBUGGERD_TOMBSTONE_H include/cutils/debugger.h +1 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ typedef struct { debugger_action_t action; pid_t tid; uintptr_t abort_msg_address; int32_t original_si_code; } debugger_msg_t; /* Dumps a process backtrace, registers, and stack to a tombstone file (requires root). Loading Loading
debuggerd/crasher.c +21 −12 Original line number Diff line number Diff line Loading @@ -126,7 +126,7 @@ static int do_action(const char* arg) return ctest(); } else if (!strcmp(arg, "exit")) { exit(1); } else if (!strcmp(arg, "crash")) { } else if (!strcmp(arg, "crash") || !strcmp(arg, "SIGSEGV")) { return crash(42); } else if (!strcmp(arg, "abort")) { maybe_abort(); Loading @@ -138,6 +138,12 @@ static int do_action(const char* arg) LOG_ALWAYS_FATAL("hello %s", "world"); } else if (!strcmp(arg, "LOG_ALWAYS_FATAL_IF")) { LOG_ALWAYS_FATAL_IF(true, "hello %s", "world"); } else if (!strcmp(arg, "SIGPIPE")) { int pipe_fds[2]; pipe(pipe_fds); close(pipe_fds[0]); write(pipe_fds[1], "oops", 4); return EXIT_SUCCESS; } else if (!strcmp(arg, "heap-usage")) { abuse_heap(); } Loading @@ -151,10 +157,13 @@ static int do_action(const char* arg) fprintf(stderr, " nostack crash with a NULL stack pointer\n"); fprintf(stderr, " ctest (obsoleted by thread-crash?)\n"); fprintf(stderr, " exit call exit(1)\n"); fprintf(stderr, " crash cause a SIGSEGV\n"); fprintf(stderr, " abort call abort()\n"); fprintf(stderr, " assert call assert() without a function\n"); fprintf(stderr, " assert2 call assert() with a function\n"); fprintf(stderr, " LOG_ALWAYS_FATAL call LOG_ALWAYS_FATAL\n"); fprintf(stderr, " LOG_ALWAYS_FATAL_IF call LOG_ALWAYS_FATAL\n"); fprintf(stderr, " SIGPIPE cause a SIGPIPE\n"); fprintf(stderr, " SIGSEGV cause a SIGSEGV (synonym: crash)\n"); fprintf(stderr, "prefix any of the above with 'thread-' to not run\n"); fprintf(stderr, "on the process' main thread.\n"); return EXIT_SUCCESS; Loading
debuggerd/debuggerd.cpp +10 −6 Original line number Diff line number Diff line Loading @@ -51,6 +51,7 @@ struct debugger_request_t { pid_t pid, tid; uid_t uid, gid; uintptr_t abort_msg_address; int32_t original_si_code; }; static int write_string(const char* file, const char* string) { Loading Loading @@ -218,6 +219,7 @@ static int read_request(int fd, debugger_request_t* out_request) { out_request->uid = cr.uid; out_request->gid = cr.gid; out_request->abort_msg_address = msg.abort_msg_address; out_request->original_si_code = msg.original_si_code; if (msg.action == DEBUGGER_ACTION_CRASH) { // Ensure that the tid reported by the crashing process is valid. Loading Loading @@ -302,8 +304,9 @@ static void handle_request(int fd) { case SIGSTOP: if (request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) { XLOG("stopped -- dumping to tombstone\n"); tombstone_path = engrave_tombstone( request.pid, request.tid, signal, request.abort_msg_address, true, true, tombstone_path = engrave_tombstone(request.pid, request.tid, signal, request.original_si_code, request.abort_msg_address, true, true, &detach_failed, &total_sleep_time_usec); } else if (request.action == DEBUGGER_ACTION_DUMP_BACKTRACE) { XLOG("stopped -- dumping to fd\n"); Loading Loading @@ -336,9 +339,10 @@ static void handle_request(int fd) { kill(request.pid, SIGSTOP); // don't dump sibling threads when attaching to GDB because it // makes the process less reliable, apparently... tombstone_path = engrave_tombstone( request.pid, request.tid, signal, request.abort_msg_address, !attach_gdb, false, &detach_failed, &total_sleep_time_usec); tombstone_path = engrave_tombstone(request.pid, request.tid, signal, request.original_si_code, request.abort_msg_address, !attach_gdb, false, &detach_failed, &total_sleep_time_usec); break; default: Loading
debuggerd/tombstone.cpp +27 −20 Original line number Diff line number Diff line Loading @@ -55,7 +55,7 @@ // Must match the path defined in NativeCrashListener.java #define NCRASH_SOCKET_PATH "/data/system/ndebugsocket" static bool signal_has_address(int sig) { static bool signal_has_si_addr(int sig) { switch (sig) { case SIGILL: case SIGFPE: Loading @@ -75,7 +75,7 @@ static const char* get_signame(int sig) { case SIGFPE: return "SIGFPE"; case SIGSEGV: return "SIGSEGV"; case SIGPIPE: return "SIGPIPE"; #ifdef SIGSTKFLT #if defined(SIGSTKFLT) case SIGSTKFLT: return "SIGSTKFLT"; #endif case SIGSTOP: return "SIGSTOP"; Loading Loading @@ -171,20 +171,26 @@ static void dump_build_info(log_t* log) { _LOG(log, SCOPE_AT_FAULT, "Build fingerprint: '%s'\n", fingerprint); } static void dump_fault_addr(log_t* log, pid_t tid, int sig) { static void dump_signal_info(log_t* log, pid_t tid, int signal, int si_code) { siginfo_t si; memset(&si, 0, sizeof(si)); if (ptrace(PTRACE_GETSIGINFO, tid, 0, &si)){ if (ptrace(PTRACE_GETSIGINFO, tid, 0, &si) == -1) { _LOG(log, SCOPE_AT_FAULT, "cannot get siginfo: %s\n", strerror(errno)); } else if (signal_has_address(sig)) { _LOG(log, SCOPE_AT_FAULT, "signal %d (%s), code %d (%s), fault addr %" PRIPTR "\n", sig, get_signame(sig), si.si_code, get_sigcode(sig, si.si_code), reinterpret_cast<uintptr_t>(si.si_addr)); return; } // bionic has to re-raise some signals, which overwrites the si_code with SI_TKILL. si.si_code = si_code; char addr_desc[32]; // ", fault addr 0x1234" if (signal_has_si_addr(signal)) { snprintf(addr_desc, sizeof(addr_desc), "%p", si.si_addr); } else { _LOG(log, SCOPE_AT_FAULT, "signal %d (%s), code %d (%s), fault addr --------\n", sig, get_signame(sig), si.si_code, get_sigcode(sig, si.si_code)); snprintf(addr_desc, sizeof(addr_desc), "--------"); } _LOG(log, SCOPE_AT_FAULT, "signal %d (%s), code %d (%s), fault addr %s\n", signal, get_signame(signal), si.si_code, get_sigcode(signal, si.si_code), addr_desc); } static void dump_thread_info(log_t* log, pid_t pid, pid_t tid, int scope_flags) { Loading Loading @@ -349,7 +355,7 @@ static void dump_nearby_maps(BacktraceMap* map, log_t* log, pid_t tid, int scope _LOG(log, scope_flags, "cannot get siginfo for %d: %s\n", tid, strerror(errno)); return; } if (!signal_has_address(si.si_signo)) { if (!signal_has_si_addr(si.si_signo)) { return; } Loading Loading @@ -588,8 +594,9 @@ static void dump_abort_message(Backtrace* backtrace, log_t* log, uintptr_t addre } // Dumps all information about the specified pid to the tombstone. static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, uintptr_t abort_msg_address, bool dump_sibling_threads, int* total_sleep_time_usec) { static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, int si_code, uintptr_t abort_msg_address, bool dump_sibling_threads, int* total_sleep_time_usec) { // don't copy log messages to tombstone unless this is a dev device char value[PROPERTY_VALUE_MAX]; property_get("ro.debuggable", value, "0"); Loading @@ -611,7 +618,7 @@ static bool dump_crash(log_t* log, pid_t pid, pid_t tid, int signal, uintptr_t a dump_revision_info(log); dump_thread_info(log, pid, tid, SCOPE_AT_FAULT); if (signal) { dump_fault_addr(log, tid, signal); dump_signal_info(log, tid, signal, si_code); } UniquePtr<BacktraceMap> map(BacktraceMap::Create(pid)); Loading Loading @@ -725,9 +732,9 @@ static int activity_manager_connect() { return amfd; } char* engrave_tombstone( pid_t pid, pid_t tid, int signal, uintptr_t abort_msg_address, bool dump_sibling_threads, bool quiet, bool* detach_failed, int* total_sleep_time_usec) { char* engrave_tombstone(pid_t pid, pid_t tid, int signal, int original_si_code, uintptr_t abort_msg_address, bool dump_sibling_threads, bool quiet, bool* detach_failed, int* total_sleep_time_usec) { if ((mkdir(TOMBSTONE_DIR, 0755) == -1) && (errno != EEXIST)) { LOG("failed to create %s: %s\n", TOMBSTONE_DIR, strerror(errno)); } Loading @@ -752,8 +759,8 @@ char* engrave_tombstone( log.tfd = fd; log.amfd = activity_manager_connect(); log.quiet = quiet; *detach_failed = dump_crash( &log, pid, tid, signal, abort_msg_address, dump_sibling_threads, total_sleep_time_usec); *detach_failed = dump_crash(&log, pid, tid, signal, original_si_code, abort_msg_address, dump_sibling_threads, total_sleep_time_usec); close(log.amfd); close(fd); Loading
debuggerd/tombstone.h +4 −2 Original line number Diff line number Diff line Loading @@ -23,7 +23,9 @@ /* Creates a tombstone file and writes the crash dump to it. * Returns the path of the tombstone, which must be freed using free(). */ char* engrave_tombstone(pid_t pid, pid_t tid, int signal, uintptr_t abort_msg_address, bool dump_sibling_threads, bool quiet, bool* detach_failed, int* total_sleep_time_usec); char* engrave_tombstone(pid_t pid, pid_t tid, int signal, int original_si_code, uintptr_t abort_msg_address, bool dump_sibling_threads, bool quiet, bool* detach_failed, int* total_sleep_time_usec); #endif // _DEBUGGERD_TOMBSTONE_H
include/cutils/debugger.h +1 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,7 @@ typedef struct { debugger_action_t action; pid_t tid; uintptr_t abort_msg_address; int32_t original_si_code; } debugger_msg_t; /* Dumps a process backtrace, registers, and stack to a tombstone file (requires root). Loading