aboutsummaryrefslogtreecommitdiffhomepage
path: root/dm/DM.cpp
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2016-10-24 11:39:43 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-10-24 16:49:18 +0000
commit3cc2d2050983bd3bbab4bf4cc714fa4d7199c959 (patch)
tree79cb8f030fdb8990a4a2d6d336825d4151f38c3d /dm/DM.cpp
parenta8834bb323302bc18f373ad18214d9d96e7af4c9 (diff)
Print what crashed DM on Android too.
This doesn't print a backtrace, but it's better than nothing. By preserving the original signal handler and calling into that, we keep the Android system stack trace, visible in logcat, the "dump log" step on bots. Tested locally on Mac and Android by making an arbitrary GM segfault. BUG=skia:5876 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=3860 Change-Id: Ia7a962ca50e09d370423a6106033e34c47d7643d Reviewed-on: https://skia-review.googlesource.com/3860 Reviewed-by: Matt Sarett <msarett@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'dm/DM.cpp')
-rw-r--r--dm/DM.cpp47
1 files changed, 28 insertions, 19 deletions
diff --git a/dm/DM.cpp b/dm/DM.cpp
index 4e66261287..36808ad168 100644
--- a/dm/DM.cpp
+++ b/dm/DM.cpp
@@ -173,18 +173,16 @@ static void print_status() {
}
}
-#if !defined(SK_BUILD_FOR_ANDROID)
- static void find_culprit() {
- // Assumes gMutex is locked.
- SkThreadID thisThread = SkGetThreadID();
- for (auto& task : gRunning) {
- if (task.thread == thisThread) {
- info("Likely culprit:\n");
- task.dump();
- }
+static void find_culprit() {
+ // Assumes gMutex is locked.
+ SkThreadID thisThread = SkGetThreadID();
+ for (auto& task : gRunning) {
+ if (task.thread == thisThread) {
+ info("Likely culprit:\n");
+ task.dump();
}
}
-#endif
+}
#if defined(SK_BUILD_FOR_WIN32)
static LONG WINAPI crash_handler(EXCEPTION_POINTERS* e) {
@@ -220,12 +218,23 @@ static void print_status() {
// Execute default exception handler... hopefully, exit.
return EXCEPTION_EXECUTE_HANDLER;
}
- static void setup_crash_handler() { SetUnhandledExceptionFilter(crash_handler); }
-#elif !defined(SK_BUILD_FOR_ANDROID)
- #include <execinfo.h>
+ static void setup_crash_handler() {
+ SetUnhandledExceptionFilter(crash_handler);
+ }
+#else
#include <signal.h>
- #include <stdlib.h>
+ #if !defined(SK_BUILD_FOR_ANDROID)
+ #include <execinfo.h>
+ #endif
+
+ static constexpr int max_of() { return 0; }
+ template <typename... Rest>
+ static constexpr int max_of(int x, Rest... rest) {
+ return x > max_of(rest...) ? x : max_of(rest...);
+ }
+
+ static void (*previous_handler[max_of(SIGABRT,SIGBUS,SIGFPE,SIGILL,SIGSEGV)+1])(int);
static void crash_handler(int sig) {
SkAutoMutexAcquire lock(gMutex);
@@ -236,6 +245,7 @@ static void print_status() {
}
find_culprit();
+ #if !defined(SK_BUILD_FOR_ANDROID)
void* stack[64];
int count = backtrace(stack, SK_ARRAY_COUNT(stack));
char** symbols = backtrace_symbols(stack, count);
@@ -243,20 +253,19 @@ static void print_status() {
for (int i = 0; i < count; i++) {
info(" %s\n", symbols[i]);
}
+ #endif
fflush(stdout);
- _Exit(sig);
+ signal(sig, previous_handler[sig]);
+ raise(sig);
}
static void setup_crash_handler() {
const int kSignals[] = { SIGABRT, SIGBUS, SIGFPE, SIGILL, SIGSEGV };
for (int sig : kSignals) {
- signal(sig, crash_handler);
+ previous_handler[sig] = signal(sig, crash_handler);
}
}
-
-#else // Android
- static void setup_crash_handler() {}
#endif
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/