Merge "debuggerd: remove some levels of indentation."
This commit is contained in:
commit
cdff80c446
1 changed files with 130 additions and 143 deletions
|
|
@ -34,9 +34,10 @@
|
||||||
|
|
||||||
#include <log/logger.h>
|
#include <log/logger.h>
|
||||||
|
|
||||||
#include <cutils/sockets.h>
|
|
||||||
#include <cutils/properties.h>
|
|
||||||
#include <cutils/debugger.h>
|
#include <cutils/debugger.h>
|
||||||
|
#include <cutils/properties.h>
|
||||||
|
#include <cutils/sockets.h>
|
||||||
|
#include <nativehelper/ScopedFd.h>
|
||||||
|
|
||||||
#include <linux/input.h>
|
#include <linux/input.h>
|
||||||
|
|
||||||
|
|
@ -336,12 +337,15 @@ static void redirect_to_32(int fd, debugger_request_t* request) {
|
||||||
static void handle_request(int fd) {
|
static void handle_request(int fd) {
|
||||||
ALOGV("handle_request(%d)\n", fd);
|
ALOGV("handle_request(%d)\n", fd);
|
||||||
|
|
||||||
|
ScopedFd closer(fd);
|
||||||
debugger_request_t request;
|
debugger_request_t request;
|
||||||
memset(&request, 0, sizeof(request));
|
memset(&request, 0, sizeof(request));
|
||||||
int status = read_request(fd, &request);
|
int status = read_request(fd, &request);
|
||||||
if (!status) {
|
if (status != 0) {
|
||||||
ALOGV("BOOM: pid=%d uid=%d gid=%d tid=%d\n",
|
return;
|
||||||
request.pid, request.uid, request.gid, request.tid);
|
}
|
||||||
|
|
||||||
|
ALOGV("BOOM: pid=%d uid=%d gid=%d tid=%d\n", request.pid, request.uid, request.gid, request.tid);
|
||||||
|
|
||||||
#if defined(__LP64__)
|
#if defined(__LP64__)
|
||||||
// On 64 bit systems, requests to dump 32 bit and 64 bit tids come
|
// On 64 bit systems, requests to dump 32 bit and 64 bit tids come
|
||||||
|
|
@ -349,14 +353,12 @@ static void handle_request(int fd) {
|
||||||
// redirect the request to the 32 bit debuggerd.
|
// redirect the request to the 32 bit debuggerd.
|
||||||
if (is32bit(request.tid)) {
|
if (is32bit(request.tid)) {
|
||||||
// Only dump backtrace and dump tombstone requests can be redirected.
|
// Only dump backtrace and dump tombstone requests can be redirected.
|
||||||
if (request.action == DEBUGGER_ACTION_DUMP_BACKTRACE
|
if (request.action == DEBUGGER_ACTION_DUMP_BACKTRACE ||
|
||||||
|| request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) {
|
request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) {
|
||||||
redirect_to_32(fd, &request);
|
redirect_to_32(fd, &request);
|
||||||
} else {
|
} else {
|
||||||
ALOGE("debuggerd: Not allowed to redirect action %d to 32 bit debuggerd\n",
|
ALOGE("debuggerd: Not allowed to redirect action %d to 32 bit debuggerd\n", request.action);
|
||||||
request.action);
|
|
||||||
}
|
}
|
||||||
close(fd);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -373,22 +375,20 @@ static void handle_request(int fd) {
|
||||||
// debugger_signal_handler().
|
// debugger_signal_handler().
|
||||||
if (ptrace(PTRACE_ATTACH, request.tid, 0, 0)) {
|
if (ptrace(PTRACE_ATTACH, request.tid, 0, 0)) {
|
||||||
ALOGE("ptrace attach failed: %s\n", strerror(errno));
|
ALOGE("ptrace attach failed: %s\n", strerror(errno));
|
||||||
} else {
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
bool detach_failed = false;
|
bool detach_failed = false;
|
||||||
bool tid_unresponsive = false;
|
bool tid_unresponsive = false;
|
||||||
bool attach_gdb = should_attach_gdb(&request);
|
bool attach_gdb = should_attach_gdb(&request);
|
||||||
if (TEMP_FAILURE_RETRY(write(fd, "\0", 1)) != 1) {
|
if (TEMP_FAILURE_RETRY(write(fd, "\0", 1)) != 1) {
|
||||||
ALOGE("failed responding to client: %s\n", strerror(errno));
|
ALOGE("failed responding to client: %s\n", strerror(errno));
|
||||||
} else {
|
return;
|
||||||
char* tombstone_path = NULL;
|
|
||||||
|
|
||||||
if (request.action == DEBUGGER_ACTION_CRASH) {
|
|
||||||
close(fd);
|
|
||||||
fd = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::unique_ptr<char> tombstone_path;
|
||||||
int total_sleep_time_usec = 0;
|
int total_sleep_time_usec = 0;
|
||||||
for (;;) {
|
while (true) {
|
||||||
int signal = wait_for_sigstop(request.tid, &total_sleep_time_usec, &detach_failed);
|
int signal = wait_for_sigstop(request.tid, &total_sleep_time_usec, &detach_failed);
|
||||||
if (signal == -1) {
|
if (signal == -1) {
|
||||||
tid_unresponsive = true;
|
tid_unresponsive = true;
|
||||||
|
|
@ -399,14 +399,12 @@ static void handle_request(int fd) {
|
||||||
case SIGSTOP:
|
case SIGSTOP:
|
||||||
if (request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) {
|
if (request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) {
|
||||||
ALOGV("stopped -- dumping to tombstone\n");
|
ALOGV("stopped -- dumping to tombstone\n");
|
||||||
tombstone_path = engrave_tombstone(request.pid, request.tid,
|
tombstone_path.reset(engrave_tombstone(
|
||||||
signal, request.original_si_code,
|
request.pid, request.tid, signal, request.original_si_code, request.abort_msg_address,
|
||||||
request.abort_msg_address, true,
|
true, &detach_failed, &total_sleep_time_usec));
|
||||||
&detach_failed, &total_sleep_time_usec);
|
|
||||||
} else if (request.action == DEBUGGER_ACTION_DUMP_BACKTRACE) {
|
} else if (request.action == DEBUGGER_ACTION_DUMP_BACKTRACE) {
|
||||||
ALOGV("stopped -- dumping to fd\n");
|
ALOGV("stopped -- dumping to fd\n");
|
||||||
dump_backtrace(fd, -1, request.pid, request.tid, &detach_failed,
|
dump_backtrace(fd, -1, request.pid, request.tid, &detach_failed, &total_sleep_time_usec);
|
||||||
&total_sleep_time_usec);
|
|
||||||
} else {
|
} else {
|
||||||
ALOGV("stopped -- continuing\n");
|
ALOGV("stopped -- continuing\n");
|
||||||
status = ptrace(PTRACE_CONT, request.tid, 0, 0);
|
status = ptrace(PTRACE_CONT, request.tid, 0, 0);
|
||||||
|
|
@ -434,10 +432,9 @@ static void handle_request(int fd) {
|
||||||
kill(request.pid, SIGSTOP);
|
kill(request.pid, SIGSTOP);
|
||||||
// don't dump sibling threads when attaching to GDB because it
|
// don't dump sibling threads when attaching to GDB because it
|
||||||
// makes the process less reliable, apparently...
|
// makes the process less reliable, apparently...
|
||||||
tombstone_path = engrave_tombstone(request.pid, request.tid,
|
tombstone_path.reset(engrave_tombstone(
|
||||||
signal, request.original_si_code,
|
request.pid, request.tid, signal, request.original_si_code, request.abort_msg_address,
|
||||||
request.abort_msg_address, !attach_gdb,
|
!attach_gdb, &detach_failed, &total_sleep_time_usec));
|
||||||
&detach_failed, &total_sleep_time_usec);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
@ -449,12 +446,8 @@ static void handle_request(int fd) {
|
||||||
|
|
||||||
if (request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) {
|
if (request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) {
|
||||||
if (tombstone_path) {
|
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) {
|
if (!tid_unresponsive) {
|
||||||
|
|
@ -487,12 +480,6 @@ static void handle_request(int fd) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
if (fd >= 0) {
|
|
||||||
close(fd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static int do_server() {
|
static int do_server() {
|
||||||
// debuggerd crashes can't be reported to debuggerd.
|
// debuggerd crashes can't be reported to debuggerd.
|
||||||
// Reset all of the crash handlers.
|
// Reset all of the crash handlers.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue