blob: 20539b040a3e4a3f87f19e8fdc3c111db1b360da [file] [log] [blame]
Jeff Brown053b8652012-06-06 16:25:03 -07001/*
Mark Salyzynfca0bd12013-12-12 12:21:20 -08002 * Copyright (C) 2012-2014 The Android Open Source Project
Jeff Brown053b8652012-06-06 16:25:03 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Brigid Smith62ba4892014-06-10 11:53:08 -070017#define LOG_TAG "DEBUG"
18
Josh Gaoc3706662017-08-29 13:08:32 -070019#include "libdebuggerd/tombstone.h"
20
Jeff Brown053b8652012-06-06 16:25:03 -070021#include <dirent.h>
Kévin PETIT4bb47722013-12-18 16:44:24 +000022#include <errno.h>
23#include <fcntl.h>
24#include <inttypes.h>
25#include <signal.h>
26#include <stddef.h>
27#include <stdio.h>
28#include <stdlib.h>
29#include <string.h>
Christopher Ferris3336c7b2019-04-08 17:18:24 -070030#include <sys/mman.h>
Jeff Brown053b8652012-06-06 16:25:03 -070031#include <sys/ptrace.h>
32#include <sys/stat.h>
Mark Salyzynff2dcd92016-09-28 15:54:45 -070033#include <time.h>
Jeff Brown053b8652012-06-06 16:25:03 -070034
Christopher Ferris6e964032015-05-15 17:30:21 -070035#include <memory>
36#include <string>
37
Josh Gao57f58f82017-03-15 23:23:22 -070038#include <android-base/file.h>
Christopher Ferris2b98c822021-09-28 15:50:04 -070039#include <android-base/logging.h>
Tom Cherry31121ca2017-10-10 13:30:57 -070040#include <android-base/properties.h>
Elliott Hughes4f713192015-12-04 22:00:26 -080041#include <android-base/stringprintf.h>
Josh Gao2b2ae0c2017-08-21 14:31:17 -070042#include <android-base/strings.h>
Josh Gao57f58f82017-03-15 23:23:22 -070043#include <android-base/unique_fd.h>
44#include <android/log.h>
Josh Gao618cea32021-01-26 17:45:43 -080045#include <async_safe/log.h>
Peter Collingbourne0ea08c22021-02-05 14:59:08 -080046#include <bionic/macros.h>
Mark Salyzyncfd5b082016-10-17 14:28:00 -070047#include <log/log.h>
Tom Cherryc5c6d7d2020-04-17 09:38:55 -070048#include <log/log_read.h>
Mark Salyzynff2dcd92016-09-28 15:54:45 -070049#include <log/logprint.h>
50#include <private/android_filesystem_config.h>
David Srbeckyb9cc4fb2019-04-05 18:23:32 +000051#include <unwindstack/DexFiles.h>
Christopher Ferris60eb1972019-01-15 15:18:43 -080052#include <unwindstack/JitDebug.h>
53#include <unwindstack/Maps.h>
Josh Gao2b2ae0c2017-08-21 14:31:17 -070054#include <unwindstack/Memory.h>
55#include <unwindstack/Regs.h>
Christopher Ferris60eb1972019-01-15 15:18:43 -080056#include <unwindstack/Unwinder.h>
Jeff Brown053b8652012-06-06 16:25:03 -070057
Josh Gaoc3706662017-08-29 13:08:32 -070058#include "libdebuggerd/backtrace.h"
Mitch Phillipse0b4bb12020-02-14 14:54:31 -080059#include "libdebuggerd/gwp_asan.h"
Josh Gaoc3706662017-08-29 13:08:32 -070060#include "libdebuggerd/open_files_list.h"
Josh Gao2b2ae0c2017-08-21 14:31:17 -070061#include "libdebuggerd/utility.h"
Elliott Hughesa660cb32020-07-23 15:26:10 -070062#include "util.h"
Jeff Brown053b8652012-06-06 16:25:03 -070063
Christopher Ferris7aad2562021-09-24 00:06:38 -070064#if defined(USE_SCUDO)
65#include "libdebuggerd/scudo.h"
66#endif
67
Mitch Phillipse0b4bb12020-02-14 14:54:31 -080068#include "gwp_asan/common.h"
69#include "gwp_asan/crash_handler.h"
70
Josh Gao76e1e302021-01-26 15:53:11 -080071#include "tombstone.pb.h"
72
Tom Cherry31121ca2017-10-10 13:30:57 -070073using android::base::GetBoolProperty;
74using android::base::GetProperty;
Elliott Hughes0ba53592017-02-01 16:59:15 -080075using android::base::StringPrintf;
Josh Gao2b2ae0c2017-08-21 14:31:17 -070076using android::base::unique_fd;
77
Elliott Hughese1415a52018-02-15 09:18:21 -080078using namespace std::literals::string_literals;
79
Jeff Brown053b8652012-06-06 16:25:03 -070080#define STACK_WORDS 16
81
Brigid Smith9c8dacc2014-06-02 15:02:20 -070082static void dump_header_info(log_t* log) {
Tom Cherry31121ca2017-10-10 13:30:57 -070083 auto fingerprint = GetProperty("ro.build.fingerprint", "unknown");
84 auto revision = GetProperty("ro.revision", "unknown");
Ben Chengd7760c12012-09-19 16:04:01 -070085
Tom Cherry31121ca2017-10-10 13:30:57 -070086 _LOG(log, logtype::HEADER, "Build fingerprint: '%s'\n", fingerprint.c_str());
87 _LOG(log, logtype::HEADER, "Revision: '%s'\n", revision.c_str());
Brigid Smith62ba4892014-06-10 11:53:08 -070088 _LOG(log, logtype::HEADER, "ABI: '%s'\n", ABI_STRING);
Jeff Brown053b8652012-06-06 16:25:03 -070089}
90
Christopher Ferris481e8372019-07-15 17:13:24 -070091static std::string get_stack_overflow_cause(uint64_t fault_addr, uint64_t sp,
92 unwindstack::Maps* maps) {
93 static constexpr uint64_t kMaxDifferenceBytes = 256;
94 uint64_t difference;
95 if (sp >= fault_addr) {
96 difference = sp - fault_addr;
97 } else {
98 difference = fault_addr - sp;
99 }
100 if (difference <= kMaxDifferenceBytes) {
101 // The faulting address is close to the current sp, check if the sp
102 // indicates a stack overflow.
103 // On arm, the sp does not get updated when the instruction faults.
104 // In this case, the sp will still be in a valid map, which is the
105 // last case below.
106 // On aarch64, the sp does get updated when the instruction faults.
107 // In this case, the sp will be in either an invalid map if triggered
108 // on the main thread, or in a guard map if in another thread, which
109 // will be the first case or second case from below.
Christopher Ferrisc6776062021-01-15 15:59:28 -0800110 auto map_info = maps->Find(sp);
Christopher Ferris481e8372019-07-15 17:13:24 -0700111 if (map_info == nullptr) {
112 return "stack pointer is in a non-existent map; likely due to stack overflow.";
David Srbeckyd8ab48b2021-05-13 00:03:26 +0100113 } else if ((map_info->flags() & (PROT_READ | PROT_WRITE)) != (PROT_READ | PROT_WRITE)) {
Christopher Ferris481e8372019-07-15 17:13:24 -0700114 return "stack pointer is not in a rw map; likely due to stack overflow.";
David Srbeckyd8ab48b2021-05-13 00:03:26 +0100115 } else if ((sp - map_info->start()) <= kMaxDifferenceBytes) {
Christopher Ferris481e8372019-07-15 17:13:24 -0700116 return "stack pointer is close to top of stack; likely stack overflow.";
117 }
118 }
119 return "";
120}
121
Christopher Ferris7aad2562021-09-24 00:06:38 -0700122static void dump_probable_cause(log_t* log, unwindstack::Unwinder* unwinder,
123 const ProcessInfo& process_info, const ThreadInfo& main_thread) {
124#if defined(USE_SCUDO)
125 ScudoCrashData scudo_crash_data(unwinder->GetProcessMemory().get(), process_info);
126 if (scudo_crash_data.CrashIsMine()) {
127 scudo_crash_data.DumpCause(log, unwinder);
128 return;
129 }
130#endif
131
132 GwpAsanCrashData gwp_asan_crash_data(unwinder->GetProcessMemory().get(), process_info,
133 main_thread);
134 if (gwp_asan_crash_data.CrashIsMine()) {
135 gwp_asan_crash_data.DumpCause(log);
136 return;
137 }
138
139 unwindstack::Maps* maps = unwinder->GetMaps();
140 unwindstack::Regs* regs = main_thread.registers.get();
141 const siginfo_t* si = main_thread.siginfo;
Elliott Hughes0ba53592017-02-01 16:59:15 -0800142 std::string cause;
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700143 if (si->si_signo == SIGSEGV && si->si_code == SEGV_MAPERR) {
144 if (si->si_addr < reinterpret_cast<void*>(4096)) {
Elliott Hughes0ba53592017-02-01 16:59:15 -0800145 cause = StringPrintf("null pointer dereference");
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700146 } else if (si->si_addr == reinterpret_cast<void*>(0xffff0ffc)) {
Elliott Hughes0ba53592017-02-01 16:59:15 -0800147 cause = "call to kuser_helper_version";
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700148 } else if (si->si_addr == reinterpret_cast<void*>(0xffff0fe0)) {
Elliott Hughes0ba53592017-02-01 16:59:15 -0800149 cause = "call to kuser_get_tls";
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700150 } else if (si->si_addr == reinterpret_cast<void*>(0xffff0fc0)) {
Elliott Hughes0ba53592017-02-01 16:59:15 -0800151 cause = "call to kuser_cmpxchg";
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700152 } else if (si->si_addr == reinterpret_cast<void*>(0xffff0fa0)) {
Elliott Hughes0ba53592017-02-01 16:59:15 -0800153 cause = "call to kuser_memory_barrier";
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700154 } else if (si->si_addr == reinterpret_cast<void*>(0xffff0f60)) {
Elliott Hughes0ba53592017-02-01 16:59:15 -0800155 cause = "call to kuser_cmpxchg64";
Christopher Ferris481e8372019-07-15 17:13:24 -0700156 } else {
157 cause = get_stack_overflow_cause(reinterpret_cast<uint64_t>(si->si_addr), regs->sp(), maps);
Elliott Hughes0ba53592017-02-01 16:59:15 -0800158 }
Ivan Lozanodf3cec92018-11-19 10:43:47 -0800159 } else if (si->si_signo == SIGSEGV && si->si_code == SEGV_ACCERR) {
Christopher Ferris481e8372019-07-15 17:13:24 -0700160 uint64_t fault_addr = reinterpret_cast<uint64_t>(si->si_addr);
Christopher Ferrisc6776062021-01-15 15:59:28 -0800161 auto map_info = maps->Find(fault_addr);
David Srbeckyd8ab48b2021-05-13 00:03:26 +0100162 if (map_info != nullptr && map_info->flags() == PROT_EXEC) {
Christopher Ferris60eb1972019-01-15 15:18:43 -0800163 cause = "execute-only (no-read) memory access error; likely due to data in .text.";
Christopher Ferris481e8372019-07-15 17:13:24 -0700164 } else {
165 cause = get_stack_overflow_cause(fault_addr, regs->sp(), maps);
Ivan Lozanodf3cec92018-11-19 10:43:47 -0800166 }
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700167 } else if (si->si_signo == SIGSYS && si->si_code == SYS_SECCOMP) {
168 cause = StringPrintf("seccomp prevented call to disallowed %s system call %d", ABI_STRING,
169 si->si_syscall);
Elliott Hughes0ba53592017-02-01 16:59:15 -0800170 }
171
172 if (!cause.empty()) _LOG(log, logtype::HEADER, "Cause: %s\n", cause.c_str());
173}
174
Christopher Ferris60eb1972019-01-15 15:18:43 -0800175static void dump_signal_info(log_t* log, const ThreadInfo& thread_info,
Peter Collingbournef03af882020-03-20 18:09:00 -0700176 const ProcessInfo& process_info, unwindstack::Memory* process_memory) {
Elliott Hughes2baf4432018-05-30 12:55:04 -0700177 char addr_desc[64]; // ", fault addr 0x1234"
Peter Collingbournef03af882020-03-20 18:09:00 -0700178 if (process_info.has_fault_address) {
Mitch Phillipse4adff02021-01-21 20:41:50 -0800179 // SIGILL faults will never have tagged addresses, so okay to
180 // indiscriminately use the tagged address here.
181 size_t addr = process_info.maybe_tagged_fault_address;
Elliott Hughes2baf4432018-05-30 12:55:04 -0700182 if (thread_info.siginfo->si_signo == SIGILL) {
183 uint32_t instruction = {};
Peter Collingbournef03af882020-03-20 18:09:00 -0700184 process_memory->Read(addr, &instruction, sizeof(instruction));
185 snprintf(addr_desc, sizeof(addr_desc), "0x%zx (*pc=%#08x)", addr, instruction);
Elliott Hughes2baf4432018-05-30 12:55:04 -0700186 } else {
Peter Collingbournef03af882020-03-20 18:09:00 -0700187 snprintf(addr_desc, sizeof(addr_desc), "0x%zx", addr);
Elliott Hughes2baf4432018-05-30 12:55:04 -0700188 }
Elliott Hughes855fcc32014-04-25 16:05:34 -0700189 } else {
190 snprintf(addr_desc, sizeof(addr_desc), "--------");
191 }
192
Elliott Hughes70d8f282018-04-25 17:00:14 -0700193 char sender_desc[32] = {}; // " from pid 1234, uid 666"
194 if (signal_has_sender(thread_info.siginfo, thread_info.pid)) {
195 get_signal_sender(sender_desc, sizeof(sender_desc), thread_info.siginfo);
196 }
Elliott Hughes0ba53592017-02-01 16:59:15 -0800197
Elliott Hughes70d8f282018-04-25 17:00:14 -0700198 _LOG(log, logtype::HEADER, "signal %d (%s), code %d (%s%s), fault addr %s\n",
199 thread_info.siginfo->si_signo, get_signame(thread_info.siginfo),
200 thread_info.siginfo->si_code, get_sigcode(thread_info.siginfo), sender_desc, addr_desc);
Jeff Brown053b8652012-06-06 16:25:03 -0700201}
202
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700203static void dump_thread_info(log_t* log, const ThreadInfo& thread_info) {
Elliott Hughes713ec252020-08-03 08:43:43 -0700204 // Don't try to collect logs from the threads that implement the logging system itself.
205 if (thread_info.uid == AID_LOGD) log->should_retrieve_logcat = false;
Christopher Ferris20303f82014-01-10 16:33:16 -0800206
Josh Gao31348a72021-03-29 21:53:42 -0700207 const char* process_name = "<unknown>";
208 if (!thread_info.command_line.empty()) {
209 process_name = thread_info.command_line[0].c_str();
210 }
211
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700212 _LOG(log, logtype::HEADER, "pid: %d, tid: %d, name: %s >>> %s <<<\n", thread_info.pid,
Josh Gao31348a72021-03-29 21:53:42 -0700213 thread_info.tid, thread_info.thread_name.c_str(), process_name);
Misha Wagner39c5b8c2019-04-18 16:07:33 +0100214 _LOG(log, logtype::HEADER, "uid: %d\n", thread_info.uid);
Peter Collingbourne864f15d2020-09-14 20:27:36 -0700215 if (thread_info.tagged_addr_ctrl != -1) {
Peter Collingbourne47d784e2021-11-05 18:40:52 -0700216 _LOG(log, logtype::HEADER, "tagged_addr_ctrl: %016lx%s\n", thread_info.tagged_addr_ctrl,
217 describe_tagged_addr_ctrl(thread_info.tagged_addr_ctrl).c_str());
Peter Collingbourne864f15d2020-09-14 20:27:36 -0700218 }
Christopher Ferris20303f82014-01-10 16:33:16 -0800219}
Jeff Brown053b8652012-06-06 16:25:03 -0700220
Christopher Ferris7937a362018-01-18 11:15:49 -0800221static std::string get_addr_string(uint64_t addr) {
Christopher Ferris862fe022015-06-02 14:52:44 -0700222 std::string addr_str;
223#if defined(__LP64__)
Josh Gao76e1e302021-01-26 15:53:11 -0800224 addr_str = StringPrintf("%08x'%08x", static_cast<uint32_t>(addr >> 32),
Elliott Hughes0ba53592017-02-01 16:59:15 -0800225 static_cast<uint32_t>(addr & 0xffffffff));
Christopher Ferris862fe022015-06-02 14:52:44 -0700226#else
Christopher Ferris7937a362018-01-18 11:15:49 -0800227 addr_str = StringPrintf("%08x", static_cast<uint32_t>(addr));
Christopher Ferris862fe022015-06-02 14:52:44 -0700228#endif
229 return addr_str;
230}
231
Christopher Ferris60eb1972019-01-15 15:18:43 -0800232static void dump_abort_message(log_t* log, unwindstack::Memory* process_memory, uint64_t address) {
Josh Gao7c89f9e2016-01-13 17:57:14 -0800233 if (address == 0) {
234 return;
235 }
236
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700237 size_t length;
238 if (!process_memory->ReadFully(address, &length, sizeof(length))) {
239 _LOG(log, logtype::HEADER, "Failed to read abort message header: %s\n", strerror(errno));
240 return;
241 }
Josh Gao7c89f9e2016-01-13 17:57:14 -0800242
Josh Gao1cc7bd82018-02-13 13:16:17 -0800243 // The length field includes the length of the length field itself.
244 if (length < sizeof(size_t)) {
245 _LOG(log, logtype::HEADER, "Abort message header malformed: claimed length = %zd\n", length);
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700246 return;
Josh Gao7c89f9e2016-01-13 17:57:14 -0800247 }
Josh Gao7c89f9e2016-01-13 17:57:14 -0800248
Josh Gao1cc7bd82018-02-13 13:16:17 -0800249 length -= sizeof(size_t);
250
Josh Gao83b8ac22018-04-20 17:31:53 -0700251 // The abort message should be null terminated already, but reserve a spot for NUL just in case.
252 std::vector<char> msg(length + 1);
Josh Gao1cc7bd82018-02-13 13:16:17 -0800253 if (!process_memory->ReadFully(address + sizeof(length), &msg[0], length)) {
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700254 _LOG(log, logtype::HEADER, "Failed to read abort message: %s\n", strerror(errno));
255 return;
256 }
257
Christopher Ferrise8891452021-08-17 17:34:53 -0700258 // Remove any trailing newlines.
259 size_t index = length;
260 while (index > 0 && (msg[index - 1] == '\0' || msg[index - 1] == '\n')) {
261 --index;
262 }
263 msg[index] = '\0';
Josh Gao1cc7bd82018-02-13 13:16:17 -0800264 _LOG(log, logtype::HEADER, "Abort message: '%s'\n", &msg[0]);
Josh Gao7c89f9e2016-01-13 17:57:14 -0800265}
266
Christopher Ferris60eb1972019-01-15 15:18:43 -0800267static void dump_all_maps(log_t* log, unwindstack::Unwinder* unwinder, uint64_t addr) {
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700268 bool print_fault_address_marker = addr;
Christopher Ferris20303f82014-01-10 16:33:16 -0800269
Christopher Ferris60eb1972019-01-15 15:18:43 -0800270 unwindstack::Maps* maps = unwinder->GetMaps();
Elliott Hughes868d39a2017-09-26 11:54:49 -0700271 _LOG(log, logtype::MAPS,
272 "\n"
Josh Gao1ce8e142017-09-27 13:59:42 -0700273 "memory map (%zu entr%s):",
Christopher Ferris60eb1972019-01-15 15:18:43 -0800274 maps->Total(), maps->Total() == 1 ? "y" : "ies");
Elliott Hughes868d39a2017-09-26 11:54:49 -0700275 if (print_fault_address_marker) {
David Srbeckyd8ab48b2021-05-13 00:03:26 +0100276 if (maps->Total() != 0 && addr < maps->Get(0)->start()) {
Josh Gao1ce8e142017-09-27 13:59:42 -0700277 _LOG(log, logtype::MAPS, "\n--->Fault address falls at %s before any mapped regions\n",
Christopher Ferris862fe022015-06-02 14:52:44 -0700278 get_addr_string(addr).c_str());
Christopher Ferrisa21bd932015-02-27 13:39:47 -0800279 print_fault_address_marker = false;
Elliott Hughes868d39a2017-09-26 11:54:49 -0700280 } else {
Josh Gao1ce8e142017-09-27 13:59:42 -0700281 _LOG(log, logtype::MAPS, " (fault address prefixed with --->)\n");
Brigid Smith8606eaa2014-07-07 12:33:50 -0700282 }
Josh Gao1ce8e142017-09-27 13:59:42 -0700283 } else {
284 _LOG(log, logtype::MAPS, "\n");
Brigid Smith8606eaa2014-07-07 12:33:50 -0700285 }
Christopher Ferrisa21bd932015-02-27 13:39:47 -0800286
Christopher Ferris60eb1972019-01-15 15:18:43 -0800287 std::shared_ptr<unwindstack::Memory>& process_memory = unwinder->GetProcessMemory();
288
Christopher Ferrisa21bd932015-02-27 13:39:47 -0800289 std::string line;
Florian Mayer3d67d342019-02-27 18:00:37 +0000290 for (auto const& map_info : *maps) {
Christopher Ferrisa21bd932015-02-27 13:39:47 -0800291 line = " ";
292 if (print_fault_address_marker) {
David Srbeckyd8ab48b2021-05-13 00:03:26 +0100293 if (addr < map_info->start()) {
Christopher Ferris862fe022015-06-02 14:52:44 -0700294 _LOG(log, logtype::MAPS, "--->Fault address falls at %s between mapped regions\n",
295 get_addr_string(addr).c_str());
Christopher Ferrisa21bd932015-02-27 13:39:47 -0800296 print_fault_address_marker = false;
David Srbeckyd8ab48b2021-05-13 00:03:26 +0100297 } else if (addr >= map_info->start() && addr < map_info->end()) {
Christopher Ferrisa21bd932015-02-27 13:39:47 -0800298 line = "--->";
299 print_fault_address_marker = false;
300 }
301 }
David Srbeckyd8ab48b2021-05-13 00:03:26 +0100302 line += get_addr_string(map_info->start()) + '-' + get_addr_string(map_info->end() - 1) + ' ';
303 if (map_info->flags() & PROT_READ) {
Christopher Ferrisa21bd932015-02-27 13:39:47 -0800304 line += 'r';
305 } else {
306 line += '-';
307 }
David Srbeckyd8ab48b2021-05-13 00:03:26 +0100308 if (map_info->flags() & PROT_WRITE) {
Christopher Ferrisa21bd932015-02-27 13:39:47 -0800309 line += 'w';
310 } else {
311 line += '-';
312 }
David Srbeckyd8ab48b2021-05-13 00:03:26 +0100313 if (map_info->flags() & PROT_EXEC) {
Christopher Ferrisa21bd932015-02-27 13:39:47 -0800314 line += 'x';
315 } else {
316 line += '-';
317 }
David Srbeckyd8ab48b2021-05-13 00:03:26 +0100318 line += StringPrintf(" %8" PRIx64 " %8" PRIx64, map_info->offset(),
319 map_info->end() - map_info->start());
Christopher Ferris862fe022015-06-02 14:52:44 -0700320 bool space_needed = true;
David Srbeckyd8ab48b2021-05-13 00:03:26 +0100321 if (!map_info->name().empty()) {
Christopher Ferris862fe022015-06-02 14:52:44 -0700322 space_needed = false;
David Srbeckyd8ab48b2021-05-13 00:03:26 +0100323 line += " " + map_info->name();
Christopher Ferris60eb1972019-01-15 15:18:43 -0800324 std::string build_id = map_info->GetPrintableBuildID();
325 if (!build_id.empty()) {
Christopher Ferrisa21bd932015-02-27 13:39:47 -0800326 line += " (BuildId: " + build_id + ")";
327 }
328 }
Christopher Ferris60eb1972019-01-15 15:18:43 -0800329 uint64_t load_bias = map_info->GetLoadBias(process_memory);
330 if (load_bias != 0) {
Christopher Ferris862fe022015-06-02 14:52:44 -0700331 if (space_needed) {
332 line += ' ';
333 }
Christopher Ferris60eb1972019-01-15 15:18:43 -0800334 line += StringPrintf(" (load bias 0x%" PRIx64 ")", load_bias);
Christopher Ferris2106f4b2015-05-01 15:02:03 -0700335 }
Christopher Ferrisa21bd932015-02-27 13:39:47 -0800336 _LOG(log, logtype::MAPS, "%s\n", line.c_str());
337 }
338 if (print_fault_address_marker) {
Christopher Ferris862fe022015-06-02 14:52:44 -0700339 _LOG(log, logtype::MAPS, "--->Fault address falls at %s after any mapped regions\n",
340 get_addr_string(addr).c_str());
Christopher Ferris20303f82014-01-10 16:33:16 -0800341 }
Jeff Brown053b8652012-06-06 16:25:03 -0700342}
343
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700344static void print_register_row(log_t* log,
345 const std::vector<std::pair<std::string, uint64_t>>& registers) {
346 std::string output;
347 for (auto& [name, value] : registers) {
Christopher Ferris7937a362018-01-18 11:15:49 -0800348 output += android::base::StringPrintf(" %-3s %0*" PRIx64, name.c_str(),
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700349 static_cast<int>(2 * sizeof(void*)),
Christopher Ferris7937a362018-01-18 11:15:49 -0800350 static_cast<uint64_t>(value));
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700351 }
352
353 _LOG(log, logtype::REGISTERS, " %s\n", output.c_str());
Josh Gao77b00ed2017-05-05 18:11:23 -0700354}
355
Christopher Ferris60eb1972019-01-15 15:18:43 -0800356void dump_registers(log_t* log, unwindstack::Regs* regs) {
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700357 // Split lr/sp/pc into their own special row.
358 static constexpr size_t column_count = 4;
359 std::vector<std::pair<std::string, uint64_t>> current_row;
360 std::vector<std::pair<std::string, uint64_t>> special_row;
361
362#if defined(__arm__) || defined(__aarch64__)
Peter Collingbournebb2f9412019-11-18 12:36:50 -0800363 static constexpr const char* special_registers[] = {"ip", "lr", "sp", "pc", "pst"};
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700364#elif defined(__i386__)
365 static constexpr const char* special_registers[] = {"ebp", "esp", "eip"};
366#elif defined(__x86_64__)
367 static constexpr const char* special_registers[] = {"rbp", "rsp", "rip"};
368#else
369 static constexpr const char* special_registers[] = {};
370#endif
371
372 regs->IterateRegisters([log, &current_row, &special_row](const char* name, uint64_t value) {
373 auto row = &current_row;
374 for (const char* special_name : special_registers) {
375 if (strcmp(special_name, name) == 0) {
376 row = &special_row;
377 break;
378 }
379 }
380
381 row->emplace_back(name, value);
382 if (current_row.size() == column_count) {
383 print_register_row(log, current_row);
384 current_row.clear();
385 }
386 });
387
388 if (!current_row.empty()) {
389 print_register_row(log, current_row);
390 }
391
392 print_register_row(log, special_row);
393}
394
Christopher Ferris60eb1972019-01-15 15:18:43 -0800395void dump_memory_and_code(log_t* log, unwindstack::Maps* maps, unwindstack::Memory* memory,
396 unwindstack::Regs* regs) {
397 regs->IterateRegisters([log, maps, memory](const char* reg_name, uint64_t reg_value) {
Elliott Hughese1415a52018-02-15 09:18:21 -0800398 std::string label{"memory near "s + reg_name};
Christopher Ferris60eb1972019-01-15 15:18:43 -0800399 if (maps) {
Christopher Ferrisc6776062021-01-15 15:59:28 -0800400 auto map_info = maps->Find(untag_address(reg_value));
David Srbeckyd8ab48b2021-05-13 00:03:26 +0100401 if (map_info != nullptr && !map_info->name().empty()) {
402 label += " (" + map_info->name() + ")";
Christopher Ferris60eb1972019-01-15 15:18:43 -0800403 }
Elliott Hughese1415a52018-02-15 09:18:21 -0800404 }
405 dump_memory(log, memory, reg_value, label);
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700406 });
407}
408
Christopher Ferris60eb1972019-01-15 15:18:43 -0800409static bool dump_thread(log_t* log, unwindstack::Unwinder* unwinder, const ThreadInfo& thread_info,
Peter Collingbourne843f7e62020-02-28 19:07:33 -0800410 const ProcessInfo& process_info, bool primary_thread) {
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700411 log->current_tid = thread_info.tid;
Josh Gao7c89f9e2016-01-13 17:57:14 -0800412 if (!primary_thread) {
Brigid Smith62ba4892014-06-10 11:53:08 -0700413 _LOG(log, logtype::THREAD, "--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---\n");
Josh Gao7c89f9e2016-01-13 17:57:14 -0800414 }
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700415 dump_thread_info(log, thread_info);
Christopher Ferris20303f82014-01-10 16:33:16 -0800416
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700417 if (thread_info.siginfo) {
Peter Collingbournef03af882020-03-20 18:09:00 -0700418 dump_signal_info(log, thread_info, process_info, unwinder->GetProcessMemory().get());
Mitch Phillipse0b4bb12020-02-14 14:54:31 -0800419 }
420
Peter Collingbourne843f7e62020-02-28 19:07:33 -0800421 if (primary_thread) {
Christopher Ferris2b98c822021-09-28 15:50:04 -0700422 // The main thread must have a valid siginfo.
423 CHECK(thread_info.siginfo != nullptr);
Christopher Ferris7aad2562021-09-24 00:06:38 -0700424 dump_probable_cause(log, unwinder, process_info, thread_info);
Peter Collingbourne843f7e62020-02-28 19:07:33 -0800425
Peter Collingbourne843f7e62020-02-28 19:07:33 -0800426 dump_abort_message(log, unwinder->GetProcessMemory().get(), process_info.abort_msg_address);
Josh Gao34c25562017-12-22 14:18:39 -0800427 }
428
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700429 dump_registers(log, thread_info.registers.get());
430
Josh Gao5d1c14f2018-04-20 12:04:41 -0700431 // Unwind will mutate the registers, so make a copy first.
Christopher Ferris60eb1972019-01-15 15:18:43 -0800432 std::unique_ptr<unwindstack::Regs> regs_copy(thread_info.registers->Clone());
433 unwinder->SetRegs(regs_copy.get());
434 unwinder->Unwind();
435 if (unwinder->NumFrames() == 0) {
Christopher Ferrisb05c4722020-09-23 15:51:46 -0700436 _LOG(log, logtype::THREAD, "Failed to unwind\n");
437 if (unwinder->LastErrorCode() != unwindstack::ERROR_NONE) {
438 _LOG(log, logtype::THREAD, " Error code: %s\n", unwinder->LastErrorCodeString());
439 _LOG(log, logtype::THREAD, " Error address: 0x%" PRIx64 "\n", unwinder->LastErrorAddress());
440 }
Christopher Ferris60eb1972019-01-15 15:18:43 -0800441 } else {
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700442 _LOG(log, logtype::BACKTRACE, "\nbacktrace:\n");
Christopher Ferris4ae266c2019-04-03 09:27:12 -0700443 log_backtrace(log, unwinder, " ");
Josh Gao7c89f9e2016-01-13 17:57:14 -0800444 }
Brigid Smith62ba4892014-06-10 11:53:08 -0700445
Josh Gao7c89f9e2016-01-13 17:57:14 -0800446 if (primary_thread) {
Christopher Ferris7aad2562021-09-24 00:06:38 -0700447 GwpAsanCrashData gwp_asan_crash_data(unwinder->GetProcessMemory().get(), process_info,
448 thread_info);
449
450 if (gwp_asan_crash_data.HasDeallocationTrace()) {
451 gwp_asan_crash_data.DumpDeallocationTrace(log, unwinder);
Mitch Phillipse0b4bb12020-02-14 14:54:31 -0800452 }
453
Christopher Ferris7aad2562021-09-24 00:06:38 -0700454 if (gwp_asan_crash_data.HasAllocationTrace()) {
455 gwp_asan_crash_data.DumpAllocationTrace(log, unwinder);
Mitch Phillipse0b4bb12020-02-14 14:54:31 -0800456 }
457
Christopher Ferris60eb1972019-01-15 15:18:43 -0800458 unwindstack::Maps* maps = unwinder->GetMaps();
459 dump_memory_and_code(log, maps, unwinder->GetProcessMemory().get(),
460 thread_info.registers.get());
461 if (maps != nullptr) {
Christopher Ferris7937a362018-01-18 11:15:49 -0800462 uint64_t addr = 0;
Mitch Phillipse4adff02021-01-21 20:41:50 -0800463 if (process_info.has_fault_address) {
464 addr = process_info.untagged_fault_address;
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700465 }
Christopher Ferris60eb1972019-01-15 15:18:43 -0800466 dump_all_maps(log, unwinder, addr);
Christopher Ferris20303f82014-01-10 16:33:16 -0800467 }
468 }
469
Josh Gao7c89f9e2016-01-13 17:57:14 -0800470 log->current_tid = log->crashed_tid;
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700471 return true;
Jeff Brown053b8652012-06-06 16:25:03 -0700472}
473
Christopher Ferris20303f82014-01-10 16:33:16 -0800474// Reads the contents of the specified log device, filters out the entries
475// that don't match the specified pid, and writes them to the tombstone file.
476//
Mark Salyzyn17e85c02014-06-27 15:55:19 -0700477// If "tail" is non-zero, log the last "tail" number of lines.
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700478static void dump_log_file(log_t* log, pid_t pid, const char* filename, unsigned int tail) {
Christopher Ferris20303f82014-01-10 16:33:16 -0800479 bool first = true;
Christopher Ferrisc637ada2018-07-13 16:55:38 -0700480 logger_list* logger_list;
Jeff Brown053b8652012-06-06 16:25:03 -0700481
Mark Salyzyn45ae4462014-07-25 12:25:48 -0700482 if (!log->should_retrieve_logcat) {
483 return;
484 }
485
Tom Cherry907b2d02020-03-23 13:40:10 -0700486 logger_list =
487 android_logger_list_open(android_name_to_log_id(filename), ANDROID_LOG_NONBLOCK, tail, pid);
Jeff Brown053b8652012-06-06 16:25:03 -0700488
Mark Salyzyn22b5cef2013-11-22 10:53:34 -0800489 if (!logger_list) {
Brigid Smith50eb5462014-06-18 14:17:57 -0700490 ALOGE("Unable to open %s: %s\n", filename, strerror(errno));
Christopher Ferris20303f82014-01-10 16:33:16 -0800491 return;
492 }
493
Christopher Ferris20303f82014-01-10 16:33:16 -0800494 while (true) {
Christopher Ferrisc637ada2018-07-13 16:55:38 -0700495 log_msg log_entry;
Mark Salyzyn22b5cef2013-11-22 10:53:34 -0800496 ssize_t actual = android_logger_list_read(logger_list, &log_entry);
497
Christopher Ferris20303f82014-01-10 16:33:16 -0800498 if (actual < 0) {
Mark Salyzyn22b5cef2013-11-22 10:53:34 -0800499 if (actual == -EINTR) {
Christopher Ferris20303f82014-01-10 16:33:16 -0800500 // interrupted by signal, retry
501 continue;
Mark Salyzyn22b5cef2013-11-22 10:53:34 -0800502 } else if (actual == -EAGAIN) {
Christopher Ferris20303f82014-01-10 16:33:16 -0800503 // non-blocking EOF; we're done
504 break;
505 } else {
Christopher Ferrisb36b5922015-06-17 18:35:59 -0700506 ALOGE("Error while reading log: %s\n", strerror(-actual));
Christopher Ferris20303f82014-01-10 16:33:16 -0800507 break;
508 }
509 } else if (actual == 0) {
Christopher Ferrisb36b5922015-06-17 18:35:59 -0700510 ALOGE("Got zero bytes while reading log: %s\n", strerror(errno));
Christopher Ferris20303f82014-01-10 16:33:16 -0800511 break;
Jeff Brown053b8652012-06-06 16:25:03 -0700512 }
513
Brigid Smith50eb5462014-06-18 14:17:57 -0700514 // NOTE: if you ALOGV something here, this will spin forever,
Christopher Ferris20303f82014-01-10 16:33:16 -0800515 // because you will be writing as fast as you're reading. Any
516 // high-frequency debug diagnostics should just be written to
517 // the tombstone file.
Jeff Brown053b8652012-06-06 16:25:03 -0700518
Christopher Ferris20303f82014-01-10 16:33:16 -0800519 if (first) {
Josh Gao76e1e302021-01-26 15:53:11 -0800520 _LOG(log, logtype::LOGS, "--------- %slog %s\n", tail ? "tail end of " : "", filename);
Christopher Ferris20303f82014-01-10 16:33:16 -0800521 first = false;
522 }
523
524 // Msg format is: <priority:1><tag:N>\0<message:N>\0
525 //
526 // We want to display it in the same format as "logcat -v threadtime"
527 // (although in this case the pid is redundant).
Mark Salyzyn989980c2014-05-14 12:37:22 -0700528 char timeBuf[32];
Christopher Ferrisc637ada2018-07-13 16:55:38 -0700529 time_t sec = static_cast<time_t>(log_entry.entry.sec);
Elliott Hughesa660cb32020-07-23 15:26:10 -0700530 tm tm;
531 localtime_r(&sec, &tm);
532 strftime(timeBuf, sizeof(timeBuf), "%m-%d %H:%M:%S", &tm);
Mark Salyzyn989980c2014-05-14 12:37:22 -0700533
Christopher Ferrisc637ada2018-07-13 16:55:38 -0700534 char* msg = log_entry.msg();
535 if (msg == nullptr) {
536 continue;
537 }
Mark Salyzyn22b5cef2013-11-22 10:53:34 -0800538 unsigned char prio = msg[0];
539 char* tag = msg + 1;
540 msg = tag + strlen(tag) + 1;
Christopher Ferris20303f82014-01-10 16:33:16 -0800541
542 // consume any trailing newlines
Mark Salyzynfca0bd12013-12-12 12:21:20 -0800543 char* nl = msg + strlen(msg) - 1;
544 while (nl >= msg && *nl == '\n') {
Mark Salyzyn17e85c02014-06-27 15:55:19 -0700545 *nl-- = '\0';
Christopher Ferris20303f82014-01-10 16:33:16 -0800546 }
547
Christopher Ferrisc637ada2018-07-13 16:55:38 -0700548 static const char* kPrioChars = "!.VDIWEFS";
Christopher Ferris20303f82014-01-10 16:33:16 -0800549 char prioChar = (prio < strlen(kPrioChars) ? kPrioChars[prio] : '?');
550
Mark Salyzynfca0bd12013-12-12 12:21:20 -0800551 // Look for line breaks ('\n') and display each text line
552 // on a separate line, prefixed with the header, like logcat does.
553 do {
554 nl = strchr(msg, '\n');
Christopher Ferrisc637ada2018-07-13 16:55:38 -0700555 if (nl != nullptr) {
Mark Salyzynfca0bd12013-12-12 12:21:20 -0800556 *nl = '\0';
557 ++nl;
558 }
559
Christopher Ferrisc637ada2018-07-13 16:55:38 -0700560 _LOG(log, logtype::LOGS, "%s.%03d %5d %5d %c %-8s: %s\n", timeBuf,
561 log_entry.entry.nsec / 1000000, log_entry.entry.pid, log_entry.entry.tid, prioChar, tag,
562 msg);
Mark Salyzynfca0bd12013-12-12 12:21:20 -0800563 } while ((msg = nl));
Christopher Ferris20303f82014-01-10 16:33:16 -0800564 }
Jeff Brown053b8652012-06-06 16:25:03 -0700565
Mark Salyzyn22b5cef2013-11-22 10:53:34 -0800566 android_logger_list_free(logger_list);
Jeff Brown053b8652012-06-06 16:25:03 -0700567}
568
Christopher Ferris20303f82014-01-10 16:33:16 -0800569// Dumps the logs generated by the specified pid to the tombstone, from both
570// "system" and "main" log devices. Ideally we'd interleave the output.
Mark Salyzyn17e85c02014-06-27 15:55:19 -0700571static void dump_logs(log_t* log, pid_t pid, unsigned int tail) {
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700572 if (pid == getpid()) {
573 // Cowardly refuse to dump logs while we're running in-process.
574 return;
575 }
576
Mark Salyzyn22b5cef2013-11-22 10:53:34 -0800577 dump_log_file(log, pid, "system", tail);
578 dump_log_file(log, pid, "main", tail);
Jeff Brown053b8652012-06-06 16:25:03 -0700579}
580
Josh Gao76e1e302021-01-26 15:53:11 -0800581void engrave_tombstone_ucontext(int tombstone_fd, int proto_fd, uint64_t abort_msg_address,
582 siginfo_t* siginfo, ucontext_t* ucontext) {
Misha Wagner39c5b8c2019-04-18 16:07:33 +0100583 pid_t uid = getuid();
Josh Gaoe1aa0ca2017-03-01 17:23:22 -0800584 pid_t pid = getpid();
585 pid_t tid = gettid();
586
Josh Gaoe73c9322017-02-08 16:06:26 -0800587 log_t log;
588 log.current_tid = tid;
589 log.crashed_tid = tid;
590 log.tfd = tombstone_fd;
591 log.amfd_data = nullptr;
592
Elliott Hughesa660cb32020-07-23 15:26:10 -0700593 std::string thread_name = get_thread_name(tid);
Josh Gao31348a72021-03-29 21:53:42 -0700594 std::vector<std::string> command_line = get_command_line(pid);
Josh Gao57f58f82017-03-15 23:23:22 -0700595
Christopher Ferris60eb1972019-01-15 15:18:43 -0800596 std::unique_ptr<unwindstack::Regs> regs(
597 unwindstack::Regs::CreateFromUcontext(unwindstack::Regs::CurrentArch(), ucontext));
Josh Gaoe73c9322017-02-08 16:06:26 -0800598
Josh Gao76e1e302021-01-26 15:53:11 -0800599 std::string selinux_label;
600 android::base::ReadFileToString("/proc/self/attr/current", &selinux_label);
601
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700602 std::map<pid_t, ThreadInfo> threads;
Elliott Hughesa660cb32020-07-23 15:26:10 -0700603 threads[tid] = ThreadInfo{
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700604 .registers = std::move(regs),
Misha Wagner39c5b8c2019-04-18 16:07:33 +0100605 .uid = uid,
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700606 .tid = tid,
Josh Gao76e1e302021-01-26 15:53:11 -0800607 .thread_name = std::move(thread_name),
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700608 .pid = pid,
Josh Gao31348a72021-03-29 21:53:42 -0700609 .command_line = std::move(command_line),
Josh Gao76e1e302021-01-26 15:53:11 -0800610 .selinux_label = std::move(selinux_label),
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700611 .siginfo = siginfo,
612 };
Josh Gao77b00ed2017-05-05 18:11:23 -0700613
Christopher Ferrisb05c4722020-09-23 15:51:46 -0700614 unwindstack::UnwinderFromPid unwinder(kMaxFrames, pid, unwindstack::Regs::CurrentArch());
yidong zhangcbf7c462021-06-24 17:51:56 +0800615 auto process_memory =
616 unwindstack::Memory::CreateProcessMemoryCached(getpid());
617 unwinder.SetProcessMemory(process_memory);
Christopher Ferrisb05c4722020-09-23 15:51:46 -0700618 if (!unwinder.Init()) {
Josh Gao618cea32021-01-26 17:45:43 -0800619 async_safe_fatal("failed to init unwinder object");
Josh Gaoe73c9322017-02-08 16:06:26 -0800620 }
Josh Gaofdc95c92017-09-13 15:33:39 -0700621
Peter Collingbourne843f7e62020-02-28 19:07:33 -0800622 ProcessInfo process_info;
623 process_info.abort_msg_address = abort_msg_address;
Josh Gao76e1e302021-01-26 15:53:11 -0800624 engrave_tombstone(unique_fd(dup(tombstone_fd)), unique_fd(dup(proto_fd)), &unwinder, threads, tid,
625 process_info, nullptr, nullptr);
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700626}
627
Josh Gao76e1e302021-01-26 15:53:11 -0800628void engrave_tombstone(unique_fd output_fd, unique_fd proto_fd, unwindstack::Unwinder* unwinder,
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700629 const std::map<pid_t, ThreadInfo>& threads, pid_t target_thread,
Peter Collingbourne843f7e62020-02-28 19:07:33 -0800630 const ProcessInfo& process_info, OpenFilesList* open_files,
631 std::string* amfd_data) {
Elliott Hughesa660cb32020-07-23 15:26:10 -0700632 // Don't copy log messages to tombstone unless this is a development device.
Josh Gao76e1e302021-01-26 15:53:11 -0800633 Tombstone tombstone;
634 engrave_tombstone_proto(&tombstone, unwinder, threads, target_thread, process_info, open_files);
635
Josh Gao618cea32021-01-26 17:45:43 -0800636 if (proto_fd != -1) {
637 if (!tombstone.SerializeToFileDescriptor(proto_fd.get())) {
638 async_safe_format_log(ANDROID_LOG_ERROR, LOG_TAG, "failed to write proto tombstone: %s",
639 strerror(errno));
640 }
Josh Gao76e1e302021-01-26 15:53:11 -0800641 }
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700642
643 log_t log;
644 log.current_tid = target_thread;
645 log.crashed_tid = target_thread;
646 log.tfd = output_fd.get();
647 log.amfd_data = amfd_data;
648
Josh Gao3be68742021-02-18 16:56:48 -0800649 bool translate_proto = GetBoolProperty("debug.debuggerd.translate_proto_to_text", true);
Josh Gao76e1e302021-01-26 15:53:11 -0800650 if (translate_proto) {
651 tombstone_proto_to_text(tombstone, [&log](const std::string& line, bool should_log) {
652 _LOG(&log, should_log ? logtype::HEADER : logtype::LOGS, "%s\n", line.c_str());
653 });
654 } else {
655 bool want_logs = GetBoolProperty("ro.debuggable", false);
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700656
Josh Gao76e1e302021-01-26 15:53:11 -0800657 _LOG(&log, logtype::HEADER,
658 "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n");
659 dump_header_info(&log);
660 _LOG(&log, logtype::HEADER, "Timestamp: %s\n", get_timestamp().c_str());
Mitch Phillipse0b4bb12020-02-14 14:54:31 -0800661
Josh Gao76e1e302021-01-26 15:53:11 -0800662 auto it = threads.find(target_thread);
663 if (it == threads.end()) {
Josh Gao618cea32021-01-26 17:45:43 -0800664 async_safe_fatal("failed to find target thread");
Josh Gaofdc95c92017-09-13 15:33:39 -0700665 }
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700666
Josh Gao76e1e302021-01-26 15:53:11 -0800667 dump_thread(&log, unwinder, it->second, process_info, true);
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700668
Josh Gao76e1e302021-01-26 15:53:11 -0800669 if (want_logs) {
670 dump_logs(&log, it->second.pid, 50);
671 }
Josh Gao2b2ae0c2017-08-21 14:31:17 -0700672
Josh Gao76e1e302021-01-26 15:53:11 -0800673 for (auto& [tid, thread_info] : threads) {
674 if (tid == target_thread) {
675 continue;
676 }
677
678 dump_thread(&log, unwinder, thread_info, process_info, false);
679 }
680
681 if (open_files) {
682 _LOG(&log, logtype::OPEN_FILES, "\nopen files:\n");
683 dump_open_files_list(&log, *open_files, " ");
684 }
685
686 if (want_logs) {
687 dump_logs(&log, it->second.pid, 0);
688 }
Josh Gaofdc95c92017-09-13 15:33:39 -0700689 }
Josh Gaoe73c9322017-02-08 16:06:26 -0800690}