2016-10-19 03:17:52 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2016, The Android Open Source Project
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdlib.h>
|
2017-02-02 01:35:31 +01:00
|
|
|
#include <sys/capability.h>
|
|
|
|
#include <sys/prctl.h>
|
2016-10-19 03:17:52 +02:00
|
|
|
#include <sys/ptrace.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/un.h>
|
2017-02-02 01:35:31 +01:00
|
|
|
#include <syscall.h>
|
2016-10-19 03:17:52 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <limits>
|
2017-03-16 07:23:22 +01:00
|
|
|
#include <map>
|
2016-10-19 03:17:52 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <set>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <android-base/file.h>
|
|
|
|
#include <android-base/logging.h>
|
|
|
|
#include <android-base/parseint.h>
|
|
|
|
#include <android-base/properties.h>
|
|
|
|
#include <android-base/stringprintf.h>
|
2017-03-16 07:23:22 +01:00
|
|
|
#include <android-base/strings.h>
|
2016-10-19 03:17:52 +02:00
|
|
|
#include <android-base/unique_fd.h>
|
|
|
|
#include <cutils/sockets.h>
|
2017-01-24 05:11:51 +01:00
|
|
|
#include <log/log.h>
|
2016-10-19 03:17:52 +02:00
|
|
|
#include <procinfo/process.h>
|
|
|
|
|
|
|
|
#include "backtrace.h"
|
|
|
|
#include "tombstone.h"
|
|
|
|
#include "utility.h"
|
|
|
|
|
|
|
|
#include "debuggerd/handler.h"
|
2017-05-10 11:58:59 +02:00
|
|
|
#include "protocol.h"
|
|
|
|
#include "tombstoned/tombstoned.h"
|
|
|
|
#include "util.h"
|
2016-10-19 03:17:52 +02:00
|
|
|
|
|
|
|
using android::base::unique_fd;
|
2017-03-16 07:23:22 +01:00
|
|
|
using android::base::ReadFileToString;
|
2016-10-19 03:17:52 +02:00
|
|
|
using android::base::StringPrintf;
|
2017-03-16 07:23:22 +01:00
|
|
|
using android::base::Trim;
|
|
|
|
|
|
|
|
static std::string get_process_name(pid_t pid) {
|
|
|
|
std::string result = "<unknown>";
|
|
|
|
ReadFileToString(StringPrintf("/proc/%d/cmdline", pid), &result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static std::string get_thread_name(pid_t tid) {
|
|
|
|
std::string result = "<unknown>";
|
|
|
|
ReadFileToString(StringPrintf("/proc/%d/comm", tid), &result);
|
|
|
|
return Trim(result);
|
|
|
|
}
|
2016-10-19 03:17:52 +02:00
|
|
|
|
2017-02-02 01:31:43 +01:00
|
|
|
static bool pid_contains_tid(int pid_proc_fd, pid_t tid) {
|
|
|
|
struct stat st;
|
|
|
|
std::string task_path = StringPrintf("task/%d", tid);
|
|
|
|
return fstatat(pid_proc_fd, task_path.c_str(), &st, 0) == 0;
|
2016-10-19 03:17:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Attach to a thread, and verify that it's still a member of the given process
|
2017-02-02 01:31:43 +01:00
|
|
|
static bool ptrace_seize_thread(int pid_proc_fd, pid_t tid, std::string* error) {
|
2017-01-23 01:42:32 +01:00
|
|
|
if (ptrace(PTRACE_SEIZE, tid, 0, 0) != 0) {
|
2017-01-20 21:51:11 +01:00
|
|
|
*error = StringPrintf("failed to attach to thread %d: %s", tid, strerror(errno));
|
2016-10-19 03:17:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure that the task we attached to is actually part of the pid we're dumping.
|
2017-02-02 01:31:43 +01:00
|
|
|
if (!pid_contains_tid(pid_proc_fd, tid)) {
|
2016-10-19 03:17:52 +02:00
|
|
|
if (ptrace(PTRACE_DETACH, tid, 0, 0) != 0) {
|
|
|
|
PLOG(FATAL) << "failed to detach from thread " << tid;
|
|
|
|
}
|
2017-02-02 01:31:43 +01:00
|
|
|
*error = StringPrintf("thread %d is not in process", tid);
|
2016-10-19 03:17:52 +02:00
|
|
|
return false;
|
|
|
|
}
|
2017-01-23 01:42:32 +01:00
|
|
|
|
|
|
|
// Put the task into ptrace-stop state.
|
|
|
|
if (ptrace(PTRACE_INTERRUPT, tid, 0, 0) != 0) {
|
|
|
|
PLOG(FATAL) << "failed to interrupt thread " << tid;
|
|
|
|
}
|
|
|
|
|
2016-10-19 03:17:52 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool activity_manager_notify(int pid, int signal, const std::string& amfd_data) {
|
|
|
|
android::base::unique_fd amfd(socket_local_client("/data/system/ndebugsocket", ANDROID_SOCKET_NAMESPACE_FILESYSTEM, SOCK_STREAM));
|
|
|
|
if (amfd.get() == -1) {
|
|
|
|
PLOG(ERROR) << "unable to connect to activity manager";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct timeval tv = {
|
|
|
|
.tv_sec = 1,
|
|
|
|
.tv_usec = 0,
|
|
|
|
};
|
|
|
|
if (setsockopt(amfd.get(), SOL_SOCKET, SO_SNDTIMEO, &tv, sizeof(tv)) == -1) {
|
|
|
|
PLOG(ERROR) << "failed to set send timeout on activity manager socket";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
tv.tv_sec = 3; // 3 seconds on handshake read
|
|
|
|
if (setsockopt(amfd.get(), SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)) == -1) {
|
|
|
|
PLOG(ERROR) << "failed to set receive timeout on activity manager socket";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Activity Manager protocol: binary 32-bit network-byte-order ints for the
|
|
|
|
// pid and signal number, followed by the raw text of the dump, culminating
|
|
|
|
// in a zero byte that marks end-of-data.
|
|
|
|
uint32_t datum = htonl(pid);
|
|
|
|
if (!android::base::WriteFully(amfd, &datum, 4)) {
|
|
|
|
PLOG(ERROR) << "AM pid write failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
datum = htonl(signal);
|
|
|
|
if (!android::base::WriteFully(amfd, &datum, 4)) {
|
|
|
|
PLOG(ERROR) << "AM signal write failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!android::base::WriteFully(amfd, amfd_data.c_str(), amfd_data.size() + 1)) {
|
|
|
|
PLOG(ERROR) << "AM data write failed";
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3 sec timeout reading the ack; we're fine if the read fails.
|
|
|
|
char ack;
|
|
|
|
android::base::ReadFully(amfd, &ack, 1);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-01-23 02:41:15 +01:00
|
|
|
static void signal_handler(int) {
|
|
|
|
// We can't log easily, because the heap might be corrupt.
|
|
|
|
// Just die and let the surrounding log context explain things.
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
|
2017-05-24 16:07:25 +02:00
|
|
|
static void abort_handler(pid_t target, const bool tombstoned_connected,
|
2016-10-19 03:17:52 +02:00
|
|
|
unique_fd& tombstoned_socket, unique_fd& output_fd,
|
|
|
|
const char* abort_msg) {
|
|
|
|
// If we abort before we get an output fd, contact tombstoned to let any
|
|
|
|
// potential listeners know that we failed.
|
|
|
|
if (!tombstoned_connected) {
|
2017-05-24 16:07:25 +02:00
|
|
|
if (!tombstoned_connect(target, &tombstoned_socket, &output_fd, kDebuggerdAnyIntercept)) {
|
2016-10-19 03:17:52 +02:00
|
|
|
// We failed to connect, not much we can do.
|
|
|
|
LOG(ERROR) << "failed to connected to tombstoned to report failure";
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-10 23:49:19 +01:00
|
|
|
dprintf(output_fd.get(), "crash_dump failed to dump process");
|
|
|
|
if (target != 1) {
|
|
|
|
dprintf(output_fd.get(), " %d: %s\n", target, abort_msg);
|
|
|
|
} else {
|
|
|
|
dprintf(output_fd.get(), ": %s\n", abort_msg);
|
|
|
|
}
|
2016-10-19 03:17:52 +02:00
|
|
|
|
|
|
|
_exit(1);
|
|
|
|
}
|
|
|
|
|
2017-02-02 01:35:31 +01:00
|
|
|
static void drop_capabilities() {
|
|
|
|
__user_cap_header_struct capheader;
|
|
|
|
memset(&capheader, 0, sizeof(capheader));
|
|
|
|
capheader.version = _LINUX_CAPABILITY_VERSION_3;
|
|
|
|
capheader.pid = 0;
|
|
|
|
|
|
|
|
__user_cap_data_struct capdata[2];
|
|
|
|
memset(&capdata, 0, sizeof(capdata));
|
|
|
|
|
|
|
|
if (capset(&capheader, &capdata[0]) == -1) {
|
|
|
|
PLOG(FATAL) << "failed to drop capabilities";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (prctl(PR_SET_NO_NEW_PRIVS, 1, 0, 0, 0) != 0) {
|
|
|
|
PLOG(FATAL) << "failed to set PR_SET_NO_NEW_PRIVS";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-19 03:17:52 +02:00
|
|
|
int main(int argc, char** argv) {
|
|
|
|
pid_t target = getppid();
|
|
|
|
bool tombstoned_connected = false;
|
|
|
|
unique_fd tombstoned_socket;
|
|
|
|
unique_fd output_fd;
|
|
|
|
|
|
|
|
android::base::InitLogging(argv);
|
|
|
|
android::base::SetAborter([&](const char* abort_msg) {
|
|
|
|
abort_handler(target, tombstoned_connected, tombstoned_socket, output_fd, abort_msg);
|
|
|
|
});
|
|
|
|
|
2017-01-23 02:41:15 +01:00
|
|
|
// Don't try to dump ourselves.
|
|
|
|
struct sigaction action = {};
|
|
|
|
action.sa_handler = signal_handler;
|
|
|
|
debuggerd_register_handlers(&action);
|
|
|
|
|
2017-06-01 20:55:25 +02:00
|
|
|
sigset_t mask;
|
|
|
|
sigemptyset(&mask);
|
|
|
|
if (sigprocmask(SIG_SETMASK, &mask, nullptr) != 0) {
|
|
|
|
PLOG(FATAL) << "failed to set signal mask";
|
|
|
|
}
|
|
|
|
|
2017-05-24 16:07:25 +02:00
|
|
|
if (argc != 4) {
|
|
|
|
LOG(FATAL) << "Wrong number of args: " << argc << " (expected 4)";
|
2016-10-19 03:17:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pid_t main_tid;
|
2017-02-13 23:46:19 +01:00
|
|
|
pid_t pseudothread_tid;
|
2017-05-24 16:07:25 +02:00
|
|
|
int dump_type;
|
2016-10-19 03:17:52 +02:00
|
|
|
|
|
|
|
if (!android::base::ParseInt(argv[1], &main_tid, 1, std::numeric_limits<pid_t>::max())) {
|
|
|
|
LOG(FATAL) << "invalid main tid: " << argv[1];
|
|
|
|
}
|
|
|
|
|
2017-02-13 23:46:19 +01:00
|
|
|
if (!android::base::ParseInt(argv[2], &pseudothread_tid, 1, std::numeric_limits<pid_t>::max())) {
|
2017-02-15 21:21:11 +01:00
|
|
|
LOG(FATAL) << "invalid pseudothread tid: " << argv[2];
|
2017-02-13 23:46:19 +01:00
|
|
|
}
|
|
|
|
|
2017-05-24 16:07:25 +02:00
|
|
|
if (!android::base::ParseInt(argv[3], &dump_type, 0, 1)) {
|
|
|
|
LOG(FATAL) << "invalid requested dump type: " << argv[3];
|
|
|
|
}
|
|
|
|
|
2017-03-13 22:13:29 +01:00
|
|
|
if (target == 1) {
|
|
|
|
LOG(FATAL) << "target died before we could attach (received main tid = " << main_tid << ")";
|
|
|
|
}
|
|
|
|
|
2016-10-19 03:17:52 +02:00
|
|
|
android::procinfo::ProcessInfo target_info;
|
|
|
|
if (!android::procinfo::GetProcessInfo(main_tid, &target_info)) {
|
|
|
|
LOG(FATAL) << "failed to fetch process info for target " << main_tid;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (main_tid != target_info.tid || target != target_info.pid) {
|
|
|
|
LOG(FATAL) << "target info mismatch, expected pid " << target << ", tid " << main_tid
|
|
|
|
<< ", received pid " << target_info.pid << ", tid " << target_info.tid;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Open /proc/`getppid()` in the original process, and pass it down to the forked child.
|
|
|
|
std::string target_proc_path = "/proc/" + std::to_string(target);
|
|
|
|
int target_proc_fd = open(target_proc_path.c_str(), O_DIRECTORY | O_RDONLY);
|
|
|
|
if (target_proc_fd == -1) {
|
|
|
|
PLOG(FATAL) << "failed to open " << target_proc_path;
|
|
|
|
}
|
|
|
|
|
2017-02-17 04:17:28 +01:00
|
|
|
// Make sure our parent didn't die.
|
|
|
|
if (getppid() != target) {
|
|
|
|
PLOG(FATAL) << "parent died";
|
|
|
|
}
|
|
|
|
|
2016-10-19 03:17:52 +02:00
|
|
|
// Reparent ourselves to init, so that the signal handler can waitpid on the
|
|
|
|
// original process to avoid leaving a zombie for non-fatal dumps.
|
|
|
|
pid_t forkpid = fork();
|
|
|
|
if (forkpid == -1) {
|
|
|
|
PLOG(FATAL) << "fork failed";
|
|
|
|
} else if (forkpid != 0) {
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
2017-01-23 02:59:02 +01:00
|
|
|
// Die if we take too long.
|
2017-06-01 20:55:25 +02:00
|
|
|
alarm(2);
|
2017-01-23 02:59:02 +01:00
|
|
|
|
2017-01-20 21:51:11 +01:00
|
|
|
std::string attach_error;
|
2017-02-13 23:46:19 +01:00
|
|
|
|
|
|
|
// Seize the main thread.
|
2017-02-02 01:31:43 +01:00
|
|
|
if (!ptrace_seize_thread(target_proc_fd, main_tid, &attach_error)) {
|
2017-01-20 21:51:11 +01:00
|
|
|
LOG(FATAL) << attach_error;
|
2016-10-19 03:17:52 +02:00
|
|
|
}
|
|
|
|
|
2017-02-13 23:46:19 +01:00
|
|
|
// Seize the siblings.
|
2017-03-16 07:23:22 +01:00
|
|
|
std::map<pid_t, std::string> threads;
|
2017-02-13 23:46:19 +01:00
|
|
|
{
|
|
|
|
std::set<pid_t> siblings;
|
|
|
|
if (!android::procinfo::GetProcessTids(target, &siblings)) {
|
|
|
|
PLOG(FATAL) << "failed to get process siblings";
|
|
|
|
}
|
|
|
|
|
|
|
|
// but not the already attached main thread.
|
|
|
|
siblings.erase(main_tid);
|
|
|
|
// or the handler pseudothread.
|
|
|
|
siblings.erase(pseudothread_tid);
|
|
|
|
|
|
|
|
for (pid_t sibling_tid : siblings) {
|
|
|
|
if (!ptrace_seize_thread(target_proc_fd, sibling_tid, &attach_error)) {
|
|
|
|
LOG(WARNING) << attach_error;
|
|
|
|
} else {
|
2017-03-16 07:23:22 +01:00
|
|
|
threads.emplace(sibling_tid, get_thread_name(sibling_tid));
|
2017-02-13 23:46:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-16 07:23:22 +01:00
|
|
|
// Collect the backtrace map, open files, and process/thread names, while we still have caps.
|
2017-02-13 23:46:19 +01:00
|
|
|
std::unique_ptr<BacktraceMap> backtrace_map(BacktraceMap::Create(main_tid));
|
|
|
|
if (!backtrace_map) {
|
|
|
|
LOG(FATAL) << "failed to create backtrace map";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Collect the list of open files.
|
|
|
|
OpenFilesList open_files;
|
|
|
|
populate_open_files_list(target, &open_files);
|
|
|
|
|
2017-03-16 07:23:22 +01:00
|
|
|
std::string process_name = get_process_name(main_tid);
|
|
|
|
threads.emplace(main_tid, get_thread_name(main_tid));
|
|
|
|
|
2017-02-13 23:46:19 +01:00
|
|
|
// Drop our capabilities now that we've attached to the threads we care about.
|
|
|
|
drop_capabilities();
|
2016-10-19 03:17:52 +02:00
|
|
|
|
2017-05-24 16:07:25 +02:00
|
|
|
const DebuggerdDumpType dump_type_enum = static_cast<DebuggerdDumpType>(dump_type);
|
|
|
|
LOG(INFO) << "obtaining output fd from tombstoned, type: " << dump_type_enum;
|
|
|
|
tombstoned_connected = tombstoned_connect(target, &tombstoned_socket, &output_fd, dump_type_enum);
|
2016-10-19 03:17:52 +02:00
|
|
|
|
|
|
|
// Write a '\1' to stdout to tell the crashing process to resume.
|
2017-02-13 23:46:19 +01:00
|
|
|
// It also restores the value of PR_SET_DUMPABLE at this point.
|
2016-10-19 03:17:52 +02:00
|
|
|
if (TEMP_FAILURE_RETRY(write(STDOUT_FILENO, "\1", 1)) == -1) {
|
|
|
|
PLOG(ERROR) << "failed to communicate to target process";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tombstoned_connected) {
|
|
|
|
if (TEMP_FAILURE_RETRY(dup2(output_fd.get(), STDOUT_FILENO)) == -1) {
|
|
|
|
PLOG(ERROR) << "failed to dup2 output fd (" << output_fd.get() << ") to STDOUT_FILENO";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unique_fd devnull(TEMP_FAILURE_RETRY(open("/dev/null", O_RDWR)));
|
|
|
|
TEMP_FAILURE_RETRY(dup2(devnull.get(), STDOUT_FILENO));
|
2017-01-25 00:20:42 +01:00
|
|
|
output_fd = std::move(devnull);
|
2016-10-19 03:17:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
LOG(INFO) << "performing dump of process " << target << " (target tid = " << main_tid << ")";
|
|
|
|
|
2017-01-23 01:42:32 +01:00
|
|
|
// At this point, the thread that made the request has been attached and is
|
|
|
|
// in ptrace-stopped state. After resumption, the triggering signal that has
|
|
|
|
// been queued will be delivered.
|
2016-10-19 03:17:52 +02:00
|
|
|
if (ptrace(PTRACE_CONT, main_tid, 0, 0) != 0) {
|
|
|
|
PLOG(ERROR) << "PTRACE_CONT(" << main_tid << ") failed";
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
siginfo_t siginfo = {};
|
|
|
|
if (!wait_for_signal(main_tid, &siginfo)) {
|
|
|
|
printf("failed to wait for signal in tid %d: %s\n", main_tid, strerror(errno));
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int signo = siginfo.si_signo;
|
2017-02-02 01:31:43 +01:00
|
|
|
bool fatal_signal = signo != DEBUGGER_SIGNAL;
|
2016-10-19 03:17:52 +02:00
|
|
|
bool backtrace = false;
|
|
|
|
uintptr_t abort_address = 0;
|
|
|
|
|
|
|
|
// si_value can represent three things:
|
|
|
|
// 0: dump tombstone
|
|
|
|
// 1: dump backtrace
|
|
|
|
// everything else: abort message address (implies dump tombstone)
|
|
|
|
if (siginfo.si_value.sival_int == 1) {
|
|
|
|
backtrace = true;
|
|
|
|
} else if (siginfo.si_value.sival_ptr != nullptr) {
|
|
|
|
abort_address = reinterpret_cast<uintptr_t>(siginfo.si_value.sival_ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Use seccomp to lock ourselves down.
|
|
|
|
|
|
|
|
std::string amfd_data;
|
|
|
|
if (backtrace) {
|
2017-03-16 07:23:22 +01:00
|
|
|
dump_backtrace(output_fd.get(), backtrace_map.get(), target, main_tid, process_name, threads, 0);
|
2016-10-19 03:17:52 +02:00
|
|
|
} else {
|
2017-02-09 01:06:26 +01:00
|
|
|
engrave_tombstone(output_fd.get(), backtrace_map.get(), &open_files, target, main_tid,
|
2017-03-16 07:23:22 +01:00
|
|
|
process_name, threads, abort_address, fatal_signal ? &amfd_data : nullptr);
|
2016-10-19 03:17:52 +02:00
|
|
|
}
|
|
|
|
|
2017-01-23 02:59:02 +01:00
|
|
|
// We don't actually need to PTRACE_DETACH, as long as our tracees aren't in
|
|
|
|
// group-stop state, which is true as long as no stopping signals are sent.
|
|
|
|
|
2016-10-19 03:17:52 +02:00
|
|
|
bool wait_for_gdb = android::base::GetBoolProperty("debug.debuggerd.wait_for_gdb", false);
|
2017-01-23 02:59:02 +01:00
|
|
|
if (!fatal_signal || siginfo.si_code == SI_USER) {
|
2016-10-19 03:17:52 +02:00
|
|
|
// Don't wait_for_gdb when the process didn't actually crash.
|
2017-01-23 02:59:02 +01:00
|
|
|
wait_for_gdb = false;
|
2016-10-19 03:17:52 +02:00
|
|
|
}
|
|
|
|
|
2017-01-23 02:59:02 +01:00
|
|
|
// If the process crashed or we need to send it SIGSTOP for wait_for_gdb,
|
|
|
|
// get it in a state where it can receive signals, and then send the relevant
|
|
|
|
// signal.
|
|
|
|
if (wait_for_gdb || fatal_signal) {
|
|
|
|
if (ptrace(PTRACE_INTERRUPT, main_tid, 0, 0) != 0) {
|
|
|
|
PLOG(ERROR) << "failed to use PTRACE_INTERRUPT on " << main_tid;
|
2016-10-19 03:17:52 +02:00
|
|
|
}
|
|
|
|
|
2017-01-23 02:59:02 +01:00
|
|
|
if (tgkill(target, main_tid, wait_for_gdb ? SIGSTOP : signo) != 0) {
|
|
|
|
PLOG(ERROR) << "failed to resend signal " << signo << " to " << main_tid;
|
|
|
|
}
|
2016-10-19 03:17:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (wait_for_gdb) {
|
2017-01-23 02:59:02 +01:00
|
|
|
// Use ALOGI to line up with output from engrave_tombstone.
|
|
|
|
ALOGI(
|
|
|
|
"***********************************************************\n"
|
|
|
|
"* Process %d has been suspended while crashing.\n"
|
|
|
|
"* To attach gdbserver and start gdb, run this on the host:\n"
|
|
|
|
"*\n"
|
|
|
|
"* gdbclient.py -p %d\n"
|
|
|
|
"*\n"
|
|
|
|
"***********************************************************",
|
|
|
|
target, main_tid);
|
2016-10-19 03:17:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (fatal_signal) {
|
|
|
|
activity_manager_notify(target, signo, amfd_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Close stdout before we notify tombstoned of completion.
|
|
|
|
close(STDOUT_FILENO);
|
2017-01-25 00:20:42 +01:00
|
|
|
if (tombstoned_connected && !tombstoned_notify_completion(tombstoned_socket.get())) {
|
2016-10-19 03:17:52 +02:00
|
|
|
LOG(ERROR) << "failed to notify tombstoned of completion";
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|