summaryrefslogtreecommitdiffstats
path: root/debuggerd/utility.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'debuggerd/utility.cpp')
-rw-r--r--debuggerd/utility.cpp26
1 files changed, 7 insertions, 19 deletions
diff --git a/debuggerd/utility.cpp b/debuggerd/utility.cpp
index ce214f921..cd252ce72 100644
--- a/debuggerd/utility.cpp
+++ b/debuggerd/utility.cpp
@@ -30,8 +30,8 @@
#include <backtrace/Backtrace.h>
#include <log/log.h>
-const int SLEEP_TIME_USEC = 50000; // 0.05 seconds
-const int MAX_TOTAL_SLEEP_USEC = 10000000; // 10 seconds
+constexpr int SLEEP_TIME_USEC = 50000; // 0.05 seconds
+constexpr int MAX_TOTAL_SLEEP_USEC = 10000000; // 10 seconds
// Whitelist output desired in the logcat output.
bool is_allowed_in_logcat(enum logtype ltype) {
@@ -78,14 +78,13 @@ void _LOG(log_t* log, enum logtype ltype, const char* fmt, ...) {
}
}
-int wait_for_sigstop(pid_t tid, int* total_sleep_time_usec, bool* detach_failed) {
- bool allow_dead_tid = false;
- for (;;) {
+int wait_for_signal(pid_t tid, int* total_sleep_time_usec) {
+ while (true) {
int status;
pid_t n = TEMP_FAILURE_RETRY(waitpid(tid, &status, __WALL | WNOHANG));
if (n == -1) {
ALOGE("waitpid failed: tid %d, %s", tid, strerror(errno));
- break;
+ return -1;
} else if (n == tid) {
if (WIFSTOPPED(status)) {
return WSTOPSIG(status);
@@ -93,29 +92,18 @@ int wait_for_sigstop(pid_t tid, int* total_sleep_time_usec, bool* detach_failed)
ALOGE("unexpected waitpid response: n=%d, status=%08x\n", n, status);
// This is the only circumstance under which we can allow a detach
// to fail with ESRCH, which indicates the tid has exited.
- allow_dead_tid = true;
- break;
+ return -1;
}
}
if (*total_sleep_time_usec > MAX_TOTAL_SLEEP_USEC) {
ALOGE("timed out waiting for stop signal: tid=%d", tid);
- break;
+ return -1;
}
usleep(SLEEP_TIME_USEC);
*total_sleep_time_usec += SLEEP_TIME_USEC;
}
-
- if (ptrace(PTRACE_DETACH, tid, 0, 0) != 0) {
- if (allow_dead_tid && errno == ESRCH) {
- ALOGE("tid exited before attach completed: tid %d", tid);
- } else {
- *detach_failed = true;
- ALOGE("detach failed: tid %d, %s", tid, strerror(errno));
- }
- }
- return -1;
}
#define MEMORY_BYTES_TO_DUMP 256