Loading debuggerd/debuggerd.cpp +123 −136 Original line number Diff line number Diff line Loading @@ -34,9 +34,10 @@ #include <log/logger.h> #include <cutils/sockets.h> #include <cutils/properties.h> #include <cutils/debugger.h> #include <cutils/properties.h> #include <cutils/sockets.h> #include <nativehelper/ScopedFd.h> #include <linux/input.h> Loading Loading @@ -336,12 +337,15 @@ static void redirect_to_32(int fd, debugger_request_t* request) { static void handle_request(int fd) { ALOGV("handle_request(%d)\n", fd); ScopedFd closer(fd); debugger_request_t request; memset(&request, 0, sizeof(request)); int status = read_request(fd, &request); if (!status) { ALOGV("BOOM: pid=%d uid=%d gid=%d tid=%d\n", request.pid, request.uid, request.gid, request.tid); if (status != 0) { return; } ALOGV("BOOM: pid=%d uid=%d gid=%d tid=%d\n", request.pid, request.uid, request.gid, request.tid); #if defined(__LP64__) // On 64 bit systems, requests to dump 32 bit and 64 bit tids come Loading @@ -349,14 +353,12 @@ static void handle_request(int fd) { // redirect the request to the 32 bit debuggerd. if (is32bit(request.tid)) { // Only dump backtrace and dump tombstone requests can be redirected. if (request.action == DEBUGGER_ACTION_DUMP_BACKTRACE || request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) { if (request.action == DEBUGGER_ACTION_DUMP_BACKTRACE || request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) { redirect_to_32(fd, &request); } else { ALOGE("debuggerd: Not allowed to redirect action %d to 32 bit debuggerd\n", request.action); ALOGE("debuggerd: Not allowed to redirect action %d to 32 bit debuggerd\n", request.action); } close(fd); return; } #endif Loading @@ -373,22 +375,20 @@ static void handle_request(int fd) { // debugger_signal_handler(). if (ptrace(PTRACE_ATTACH, request.tid, 0, 0)) { ALOGE("ptrace attach failed: %s\n", strerror(errno)); } else { return; } bool detach_failed = false; bool tid_unresponsive = false; bool attach_gdb = should_attach_gdb(&request); if (TEMP_FAILURE_RETRY(write(fd, "\0", 1)) != 1) { ALOGE("failed responding to client: %s\n", strerror(errno)); } else { char* tombstone_path = NULL; if (request.action == DEBUGGER_ACTION_CRASH) { close(fd); fd = -1; return; } std::unique_ptr<char> tombstone_path; int total_sleep_time_usec = 0; for (;;) { while (true) { int signal = wait_for_sigstop(request.tid, &total_sleep_time_usec, &detach_failed); if (signal == -1) { tid_unresponsive = true; Loading @@ -399,14 +399,12 @@ static void handle_request(int fd) { case SIGSTOP: if (request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) { ALOGV("stopped -- dumping to tombstone\n"); tombstone_path = engrave_tombstone(request.pid, request.tid, signal, request.original_si_code, request.abort_msg_address, true, &detach_failed, &total_sleep_time_usec); tombstone_path.reset(engrave_tombstone( request.pid, request.tid, signal, request.original_si_code, request.abort_msg_address, true, &detach_failed, &total_sleep_time_usec)); } else if (request.action == DEBUGGER_ACTION_DUMP_BACKTRACE) { ALOGV("stopped -- dumping to fd\n"); dump_backtrace(fd, -1, request.pid, request.tid, &detach_failed, &total_sleep_time_usec); dump_backtrace(fd, -1, request.pid, request.tid, &detach_failed, &total_sleep_time_usec); } else { ALOGV("stopped -- continuing\n"); status = ptrace(PTRACE_CONT, request.tid, 0, 0); Loading Loading @@ -434,10 +432,9 @@ 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.original_si_code, request.abort_msg_address, !attach_gdb, &detach_failed, &total_sleep_time_usec); tombstone_path.reset(engrave_tombstone( request.pid, request.tid, signal, request.original_si_code, request.abort_msg_address, !attach_gdb, &detach_failed, &total_sleep_time_usec)); break; default: Loading @@ -449,12 +446,8 @@ static void handle_request(int fd) { if (request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) { if (tombstone_path) { write(fd, tombstone_path, strlen(tombstone_path)); write(fd, tombstone_path.get(), strlen(tombstone_path.get())); } close(fd); fd = -1; } free(tombstone_path); } if (!tid_unresponsive) { Loading Loading @@ -487,12 +480,6 @@ static void handle_request(int fd) { } } } if (fd >= 0) { close(fd); } } static int do_server() { // debuggerd crashes can't be reported to debuggerd. // Reset all of the crash handlers. Loading Loading
debuggerd/debuggerd.cpp +123 −136 Original line number Diff line number Diff line Loading @@ -34,9 +34,10 @@ #include <log/logger.h> #include <cutils/sockets.h> #include <cutils/properties.h> #include <cutils/debugger.h> #include <cutils/properties.h> #include <cutils/sockets.h> #include <nativehelper/ScopedFd.h> #include <linux/input.h> Loading Loading @@ -336,12 +337,15 @@ static void redirect_to_32(int fd, debugger_request_t* request) { static void handle_request(int fd) { ALOGV("handle_request(%d)\n", fd); ScopedFd closer(fd); debugger_request_t request; memset(&request, 0, sizeof(request)); int status = read_request(fd, &request); if (!status) { ALOGV("BOOM: pid=%d uid=%d gid=%d tid=%d\n", request.pid, request.uid, request.gid, request.tid); if (status != 0) { return; } ALOGV("BOOM: pid=%d uid=%d gid=%d tid=%d\n", request.pid, request.uid, request.gid, request.tid); #if defined(__LP64__) // On 64 bit systems, requests to dump 32 bit and 64 bit tids come Loading @@ -349,14 +353,12 @@ static void handle_request(int fd) { // redirect the request to the 32 bit debuggerd. if (is32bit(request.tid)) { // Only dump backtrace and dump tombstone requests can be redirected. if (request.action == DEBUGGER_ACTION_DUMP_BACKTRACE || request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) { if (request.action == DEBUGGER_ACTION_DUMP_BACKTRACE || request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) { redirect_to_32(fd, &request); } else { ALOGE("debuggerd: Not allowed to redirect action %d to 32 bit debuggerd\n", request.action); ALOGE("debuggerd: Not allowed to redirect action %d to 32 bit debuggerd\n", request.action); } close(fd); return; } #endif Loading @@ -373,22 +375,20 @@ static void handle_request(int fd) { // debugger_signal_handler(). if (ptrace(PTRACE_ATTACH, request.tid, 0, 0)) { ALOGE("ptrace attach failed: %s\n", strerror(errno)); } else { return; } bool detach_failed = false; bool tid_unresponsive = false; bool attach_gdb = should_attach_gdb(&request); if (TEMP_FAILURE_RETRY(write(fd, "\0", 1)) != 1) { ALOGE("failed responding to client: %s\n", strerror(errno)); } else { char* tombstone_path = NULL; if (request.action == DEBUGGER_ACTION_CRASH) { close(fd); fd = -1; return; } std::unique_ptr<char> tombstone_path; int total_sleep_time_usec = 0; for (;;) { while (true) { int signal = wait_for_sigstop(request.tid, &total_sleep_time_usec, &detach_failed); if (signal == -1) { tid_unresponsive = true; Loading @@ -399,14 +399,12 @@ static void handle_request(int fd) { case SIGSTOP: if (request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) { ALOGV("stopped -- dumping to tombstone\n"); tombstone_path = engrave_tombstone(request.pid, request.tid, signal, request.original_si_code, request.abort_msg_address, true, &detach_failed, &total_sleep_time_usec); tombstone_path.reset(engrave_tombstone( request.pid, request.tid, signal, request.original_si_code, request.abort_msg_address, true, &detach_failed, &total_sleep_time_usec)); } else if (request.action == DEBUGGER_ACTION_DUMP_BACKTRACE) { ALOGV("stopped -- dumping to fd\n"); dump_backtrace(fd, -1, request.pid, request.tid, &detach_failed, &total_sleep_time_usec); dump_backtrace(fd, -1, request.pid, request.tid, &detach_failed, &total_sleep_time_usec); } else { ALOGV("stopped -- continuing\n"); status = ptrace(PTRACE_CONT, request.tid, 0, 0); Loading Loading @@ -434,10 +432,9 @@ 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.original_si_code, request.abort_msg_address, !attach_gdb, &detach_failed, &total_sleep_time_usec); tombstone_path.reset(engrave_tombstone( request.pid, request.tid, signal, request.original_si_code, request.abort_msg_address, !attach_gdb, &detach_failed, &total_sleep_time_usec)); break; default: Loading @@ -449,12 +446,8 @@ static void handle_request(int fd) { if (request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) { if (tombstone_path) { write(fd, tombstone_path, strlen(tombstone_path)); write(fd, tombstone_path.get(), strlen(tombstone_path.get())); } close(fd); fd = -1; } free(tombstone_path); } if (!tid_unresponsive) { Loading Loading @@ -487,12 +480,6 @@ static void handle_request(int fd) { } } } if (fd >= 0) { close(fd); } } static int do_server() { // debuggerd crashes can't be reported to debuggerd. // Reset all of the crash handlers. Loading