Removed log.quiet and log = NULL cases from debuggerd.
Now the functionality implemented by these semi-confusing cases has been
replaced with the same logtype enum behavior that is easier to
understand, and cases that used log-looking behavior to print to logcat
(when log = NULL) now use the more transparent ALOGE/ALOGD functions.
Change-Id: I7e38f2d4ca74a828df4d2266b3ea34edd3c6f5bb
diff --git a/debuggerd/debuggerd.cpp b/debuggerd/debuggerd.cpp
index dde8f90..c2ef264 100644
--- a/debuggerd/debuggerd.cpp
+++ b/debuggerd/debuggerd.cpp
@@ -61,7 +61,7 @@
char exe[PATH_MAX];
int count;
if ((count = readlink(path, exe, sizeof(exe) - 1)) == -1) {
- LOG_ERROR("readlink('%s') failed: %s", path, strerror(errno));
+ ALOGE("readlink('%s') failed: %s", path, strerror(errno));
strlcpy(exe, "unknown", sizeof(exe));
} else {
exe[count] = '\0';
@@ -78,17 +78,17 @@
}
// Explain how to attach the debugger.
- LOG_ERROR( "********************************************************\n"
- "* Process %d has been suspended while crashing.\n"
- "* To attach gdbserver for a gdb connection on port 5039\n"
- "* and start gdbclient:\n"
- "*\n"
- "* gdbclient %s :5039 %d\n"
- "*\n"
- "* Wait for gdb to start, then press the VOLUME DOWN key\n"
- "* to let the process continue crashing.\n"
- "********************************************************\n",
- pid, name, pid);
+ ALOGI("********************************************************\n"
+ "* Process %d has been suspended while crashing.\n"
+ "* To attach gdbserver for a gdb connection on port 5039\n"
+ "* and start gdbclient:\n"
+ "*\n"
+ "* gdbclient %s :5039 %d\n"
+ "*\n"
+ "* Wait for gdb to start, then press the VOLUME DOWN key\n"
+ "* to let the process continue crashing.\n"
+ "********************************************************\n",
+ pid, name, pid);
// Wait for VOLUME DOWN.
if (init_getevent() == 0) {
@@ -103,7 +103,7 @@
uninit_getevent();
}
- LOG_ERROR("debuggerd resuming process %d", pid);
+ ALOGI("debuggerd resuming process %d", pid);
}
static int get_process_info(pid_t tid, pid_t* out_pid, uid_t* out_uid, uid_t* out_gid) {
@@ -139,11 +139,11 @@
socklen_t len = sizeof(cr);
int status = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &cr, &len);
if (status != 0) {
- LOG_ERROR("cannot get credentials\n");
+ ALOGE("cannot get credentials\n");
return -1;
}
- XLOG("reading tid\n");
+ ALOGV("reading tid\n");
fcntl(fd, F_SETFL, O_NONBLOCK);
pollfd pollfds[1];
@@ -152,7 +152,7 @@
pollfds[0].revents = 0;
status = TEMP_FAILURE_RETRY(poll(pollfds, 1, 3000));
if (status != 1) {
- LOG_ERROR("timed out reading tid (from pid=%d uid=%d)\n", cr.pid, cr.uid);
+ ALOGE("timed out reading tid (from pid=%d uid=%d)\n", cr.pid, cr.uid);
return -1;
}
@@ -160,14 +160,13 @@
memset(&msg, 0, sizeof(msg));
status = TEMP_FAILURE_RETRY(read(fd, &msg, sizeof(msg)));
if (status < 0) {
- LOG_ERROR("read failure? %s (pid=%d uid=%d)\n", strerror(errno), cr.pid, cr.uid);
+ ALOGE("read failure? %s (pid=%d uid=%d)\n", strerror(errno), cr.pid, cr.uid);
return -1;
}
if (status == sizeof(debugger_msg_t)) {
- XLOG("crash request of size %d abort_msg_address=0x%" PRIPTR "\n",
- status, msg.abort_msg_address);
+ ALOGV("crash request of size %d abort_msg_address=%p\n", status, msg.abort_msg_address);
} else {
- LOG_ERROR("invalid crash request of size %d (from pid=%d uid=%d)\n", status, cr.pid, cr.uid);
+ ALOGE("invalid crash request of size %d (from pid=%d uid=%d)\n", status, cr.pid, cr.uid);
return -1;
}
@@ -185,7 +184,7 @@
struct stat s;
snprintf(buf, sizeof buf, "/proc/%d/task/%d", out_request->pid, out_request->tid);
if (stat(buf, &s)) {
- LOG_ERROR("tid %d does not exist in pid %d. ignoring debug request\n",
+ ALOGE("tid %d does not exist in pid %d. ignoring debug request\n",
out_request->tid, out_request->pid);
return -1;
}
@@ -196,7 +195,7 @@
status = get_process_info(out_request->tid, &out_request->pid,
&out_request->uid, &out_request->gid);
if (status < 0) {
- LOG_ERROR("tid %d does not exist. ignoring explicit dump request\n", out_request->tid);
+ ALOGE("tid %d does not exist. ignoring explicit dump request\n", out_request->tid);
return -1;
}
} else {
@@ -217,13 +216,13 @@
}
static void handle_request(int fd) {
- XLOG("handle_request(%d)\n", fd);
+ ALOGV("handle_request(%d)\n", fd);
debugger_request_t request;
memset(&request, 0, sizeof(request));
int status = read_request(fd, &request);
if (!status) {
- XLOG("BOOM: pid=%d uid=%d gid=%d tid=%d\n",
+ ALOGV("BOOM: pid=%d uid=%d gid=%d tid=%d\n",
request.pid, request.uid, request.gid, request.tid);
// At this point, the thread that made the request is blocked in
@@ -237,12 +236,12 @@
// See details in bionic/libc/linker/debugger.c, in function
// debugger_signal_handler().
if (ptrace(PTRACE_ATTACH, request.tid, 0, 0)) {
- LOG_ERROR("ptrace attach failed: %s\n", strerror(errno));
+ ALOGE("ptrace attach failed: %s\n", strerror(errno));
} else {
bool detach_failed = false;
bool attach_gdb = should_attach_gdb(&request);
if (TEMP_FAILURE_RETRY(write(fd, "\0", 1)) != 1) {
- LOG_ERROR("failed responding to client: %s\n", strerror(errno));
+ ALOGE("failed responding to client: %s\n", strerror(errno));
} else {
char* tombstone_path = NULL;
@@ -261,20 +260,20 @@
switch (signal) {
case SIGSTOP:
if (request.action == DEBUGGER_ACTION_DUMP_TOMBSTONE) {
- XLOG("stopped -- dumping to tombstone\n");
+ ALOGV("stopped -- dumping to tombstone\n");
tombstone_path = engrave_tombstone(request.pid, request.tid,
signal, request.original_si_code,
- request.abort_msg_address, true, true,
+ request.abort_msg_address, true,
&detach_failed, &total_sleep_time_usec);
} else if (request.action == DEBUGGER_ACTION_DUMP_BACKTRACE) {
- XLOG("stopped -- dumping to fd\n");
+ ALOGV("stopped -- dumping to fd\n");
dump_backtrace(fd, -1, request.pid, request.tid, &detach_failed,
&total_sleep_time_usec);
} else {
- XLOG("stopped -- continuing\n");
+ ALOGV("stopped -- continuing\n");
status = ptrace(PTRACE_CONT, request.tid, 0, 0);
if (status) {
- LOG_ERROR("ptrace continue failed: %s\n", strerror(errno));
+ ALOGE("ptrace continue failed: %s\n", strerror(errno));
}
continue; // loop again
}
@@ -290,7 +289,7 @@
case SIGSTKFLT:
#endif
case SIGTRAP:
- XLOG("stopped -- fatal signal\n");
+ ALOGV("stopped -- fatal signal\n");
// Send a SIGSTOP to the process to make all of
// the non-signaled threads stop moving. Without
// this we get a lot of "ptrace detach failed:
@@ -300,13 +299,12 @@
// 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, false,
+ request.abort_msg_address, !attach_gdb,
&detach_failed, &total_sleep_time_usec);
break;
default:
- XLOG("stopped -- unexpected signal\n");
- LOG_ERROR("process stopped due to unexpected signal %d\n", signal);
+ ALOGE("process stopped due to unexpected signal %d\n", signal);
break;
}
break;
@@ -322,14 +320,14 @@
free(tombstone_path);
}
- XLOG("detaching\n");
+ ALOGV("detaching\n");
if (attach_gdb) {
// stop the process so we can debug
kill(request.pid, SIGSTOP);
// detach so we can attach gdbserver
if (ptrace(PTRACE_DETACH, request.tid, 0, 0)) {
- LOG_ERROR("ptrace detach from %d failed: %s\n", request.tid, strerror(errno));
+ ALOGE("ptrace detach from %d failed: %s\n", request.tid, strerror(errno));
detach_failed = true;
}
@@ -341,7 +339,7 @@
} else {
// just detach
if (ptrace(PTRACE_DETACH, request.tid, 0, 0)) {
- LOG_ERROR("ptrace detach from %d failed: %s\n", request.tid, strerror(errno));
+ ALOGE("ptrace detach from %d failed: %s\n", request.tid, strerror(errno));
detach_failed = true;
}
}
@@ -353,7 +351,7 @@
// actual parent won't receive a death notification via wait(2). At this point
// there's not much we can do about that.
if (detach_failed) {
- LOG_ERROR("debuggerd committing suicide to free the zombie!\n");
+ ALOGE("debuggerd committing suicide to free the zombie!\n");
kill(getpid(), SIGKILL);
}
}
@@ -399,16 +397,16 @@
return 1;
fcntl(s, F_SETFD, FD_CLOEXEC);
- LOG_ERROR("debuggerd: " __DATE__ " " __TIME__ "\n");
+ ALOGI("debuggerd: " __DATE__ " " __TIME__ "\n");
for (;;) {
sockaddr addr;
socklen_t alen = sizeof(addr);
- XLOG("waiting for connection\n");
+ ALOGV("waiting for connection\n");
int fd = accept(s, &addr, &alen);
if (fd < 0) {
- XLOG("accept failed: %s\n", strerror(errno));
+ ALOGV("accept failed: %s\n", strerror(errno));
continue;
}