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-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-03-16 07:23:22 +01:00
|
|
|
#include <android-base/unique_fd.h>
|
|
|
|
#include <android/log.h>
|
2016-09-29 00:54:45 +02:00
|
|
|
#include <backtrace/Backtrace.h>
|
|
|
|
#include <backtrace/BacktraceMap.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>
|
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/elf_utils.h"
|
|
|
|
#include "libdebuggerd/machine.h"
|
|
|
|
#include "libdebuggerd/open_files_list.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;
|
|
|
|
|
2012-06-07 01:25:03 +02:00
|
|
|
#define STACK_WORDS 16
|
|
|
|
|
2016-08-23 20:09:06 +02:00
|
|
|
static bool signal_has_si_addr(int si_signo, int si_code) {
|
|
|
|
// Manually sent signals won't have si_addr.
|
|
|
|
if (si_code == SI_USER || si_code == SI_QUEUE || si_code == SI_TKILL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (si_signo) {
|
2014-05-17 06:12:17 +02:00
|
|
|
case SIGBUS:
|
2014-01-11 01:33:16 +01:00
|
|
|
case SIGFPE:
|
2014-05-17 06:12:17 +02:00
|
|
|
case SIGILL:
|
2014-01-11 01:33:16 +01:00
|
|
|
case SIGSEGV:
|
2014-08-09 01:30:13 +02:00
|
|
|
case SIGTRAP:
|
2014-01-11 01:33:16 +01:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2014-01-11 01:33:16 +01:00
|
|
|
static const char* get_signame(int sig) {
|
2017-02-02 01:59:15 +01:00
|
|
|
switch (sig) {
|
2014-01-11 01:33:16 +01:00
|
|
|
case SIGABRT: return "SIGABRT";
|
|
|
|
case SIGBUS: return "SIGBUS";
|
|
|
|
case SIGFPE: return "SIGFPE";
|
2014-05-17 06:12:17 +02:00
|
|
|
case SIGILL: return "SIGILL";
|
|
|
|
case SIGSEGV: return "SIGSEGV";
|
2014-04-26 01:05:34 +02:00
|
|
|
#if defined(SIGSTKFLT)
|
2014-01-11 01:33:16 +01:00
|
|
|
case SIGSTKFLT: return "SIGSTKFLT";
|
2012-08-11 02:06:20 +02:00
|
|
|
#endif
|
2014-01-11 01:33:16 +01:00
|
|
|
case SIGSTOP: return "SIGSTOP";
|
2016-09-03 01:15:58 +02:00
|
|
|
case SIGSYS: return "SIGSYS";
|
2014-05-17 06:12:17 +02:00
|
|
|
case SIGTRAP: return "SIGTRAP";
|
2016-10-19 03:17:52 +02:00
|
|
|
case DEBUGGER_SIGNAL: return "<debuggerd signal>";
|
2014-01-11 01:33:16 +01:00
|
|
|
default: return "?";
|
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2014-01-11 01:33:16 +01:00
|
|
|
static const char* get_sigcode(int signo, int code) {
|
|
|
|
// Try the signal-specific codes...
|
|
|
|
switch (signo) {
|
2012-06-07 01:25:03 +02:00
|
|
|
case SIGILL:
|
2014-01-11 01:33:16 +01:00
|
|
|
switch (code) {
|
2012-06-07 01:25:03 +02:00
|
|
|
case ILL_ILLOPC: return "ILL_ILLOPC";
|
|
|
|
case ILL_ILLOPN: return "ILL_ILLOPN";
|
|
|
|
case ILL_ILLADR: return "ILL_ILLADR";
|
|
|
|
case ILL_ILLTRP: return "ILL_ILLTRP";
|
|
|
|
case ILL_PRVOPC: return "ILL_PRVOPC";
|
|
|
|
case ILL_PRVREG: return "ILL_PRVREG";
|
|
|
|
case ILL_COPROC: return "ILL_COPROC";
|
|
|
|
case ILL_BADSTK: return "ILL_BADSTK";
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2014-04-24 22:53:22 +02:00
|
|
|
static_assert(NSIGILL == ILL_BADSTK, "missing ILL_* si_code");
|
2014-01-11 01:33:16 +01:00
|
|
|
break;
|
2012-06-07 01:25:03 +02:00
|
|
|
case SIGBUS:
|
2014-01-11 01:33:16 +01:00
|
|
|
switch (code) {
|
2012-06-07 01:25:03 +02:00
|
|
|
case BUS_ADRALN: return "BUS_ADRALN";
|
|
|
|
case BUS_ADRERR: return "BUS_ADRERR";
|
|
|
|
case BUS_OBJERR: return "BUS_OBJERR";
|
2014-04-24 22:53:22 +02:00
|
|
|
case BUS_MCEERR_AR: return "BUS_MCEERR_AR";
|
|
|
|
case BUS_MCEERR_AO: return "BUS_MCEERR_AO";
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2014-04-24 22:53:22 +02:00
|
|
|
static_assert(NSIGBUS == BUS_MCEERR_AO, "missing BUS_* si_code");
|
2014-01-11 01:33:16 +01:00
|
|
|
break;
|
2012-06-07 01:25:03 +02:00
|
|
|
case SIGFPE:
|
2014-01-11 01:33:16 +01:00
|
|
|
switch (code) {
|
2012-06-07 01:25:03 +02:00
|
|
|
case FPE_INTDIV: return "FPE_INTDIV";
|
|
|
|
case FPE_INTOVF: return "FPE_INTOVF";
|
|
|
|
case FPE_FLTDIV: return "FPE_FLTDIV";
|
|
|
|
case FPE_FLTOVF: return "FPE_FLTOVF";
|
|
|
|
case FPE_FLTUND: return "FPE_FLTUND";
|
|
|
|
case FPE_FLTRES: return "FPE_FLTRES";
|
|
|
|
case FPE_FLTINV: return "FPE_FLTINV";
|
|
|
|
case FPE_FLTSUB: return "FPE_FLTSUB";
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2014-04-24 22:53:22 +02:00
|
|
|
static_assert(NSIGFPE == FPE_FLTSUB, "missing FPE_* si_code");
|
2014-01-11 01:33:16 +01:00
|
|
|
break;
|
2012-06-07 01:25:03 +02:00
|
|
|
case SIGSEGV:
|
2014-01-11 01:33:16 +01:00
|
|
|
switch (code) {
|
2012-06-07 01:25:03 +02:00
|
|
|
case SEGV_MAPERR: return "SEGV_MAPERR";
|
|
|
|
case SEGV_ACCERR: return "SEGV_ACCERR";
|
2016-02-04 23:07:23 +01:00
|
|
|
#if defined(SEGV_BNDERR)
|
|
|
|
case SEGV_BNDERR: return "SEGV_BNDERR";
|
2016-08-24 23:49:18 +02:00
|
|
|
#endif
|
|
|
|
#if defined(SEGV_PKUERR)
|
|
|
|
case SEGV_PKUERR: return "SEGV_PKUERR";
|
2016-02-04 23:07:23 +01:00
|
|
|
#endif
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2016-08-24 23:49:18 +02:00
|
|
|
#if defined(SEGV_PKUERR)
|
|
|
|
static_assert(NSIGSEGV == SEGV_PKUERR, "missing SEGV_* si_code");
|
|
|
|
#elif defined(SEGV_BNDERR)
|
2016-02-04 23:07:23 +01:00
|
|
|
static_assert(NSIGSEGV == SEGV_BNDERR, "missing SEGV_* si_code");
|
|
|
|
#else
|
2014-04-24 22:53:22 +02:00
|
|
|
static_assert(NSIGSEGV == SEGV_ACCERR, "missing SEGV_* si_code");
|
2016-02-04 23:07:23 +01:00
|
|
|
#endif
|
2014-01-11 01:33:16 +01:00
|
|
|
break;
|
2016-09-03 01:15:58 +02:00
|
|
|
#if defined(SYS_SECCOMP) // Our glibc is too old, and we build this for the host too.
|
|
|
|
case SIGSYS:
|
|
|
|
switch (code) {
|
|
|
|
case SYS_SECCOMP: return "SYS_SECCOMP";
|
|
|
|
}
|
|
|
|
static_assert(NSIGSYS == SYS_SECCOMP, "missing SYS_* si_code");
|
|
|
|
break;
|
|
|
|
#endif
|
2012-12-10 19:29:05 +01:00
|
|
|
case SIGTRAP:
|
2014-01-11 01:33:16 +01:00
|
|
|
switch (code) {
|
2012-12-10 19:29:05 +01:00
|
|
|
case TRAP_BRKPT: return "TRAP_BRKPT";
|
|
|
|
case TRAP_TRACE: return "TRAP_TRACE";
|
2014-04-24 22:53:22 +02:00
|
|
|
case TRAP_BRANCH: return "TRAP_BRANCH";
|
|
|
|
case TRAP_HWBKPT: return "TRAP_HWBKPT";
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2017-06-21 17:39:41 +02:00
|
|
|
if ((code & 0xff) == SIGTRAP) {
|
|
|
|
switch ((code >> 8) & 0xff) {
|
|
|
|
case PTRACE_EVENT_FORK:
|
|
|
|
return "PTRACE_EVENT_FORK";
|
|
|
|
case PTRACE_EVENT_VFORK:
|
|
|
|
return "PTRACE_EVENT_VFORK";
|
|
|
|
case PTRACE_EVENT_CLONE:
|
|
|
|
return "PTRACE_EVENT_CLONE";
|
|
|
|
case PTRACE_EVENT_EXEC:
|
|
|
|
return "PTRACE_EVENT_EXEC";
|
|
|
|
case PTRACE_EVENT_VFORK_DONE:
|
|
|
|
return "PTRACE_EVENT_VFORK_DONE";
|
|
|
|
case PTRACE_EVENT_EXIT:
|
|
|
|
return "PTRACE_EVENT_EXIT";
|
|
|
|
case PTRACE_EVENT_SECCOMP:
|
|
|
|
return "PTRACE_EVENT_SECCOMP";
|
|
|
|
case PTRACE_EVENT_STOP:
|
|
|
|
return "PTRACE_EVENT_STOP";
|
|
|
|
}
|
|
|
|
}
|
2014-04-24 22:53:22 +02:00
|
|
|
static_assert(NSIGTRAP == TRAP_HWBKPT, "missing TRAP_* si_code");
|
2014-01-11 01:33:16 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
// Then the other codes...
|
|
|
|
switch (code) {
|
|
|
|
case SI_USER: return "SI_USER";
|
|
|
|
case SI_KERNEL: return "SI_KERNEL";
|
|
|
|
case SI_QUEUE: return "SI_QUEUE";
|
|
|
|
case SI_TIMER: return "SI_TIMER";
|
|
|
|
case SI_MESGQ: return "SI_MESGQ";
|
2012-12-10 19:29:05 +01:00
|
|
|
case SI_ASYNCIO: return "SI_ASYNCIO";
|
2014-01-11 01:33:16 +01:00
|
|
|
case SI_SIGIO: return "SI_SIGIO";
|
|
|
|
case SI_TKILL: return "SI_TKILL";
|
2014-04-24 22:53:22 +02:00
|
|
|
case SI_DETHREAD: return "SI_DETHREAD";
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
|
|
|
// Then give up...
|
|
|
|
return "?";
|
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
|
|
|
}
|
|
|
|
|
2017-02-02 01:59:15 +01:00
|
|
|
static void dump_probable_cause(log_t* log, const siginfo_t& si) {
|
|
|
|
std::string cause;
|
|
|
|
if (si.si_signo == SIGSEGV && si.si_code == SEGV_MAPERR) {
|
|
|
|
if (si.si_addr < reinterpret_cast<void*>(4096)) {
|
|
|
|
cause = StringPrintf("null pointer dereference");
|
|
|
|
} else if (si.si_addr == reinterpret_cast<void*>(0xffff0ffc)) {
|
|
|
|
cause = "call to kuser_helper_version";
|
|
|
|
} else if (si.si_addr == reinterpret_cast<void*>(0xffff0fe0)) {
|
|
|
|
cause = "call to kuser_get_tls";
|
|
|
|
} else if (si.si_addr == reinterpret_cast<void*>(0xffff0fc0)) {
|
|
|
|
cause = "call to kuser_cmpxchg";
|
|
|
|
} else if (si.si_addr == reinterpret_cast<void*>(0xffff0fa0)) {
|
|
|
|
cause = "call to kuser_memory_barrier";
|
|
|
|
} else if (si.si_addr == reinterpret_cast<void*>(0xffff0f60)) {
|
|
|
|
cause = "call to kuser_cmpxchg64";
|
|
|
|
}
|
|
|
|
} else if (si.si_signo == SIGSYS && si.si_code == SYS_SECCOMP) {
|
2017-03-03 04:01:20 +01:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2017-02-09 01:06:26 +01:00
|
|
|
static void dump_signal_info(log_t* log, const siginfo_t* siginfo) {
|
|
|
|
const siginfo_t& si = *siginfo;
|
2014-04-26 01:05:34 +02:00
|
|
|
char addr_desc[32]; // ", fault addr 0x1234"
|
2016-08-23 20:09:06 +02:00
|
|
|
if (signal_has_si_addr(si.si_signo, si.si_code)) {
|
2014-04-26 01:05:34 +02:00
|
|
|
snprintf(addr_desc, sizeof(addr_desc), "%p", si.si_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
|
|
|
|
2016-08-11 21:50:32 +02:00
|
|
|
_LOG(log, logtype::HEADER, "signal %d (%s), code %d (%s), fault addr %s\n", si.si_signo,
|
|
|
|
get_signame(si.si_signo), si.si_code, get_sigcode(si.si_signo, si.si_code), addr_desc);
|
2017-02-02 01:59:15 +01:00
|
|
|
|
|
|
|
dump_probable_cause(log, si);
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2017-02-09 01:06:26 +01:00
|
|
|
static void dump_signal_info(log_t* log, pid_t tid) {
|
|
|
|
siginfo_t si;
|
|
|
|
memset(&si, 0, sizeof(si));
|
|
|
|
if (ptrace(PTRACE_GETSIGINFO, tid, 0, &si) == -1) {
|
|
|
|
ALOGE("cannot get siginfo: %s\n", strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_signal_info(log, &si);
|
|
|
|
}
|
|
|
|
|
2017-03-16 07:23:22 +01:00
|
|
|
static void dump_thread_info(log_t* log, pid_t pid, pid_t tid, const char* process_name,
|
|
|
|
const char* thread_name) {
|
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?
|
|
|
|
if (strcmp(thread_name, "logd") == 0 || strncmp(thread_name, "logd.", 4) == 0) {
|
2014-07-25 21:25:48 +02:00
|
|
|
log->should_retrieve_logcat = false;
|
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2017-03-16 07:23:22 +01:00
|
|
|
_LOG(log, logtype::HEADER, "pid: %d, tid: %d, name: %s >>> %s <<<\n", pid, tid, thread_name,
|
|
|
|
process_name);
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2014-01-11 01:33:16 +01:00
|
|
|
static void dump_stack_segment(
|
2014-06-10 20:53:08 +02:00
|
|
|
Backtrace* backtrace, log_t* log, uintptr_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];
|
|
|
|
size_t bytes_read = backtrace->Read(*sp, reinterpret_cast<uint8_t*>(&stack_data[0]), sizeof(word_t) * words);
|
|
|
|
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
|
|
|
}
|
2017-02-02 01:59:15 +01:00
|
|
|
line += StringPrintf("%" PRIPTR " %" PRIPTR, *sp, stack_data[i]);
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2015-02-06 22:22:01 +01:00
|
|
|
backtrace_map_t map;
|
2015-02-27 22:39:47 +01:00
|
|
|
backtrace->FillInMap(stack_data[i], &map);
|
|
|
|
if (BacktraceMap::IsValid(map) && !map.name.empty()) {
|
|
|
|
line += " " + map.name;
|
|
|
|
uintptr_t offset = 0;
|
2017-03-22 21:18:31 +01:00
|
|
|
std::string func_name(backtrace->GetFunctionName(stack_data[i], &offset, &map));
|
2015-02-27 22:39:47 +01:00
|
|
|
if (!func_name.empty()) {
|
|
|
|
line += " (" + func_name;
|
2014-01-11 01:33:16 +01:00
|
|
|
if (offset) {
|
2017-02-02 01:59:15 +01:00
|
|
|
line += StringPrintf("+%" PRIuPTR, 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
|
|
|
}
|
|
|
|
|
2014-06-10 20:53:08 +02:00
|
|
|
static void dump_stack(Backtrace* backtrace, log_t* log) {
|
2014-01-11 01:33:16 +01:00
|
|
|
size_t first = 0, last;
|
|
|
|
for (size_t i = 0; i < backtrace->NumFrames(); i++) {
|
|
|
|
const backtrace_frame_data_t* frame = backtrace->GetFrame(i);
|
|
|
|
if (frame->sp) {
|
|
|
|
if (!first) {
|
|
|
|
first = i+1;
|
|
|
|
}
|
|
|
|
last = i;
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
|
|
|
if (!first) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
first--;
|
|
|
|
|
|
|
|
// Dump a few words before the first frame.
|
2013-11-21 20:17:20 +01:00
|
|
|
word_t sp = backtrace->GetFrame(first)->sp - STACK_WORDS * sizeof(word_t);
|
2014-06-10 20:53:08 +02:00
|
|
|
dump_stack_segment(backtrace, log, &sp, STACK_WORDS, -1);
|
2014-01-11 01:33:16 +01:00
|
|
|
|
|
|
|
// Dump a few words from all successive frames.
|
|
|
|
// Only log the first 3 frames, put the rest in the tombstone.
|
|
|
|
for (size_t i = first; i <= last; i++) {
|
|
|
|
const backtrace_frame_data_t* frame = backtrace->GetFrame(i);
|
|
|
|
if (sp != frame->sp) {
|
2014-06-10 20:53:08 +02:00
|
|
|
_LOG(log, logtype::STACK, " ........ ........\n");
|
2014-01-11 01:33:16 +01:00
|
|
|
sp = frame->sp;
|
|
|
|
}
|
|
|
|
if (i == last) {
|
2014-06-10 20:53:08 +02:00
|
|
|
dump_stack_segment(backtrace, log, &sp, STACK_WORDS, i);
|
2014-01-11 01:33:16 +01:00
|
|
|
if (sp < frame->sp + frame->stack_size) {
|
2014-06-10 20:53:08 +02:00
|
|
|
_LOG(log, logtype::STACK, " ........ ........\n");
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
|
|
|
} else {
|
2013-11-21 20:17:20 +01:00
|
|
|
size_t words = frame->stack_size / sizeof(word_t);
|
2014-01-11 01:33:16 +01:00
|
|
|
if (words == 0) {
|
|
|
|
words = 1;
|
|
|
|
} else if (words > STACK_WORDS) {
|
|
|
|
words = STACK_WORDS;
|
|
|
|
}
|
2014-06-10 20:53:08 +02:00
|
|
|
dump_stack_segment(backtrace, log, &sp, 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
|
|
|
}
|
|
|
|
|
2015-06-02 23:52:44 +02:00
|
|
|
static std::string get_addr_string(uintptr_t addr) {
|
|
|
|
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
|
2017-02-02 01:59:15 +01:00
|
|
|
addr_str = StringPrintf("%08x", addr);
|
2015-06-02 23:52:44 +02:00
|
|
|
#endif
|
|
|
|
return addr_str;
|
|
|
|
}
|
|
|
|
|
2016-01-14 02:57:14 +01:00
|
|
|
static void dump_abort_message(Backtrace* backtrace, log_t* log, uintptr_t address) {
|
|
|
|
if (address == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
address += sizeof(size_t); // Skip the buffer length.
|
|
|
|
|
|
|
|
char msg[512];
|
|
|
|
memset(msg, 0, sizeof(msg));
|
|
|
|
char* p = &msg[0];
|
|
|
|
while (p < &msg[sizeof(msg)]) {
|
|
|
|
word_t data;
|
|
|
|
size_t len = sizeof(word_t);
|
|
|
|
if (!backtrace->ReadWord(address, &data)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
address += sizeof(word_t);
|
|
|
|
|
|
|
|
while (len > 0 && (*p++ = (data >> (sizeof(word_t) - len) * 8) & 0xff) != 0) {
|
|
|
|
len--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
msg[sizeof(msg) - 1] = '\0';
|
|
|
|
|
|
|
|
_LOG(log, logtype::HEADER, "Abort message: '%s'\n", msg);
|
|
|
|
}
|
|
|
|
|
2015-02-27 22:39:47 +01:00
|
|
|
static void dump_all_maps(Backtrace* backtrace, BacktraceMap* map, log_t* log, pid_t tid) {
|
|
|
|
bool print_fault_address_marker = false;
|
2015-02-10 02:06:27 +01:00
|
|
|
uintptr_t addr = 0;
|
2014-01-11 01:33:16 +01:00
|
|
|
siginfo_t si;
|
|
|
|
memset(&si, 0, sizeof(si));
|
2015-06-02 23:52:44 +02:00
|
|
|
if (ptrace(PTRACE_GETSIGINFO, tid, 0, &si) != -1) {
|
2016-08-23 20:09:06 +02:00
|
|
|
print_fault_address_marker = signal_has_si_addr(si.si_signo, si.si_code);
|
2015-02-10 02:06:27 +01:00
|
|
|
addr = reinterpret_cast<uintptr_t>(si.si_addr);
|
2015-06-02 23:52:44 +02:00
|
|
|
} else {
|
2015-06-18 03:35:59 +02:00
|
|
|
ALOGE("Cannot get siginfo for %d: %s\n", tid, strerror(errno));
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2016-06-16 00:49:50 +02:00
|
|
|
ScopedBacktraceMapIteratorLock lock(map);
|
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):",
|
|
|
|
map->size(), map->size() == 1 ? "y" : "ies");
|
2017-09-26 20:54:49 +02:00
|
|
|
if (print_fault_address_marker) {
|
2015-02-27 22:39:47 +01:00
|
|
|
if (map->begin() != map->end() && addr < map->begin()->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
|
|
|
|
2015-02-27 22:39:47 +01:00
|
|
|
std::string line;
|
2014-01-15 05:16:30 +01:00
|
|
|
for (BacktraceMap::const_iterator it = map->begin(); it != map->end(); ++it) {
|
2015-02-27 22:39:47 +01:00
|
|
|
line = " ";
|
|
|
|
if (print_fault_address_marker) {
|
|
|
|
if (addr < it->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;
|
|
|
|
} else if (addr >= it->start && addr < it->end) {
|
|
|
|
line = "--->";
|
|
|
|
print_fault_address_marker = false;
|
|
|
|
}
|
|
|
|
}
|
2015-06-02 23:52:44 +02:00
|
|
|
line += get_addr_string(it->start) + '-' + get_addr_string(it->end - 1) + ' ';
|
2015-02-27 22:39:47 +01:00
|
|
|
if (it->flags & PROT_READ) {
|
|
|
|
line += 'r';
|
|
|
|
} else {
|
|
|
|
line += '-';
|
|
|
|
}
|
|
|
|
if (it->flags & PROT_WRITE) {
|
|
|
|
line += 'w';
|
|
|
|
} else {
|
|
|
|
line += '-';
|
|
|
|
}
|
|
|
|
if (it->flags & PROT_EXEC) {
|
|
|
|
line += 'x';
|
|
|
|
} else {
|
|
|
|
line += '-';
|
|
|
|
}
|
2017-02-02 01:59:15 +01:00
|
|
|
line += StringPrintf(" %8" PRIxPTR " %8" PRIxPTR, it->offset, it->end - it->start);
|
2015-06-02 23:52:44 +02:00
|
|
|
bool space_needed = true;
|
2015-02-27 22:39:47 +01:00
|
|
|
if (it->name.length() > 0) {
|
2015-06-02 23:52:44 +02:00
|
|
|
space_needed = false;
|
2015-02-27 22:39:47 +01:00
|
|
|
line += " " + it->name;
|
|
|
|
std::string build_id;
|
|
|
|
if ((it->flags & PROT_READ) && elf_get_build_id(backtrace, it->start, &build_id)) {
|
|
|
|
line += " (BuildId: " + build_id + ")";
|
|
|
|
}
|
2014-06-20 01:47:59 +02:00
|
|
|
}
|
2017-07-19 23:20:46 +02:00
|
|
|
if (it->load_bias != 0) {
|
2015-06-02 23:52:44 +02:00
|
|
|
if (space_needed) {
|
|
|
|
line += ' ';
|
|
|
|
}
|
2017-07-19 23:20:46 +02:00
|
|
|
line += StringPrintf(" (load bias 0x%" PRIxPTR ")", it->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
|
|
|
}
|
|
|
|
|
2015-02-10 02:06:27 +01:00
|
|
|
static void dump_backtrace_and_stack(Backtrace* backtrace, log_t* log) {
|
|
|
|
if (backtrace->NumFrames()) {
|
|
|
|
_LOG(log, logtype::BACKTRACE, "\nbacktrace:\n");
|
|
|
|
dump_backtrace_to_log(backtrace, log, " ");
|
2014-06-10 20:53:08 +02:00
|
|
|
|
2015-02-10 02:06:27 +01:00
|
|
|
_LOG(log, logtype::STACK, "\nstack:\n");
|
|
|
|
dump_stack(backtrace, log);
|
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2017-05-06 03:11:23 +02:00
|
|
|
// Weak noop implementation, real implementations are in <arch>/machine.cpp.
|
|
|
|
__attribute__((weak)) void dump_registers(log_t* log, const ucontext_t*) {
|
|
|
|
_LOG(log, logtype::REGISTERS, " register dumping unimplemented on this architecture");
|
|
|
|
}
|
|
|
|
|
2017-10-27 19:29:29 +02:00
|
|
|
static void dump_thread(log_t* log, pid_t pid, pid_t tid, const std::string& process_name,
|
|
|
|
const std::string& thread_name, BacktraceMap* map,
|
2016-08-11 21:50:32 +02:00
|
|
|
uintptr_t abort_msg_address, bool primary_thread) {
|
2016-01-14 02:57:14 +01:00
|
|
|
log->current_tid = tid;
|
|
|
|
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-03-16 07:23:22 +01:00
|
|
|
dump_thread_info(log, pid, tid, process_name.c_str(), thread_name.c_str());
|
2016-08-11 21:50:32 +02:00
|
|
|
dump_signal_info(log, tid);
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2016-01-14 02:57:14 +01:00
|
|
|
std::unique_ptr<Backtrace> backtrace(Backtrace::Create(pid, tid, map));
|
|
|
|
if (primary_thread) {
|
|
|
|
dump_abort_message(backtrace.get(), log, abort_msg_address);
|
|
|
|
}
|
|
|
|
dump_registers(log, tid);
|
|
|
|
if (backtrace->Unwind(0)) {
|
|
|
|
dump_backtrace_and_stack(backtrace.get(), log);
|
|
|
|
} else {
|
|
|
|
ALOGE("Unwind failed: pid = %d, tid = %d", pid, tid);
|
|
|
|
}
|
2014-06-10 20:53:08 +02:00
|
|
|
|
2016-01-14 02:57:14 +01:00
|
|
|
if (primary_thread) {
|
|
|
|
dump_memory_and_code(log, backtrace.get());
|
|
|
|
if (map) {
|
|
|
|
dump_all_maps(backtrace.get(), map, log, tid);
|
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;
|
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;
|
|
|
|
|
2014-06-28 00:55:19 +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;
|
2014-06-28 00:55:19 +02:00
|
|
|
struct 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;
|
|
|
|
}
|
|
|
|
|
2013-11-22 19:53:34 +01:00
|
|
|
struct log_msg log_entry;
|
2014-01-11 01:33:16 +01:00
|
|
|
|
|
|
|
while (true) {
|
2013-11-22 19:53:34 +01:00
|
|
|
ssize_t actual = android_logger_list_read(logger_list, &log_entry);
|
2014-06-28 00:55:19 +02:00
|
|
|
struct logger_entry* entry;
|
2013-11-22 19:53:34 +01:00
|
|
|
|
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-06-28 00:55:19 +02:00
|
|
|
entry = &log_entry.entry_v1;
|
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).
|
|
|
|
static const char* kPrioChars = "!.VDIWEFS";
|
2013-11-22 19:53:34 +01:00
|
|
|
unsigned hdr_size = log_entry.entry.hdr_size;
|
|
|
|
if (!hdr_size) {
|
|
|
|
hdr_size = sizeof(log_entry.entry_v1);
|
|
|
|
}
|
2016-08-18 23:59:41 +02:00
|
|
|
if ((hdr_size < sizeof(log_entry.entry_v1)) ||
|
|
|
|
(hdr_size > sizeof(log_entry.entry))) {
|
|
|
|
continue;
|
|
|
|
}
|
2014-05-14 21:37:22 +02:00
|
|
|
char* msg = reinterpret_cast<char*>(log_entry.buf) + hdr_size;
|
|
|
|
|
|
|
|
char timeBuf[32];
|
|
|
|
time_t sec = static_cast<time_t>(entry->sec);
|
|
|
|
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) {
|
2016-11-11 18:48:56 +01:00
|
|
|
g_eventTagMap = android_openEventTagMap(NULL);
|
2014-05-14 21:37:22 +02:00
|
|
|
}
|
|
|
|
AndroidLogEntry e;
|
|
|
|
char buf[512];
|
|
|
|
android_log_processBinaryLogBuffer(entry, &e, g_eventTagMap, buf, sizeof(buf));
|
2016-10-24 22:11:46 +02:00
|
|
|
_LOG(log, logtype::LOGS, "%s.%03d %5d %5d %c %-8.*s: %s\n",
|
2014-05-14 21:37:22 +02:00
|
|
|
timeBuf, entry->nsec / 1000000, entry->pid, entry->tid,
|
2016-10-24 22:11:46 +02:00
|
|
|
'I', (int)e.tagLen, e.tag, e.message);
|
2014-05-14 21:37:22 +02:00
|
|
|
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
|
|
|
|
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');
|
|
|
|
if (nl) {
|
|
|
|
*nl = '\0';
|
|
|
|
++nl;
|
|
|
|
}
|
|
|
|
|
2014-06-10 20:53:08 +02:00
|
|
|
_LOG(log, logtype::LOGS, "%s.%03d %5d %5d %c %-8s: %s\n",
|
2013-12-12 21:21:20 +01:00
|
|
|
timeBuf, entry->nsec / 1000000, entry->pid, entry->tid,
|
|
|
|
prioChar, tag, msg);
|
|
|
|
} 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) {
|
2013-11-22 19:53:34 +01:00
|
|
|
dump_log_file(log, pid, "system", tail);
|
|
|
|
dump_log_file(log, pid, "main", tail);
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
|
|
|
|
2014-01-11 01:33:16 +01:00
|
|
|
// Dumps all information about the specified pid to the tombstone.
|
2017-10-27 19:29:29 +02:00
|
|
|
static void dump_crash(log_t* log, BacktraceMap* map, const OpenFilesList* open_files, pid_t pid,
|
|
|
|
pid_t tid, const std::string& process_name,
|
|
|
|
const std::map<pid_t, std::string>& threads, uintptr_t abort_msg_address) {
|
2014-01-11 01:33:16 +01:00
|
|
|
// don't copy log messages to tombstone unless this is a dev device
|
2017-10-10 22:30:57 +02:00
|
|
|
bool want_logs = GetBoolProperty("ro.debuggable", false);
|
2014-01-11 01:33:16 +01:00
|
|
|
|
2014-06-10 20:53:08 +02:00
|
|
|
_LOG(log, logtype::HEADER,
|
2014-01-11 01:33:16 +01:00
|
|
|
"*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n");
|
2014-06-03 00:02:20 +02:00
|
|
|
dump_header_info(log);
|
2017-10-27 19:29:29 +02:00
|
|
|
dump_thread(log, pid, tid, process_name, threads.find(tid)->second, map, abort_msg_address, true);
|
2014-01-11 01:33:16 +01:00
|
|
|
if (want_logs) {
|
2013-11-22 19:53:34 +01:00
|
|
|
dump_logs(log, pid, 5);
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2014-01-07 04:16:33 +01:00
|
|
|
|
2017-03-16 07:23:22 +01:00
|
|
|
for (const auto& it : threads) {
|
|
|
|
pid_t thread_tid = it.first;
|
|
|
|
const std::string& thread_name = it.second;
|
|
|
|
|
|
|
|
if (thread_tid != tid) {
|
2017-10-27 19:29:29 +02:00
|
|
|
dump_thread(log, pid, thread_tid, process_name, thread_name, map, 0, false);
|
2016-01-14 02:57:14 +01:00
|
|
|
}
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
2013-03-19 21:12:23 +01:00
|
|
|
|
2017-02-09 01:06:26 +01:00
|
|
|
if (open_files) {
|
|
|
|
_LOG(log, logtype::OPEN_FILES, "\nopen files:\n");
|
|
|
|
dump_open_files_list_to_log(*open_files, log, " ");
|
|
|
|
}
|
2016-10-28 17:37:33 +02:00
|
|
|
|
2014-01-11 01:33:16 +01:00
|
|
|
if (want_logs) {
|
2013-11-22 19:53:34 +01:00
|
|
|
dump_logs(log, pid, 0);
|
2014-01-11 01:33:16 +01:00
|
|
|
}
|
|
|
|
}
|
2012-06-07 01:25:03 +02:00
|
|
|
|
2017-10-27 19:29:29 +02:00
|
|
|
void engrave_tombstone(int tombstone_fd, BacktraceMap* map, const OpenFilesList* open_files,
|
|
|
|
pid_t pid, pid_t tid, const std::string& process_name,
|
|
|
|
const std::map<pid_t, std::string>& threads, uintptr_t abort_msg_address,
|
|
|
|
std::string* amfd_data) {
|
2014-06-10 20:53:08 +02:00
|
|
|
log_t log;
|
|
|
|
log.current_tid = tid;
|
|
|
|
log.crashed_tid = tid;
|
2015-11-17 22:57:03 +01:00
|
|
|
log.tfd = tombstone_fd;
|
2016-05-04 01:32:13 +02:00
|
|
|
log.amfd_data = amfd_data;
|
2017-10-27 19:29:29 +02:00
|
|
|
dump_crash(&log, map, open_files, pid, tid, process_name, threads, abort_msg_address);
|
2012-06-07 01:25:03 +02:00
|
|
|
}
|
2017-02-09 01:06:26 +01:00
|
|
|
|
2017-03-02 02:23:22 +01:00
|
|
|
void engrave_tombstone_ucontext(int tombstone_fd, uintptr_t abort_msg_address, siginfo_t* siginfo,
|
|
|
|
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>");
|
|
|
|
|
2017-05-08 21:59:17 +02:00
|
|
|
_LOG(&log, logtype::HEADER, "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n");
|
|
|
|
dump_header_info(&log);
|
2017-03-16 07:23:22 +01:00
|
|
|
dump_thread_info(&log, pid, tid, thread_name, process_name);
|
2017-02-09 01:06:26 +01:00
|
|
|
dump_signal_info(&log, siginfo);
|
|
|
|
|
|
|
|
std::unique_ptr<Backtrace> backtrace(Backtrace::Create(pid, tid));
|
|
|
|
dump_abort_message(backtrace.get(), &log, abort_msg_address);
|
2017-05-06 03:11:23 +02:00
|
|
|
dump_registers(&log, ucontext);
|
|
|
|
|
2017-02-09 01:06:26 +01:00
|
|
|
if (backtrace->Unwind(0, ucontext)) {
|
|
|
|
dump_backtrace_and_stack(backtrace.get(), &log);
|
|
|
|
} else {
|
|
|
|
ALOGE("Unwind failed: pid = %d, tid = %d", pid, tid);
|
|
|
|
}
|
2017-09-14 00:33:39 +02:00
|
|
|
|
|
|
|
// TODO: Make this match the format of dump_all_maps above.
|
|
|
|
_LOG(&log, logtype::MAPS, "memory map:\n");
|
|
|
|
android::base::unique_fd maps_fd(open("/proc/self/maps", O_RDONLY | O_CLOEXEC));
|
|
|
|
if (maps_fd == -1) {
|
|
|
|
_LOG(&log, logtype::MAPS, " failed to open /proc/self/maps: %s", strerror(errno));
|
|
|
|
} else {
|
|
|
|
char buf[256];
|
|
|
|
ssize_t rc;
|
|
|
|
while ((rc = TEMP_FAILURE_RETRY(read(maps_fd.get(), buf, sizeof(buf)))) > 0) {
|
|
|
|
android::base::WriteFully(tombstone_fd, buf, rc);
|
|
|
|
}
|
|
|
|
}
|
2017-02-09 01:06:26 +01:00
|
|
|
}
|