From cbb59dd2408e77d2cb8b80112ec9903d4cb68109 Mon Sep 17 00:00:00 2001 From: Christopher Ferris Date: Thu, 14 Nov 2024 03:54:13 +0000 Subject: [PATCH] Add source of unwind when fatal error. Sometimes the only log left is the errors messages. This means that the information about why the unwind part of debuggerd is being called. Therefore, add a little bit of extra information in the error message to indicate why the unwind was triggered. Bug: 377050125 Test: Forced the exec of the crash dump to fail and verified that the Test: message is crash for a crash and unwind for debuggerd -b Test: and debuggerd . Change-Id: I0632ed9118c79caf4dabe6f174b25066fa9058fc --- debuggerd/handler/debuggerd_handler.cpp | 31 +++++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/debuggerd/handler/debuggerd_handler.cpp b/debuggerd/handler/debuggerd_handler.cpp index ddc3244f1..88278ca66 100644 --- a/debuggerd/handler/debuggerd_handler.cpp +++ b/debuggerd/handler/debuggerd_handler.cpp @@ -389,6 +389,13 @@ static DebuggerdDumpType get_dump_type(const debugger_thread_info* thread_info) return kDebuggerdTombstoneProto; } +static const char* get_unwind_type(const debugger_thread_info* thread_info) { + if (thread_info->siginfo->si_signo == BIONIC_SIGNAL_DEBUGGER) { + return "Unwind request"; + } + return "Crash due to signal"; +} + static int debuggerd_dispatch_pseudothread(void* arg) { debugger_thread_info* thread_info = static_cast(arg); @@ -502,8 +509,8 @@ static int debuggerd_dispatch_pseudothread(void* arg) { execle(CRASH_DUMP_PATH, CRASH_DUMP_NAME, main_tid, pseudothread_tid, debuggerd_dump_type, nullptr, nullptr); - async_safe_format_log(ANDROID_LOG_FATAL, "libc", "failed to exec crash_dump helper: %s", - strerror(errno)); + async_safe_format_log(ANDROID_LOG_FATAL, "libc", "%s: failed to exec crash_dump helper: %s", + get_unwind_type(thread_info), strerror(errno)); return 1; } @@ -524,26 +531,30 @@ static int debuggerd_dispatch_pseudothread(void* arg) { } else { // Something went wrong, log it. if (rc == -1) { - async_safe_format_log(ANDROID_LOG_FATAL, "libc", "read of IPC pipe failed: %s", - strerror(errno)); + async_safe_format_log(ANDROID_LOG_FATAL, "libc", "%s: read of IPC pipe failed: %s", + get_unwind_type(thread_info), strerror(errno)); } else if (rc == 0) { async_safe_format_log(ANDROID_LOG_FATAL, "libc", - "crash_dump helper failed to exec, or was killed"); + "%s: crash_dump helper failed to exec, or was killed", + get_unwind_type(thread_info)); } else if (rc != 1) { async_safe_format_log(ANDROID_LOG_FATAL, "libc", - "read of IPC pipe returned unexpected value: %zd", rc); + "%s: read of IPC pipe returned unexpected value: %zd", + get_unwind_type(thread_info), rc); } else if (buf[0] != '\1') { - async_safe_format_log(ANDROID_LOG_FATAL, "libc", "crash_dump helper reported failure"); + async_safe_format_log(ANDROID_LOG_FATAL, "libc", "%s: crash_dump helper reported failure", + get_unwind_type(thread_info)); } } // Don't leave a zombie child. int status; if (TEMP_FAILURE_RETRY(waitpid(crash_dump_pid, &status, 0)) == -1) { - async_safe_format_log(ANDROID_LOG_FATAL, "libc", "failed to wait for crash_dump helper: %s", - strerror(errno)); + async_safe_format_log(ANDROID_LOG_FATAL, "libc", "%s: failed to wait for crash_dump helper: %s", + get_unwind_type(thread_info), strerror(errno)); } else if (WIFSTOPPED(status) || WIFSIGNALED(status)) { - async_safe_format_log(ANDROID_LOG_FATAL, "libc", "crash_dump helper crashed or stopped"); + async_safe_format_log(ANDROID_LOG_FATAL, "libc", "%s: crash_dump helper crashed or stopped", + get_unwind_type(thread_info)); } if (success) {