diff --git a/debuggerd/debuggerd_test.cpp b/debuggerd/debuggerd_test.cpp index a00a2026f..39d7fff1c 100644 --- a/debuggerd/debuggerd_test.cpp +++ b/debuggerd/debuggerd_test.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -2703,3 +2704,58 @@ TEST_F(CrasherTest, verify_build_id) { } ASSERT_TRUE(found_valid_elf) << "Did not find any elf files with valid BuildIDs to check."; } + +const char kLogMessage[] = "Should not see this log message."; + +// Verify that the logd process does not read the log. +TEST_F(CrasherTest, logd_skips_reading_logs) { + StartProcess([]() { + pthread_setname_np(pthread_self(), "logd"); + LOG(INFO) << kLogMessage; + abort(); + }); + + unique_fd output_fd; + StartIntercept(&output_fd); + FinishCrasher(); + AssertDeath(SIGABRT); + int intercept_result; + FinishIntercept(&intercept_result); + ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; + + std::string result; + ConsumeFd(std::move(output_fd), &result); + // logd should not contain our log message. + ASSERT_NOT_MATCH(result, kLogMessage); +} + +// Verify that the logd process does not read the log when the non-main +// thread crashes. +TEST_F(CrasherTest, logd_skips_reading_logs_not_main_thread) { + StartProcess([]() { + pthread_setname_np(pthread_self(), "logd"); + LOG(INFO) << kLogMessage; + + std::thread thread([]() { + pthread_setname_np(pthread_self(), "not_logd_thread"); + // Raise the signal on the side thread. + raise_debugger_signal(kDebuggerdTombstone); + }); + thread.join(); + _exit(0); + }); + + unique_fd output_fd; + StartIntercept(&output_fd, kDebuggerdTombstone); + FinishCrasher(); + AssertDeath(0); + + int intercept_result; + FinishIntercept(&intercept_result); + ASSERT_EQ(1, intercept_result) << "tombstoned reported failure"; + + std::string result; + ConsumeFd(std::move(output_fd), &result); + ASSERT_BACKTRACE_FRAME(result, "raise_debugger_signal"); + ASSERT_NOT_MATCH(result, kLogMessage); +} diff --git a/debuggerd/libdebuggerd/tombstone_proto.cpp b/debuggerd/libdebuggerd/tombstone_proto.cpp index 9a565deb6..acd814efa 100644 --- a/debuggerd/libdebuggerd/tombstone_proto.cpp +++ b/debuggerd/libdebuggerd/tombstone_proto.cpp @@ -690,7 +690,14 @@ void engrave_tombstone_proto(Tombstone* tombstone, unwindstack::AndroidUnwinder* // Only dump logs on debuggable devices. if (android::base::GetBoolProperty("ro.debuggable", false)) { - dump_logcat(&result, main_thread.pid); + // Get the thread that corresponds to the main pid of the process. + const ThreadInfo& thread = threads.at(main_thread.pid); + + // Do not attempt to dump logs of the logd process because the gathering + // of logs can hang until a timeout occurs. + if (thread.thread_name != "logd") { + dump_logcat(&result, main_thread.pid); + } } dump_open_fds(&result, open_files);