Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 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 | */ |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 16 | |
| 17 | #include "runtime.h" |
| 18 | |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 19 | #include <signal.h> |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 20 | #include <string.h> |
Elliott Hughes | 058a6de | 2012-05-24 19:13:02 -0700 | [diff] [blame] | 21 | #include <sys/utsname.h> |
Dmitry Petrochenko | 611c2c3 | 2014-02-10 14:48:12 +0700 | [diff] [blame] | 22 | #include <inttypes.h> |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 23 | |
Elliott Hughes | 07ed66b | 2012-12-12 18:34:25 -0800 | [diff] [blame] | 24 | #include "base/logging.h" |
Elliott Hughes | 76b6167 | 2012-12-12 17:47:30 -0800 | [diff] [blame] | 25 | #include "base/mutex.h" |
Elliott Hughes | e222ee0 | 2012-12-13 14:41:43 -0800 | [diff] [blame] | 26 | #include "base/stringprintf.h" |
Ian Rogers | b48b9eb | 2014-02-28 16:20:21 -0800 | [diff] [blame] | 27 | #include "thread-inl.h" |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 28 | #include "utils.h" |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 29 | |
| 30 | namespace art { |
| 31 | |
Mathieu Chartier | c2f4d02 | 2014-03-03 16:11:42 -0800 | [diff] [blame] | 32 | static constexpr bool kDumpHeapObjectOnSigsevg = false; |
| 33 | |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 34 | struct Backtrace { |
| 35 | void Dump(std::ostream& os) { |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 36 | DumpNativeStack(os, GetTid(), "\t", true); |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 37 | } |
| 38 | }; |
| 39 | |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 40 | struct OsInfo { |
Elliott Hughes | 058a6de | 2012-05-24 19:13:02 -0700 | [diff] [blame] | 41 | void Dump(std::ostream& os) { |
| 42 | utsname info; |
| 43 | uname(&info); |
| 44 | // Linux 2.6.38.8-gg784 (x86_64) |
| 45 | // Darwin 11.4.0 (x86_64) |
| 46 | os << info.sysname << " " << info.release << " (" << info.machine << ")"; |
| 47 | } |
| 48 | }; |
| 49 | |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 50 | static const char* GetSignalName(int signal_number) { |
| 51 | switch (signal_number) { |
| 52 | case SIGABRT: return "SIGABRT"; |
| 53 | case SIGBUS: return "SIGBUS"; |
| 54 | case SIGFPE: return "SIGFPE"; |
| 55 | case SIGILL: return "SIGILL"; |
| 56 | case SIGPIPE: return "SIGPIPE"; |
| 57 | case SIGSEGV: return "SIGSEGV"; |
Elliott Hughes | 833770b | 2012-05-01 15:41:03 -0700 | [diff] [blame] | 58 | #if defined(SIGSTKFLT) |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 59 | case SIGSTKFLT: return "SIGSTKFLT"; |
| 60 | #endif |
| 61 | case SIGTRAP: return "SIGTRAP"; |
| 62 | } |
| 63 | return "??"; |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 66 | static const char* GetSignalCodeName(int signal_number, int signal_code) { |
| 67 | // Try the signal-specific codes... |
| 68 | switch (signal_number) { |
| 69 | case SIGILL: |
| 70 | switch (signal_code) { |
| 71 | case ILL_ILLOPC: return "ILL_ILLOPC"; |
| 72 | case ILL_ILLOPN: return "ILL_ILLOPN"; |
| 73 | case ILL_ILLADR: return "ILL_ILLADR"; |
| 74 | case ILL_ILLTRP: return "ILL_ILLTRP"; |
| 75 | case ILL_PRVOPC: return "ILL_PRVOPC"; |
| 76 | case ILL_PRVREG: return "ILL_PRVREG"; |
| 77 | case ILL_COPROC: return "ILL_COPROC"; |
| 78 | case ILL_BADSTK: return "ILL_BADSTK"; |
| 79 | } |
| 80 | break; |
| 81 | case SIGBUS: |
| 82 | switch (signal_code) { |
| 83 | case BUS_ADRALN: return "BUS_ADRALN"; |
| 84 | case BUS_ADRERR: return "BUS_ADRERR"; |
| 85 | case BUS_OBJERR: return "BUS_OBJERR"; |
| 86 | } |
| 87 | break; |
| 88 | case SIGFPE: |
| 89 | switch (signal_code) { |
| 90 | case FPE_INTDIV: return "FPE_INTDIV"; |
| 91 | case FPE_INTOVF: return "FPE_INTOVF"; |
| 92 | case FPE_FLTDIV: return "FPE_FLTDIV"; |
| 93 | case FPE_FLTOVF: return "FPE_FLTOVF"; |
| 94 | case FPE_FLTUND: return "FPE_FLTUND"; |
| 95 | case FPE_FLTRES: return "FPE_FLTRES"; |
| 96 | case FPE_FLTINV: return "FPE_FLTINV"; |
| 97 | case FPE_FLTSUB: return "FPE_FLTSUB"; |
| 98 | } |
| 99 | break; |
| 100 | case SIGSEGV: |
| 101 | switch (signal_code) { |
| 102 | case SEGV_MAPERR: return "SEGV_MAPERR"; |
| 103 | case SEGV_ACCERR: return "SEGV_ACCERR"; |
| 104 | } |
| 105 | break; |
| 106 | case SIGTRAP: |
| 107 | switch (signal_code) { |
| 108 | case TRAP_BRKPT: return "TRAP_BRKPT"; |
| 109 | case TRAP_TRACE: return "TRAP_TRACE"; |
| 110 | } |
| 111 | break; |
| 112 | } |
| 113 | // Then the other codes... |
| 114 | switch (signal_code) { |
| 115 | case SI_USER: return "SI_USER"; |
Elliott Hughes | ac8097f | 2012-04-16 14:59:44 -0700 | [diff] [blame] | 116 | #if defined(SI_KERNEL) |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 117 | case SI_KERNEL: return "SI_KERNEL"; |
Elliott Hughes | ac8097f | 2012-04-16 14:59:44 -0700 | [diff] [blame] | 118 | #endif |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 119 | case SI_QUEUE: return "SI_QUEUE"; |
| 120 | case SI_TIMER: return "SI_TIMER"; |
| 121 | case SI_MESGQ: return "SI_MESGQ"; |
| 122 | case SI_ASYNCIO: return "SI_ASYNCIO"; |
Elliott Hughes | ac8097f | 2012-04-16 14:59:44 -0700 | [diff] [blame] | 123 | #if defined(SI_SIGIO) |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 124 | case SI_SIGIO: return "SI_SIGIO"; |
Elliott Hughes | ac8097f | 2012-04-16 14:59:44 -0700 | [diff] [blame] | 125 | #endif |
| 126 | #if defined(SI_TKILL) |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 127 | case SI_TKILL: return "SI_TKILL"; |
Elliott Hughes | ac8097f | 2012-04-16 14:59:44 -0700 | [diff] [blame] | 128 | #endif |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 129 | } |
| 130 | // Then give up... |
| 131 | return "?"; |
| 132 | } |
| 133 | |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 134 | struct UContext { |
Elliott Hughes | 7484741 | 2012-06-20 18:10:21 -0700 | [diff] [blame] | 135 | explicit UContext(void* raw_context) : context(reinterpret_cast<ucontext_t*>(raw_context)->uc_mcontext) {} |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 136 | |
| 137 | void Dump(std::ostream& os) { |
| 138 | // TODO: support non-x86 hosts (not urgent because this code doesn't run on targets). |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 139 | #if defined(__APPLE__) && defined(__i386__) |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 140 | DumpRegister32(os, "eax", context->__ss.__eax); |
| 141 | DumpRegister32(os, "ebx", context->__ss.__ebx); |
| 142 | DumpRegister32(os, "ecx", context->__ss.__ecx); |
| 143 | DumpRegister32(os, "edx", context->__ss.__edx); |
| 144 | os << '\n'; |
| 145 | |
| 146 | DumpRegister32(os, "edi", context->__ss.__edi); |
| 147 | DumpRegister32(os, "esi", context->__ss.__esi); |
| 148 | DumpRegister32(os, "ebp", context->__ss.__ebp); |
| 149 | DumpRegister32(os, "esp", context->__ss.__esp); |
| 150 | os << '\n'; |
| 151 | |
| 152 | DumpRegister32(os, "eip", context->__ss.__eip); |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 153 | os << " "; |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 154 | DumpRegister32(os, "eflags", context->__ss.__eflags); |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 155 | DumpX86Flags(os, context->__ss.__eflags); |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 156 | os << '\n'; |
| 157 | |
| 158 | DumpRegister32(os, "cs", context->__ss.__cs); |
| 159 | DumpRegister32(os, "ds", context->__ss.__ds); |
| 160 | DumpRegister32(os, "es", context->__ss.__es); |
| 161 | DumpRegister32(os, "fs", context->__ss.__fs); |
| 162 | os << '\n'; |
| 163 | DumpRegister32(os, "gs", context->__ss.__gs); |
| 164 | DumpRegister32(os, "ss", context->__ss.__ss); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 165 | #elif defined(__linux__) && defined(__i386__) |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 166 | DumpRegister32(os, "eax", context.gregs[REG_EAX]); |
| 167 | DumpRegister32(os, "ebx", context.gregs[REG_EBX]); |
| 168 | DumpRegister32(os, "ecx", context.gregs[REG_ECX]); |
| 169 | DumpRegister32(os, "edx", context.gregs[REG_EDX]); |
| 170 | os << '\n'; |
| 171 | |
| 172 | DumpRegister32(os, "edi", context.gregs[REG_EDI]); |
| 173 | DumpRegister32(os, "esi", context.gregs[REG_ESI]); |
| 174 | DumpRegister32(os, "ebp", context.gregs[REG_EBP]); |
| 175 | DumpRegister32(os, "esp", context.gregs[REG_ESP]); |
| 176 | os << '\n'; |
| 177 | |
| 178 | DumpRegister32(os, "eip", context.gregs[REG_EIP]); |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 179 | os << " "; |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 180 | DumpRegister32(os, "eflags", context.gregs[REG_EFL]); |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 181 | DumpX86Flags(os, context.gregs[REG_EFL]); |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 182 | os << '\n'; |
| 183 | |
| 184 | DumpRegister32(os, "cs", context.gregs[REG_CS]); |
| 185 | DumpRegister32(os, "ds", context.gregs[REG_DS]); |
| 186 | DumpRegister32(os, "es", context.gregs[REG_ES]); |
| 187 | DumpRegister32(os, "fs", context.gregs[REG_FS]); |
| 188 | os << '\n'; |
| 189 | DumpRegister32(os, "gs", context.gregs[REG_GS]); |
| 190 | DumpRegister32(os, "ss", context.gregs[REG_SS]); |
Dmitry Petrochenko | 611c2c3 | 2014-02-10 14:48:12 +0700 | [diff] [blame] | 191 | #elif defined(__linux__) && defined(__x86_64__) |
| 192 | DumpRegister64(os, "rax", context.gregs[REG_RAX]); |
| 193 | DumpRegister64(os, "rbx", context.gregs[REG_RBX]); |
| 194 | DumpRegister64(os, "rcx", context.gregs[REG_RCX]); |
| 195 | DumpRegister64(os, "rdx", context.gregs[REG_RDX]); |
| 196 | os << '\n'; |
| 197 | |
| 198 | DumpRegister64(os, "rdi", context.gregs[REG_RDI]); |
| 199 | DumpRegister64(os, "rsi", context.gregs[REG_RSI]); |
| 200 | DumpRegister64(os, "rbp", context.gregs[REG_RBP]); |
| 201 | DumpRegister64(os, "rsp", context.gregs[REG_RSP]); |
| 202 | os << '\n'; |
| 203 | |
| 204 | DumpRegister64(os, "r8 ", context.gregs[REG_R8]); |
| 205 | DumpRegister64(os, "r9 ", context.gregs[REG_R9]); |
| 206 | DumpRegister64(os, "r10", context.gregs[REG_R10]); |
| 207 | DumpRegister64(os, "r11", context.gregs[REG_R11]); |
| 208 | os << '\n'; |
| 209 | |
| 210 | DumpRegister64(os, "r12", context.gregs[REG_R12]); |
| 211 | DumpRegister64(os, "r13", context.gregs[REG_R13]); |
| 212 | DumpRegister64(os, "r14", context.gregs[REG_R14]); |
| 213 | DumpRegister64(os, "r15", context.gregs[REG_R15]); |
| 214 | os << '\n'; |
| 215 | |
| 216 | DumpRegister64(os, "rip", context.gregs[REG_RIP]); |
| 217 | os << " "; |
| 218 | DumpRegister32(os, "eflags", context.gregs[REG_EFL]); |
| 219 | DumpX86Flags(os, context.gregs[REG_EFL]); |
| 220 | os << '\n'; |
| 221 | |
| 222 | DumpRegister32(os, "cs", (context.gregs[REG_CSGSFS]) & 0x0FFFF); |
| 223 | DumpRegister32(os, "gs", (context.gregs[REG_CSGSFS] >> 16) & 0x0FFFF); |
| 224 | DumpRegister32(os, "fs", (context.gregs[REG_CSGSFS] >> 32) & 0x0FFFF); |
| 225 | os << '\n'; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 226 | #else |
| 227 | os << "Unknown architecture/word size/OS in ucontext dump"; |
Elliott Hughes | ac8097f | 2012-04-16 14:59:44 -0700 | [diff] [blame] | 228 | #endif |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 229 | } |
| 230 | |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 231 | void DumpRegister32(std::ostream& os, const char* name, uint32_t value) { |
| 232 | os << StringPrintf(" %6s: 0x%08x", name, value); |
| 233 | } |
| 234 | |
Dmitry Petrochenko | 611c2c3 | 2014-02-10 14:48:12 +0700 | [diff] [blame] | 235 | void DumpRegister64(std::ostream& os, const char* name, uint64_t value) { |
| 236 | os << StringPrintf(" %6s: 0x%016" PRIx64, name, value); |
| 237 | } |
| 238 | |
Elliott Hughes | 46e251b | 2012-05-22 15:10:45 -0700 | [diff] [blame] | 239 | void DumpX86Flags(std::ostream& os, uint32_t flags) { |
| 240 | os << " ["; |
| 241 | if ((flags & (1 << 0)) != 0) { |
| 242 | os << " CF"; |
| 243 | } |
| 244 | if ((flags & (1 << 2)) != 0) { |
| 245 | os << " PF"; |
| 246 | } |
| 247 | if ((flags & (1 << 4)) != 0) { |
| 248 | os << " AF"; |
| 249 | } |
| 250 | if ((flags & (1 << 6)) != 0) { |
| 251 | os << " ZF"; |
| 252 | } |
| 253 | if ((flags & (1 << 7)) != 0) { |
| 254 | os << " SF"; |
| 255 | } |
| 256 | if ((flags & (1 << 8)) != 0) { |
| 257 | os << " TF"; |
| 258 | } |
| 259 | if ((flags & (1 << 9)) != 0) { |
| 260 | os << " IF"; |
| 261 | } |
| 262 | if ((flags & (1 << 10)) != 0) { |
| 263 | os << " DF"; |
| 264 | } |
| 265 | if ((flags & (1 << 11)) != 0) { |
| 266 | os << " OF"; |
| 267 | } |
| 268 | os << " ]"; |
| 269 | } |
| 270 | |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 271 | mcontext_t& context; |
| 272 | }; |
| 273 | |
Brian Carlstrom | af1b892 | 2012-11-27 15:19:57 -0800 | [diff] [blame] | 274 | void HandleUnexpectedSignal(int signal_number, siginfo_t* info, void* raw_context) { |
| 275 | static bool handlingUnexpectedSignal = false; |
| 276 | if (handlingUnexpectedSignal) { |
| 277 | LogMessageData data(__FILE__, __LINE__, INTERNAL_FATAL, -1); |
| 278 | LogMessage::LogLine(data, "HandleUnexpectedSignal reentered\n"); |
| 279 | _exit(1); |
| 280 | } |
| 281 | handlingUnexpectedSignal = true; |
| 282 | |
Ian Rogers | f08e473 | 2013-04-09 09:45:49 -0700 | [diff] [blame] | 283 | gAborting++; // set before taking any locks |
Ian Rogers | 50b35e2 | 2012-10-04 10:09:15 -0700 | [diff] [blame] | 284 | MutexLock mu(Thread::Current(), *Locks::unexpected_signal_lock_); |
Elliott Hughes | d06a6c7 | 2012-05-30 17:59:06 -0700 | [diff] [blame] | 285 | |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 286 | bool has_address = (signal_number == SIGILL || signal_number == SIGBUS || |
| 287 | signal_number == SIGFPE || signal_number == SIGSEGV); |
| 288 | |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 289 | OsInfo os_info; |
Elliott Hughes | 98eedd8 | 2012-06-11 17:52:56 -0700 | [diff] [blame] | 290 | const char* cmd_line = GetCmdLine(); |
| 291 | if (cmd_line == NULL) { |
Brian Carlstrom | 7934ac2 | 2013-07-26 10:54:15 -0700 | [diff] [blame] | 292 | cmd_line = "<unset>"; // Because no-one called InitLogging. |
Elliott Hughes | 98eedd8 | 2012-06-11 17:52:56 -0700 | [diff] [blame] | 293 | } |
Elliott Hughes | 289be85 | 2012-06-12 13:57:20 -0700 | [diff] [blame] | 294 | pid_t tid = GetTid(); |
| 295 | std::string thread_name(GetThreadName(tid)); |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 296 | UContext thread_context(raw_context); |
| 297 | Backtrace thread_backtrace; |
Elliott Hughes | 8593fdb | 2012-04-21 20:53:44 -0700 | [diff] [blame] | 298 | |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 299 | LOG(INTERNAL_FATAL) << "*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***\n" |
| 300 | << StringPrintf("Fatal signal %d (%s), code %d (%s)", |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 301 | signal_number, GetSignalName(signal_number), |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 302 | info->si_code, |
| 303 | GetSignalCodeName(signal_number, info->si_code)) |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 304 | << (has_address ? StringPrintf(" fault addr %p", info->si_addr) : "") << "\n" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 305 | << "OS: " << Dumpable<OsInfo>(os_info) << "\n" |
Elliott Hughes | 98eedd8 | 2012-06-11 17:52:56 -0700 | [diff] [blame] | 306 | << "Cmdline: " << cmd_line << "\n" |
Elliott Hughes | 289be85 | 2012-06-12 13:57:20 -0700 | [diff] [blame] | 307 | << "Thread: " << tid << " \"" << thread_name << "\"\n" |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 308 | << "Registers:\n" << Dumpable<UContext>(thread_context) << "\n" |
| 309 | << "Backtrace:\n" << Dumpable<Backtrace>(thread_backtrace); |
Mathieu Chartier | 15d3402 | 2014-02-26 17:16:38 -0800 | [diff] [blame] | 310 | Runtime* runtime = Runtime::Current(); |
| 311 | if (runtime != nullptr) { |
| 312 | gc::Heap* heap = runtime->GetHeap(); |
| 313 | LOG(INTERNAL_FATAL) << "Fault message: " << runtime->GetFaultMessage(); |
Mathieu Chartier | c2f4d02 | 2014-03-03 16:11:42 -0800 | [diff] [blame] | 314 | if (kDumpHeapObjectOnSigsevg && heap != nullptr && info != nullptr) { |
Mathieu Chartier | 15d3402 | 2014-02-26 17:16:38 -0800 | [diff] [blame] | 315 | LOG(INTERNAL_FATAL) << "Dump heap object at fault address: "; |
| 316 | heap->DumpObject(LOG(INTERNAL_FATAL), reinterpret_cast<mirror::Object*>(info->si_addr)); |
| 317 | } |
| 318 | } |
Elliott Hughes | 4909ba4 | 2012-06-14 13:33:49 -0700 | [diff] [blame] | 319 | if (getenv("debug_db_uid") != NULL || getenv("art_wait_for_gdb_on_crash") != NULL) { |
Elliott Hughes | 2554cb9 | 2012-04-18 17:19:26 -0700 | [diff] [blame] | 320 | LOG(INTERNAL_FATAL) << "********************************************************\n" |
Elliott Hughes | 289be85 | 2012-06-12 13:57:20 -0700 | [diff] [blame] | 321 | << "* Process " << getpid() << " thread " << tid << " \"" << thread_name << "\"" |
| 322 | << " has been suspended while crashing.\n" |
| 323 | << "* Attach gdb:\n" |
| 324 | << "* gdb -p " << tid << "\n" |
Elliott Hughes | 2554cb9 | 2012-04-18 17:19:26 -0700 | [diff] [blame] | 325 | << "********************************************************\n"; |
| 326 | // Wait for debugger to attach. |
| 327 | while (true) { |
| 328 | } |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 329 | } |
Elliott Hughes | d06a6c7 | 2012-05-30 17:59:06 -0700 | [diff] [blame] | 330 | |
| 331 | // Remove our signal handler for this signal... |
| 332 | struct sigaction action; |
| 333 | memset(&action, 0, sizeof(action)); |
| 334 | sigemptyset(&action.sa_mask); |
| 335 | action.sa_handler = SIG_DFL; |
| 336 | sigaction(signal_number, &action, NULL); |
| 337 | // ...and re-raise so we die with the appropriate status. |
| 338 | kill(getpid(), signal_number); |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 341 | void Runtime::InitPlatformSignalHandlers() { |
| 342 | // On the host, we don't have debuggerd to dump a stack for us when something unexpected happens. |
| 343 | struct sigaction action; |
| 344 | memset(&action, 0, sizeof(action)); |
| 345 | sigemptyset(&action.sa_mask); |
| 346 | action.sa_sigaction = HandleUnexpectedSignal; |
Elliott Hughes | 6c1c69e | 2012-04-23 16:12:51 -0700 | [diff] [blame] | 347 | // Use the three-argument sa_sigaction handler. |
| 348 | action.sa_flags |= SA_SIGINFO; |
Elliott Hughes | d06a6c7 | 2012-05-30 17:59:06 -0700 | [diff] [blame] | 349 | // Use the alternate signal stack so we can catch stack overflows. |
| 350 | action.sa_flags |= SA_ONSTACK; |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 351 | |
| 352 | int rc = 0; |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 353 | rc += sigaction(SIGABRT, &action, NULL); |
| 354 | rc += sigaction(SIGBUS, &action, NULL); |
| 355 | rc += sigaction(SIGFPE, &action, NULL); |
Elliott Hughes | 058a6de | 2012-05-24 19:13:02 -0700 | [diff] [blame] | 356 | rc += sigaction(SIGILL, &action, NULL); |
| 357 | rc += sigaction(SIGPIPE, &action, NULL); |
| 358 | rc += sigaction(SIGSEGV, &action, NULL); |
Elliott Hughes | ac8097f | 2012-04-16 14:59:44 -0700 | [diff] [blame] | 359 | #if defined(SIGSTKFLT) |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 360 | rc += sigaction(SIGSTKFLT, &action, NULL); |
Elliott Hughes | ac8097f | 2012-04-16 14:59:44 -0700 | [diff] [blame] | 361 | #endif |
Elliott Hughes | 058a6de | 2012-05-24 19:13:02 -0700 | [diff] [blame] | 362 | rc += sigaction(SIGTRAP, &action, NULL); |
Elliott Hughes | 457005c | 2012-04-16 13:54:25 -0700 | [diff] [blame] | 363 | CHECK_EQ(rc, 0); |
| 364 | } |
| 365 | |
Elliott Hughes | ffe6736 | 2011-07-17 12:09:27 -0700 | [diff] [blame] | 366 | } // namespace art |