Merge "Fix potential miscellaneous debuggerd issues." into main

This commit is contained in:
Christopher Ferris 2023-08-10 19:53:19 +00:00 committed by Gerrit Code Review
commit 9f32fba6d3
3 changed files with 37 additions and 10 deletions

View file

@ -2264,10 +2264,14 @@ TEST_F(CrasherTest, fault_address_after_last_map) {
ASSERT_MATCH(result, R"(\nmemory map \(.*\): \(fault address prefixed with --->)\n)"); ASSERT_MATCH(result, R"(\nmemory map \(.*\): \(fault address prefixed with --->)\n)");
// Assumes that the open files section comes after the map section. // Verifies that the fault address error message is at the end of the
// If that assumption changes, the regex below needs to change. // maps section. To do this, the check below looks for the start of the
// open files section or the start of the log file section. It's possible
// for either of these sections to be present after the maps section right
// now.
// If the sections move around, this check might need to be modified.
match_str = android::base::StringPrintf( match_str = android::base::StringPrintf(
R"(\n--->Fault address falls at %s after any mapped regions\n\nopen files:)", R"(\n--->Fault address falls at %s after any mapped regions\n(---------|\nopen files:))",
format_pointer(crash_uptr).c_str()); format_pointer(crash_uptr).c_str());
ASSERT_MATCH(result, match_str); ASSERT_MATCH(result, match_str);
} }

View file

@ -493,27 +493,48 @@ static void dump_mappings(Tombstone* tombstone, unwindstack::Maps* maps,
} }
} }
// This creates a fake log message that indicates an error occurred when
// reading the log.
static void add_error_log_msg(Tombstone* tombstone, const std::string&& error_msg) {
LogBuffer buffer;
buffer.set_name("ERROR");
LogMessage* log_msg = buffer.add_logs();
log_msg->set_timestamp("00-00 00:00:00.000");
log_msg->set_pid(0);
log_msg->set_tid(0);
log_msg->set_priority(ANDROID_LOG_ERROR);
log_msg->set_tag("");
log_msg->set_message(error_msg);
*tombstone->add_log_buffers() = std::move(buffer);
async_safe_format_log(ANDROID_LOG_ERROR, LOG_TAG, "%s", error_msg.c_str());
}
static void dump_log_file(Tombstone* tombstone, const char* logger, pid_t pid) { static void dump_log_file(Tombstone* tombstone, const char* logger, pid_t pid) {
logger_list* logger_list = android_logger_list_open(android_name_to_log_id(logger), logger_list* logger_list = android_logger_list_open(android_name_to_log_id(logger),
ANDROID_LOG_NONBLOCK, kMaxLogMessages, pid); ANDROID_LOG_NONBLOCK, kMaxLogMessages, pid);
if (logger_list == nullptr) {
add_error_log_msg(tombstone, android::base::StringPrintf("Cannot open log file %s", logger));
return;
}
LogBuffer buffer; LogBuffer buffer;
while (true) { while (true) {
log_msg log_entry; log_msg log_entry;
ssize_t actual = android_logger_list_read(logger_list, &log_entry); ssize_t actual = android_logger_list_read(logger_list, &log_entry);
if (actual < 0) { if (actual < 0) {
if (actual == -EINTR) { if (actual == -EINTR) {
// interrupted by signal, retry // interrupted by signal, retry
continue; continue;
} }
if (actual == -EAGAIN) { // Don't consider EAGAIN an error since this is a non-blocking call.
// non-blocking EOF; we're done if (actual != -EAGAIN) {
break; add_error_log_msg(tombstone, android::base::StringPrintf("reading log %s failed (%s)",
} else { logger, strerror(-actual)));
break;
} }
break;
} else if (actual == 0) { } else if (actual == 0) {
break; break;
} }

View file

@ -81,6 +81,8 @@ static void print_thread_header(CallbackType callback, const Tombstone& tombston
if (!tombstone.command_line().empty()) { if (!tombstone.command_line().empty()) {
process_name = tombstone.command_line()[0].c_str(); process_name = tombstone.command_line()[0].c_str();
CB(should_log, "Cmdline: %s", android::base::Join(tombstone.command_line(), " ").c_str()); CB(should_log, "Cmdline: %s", android::base::Join(tombstone.command_line(), " ").c_str());
} else {
CB(should_log, "Cmdline: <unknown>");
} }
CB(should_log, "pid: %d, tid: %d, name: %s >>> %s <<<", tombstone.pid(), thread.id(), CB(should_log, "pid: %d, tid: %d, name: %s >>> %s <<<", tombstone.pid(), thread.id(),
thread.name().c_str(), process_name); thread.name().c_str(), process_name);