OLD | NEW |
| 1 /* |
| 2 * Copyright 2014 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
1 #include "CrashHandler.h" | 8 #include "CrashHandler.h" |
2 | 9 |
3 #include "SkTypes.h" | 10 #include "SkTypes.h" |
4 | 11 |
5 #include <stdlib.h> | 12 #include <stdlib.h> |
6 | 13 |
7 // Disable SetupCrashHandler() unless SK_CRASH_HANDLER is defined. | 14 // Disable SetupCrashHandler() unless SK_CRASH_HANDLER is defined. |
8 #ifndef SK_CRASH_HANDLER | 15 #ifndef SK_CRASH_HANDLER |
9 void SetupCrashHandler() { } | 16 void SetupCrashHandler() { } |
10 | 17 |
(...skipping 29 matching lines...) Expand all Loading... |
40 abi::__cxa_demangle(mangled, demangled, &len, &ok); | 47 abi::__cxa_demangle(mangled, demangled, &len, &ok); |
41 | 48 |
42 SkDebugf("%s (+0x%zx)\n", ok == 0 ? demangled : mangled, (size_t
)offset); | 49 SkDebugf("%s (+0x%zx)\n", ok == 0 ? demangled : mangled, (size_t
)offset); |
43 } | 50 } |
44 SkDebugf("\n"); | 51 SkDebugf("\n"); |
45 | 52 |
46 // Exit NOW. Don't notify other threads, don't call anything regist
ered with atexit(). | 53 // Exit NOW. Don't notify other threads, don't call anything regist
ered with atexit(). |
47 _Exit(sig); | 54 _Exit(sig); |
48 } | 55 } |
49 | 56 |
50 #elif defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_NACL) // NACL doe
sn't have backtrace. | 57 #elif defined(SK_BUILD_FOR_UNIX) |
51 | 58 |
52 // We'd use libunwind here too, but it's a pain to get installed for | 59 // We'd use libunwind here too, but it's a pain to get installed for |
53 // both 32 and 64 bit on bots. Doesn't matter much: catchsegv is best a
nyway. | 60 // both 32 and 64 bit on bots. Doesn't matter much: catchsegv is best a
nyway. |
54 #include <execinfo.h> | 61 #include <execinfo.h> |
55 | 62 |
56 static void handler(int sig) { | 63 static void handler(int sig) { |
57 static const int kMax = 64; | 64 static const int kMax = 64; |
58 void* stack[kMax]; | 65 void* stack[kMax]; |
59 const int count = backtrace(stack, kMax); | 66 const int count = backtrace(stack, kMax); |
60 | 67 |
61 SkDebugf("\nSignal %d [%s]:\n", sig, strsignal(sig)); | 68 SkDebugf("\nSignal %d [%s]:\n", sig, strsignal(sig)); |
62 backtrace_symbols_fd(stack, count, 2/*stderr*/); | 69 backtrace_symbols_fd(stack, count, 2/*stderr*/); |
63 | 70 |
64 // Exit NOW. Don't notify other threads, don't call anything regist
ered with atexit(). | 71 // Exit NOW. Don't notify other threads, don't call anything regist
ered with atexit(). |
65 _Exit(sig); | 72 _Exit(sig); |
66 } | 73 } |
67 | 74 |
68 #endif | 75 #endif |
69 | 76 |
70 #if (defined(SK_BUILD_FOR_MAC) || (defined(SK_BUILD_FOR_UNIX) && !defined(SK
_BUILD_FOR_NACL))) | 77 #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_UNIX) |
71 #include <signal.h> | 78 #include <signal.h> |
72 | 79 |
73 void SetupCrashHandler() { | 80 void SetupCrashHandler() { |
74 static const int kSignals[] = { | 81 static const int kSignals[] = { |
75 SIGABRT, | 82 SIGABRT, |
76 SIGBUS, | 83 SIGBUS, |
77 SIGFPE, | 84 SIGFPE, |
78 SIGILL, | 85 SIGILL, |
79 SIGSEGV, | 86 SIGSEGV, |
80 }; | 87 }; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 void SetupCrashHandler() { | 183 void SetupCrashHandler() { |
177 SetUnhandledExceptionFilter(handler); | 184 SetUnhandledExceptionFilter(handler); |
178 } | 185 } |
179 | 186 |
180 #else // We asked for SK_CRASH_HANDLER, but it's not Mac, Linux, or Windows
. Sorry! | 187 #else // We asked for SK_CRASH_HANDLER, but it's not Mac, Linux, or Windows
. Sorry! |
181 | 188 |
182 void SetupCrashHandler() { } | 189 void SetupCrashHandler() { } |
183 | 190 |
184 #endif | 191 #endif |
185 #endif // SK_CRASH_HANDLER | 192 #endif // SK_CRASH_HANDLER |
OLD | NEW |