| OLD | NEW |
| 1 #include "CrashHandler.h" | 1 #include "CrashHandler.h" |
| 2 | 2 |
| 3 #include "SkTypes.h" | 3 #include "SkTypes.h" |
| 4 | 4 |
| 5 #include <stdio.h> | 5 #include <stdio.h> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 #include <signal.h> | 7 #include <signal.h> |
| 8 | 8 |
| 9 #if defined(SK_BUILD_FOR_MAC) | 9 #if defined(SK_BUILD_FOR_MAC) |
| 10 | 10 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 abi::__cxa_demangle(mangled, demangled, &len, &ok); | 32 abi::__cxa_demangle(mangled, demangled, &len, &ok); |
| 33 | 33 |
| 34 fprintf(stderr, "%s (+0x%zx)\n", ok == 0 ? demangled : mangled, (size_t)
offset); | 34 fprintf(stderr, "%s (+0x%zx)\n", ok == 0 ? demangled : mangled, (size_t)
offset); |
| 35 } | 35 } |
| 36 fprintf(stderr, "\n"); | 36 fprintf(stderr, "\n"); |
| 37 | 37 |
| 38 // Exit NOW. Don't notify other threads, don't call anything registered wit
h atexit(). | 38 // Exit NOW. Don't notify other threads, don't call anything registered wit
h atexit(). |
| 39 _Exit(sig); | 39 _Exit(sig); |
| 40 } | 40 } |
| 41 | 41 |
| 42 #elif defined(SK_BUILD_FOR_UNIX) | 42 #elif defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUILD_FOR_NACL) // NACL doesn'
t have backtrace(). |
| 43 | 43 |
| 44 // We'd use libunwind here too, but it's a pain to get installed for both 32 and
64 bit on bots. | 44 // We'd use libunwind here too, but it's a pain to get installed for both 32 and
64 bit on bots. |
| 45 // Doesn't matter much: catchsegv is best anyway. | 45 // Doesn't matter much: catchsegv is best anyway. |
| 46 #include <execinfo.h> | 46 #include <execinfo.h> |
| 47 | 47 |
| 48 static void handler(int sig) { | 48 static void handler(int sig) { |
| 49 static const int kMax = 64; | 49 static const int kMax = 64; |
| 50 void* stack[kMax]; | 50 void* stack[kMax]; |
| 51 const int count = backtrace(stack, kMax); | 51 const int count = backtrace(stack, kMax); |
| 52 | 52 |
| 53 fprintf(stderr, "\nSignal %d:\n", sig); | 53 fprintf(stderr, "\nSignal %d:\n", sig); |
| 54 backtrace_symbols_fd(stack, count, 2/*stderr*/); | 54 backtrace_symbols_fd(stack, count, 2/*stderr*/); |
| 55 | 55 |
| 56 // Exit NOW. Don't notify other threads, don't call anything registered wit
h atexit(). | 56 // Exit NOW. Don't notify other threads, don't call anything registered wit
h atexit(). |
| 57 _Exit(sig); | 57 _Exit(sig); |
| 58 } | 58 } |
| 59 | 59 |
| 60 #endif | 60 #endif |
| 61 | 61 |
| 62 #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) | 62 #if defined(SK_BUILD_FOR_MAC) || (defined(SK_BUILD_FOR_UNIX) && !defined(SK_BUIL
D_FOR_NACL)) |
| 63 | 63 |
| 64 void SetupCrashHandler() { | 64 void SetupCrashHandler() { |
| 65 static const int kSignals[] = { | 65 static const int kSignals[] = { |
| 66 SIGABRT, | 66 SIGABRT, |
| 67 SIGBUS, | 67 SIGBUS, |
| 68 SIGFPE, | 68 SIGFPE, |
| 69 SIGILL, | 69 SIGILL, |
| 70 SIGSEGV, | 70 SIGSEGV, |
| 71 }; | 71 }; |
| 72 | 72 |
| 73 for (size_t i = 0; i < sizeof(kSignals) / sizeof(kSignals[0]); i++) { | 73 for (size_t i = 0; i < sizeof(kSignals) / sizeof(kSignals[0]); i++) { |
| 74 // Register our signal handler unless something's already done so (e.g.
catchsegv). | 74 // Register our signal handler unless something's already done so (e.g.
catchsegv). |
| 75 void (*prev)(int) = signal(kSignals[i], handler); | 75 void (*prev)(int) = signal(kSignals[i], handler); |
| 76 if (prev != SIG_DFL) { | 76 if (prev != SIG_DFL) { |
| 77 signal(kSignals[i], prev); | 77 signal(kSignals[i], prev); |
| 78 } | 78 } |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 // TODO: #elif defined(SK_BUILD_FOR_WIN) when I find a Windows machine to work f
rom. | 82 // TODO: #elif defined(SK_BUILD_FOR_WIN) when I find a Windows machine to work f
rom. |
| 83 | 83 |
| 84 #else | 84 #else |
| 85 | 85 |
| 86 void SetupCrashHandler() { } | 86 void SetupCrashHandler() { } |
| 87 | 87 |
| 88 #endif | 88 #endif |
| OLD | NEW |