2012-06-07 01:25:03 +02:00
|
|
|
/*
|
2013-12-12 21:21:20 +01:00
|
|
|
* Copyright (C) 2012-2014 The Android Open Source Project
|
2012-06-07 01:25:03 +02:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2014-06-10 20:53:08 +02:00
|
|
|
#define LOG_TAG "DEBUG"
|
|
|
|
|
2017-08-29 22:08:32 +02:00
|
|
|
#include "libdebuggerd/tombstone.h"
|
|
|
|
|
2013-12-18 17:44:24 +01:00
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
#include <signal.h>
|
2012-06-07 01:25:03 +02:00
|
|
|
#include <stddef.h>
|
2013-12-18 17:44:24 +01:00
|
|
|
#include <stdio.h>
|
2012-06-07 01:25:03 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sys/ptrace.h>
|
|
|
|
#include <sys/stat.h>
|
2016-09-29 00:54:45 +02:00
|
|
|
#include <time.h>
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2015-05-16 02:30:21 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
2017-03-16 07:23:22 +01:00
|
|
|
#include <android-base/file.h>
|
2017-08-21 23:31:17 +02:00
|
|
|
#include <android-base/logging.h>
|
2017-10-10 22:30:57 +02:00
|
|
|
#include <android-base/properties.h>
|
2015-12-05 07:00:26 +01:00
|
|
|
#include <android-base/stringprintf.h>
|
2017-08-21 23:31:17 +02:00
|
|
|
#include <android-base/strings.h>
|
2017-03-16 07:23:22 +01:00
|
|
|
#include <android-base/unique_fd.h>
|
|
|
|
#include <android/log.h>
|
2016-10-17 23:28:00 +02:00
|
|
|
#include <log/log.h>
|
2014-05-14 21:37:22 +02:00
|
|
|
#include <log/logprint.h>
|
2016-09-29 00:54:45 +02:00
|
|
|
#include <private/android_filesystem_config.h>
|
2019-04-05 20:23:32 +02:00
|
|
|
#include <unwindstack/DexFiles.h>
|
2019-01-16 00:18:43 +01:00
|
|
|
#include <unwindstack/JitDebug.h>
|
|
|
|
#include <unwindstack/Maps.h>
|
2017-08-21 23:31:17 +02:00
|
|
|
#include <unwindstack/Memory.h>
|
|
|
|
#include <unwindstack/Regs.h>
|
2019-01-16 00:18:43 +01:00
|
|
|
#include <unwindstack/Unwinder.h>
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2017-08-29 22:08:32 +02:00
|
|
|
// Needed to get DEBUGGER_SIGNAL.
|
2016-10-19 03:17:52 +02:00
|
|
|
#include "debuggerd/handler.h"
|
2012-07-19 15:38:06 +02:00
|
|
|
|
2017-08-29 22:08:32 +02:00
|
|
|
#include "libdebuggerd/backtrace.h"
|
|
|
|
#include "libdebuggerd/open_files_list.h"
|
2017-08-21 23:31:17 +02:00
|
|
|
#include "libdebuggerd/utility.h"
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2017-10-10 22:30:57 +02:00
|
|
|
using android::base::GetBoolProperty;
|
|
|
|
using android::base::GetProperty;
|
2017-02-02 01:59:15 +01:00
|
|
|
using android::base::StringPrintf;
|
2017-08-21 23:31:17 +02:00
|
|
|
using android::base::unique_fd;
|
2017-02-02 01:59:15 +01:00
|
|
|
|
2018-02-15 18:18:21 +01:00
|
|
|
using namespace std::literals::string_literals;
|
|
|
|
|
2017-08-21 23:31:17 +02:00
|
|
|
#define STACK_WORDS 16
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2014-06-03 00:02:20 +02:00
|
|
|
static void dump_header_info(log_t* log) {
|
2017-10-10 22:30:57 +02:00
|
|
|
auto fingerprint = GetProperty("ro.build.fingerprint", "unknown");
|
|
|
|
auto revision = GetProperty("ro.revision", "unknown");
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2017-10-10 22:30:57 +02:00
|
|
|
_LOG(log, logtype::HEADER, "Build fingerprint: '%s'\n", fingerprint.c_str());
|
|
|
|
_LOG(log, logtype::HEADER, "Revision: '%s'\n", revision.c_str());
|
2014-06-10 20:53:08 +02:00
|
|
|
_LOG(log, logtype::HEADER, "ABI: '%s'\n", ABI_STRING);
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2018-12-14 22:05:12 +01:00
|
|
|
static void dump_timestamp(log_t* log, time_t time) {
|
|
|
|
struct tm tm;
|
|
|
|
localtime_r(&time, &tm);
|
|
|
|
|
|
|
|
char buf[strlen("1970-01-01 00:00:00+0830") + 1];
|
|
|
|
strftime(buf, sizeof(buf), "%F %T%z", &tm);
|
|
|
|
_LOG(log, logtype::HEADER, "Timestamp: %s\n", buf);
|
|
|
|
}
|
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
static void dump_probable_cause(log_t* log, const siginfo_t* si, unwindstack::Maps* maps) {
|
2017-02-02 01:59:15 +01:00
|
|
|
std::string cause;
|
2017-08-21 23:31:17 +02:00
|
|
|
if (si->si_signo == SIGSEGV && si->si_code == SEGV_MAPERR) {
|
|
|
|
if (si->si_addr < reinterpret_cast<void*>(4096)) {
|
2017-02-02 01:59:15 +01:00
|
|
|
cause = StringPrintf("null pointer dereference");
|
2017-08-21 23:31:17 +02:00
|
|
|
} else if (si->si_addr == reinterpret_cast<void*>(0xffff0ffc)) {
|
2017-02-02 01:59:15 +01:00
|
|
|
cause = "call to kuser_helper_version";
|
2017-08-21 23:31:17 +02:00
|
|
|
} else if (si->si_addr == reinterpret_cast<void*>(0xffff0fe0)) {
|
2017-02-02 01:59:15 +01:00
|
|
|
cause = "call to kuser_get_tls";
|
2017-08-21 23:31:17 +02:00
|
|
|
} else if (si->si_addr == reinterpret_cast<void*>(0xffff0fc0)) {
|
2017-02-02 01:59:15 +01:00
|
|
|
cause = "call to kuser_cmpxchg";
|
2017-08-21 23:31:17 +02:00
|
|
|
} else if (si->si_addr == reinterpret_cast<void*>(0xffff0fa0)) {
|
2017-02-02 01:59:15 +01:00
|
|
|
cause = "call to kuser_memory_barrier";
|
2017-08-21 23:31:17 +02:00
|
|
|
} else if (si->si_addr == reinterpret_cast<void*>(0xffff0f60)) {
|
2017-02-02 01:59:15 +01:00
|
|
|
cause = "call to kuser_cmpxchg64";
|
|
|
|
}
|
2018-11-19 19:43:47 +01:00
|
|
|
} else if (si->si_signo == SIGSEGV && si->si_code == SEGV_ACCERR) {
|
2019-01-16 00:18:43 +01:00
|
|
|
unwindstack::MapInfo* map_info = maps->Find(reinterpret_cast<uint64_t>(si->si_addr));
|
|
|
|
if (map_info != nullptr && map_info->flags == PROT_EXEC) {
|
|
|
|
cause = "execute-only (no-read) memory access error; likely due to data in .text.";
|
2018-11-19 19:43:47 +01:00
|
|
|
}
|
2017-08-21 23:31:17 +02:00
|
|
|
} else if (si->si_signo == SIGSYS && si->si_code == SYS_SECCOMP) {
|
|
|
|
cause = StringPrintf("seccomp prevented call to disallowed %s system call %d", ABI_STRING,
|
|
|
|
si->si_syscall);
|
2017-02-02 01:59:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!cause.empty()) _LOG(log, logtype::HEADER, "Cause: %s\n", cause.c_str());
|
|
|
|
}
|
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
static void dump_signal_info(log_t* log, const ThreadInfo& thread_info,
|
|
|
|
unwindstack::Memory* process_memory) {
|
2018-05-30 21:55:04 +02:00
|
|
|
char addr_desc[64]; // ", fault addr 0x1234"
|
2018-04-26 02:00:14 +02:00
|
|
|
if (signal_has_si_addr(thread_info.siginfo)) {
|
2018-05-30 21:55:04 +02:00
|
|
|
void* addr = thread_info.siginfo->si_addr;
|
|
|
|
if (thread_info.siginfo->si_signo == SIGILL) {
|
|
|
|
uint32_t instruction = {};
|
|
|
|
process_memory->Read(reinterpret_cast<uint64_t>(addr), &instruction, sizeof(instruction));
|
|
|
|
snprintf(addr_desc, sizeof(addr_desc), "%p (*pc=%#08x)", addr, instruction);
|
|
|
|
} else {
|
|
|
|
snprintf(addr_desc, sizeof(addr_desc), "%p", addr);
|
|
|
|
}
|
2014-01-11 01:33:16 +01:00
|
|
|
} else {
|
2014-04-26 01:05:34 +02:00
|
|
|
snprintf(addr_desc, sizeof(addr_desc), "--------");
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2014-04-26 01:05:34 +02:00
|
|
|
|
2018-04-26 02:00:14 +02:00
|
|
|
char sender_desc[32] = {}; // " from pid 1234, uid 666"
|
|
|
|
if (signal_has_sender(thread_info.siginfo, thread_info.pid)) {
|
|
|
|
get_signal_sender(sender_desc, sizeof(sender_desc), thread_info.siginfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
_LOG(log, logtype::HEADER, "signal %d (%s), code %d (%s%s), fault addr %s\n",
|
|
|
|
thread_info.siginfo->si_signo, get_signame(thread_info.siginfo),
|
|
|
|
thread_info.siginfo->si_code, get_sigcode(thread_info.siginfo), sender_desc, addr_desc);
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2017-08-21 23:31:17 +02:00
|
|
|
static void dump_thread_info(log_t* log, const ThreadInfo& thread_info) {
|
2014-07-25 21:25:48 +02:00
|
|
|
// Blacklist logd, logd.reader, logd.writer, logd.auditd, logd.control ...
|
2017-03-16 07:23:22 +01:00
|
|
|
// TODO: Why is this controlled by thread name?
|
2017-08-21 23:31:17 +02:00
|
|
|
if (thread_info.thread_name == "logd" ||
|
|
|
|
android::base::StartsWith(thread_info.thread_name, "logd.")) {
|
2014-07-25 21:25:48 +02:00
|
|
|
log->should_retrieve_logcat = false;
|
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2017-08-21 23:31:17 +02:00
|
|
|
_LOG(log, logtype::HEADER, "pid: %d, tid: %d, name: %s >>> %s <<<\n", thread_info.pid,
|
|
|
|
thread_info.tid, thread_info.thread_name.c_str(), thread_info.process_name.c_str());
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
static void dump_stack_segment(log_t* log, unwindstack::Maps* maps, unwindstack::Memory* memory,
|
2018-01-18 20:15:49 +01:00
|
|
|
uint64_t* sp, size_t words, int label) {
|
2015-02-27 22:39:47 +01:00
|
|
|
// Read the data all at once.
|
|
|
|
word_t stack_data[words];
|
2017-08-21 23:31:17 +02:00
|
|
|
|
|
|
|
// TODO: Do we need to word align this for crashes caused by a misaligned sp?
|
|
|
|
// The process_vm_readv implementation of Memory should handle this appropriately?
|
2019-01-16 00:18:43 +01:00
|
|
|
size_t bytes_read = memory->Read(*sp, stack_data, sizeof(word_t) * words);
|
2015-02-27 22:39:47 +01:00
|
|
|
words = bytes_read / sizeof(word_t);
|
|
|
|
std::string line;
|
2014-01-11 01:33:16 +01:00
|
|
|
for (size_t i = 0; i < words; i++) {
|
2015-02-27 22:39:47 +01:00
|
|
|
line = " ";
|
|
|
|
if (i == 0 && label >= 0) {
|
|
|
|
// Print the label once.
|
2017-02-02 01:59:15 +01:00
|
|
|
line += StringPrintf("#%02d ", label);
|
2015-02-27 22:39:47 +01:00
|
|
|
} else {
|
|
|
|
line += " ";
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2018-01-20 09:59:11 +01:00
|
|
|
line += StringPrintf("%" PRIPTR " %" PRIPTR, *sp, static_cast<uint64_t>(stack_data[i]));
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
unwindstack::MapInfo* map_info = maps->Find(stack_data[i]);
|
|
|
|
if (map_info != nullptr && !map_info->name.empty()) {
|
|
|
|
line += " " + map_info->name;
|
|
|
|
std::string func_name;
|
|
|
|
uint64_t func_offset = 0;
|
|
|
|
if (map_info->GetFunctionName(stack_data[i], &func_name, &func_offset)) {
|
2015-02-27 22:39:47 +01:00
|
|
|
line += " (" + func_name;
|
2019-01-16 00:18:43 +01:00
|
|
|
if (func_offset) {
|
|
|
|
line += StringPrintf("+%" PRIu64, func_offset);
|
2013-10-02 21:26:48 +02:00
|
|
|
}
|
2015-02-27 22:39:47 +01:00
|
|
|
line += ')';
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
2015-02-27 22:39:47 +01:00
|
|
|
_LOG(log, logtype::STACK, "%s\n", line.c_str());
|
2014-01-11 01:33:16 +01:00
|
|
|
|
2013-11-21 20:17:20 +01:00
|
|
|
*sp += sizeof(word_t);
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
static void dump_stack(log_t* log, const std::vector<unwindstack::FrameData>& frames,
|
|
|
|
unwindstack::Maps* maps, unwindstack::Memory* memory) {
|
2014-01-11 01:33:16 +01:00
|
|
|
size_t first = 0, last;
|
2017-08-21 23:31:17 +02:00
|
|
|
for (size_t i = 0; i < frames.size(); i++) {
|
2019-01-16 00:18:43 +01:00
|
|
|
if (frames[i].sp) {
|
2014-01-11 01:33:16 +01:00
|
|
|
if (!first) {
|
|
|
|
first = i+1;
|
|
|
|
}
|
|
|
|
last = i;
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2017-08-21 23:31:17 +02:00
|
|
|
|
2014-01-11 01:33:16 +01:00
|
|
|
if (!first) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
first--;
|
|
|
|
|
|
|
|
// Dump a few words before the first frame.
|
2018-01-18 20:15:49 +01:00
|
|
|
uint64_t sp = frames[first].sp - STACK_WORDS * sizeof(word_t);
|
2019-01-16 00:18:43 +01:00
|
|
|
dump_stack_segment(log, maps, memory, &sp, STACK_WORDS, -1);
|
|
|
|
|
|
|
|
#if defined(__LP64__)
|
|
|
|
static constexpr const char delimiter[] = " ................ ................\n";
|
|
|
|
#else
|
|
|
|
static constexpr const char delimiter[] = " ........ ........\n";
|
|
|
|
#endif
|
2014-01-11 01:33:16 +01:00
|
|
|
|
|
|
|
// Dump a few words from all successive frames.
|
|
|
|
for (size_t i = first; i <= last; i++) {
|
2019-01-16 00:18:43 +01:00
|
|
|
auto* frame = &frames[i];
|
2014-01-11 01:33:16 +01:00
|
|
|
if (sp != frame->sp) {
|
2019-01-16 00:18:43 +01:00
|
|
|
_LOG(log, logtype::STACK, delimiter);
|
2014-01-11 01:33:16 +01:00
|
|
|
sp = frame->sp;
|
|
|
|
}
|
2019-01-16 00:18:43 +01:00
|
|
|
if (i != last) {
|
|
|
|
// Print stack data up to the stack from the next frame.
|
|
|
|
size_t words;
|
|
|
|
uint64_t next_sp = frames[i + 1].sp;
|
|
|
|
if (next_sp < sp) {
|
|
|
|
// The next frame is probably using a completely different stack,
|
|
|
|
// so dump the max from this stack.
|
2014-01-11 01:33:16 +01:00
|
|
|
words = STACK_WORDS;
|
2019-01-16 00:18:43 +01:00
|
|
|
} else {
|
|
|
|
words = (next_sp - sp) / sizeof(word_t);
|
|
|
|
if (words == 0) {
|
|
|
|
// The sp is the same as the next frame, print at least
|
|
|
|
// one line for this frame.
|
|
|
|
words = 1;
|
|
|
|
} else if (words > STACK_WORDS) {
|
|
|
|
words = STACK_WORDS;
|
|
|
|
}
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2019-01-16 00:18:43 +01:00
|
|
|
dump_stack_segment(log, maps, memory, &sp, words, i);
|
|
|
|
} else {
|
|
|
|
// Print some number of words past the last stack frame since we
|
|
|
|
// don't know how large the stack is.
|
|
|
|
dump_stack_segment(log, maps, memory, &sp, STACK_WORDS, i);
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2018-01-18 20:15:49 +01:00
|
|
|
static std::string get_addr_string(uint64_t addr) {
|
2015-06-02 23:52:44 +02:00
|
|
|
std::string addr_str;
|
|
|
|
#if defined(__LP64__)
|
2017-02-02 01:59:15 +01:00
|
|
|
addr_str = StringPrintf("%08x'%08x",
|
|
|
|
static_cast<uint32_t>(addr >> 32),
|
|
|
|
static_cast<uint32_t>(addr & 0xffffffff));
|
2015-06-02 23:52:44 +02:00
|
|
|
#else
|
2018-01-18 20:15:49 +01:00
|
|
|
addr_str = StringPrintf("%08x", static_cast<uint32_t>(addr));
|
2015-06-02 23:52:44 +02:00
|
|
|
#endif
|
|
|
|
return addr_str;
|
|
|
|
}
|
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
static void dump_abort_message(log_t* log, unwindstack::Memory* process_memory, uint64_t address) {
|
2016-01-14 02:57:14 +01:00
|
|
|
if (address == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-08-21 23:31:17 +02:00
|
|
|
size_t length;
|
|
|
|
if (!process_memory->ReadFully(address, &length, sizeof(length))) {
|
|
|
|
_LOG(log, logtype::HEADER, "Failed to read abort message header: %s\n", strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
2016-01-14 02:57:14 +01:00
|
|
|
|
2018-02-13 22:16:17 +01:00
|
|
|
// The length field includes the length of the length field itself.
|
|
|
|
if (length < sizeof(size_t)) {
|
|
|
|
_LOG(log, logtype::HEADER, "Abort message header malformed: claimed length = %zd\n", length);
|
2017-08-21 23:31:17 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-01-14 02:57:14 +01:00
|
|
|
|
2018-02-13 22:16:17 +01:00
|
|
|
length -= sizeof(size_t);
|
|
|
|
|
2018-04-21 02:31:53 +02:00
|
|
|
// The abort message should be null terminated already, but reserve a spot for NUL just in case.
|
|
|
|
std::vector<char> msg(length + 1);
|
2018-02-13 22:16:17 +01:00
|
|
|
if (!process_memory->ReadFully(address + sizeof(length), &msg[0], length)) {
|
2017-08-21 23:31:17 +02:00
|
|
|
_LOG(log, logtype::HEADER, "Failed to read abort message: %s\n", strerror(errno));
|
|
|
|
return;
|
2016-01-14 02:57:14 +01:00
|
|
|
}
|
|
|
|
|
2018-02-13 22:16:17 +01:00
|
|
|
_LOG(log, logtype::HEADER, "Abort message: '%s'\n", &msg[0]);
|
2016-01-14 02:57:14 +01:00
|
|
|
}
|
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
static void dump_all_maps(log_t* log, unwindstack::Unwinder* unwinder, uint64_t addr) {
|
2017-08-21 23:31:17 +02:00
|
|
|
bool print_fault_address_marker = addr;
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
unwindstack::Maps* maps = unwinder->GetMaps();
|
2017-09-26 20:54:49 +02:00
|
|
|
_LOG(log, logtype::MAPS,
|
|
|
|
"\n"
|
2017-09-27 22:59:42 +02:00
|
|
|
"memory map (%zu entr%s):",
|
2019-01-16 00:18:43 +01:00
|
|
|
maps->Total(), maps->Total() == 1 ? "y" : "ies");
|
2017-09-26 20:54:49 +02:00
|
|
|
if (print_fault_address_marker) {
|
2019-01-16 00:18:43 +01:00
|
|
|
if (maps->Total() != 0 && addr < maps->Get(0)->start) {
|
2017-09-27 22:59:42 +02:00
|
|
|
_LOG(log, logtype::MAPS, "\n--->Fault address falls at %s before any mapped regions\n",
|
2015-06-02 23:52:44 +02:00
|
|
|
get_addr_string(addr).c_str());
|
2015-02-27 22:39:47 +01:00
|
|
|
print_fault_address_marker = false;
|
2017-09-26 20:54:49 +02:00
|
|
|
} else {
|
2017-09-27 22:59:42 +02:00
|
|
|
_LOG(log, logtype::MAPS, " (fault address prefixed with --->)\n");
|
2015-02-27 22:39:47 +01:00
|
|
|
}
|
2017-09-27 22:59:42 +02:00
|
|
|
} else {
|
|
|
|
_LOG(log, logtype::MAPS, "\n");
|
2014-07-07 21:33:50 +02:00
|
|
|
}
|
2014-01-11 01:33:16 +01:00
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
std::shared_ptr<unwindstack::Memory>& process_memory = unwinder->GetProcessMemory();
|
|
|
|
|
2015-02-27 22:39:47 +01:00
|
|
|
std::string line;
|
2019-02-27 19:00:37 +01:00
|
|
|
for (auto const& map_info : *maps) {
|
2015-02-27 22:39:47 +01:00
|
|
|
line = " ";
|
|
|
|
if (print_fault_address_marker) {
|
2019-01-16 00:18:43 +01:00
|
|
|
if (addr < map_info->start) {
|
2015-06-02 23:52:44 +02:00
|
|
|
_LOG(log, logtype::MAPS, "--->Fault address falls at %s between mapped regions\n",
|
|
|
|
get_addr_string(addr).c_str());
|
2015-02-27 22:39:47 +01:00
|
|
|
print_fault_address_marker = false;
|
2019-01-16 00:18:43 +01:00
|
|
|
} else if (addr >= map_info->start && addr < map_info->end) {
|
2015-02-27 22:39:47 +01:00
|
|
|
line = "--->";
|
|
|
|
print_fault_address_marker = false;
|
|
|
|
}
|
|
|
|
}
|
2019-01-16 00:18:43 +01:00
|
|
|
line += get_addr_string(map_info->start) + '-' + get_addr_string(map_info->end - 1) + ' ';
|
|
|
|
if (map_info->flags & PROT_READ) {
|
2015-02-27 22:39:47 +01:00
|
|
|
line += 'r';
|
|
|
|
} else {
|
|
|
|
line += '-';
|
|
|
|
}
|
2019-01-16 00:18:43 +01:00
|
|
|
if (map_info->flags & PROT_WRITE) {
|
2015-02-27 22:39:47 +01:00
|
|
|
line += 'w';
|
|
|
|
} else {
|
|
|
|
line += '-';
|
|
|
|
}
|
2019-01-16 00:18:43 +01:00
|
|
|
if (map_info->flags & PROT_EXEC) {
|
2015-02-27 22:39:47 +01:00
|
|
|
line += 'x';
|
|
|
|
} else {
|
|
|
|
line += '-';
|
|
|
|
}
|
2019-01-16 00:18:43 +01:00
|
|
|
line += StringPrintf(" %8" PRIx64 " %8" PRIx64, map_info->offset,
|
|
|
|
map_info->end - map_info->start);
|
2015-06-02 23:52:44 +02:00
|
|
|
bool space_needed = true;
|
2019-01-16 00:18:43 +01:00
|
|
|
if (!map_info->name.empty()) {
|
2015-06-02 23:52:44 +02:00
|
|
|
space_needed = false;
|
2019-01-16 00:18:43 +01:00
|
|
|
line += " " + map_info->name;
|
|
|
|
std::string build_id = map_info->GetPrintableBuildID();
|
|
|
|
if (!build_id.empty()) {
|
2015-02-27 22:39:47 +01:00
|
|
|
line += " (BuildId: " + build_id + ")";
|
|
|
|
}
|
2014-06-20 01:47:59 +02:00
|
|
|
}
|
2019-01-16 00:18:43 +01:00
|
|
|
uint64_t load_bias = map_info->GetLoadBias(process_memory);
|
|
|
|
if (load_bias != 0) {
|
2015-06-02 23:52:44 +02:00
|
|
|
if (space_needed) {
|
|
|
|
line += ' ';
|
|
|
|
}
|
2019-01-16 00:18:43 +01:00
|
|
|
line += StringPrintf(" (load bias 0x%" PRIx64 ")", load_bias);
|
2015-05-02 00:02:03 +02:00
|
|
|
}
|
2015-02-27 22:39:47 +01:00
|
|
|
_LOG(log, logtype::MAPS, "%s\n", line.c_str());
|
2014-06-20 01:47:59 +02:00
|
|
|
}
|
2015-02-27 22:39:47 +01:00
|
|
|
if (print_fault_address_marker) {
|
2015-06-02 23:52:44 +02:00
|
|
|
_LOG(log, logtype::MAPS, "--->Fault address falls at %s after any mapped regions\n",
|
|
|
|
get_addr_string(addr).c_str());
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
void dump_backtrace(log_t* log, unwindstack::Unwinder* unwinder, const char* prefix) {
|
2019-03-14 21:44:38 +01:00
|
|
|
unwinder->SetDisplayBuildID(true);
|
2019-01-16 00:18:43 +01:00
|
|
|
for (size_t i = 0; i < unwinder->NumFrames(); i++) {
|
|
|
|
_LOG(log, logtype::BACKTRACE, "%s%s\n", prefix, unwinder->FormatFrame(i).c_str());
|
2017-08-21 23:31:17 +02:00
|
|
|
}
|
|
|
|
}
|
2014-06-10 20:53:08 +02:00
|
|
|
|
2017-08-21 23:31:17 +02:00
|
|
|
static void print_register_row(log_t* log,
|
|
|
|
const std::vector<std::pair<std::string, uint64_t>>& registers) {
|
|
|
|
std::string output;
|
|
|
|
for (auto& [name, value] : registers) {
|
2018-01-18 20:15:49 +01:00
|
|
|
output += android::base::StringPrintf(" %-3s %0*" PRIx64, name.c_str(),
|
2017-08-21 23:31:17 +02:00
|
|
|
static_cast<int>(2 * sizeof(void*)),
|
2018-01-18 20:15:49 +01:00
|
|
|
static_cast<uint64_t>(value));
|
2015-02-10 02:06:27 +01:00
|
|
|
}
|
2017-08-21 23:31:17 +02:00
|
|
|
|
|
|
|
_LOG(log, logtype::REGISTERS, " %s\n", output.c_str());
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
void dump_registers(log_t* log, unwindstack::Regs* regs) {
|
2017-08-21 23:31:17 +02:00
|
|
|
// Split lr/sp/pc into their own special row.
|
|
|
|
static constexpr size_t column_count = 4;
|
|
|
|
std::vector<std::pair<std::string, uint64_t>> current_row;
|
|
|
|
std::vector<std::pair<std::string, uint64_t>> special_row;
|
|
|
|
|
|
|
|
#if defined(__arm__) || defined(__aarch64__)
|
|
|
|
static constexpr const char* special_registers[] = {"ip", "lr", "sp", "pc"};
|
|
|
|
#elif defined(__i386__)
|
|
|
|
static constexpr const char* special_registers[] = {"ebp", "esp", "eip"};
|
|
|
|
#elif defined(__x86_64__)
|
|
|
|
static constexpr const char* special_registers[] = {"rbp", "rsp", "rip"};
|
|
|
|
#else
|
|
|
|
static constexpr const char* special_registers[] = {};
|
|
|
|
#endif
|
|
|
|
|
|
|
|
regs->IterateRegisters([log, ¤t_row, &special_row](const char* name, uint64_t value) {
|
|
|
|
auto row = ¤t_row;
|
|
|
|
for (const char* special_name : special_registers) {
|
|
|
|
if (strcmp(special_name, name) == 0) {
|
|
|
|
row = &special_row;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
row->emplace_back(name, value);
|
|
|
|
if (current_row.size() == column_count) {
|
|
|
|
print_register_row(log, current_row);
|
|
|
|
current_row.clear();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if (!current_row.empty()) {
|
|
|
|
print_register_row(log, current_row);
|
|
|
|
}
|
|
|
|
|
|
|
|
print_register_row(log, special_row);
|
2017-05-06 03:11:23 +02:00
|
|
|
}
|
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
void dump_memory_and_code(log_t* log, unwindstack::Maps* maps, unwindstack::Memory* memory,
|
|
|
|
unwindstack::Regs* regs) {
|
|
|
|
regs->IterateRegisters([log, maps, memory](const char* reg_name, uint64_t reg_value) {
|
2018-02-15 18:18:21 +01:00
|
|
|
std::string label{"memory near "s + reg_name};
|
2019-01-16 00:18:43 +01:00
|
|
|
if (maps) {
|
|
|
|
unwindstack::MapInfo* map_info = maps->Find(reg_value);
|
|
|
|
if (map_info != nullptr && !map_info->name.empty()) {
|
|
|
|
label += " (" + map_info->name + ")";
|
|
|
|
}
|
2018-02-15 18:18:21 +01:00
|
|
|
}
|
|
|
|
dump_memory(log, memory, reg_value, label);
|
2017-08-21 23:31:17 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
static bool dump_thread(log_t* log, unwindstack::Unwinder* unwinder, const ThreadInfo& thread_info,
|
|
|
|
uint64_t abort_msg_address, bool primary_thread) {
|
2017-08-21 23:31:17 +02:00
|
|
|
log->current_tid = thread_info.tid;
|
2016-01-14 02:57:14 +01:00
|
|
|
if (!primary_thread) {
|
2014-06-10 20:53:08 +02:00
|
|
|
_LOG(log, logtype::THREAD, "--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n");
|
2016-01-14 02:57:14 +01:00
|
|
|
}
|
2017-08-21 23:31:17 +02:00
|
|
|
dump_thread_info(log, thread_info);
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2017-08-21 23:31:17 +02:00
|
|
|
if (thread_info.siginfo) {
|
2019-01-16 00:18:43 +01:00
|
|
|
dump_signal_info(log, thread_info, unwinder->GetProcessMemory().get());
|
|
|
|
dump_probable_cause(log, thread_info.siginfo, unwinder->GetMaps());
|
2016-01-14 02:57:14 +01:00
|
|
|
}
|
2017-08-21 23:31:17 +02:00
|
|
|
|
2017-12-22 23:18:39 +01:00
|
|
|
if (primary_thread) {
|
2019-01-16 00:18:43 +01:00
|
|
|
dump_abort_message(log, unwinder->GetProcessMemory().get(), abort_msg_address);
|
2017-12-22 23:18:39 +01:00
|
|
|
}
|
|
|
|
|
2017-08-21 23:31:17 +02:00
|
|
|
dump_registers(log, thread_info.registers.get());
|
|
|
|
|
2018-04-20 21:04:41 +02:00
|
|
|
// Unwind will mutate the registers, so make a copy first.
|
2019-01-16 00:18:43 +01:00
|
|
|
std::unique_ptr<unwindstack::Regs> regs_copy(thread_info.registers->Clone());
|
|
|
|
unwinder->SetRegs(regs_copy.get());
|
|
|
|
unwinder->Unwind();
|
|
|
|
if (unwinder->NumFrames() == 0) {
|
2017-08-21 23:31:17 +02:00
|
|
|
_LOG(log, logtype::THREAD, "Failed to unwind");
|
2019-01-16 00:18:43 +01:00
|
|
|
} else {
|
2017-08-21 23:31:17 +02:00
|
|
|
_LOG(log, logtype::BACKTRACE, "\nbacktrace:\n");
|
2019-01-16 00:18:43 +01:00
|
|
|
dump_backtrace(log, unwinder, " ");
|
2017-08-21 23:31:17 +02:00
|
|
|
|
|
|
|
_LOG(log, logtype::STACK, "\nstack:\n");
|
2019-01-16 00:18:43 +01:00
|
|
|
dump_stack(log, unwinder->frames(), unwinder->GetMaps(), unwinder->GetProcessMemory().get());
|
2017-08-21 23:31:17 +02:00
|
|
|
}
|
|
|
|
|
2016-01-14 02:57:14 +01:00
|
|
|
if (primary_thread) {
|
2019-01-16 00:18:43 +01:00
|
|
|
unwindstack::Maps* maps = unwinder->GetMaps();
|
|
|
|
dump_memory_and_code(log, maps, unwinder->GetProcessMemory().get(),
|
|
|
|
thread_info.registers.get());
|
|
|
|
if (maps != nullptr) {
|
2018-01-18 20:15:49 +01:00
|
|
|
uint64_t addr = 0;
|
2017-08-21 23:31:17 +02:00
|
|
|
siginfo_t* si = thread_info.siginfo;
|
2018-04-26 02:00:14 +02:00
|
|
|
if (signal_has_si_addr(si)) {
|
2018-01-18 20:15:49 +01:00
|
|
|
addr = reinterpret_cast<uint64_t>(si->si_addr);
|
2017-08-21 23:31:17 +02:00
|
|
|
}
|
2019-01-16 00:18:43 +01:00
|
|
|
dump_all_maps(log, unwinder, addr);
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2016-01-14 02:57:14 +01:00
|
|
|
log->current_tid = log->crashed_tid;
|
2017-08-21 23:31:17 +02:00
|
|
|
return true;
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2014-01-11 01:33:16 +01:00
|
|
|
// Reads the contents of the specified log device, filters out the entries
|
|
|
|
// that don't match the specified pid, and writes them to the tombstone file.
|
|
|
|
//
|
2014-06-28 00:55:19 +02:00
|
|
|
// If "tail" is non-zero, log the last "tail" number of lines.
|
2014-05-14 21:37:22 +02:00
|
|
|
static EventTagMap* g_eventTagMap = NULL;
|
|
|
|
|
2017-08-21 23:31:17 +02:00
|
|
|
static void dump_log_file(log_t* log, pid_t pid, const char* filename, unsigned int tail) {
|
2014-01-11 01:33:16 +01:00
|
|
|
bool first = true;
|
2018-07-14 01:55:38 +02:00
|
|
|
logger_list* logger_list;
|
2014-01-11 01:33:16 +01:00
|
|
|
|
2014-07-25 21:25:48 +02:00
|
|
|
if (!log->should_retrieve_logcat) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-22 19:53:34 +01:00
|
|
|
logger_list = android_logger_list_open(
|
2015-01-26 19:46:44 +01:00
|
|
|
android_name_to_log_id(filename), ANDROID_LOG_RDONLY | ANDROID_LOG_NONBLOCK, tail, pid);
|
2014-01-11 01:33:16 +01:00
|
|
|
|
2013-11-22 19:53:34 +01:00
|
|
|
if (!logger_list) {
|
2014-06-18 23:17:57 +02:00
|
|
|
ALOGE("Unable to open %s: %s\n", filename, strerror(errno));
|
2014-01-11 01:33:16 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (true) {
|
2018-07-14 01:55:38 +02:00
|
|
|
log_msg log_entry;
|
2013-11-22 19:53:34 +01:00
|
|
|
ssize_t actual = android_logger_list_read(logger_list, &log_entry);
|
|
|
|
|
2014-01-11 01:33:16 +01:00
|
|
|
if (actual < 0) {
|
2013-11-22 19:53:34 +01:00
|
|
|
if (actual == -EINTR) {
|
2014-01-11 01:33:16 +01:00
|
|
|
// interrupted by signal, retry
|
|
|
|
continue;
|
2013-11-22 19:53:34 +01:00
|
|
|
} else if (actual == -EAGAIN) {
|
2014-01-11 01:33:16 +01:00
|
|
|
// non-blocking EOF; we're done
|
|
|
|
break;
|
|
|
|
} else {
|
2015-06-18 03:35:59 +02:00
|
|
|
ALOGE("Error while reading log: %s\n", strerror(-actual));
|
2014-01-11 01:33:16 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (actual == 0) {
|
2015-06-18 03:35:59 +02:00
|
|
|
ALOGE("Got zero bytes while reading log: %s\n", strerror(errno));
|
2014-01-11 01:33:16 +01:00
|
|
|
break;
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2014-06-18 23:17:57 +02:00
|
|
|
// NOTE: if you ALOGV something here, this will spin forever,
|
2014-01-11 01:33:16 +01:00
|
|
|
// because you will be writing as fast as you're reading. Any
|
|
|
|
// high-frequency debug diagnostics should just be written to
|
|
|
|
// the tombstone file.
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2014-01-11 01:33:16 +01:00
|
|
|
if (first) {
|
2014-06-27 19:32:22 +02:00
|
|
|
_LOG(log, logtype::LOGS, "--------- %slog %s\n",
|
2013-11-22 19:53:34 +01:00
|
|
|
tail ? "tail end of " : "", filename);
|
2014-01-11 01:33:16 +01:00
|
|
|
first = false;
|
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2014-01-11 01:33:16 +01:00
|
|
|
// Msg format is: <priority:1><tag:N>\0<message:N>\0
|
|
|
|
//
|
|
|
|
// We want to display it in the same format as "logcat -v threadtime"
|
|
|
|
// (although in this case the pid is redundant).
|
2014-05-14 21:37:22 +02:00
|
|
|
char timeBuf[32];
|
2018-07-14 01:55:38 +02:00
|
|
|
time_t sec = static_cast<time_t>(log_entry.entry.sec);
|
2014-05-14 21:37:22 +02:00
|
|
|
struct tm tmBuf;
|
|
|
|
struct tm* ptm;
|
|
|
|
ptm = localtime_r(&sec, &tmBuf);
|
|
|
|
strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", ptm);
|
|
|
|
|
|
|
|
if (log_entry.id() == LOG_ID_EVENTS) {
|
|
|
|
if (!g_eventTagMap) {
|
2018-07-14 01:55:38 +02:00
|
|
|
g_eventTagMap = android_openEventTagMap(nullptr);
|
2014-05-14 21:37:22 +02:00
|
|
|
}
|
|
|
|
AndroidLogEntry e;
|
|
|
|
char buf[512];
|
2018-07-14 01:55:38 +02:00
|
|
|
if (android_log_processBinaryLogBuffer(&log_entry.entry_v1, &e, g_eventTagMap, buf,
|
|
|
|
sizeof(buf)) == 0) {
|
|
|
|
_LOG(log, logtype::LOGS, "%s.%03d %5d %5d %c %-8.*s: %s\n", timeBuf,
|
|
|
|
log_entry.entry.nsec / 1000000, log_entry.entry.pid, log_entry.entry.tid, 'I',
|
|
|
|
(int)e.tagLen, e.tag, e.message);
|
|
|
|
}
|
2014-05-14 21:37:22 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-07-14 01:55:38 +02:00
|
|
|
char* msg = log_entry.msg();
|
|
|
|
if (msg == nullptr) {
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-22 19:53:34 +01:00
|
|
|
unsigned char prio = msg[0];
|
|
|
|
char* tag = msg + 1;
|
|
|
|
msg = tag + strlen(tag) + 1;
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2014-01-11 01:33:16 +01:00
|
|
|
// consume any trailing newlines
|
2013-12-12 21:21:20 +01:00
|
|
|
char* nl = msg + strlen(msg) - 1;
|
|
|
|
while (nl >= msg && *nl == '\n') {
|
2014-06-28 00:55:19 +02:00
|
|
|
*nl-- = '\0';
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2018-07-14 01:55:38 +02:00
|
|
|
static const char* kPrioChars = "!.VDIWEFS";
|
2014-01-11 01:33:16 +01:00
|
|
|
char prioChar = (prio < strlen(kPrioChars) ? kPrioChars[prio] : '?');
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2013-12-12 21:21:20 +01:00
|
|
|
// Look for line breaks ('\n') and display each text line
|
|
|
|
// on a separate line, prefixed with the header, like logcat does.
|
|
|
|
do {
|
|
|
|
nl = strchr(msg, '\n');
|
2018-07-14 01:55:38 +02:00
|
|
|
if (nl != nullptr) {
|
2013-12-12 21:21:20 +01:00
|
|
|
*nl = '\0';
|
|
|
|
++nl;
|
|
|
|
}
|
|
|
|
|
2018-07-14 01:55:38 +02:00
|
|
|
_LOG(log, logtype::LOGS, "%s.%03d %5d %5d %c %-8s: %s\n", timeBuf,
|
|
|
|
log_entry.entry.nsec / 1000000, log_entry.entry.pid, log_entry.entry.tid, prioChar, tag,
|
|
|
|
msg);
|
2013-12-12 21:21:20 +01:00
|
|
|
} while ((msg = nl));
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2013-11-22 19:53:34 +01:00
|
|
|
android_logger_list_free(logger_list);
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2014-01-11 01:33:16 +01:00
|
|
|
// Dumps the logs generated by the specified pid to the tombstone, from both
|
|
|
|
// "system" and "main" log devices. Ideally we'd interleave the output.
|
2014-06-28 00:55:19 +02:00
|
|
|
static void dump_logs(log_t* log, pid_t pid, unsigned int tail) {
|
2017-08-21 23:31:17 +02:00
|
|
|
if (pid == getpid()) {
|
|
|
|
// Cowardly refuse to dump logs while we're running in-process.
|
|
|
|
return;
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2017-08-21 23:31:17 +02:00
|
|
|
dump_log_file(log, pid, "system", tail);
|
|
|
|
dump_log_file(log, pid, "main", tail);
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
2017-02-09 01:06:26 +01:00
|
|
|
|
2018-01-18 20:15:49 +01:00
|
|
|
void engrave_tombstone_ucontext(int tombstone_fd, uint64_t abort_msg_address, siginfo_t* siginfo,
|
2017-03-02 02:23:22 +01:00
|
|
|
ucontext_t* ucontext) {
|
|
|
|
pid_t pid = getpid();
|
|
|
|
pid_t tid = gettid();
|
|
|
|
|
2017-02-09 01:06:26 +01:00
|
|
|
log_t log;
|
|
|
|
log.current_tid = tid;
|
|
|
|
log.crashed_tid = tid;
|
|
|
|
log.tfd = tombstone_fd;
|
|
|
|
log.amfd_data = nullptr;
|
|
|
|
|
2017-03-16 07:23:22 +01:00
|
|
|
char thread_name[16];
|
|
|
|
char process_name[128];
|
|
|
|
|
|
|
|
read_with_default("/proc/self/comm", thread_name, sizeof(thread_name), "<unknown>");
|
|
|
|
read_with_default("/proc/self/cmdline", process_name, sizeof(process_name), "<unknown>");
|
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
std::unique_ptr<unwindstack::Regs> regs(
|
|
|
|
unwindstack::Regs::CreateFromUcontext(unwindstack::Regs::CurrentArch(), ucontext));
|
2017-08-21 23:31:17 +02:00
|
|
|
|
|
|
|
std::map<pid_t, ThreadInfo> threads;
|
|
|
|
threads[gettid()] = ThreadInfo{
|
|
|
|
.registers = std::move(regs),
|
|
|
|
.tid = tid,
|
|
|
|
.thread_name = thread_name,
|
|
|
|
.pid = pid,
|
|
|
|
.process_name = process_name,
|
|
|
|
.siginfo = siginfo,
|
|
|
|
};
|
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
unwindstack::UnwinderFromPid unwinder(kMaxFrames, pid);
|
2019-04-05 20:23:32 +02:00
|
|
|
if (!unwinder.Init(unwindstack::Regs::CurrentArch())) {
|
2019-01-16 00:18:43 +01:00
|
|
|
LOG(FATAL) << "Failed to init unwinder object.";
|
2017-08-21 23:31:17 +02:00
|
|
|
}
|
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
engrave_tombstone(unique_fd(dup(tombstone_fd)), &unwinder, threads, tid, abort_msg_address,
|
|
|
|
nullptr, nullptr);
|
2017-08-21 23:31:17 +02:00
|
|
|
}
|
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
void engrave_tombstone(unique_fd output_fd, unwindstack::Unwinder* unwinder,
|
2017-08-21 23:31:17 +02:00
|
|
|
const std::map<pid_t, ThreadInfo>& threads, pid_t target_thread,
|
2018-01-18 20:15:49 +01:00
|
|
|
uint64_t abort_msg_address, OpenFilesList* open_files,
|
2017-08-21 23:31:17 +02:00
|
|
|
std::string* amfd_data) {
|
|
|
|
// don't copy log messages to tombstone unless this is a dev device
|
|
|
|
bool want_logs = android::base::GetBoolProperty("ro.debuggable", false);
|
|
|
|
|
|
|
|
log_t log;
|
|
|
|
log.current_tid = target_thread;
|
|
|
|
log.crashed_tid = target_thread;
|
|
|
|
log.tfd = output_fd.get();
|
|
|
|
log.amfd_data = amfd_data;
|
|
|
|
|
2017-05-08 21:59:17 +02:00
|
|
|
_LOG(&log, logtype::HEADER, "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n");
|
|
|
|
dump_header_info(&log);
|
2018-12-14 22:05:12 +01:00
|
|
|
dump_timestamp(&log, time(nullptr));
|
2017-02-09 01:06:26 +01:00
|
|
|
|
2017-08-21 23:31:17 +02:00
|
|
|
auto it = threads.find(target_thread);
|
|
|
|
if (it == threads.end()) {
|
|
|
|
LOG(FATAL) << "failed to find target thread";
|
|
|
|
}
|
2019-01-16 00:18:43 +01:00
|
|
|
dump_thread(&log, unwinder, it->second, abort_msg_address, true);
|
2017-05-06 03:11:23 +02:00
|
|
|
|
2017-08-21 23:31:17 +02:00
|
|
|
if (want_logs) {
|
2017-04-20 11:22:06 +02:00
|
|
|
dump_logs(&log, it->second.pid, 50);
|
2017-02-09 01:06:26 +01:00
|
|
|
}
|
2017-09-14 00:33:39 +02:00
|
|
|
|
2017-08-21 23:31:17 +02:00
|
|
|
for (auto& [tid, thread_info] : threads) {
|
|
|
|
if (tid == target_thread) {
|
|
|
|
continue;
|
2017-09-14 00:33:39 +02:00
|
|
|
}
|
2017-08-21 23:31:17 +02:00
|
|
|
|
2019-01-16 00:18:43 +01:00
|
|
|
dump_thread(&log, unwinder, thread_info, 0, false);
|
2017-08-21 23:31:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (open_files) {
|
|
|
|
_LOG(&log, logtype::OPEN_FILES, "\nopen files:\n");
|
|
|
|
dump_open_files_list(&log, *open_files, " ");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (want_logs) {
|
|
|
|
dump_logs(&log, it->second.pid, 0);
|
2017-09-14 00:33:39 +02:00
|
|
|
}
|
2017-02-09 01:06:26 +01:00
|
|
|
}
|