Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(421)

Unified Diff: runtime/bin/platform_win.cc

Issue 2976063002: Add top-level exception handler on Windows to dump stack traces (Closed)
Patch Set: Added more comments and restoring of console Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | runtime/vm/profiler.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/bin/platform_win.cc
diff --git a/runtime/bin/platform_win.cc b/runtime/bin/platform_win.cc
index b0e8eabb1e78c9126fe2bcca2f76107c7c18a0f3..37e33c3055e117465d043b003033c7d8b2ec7dcf 100644
--- a/runtime/bin/platform_win.cc
+++ b/runtime/bin/platform_win.cc
@@ -62,6 +62,10 @@ class PlatformWin {
// CTRL_C_EVENT signal. This will only run when there is no signal handler
// registered for the CTRL_C_EVENT from Dart code.
SetConsoleCtrlHandler(SignalHandler, TRUE);
+#ifndef PRODUCT
+ // Set up global exception handler to be able to dump stack trace on crash.
+ SetExceptionHandler();
+#endif
}
static BOOL WINAPI SignalHandler(DWORD signal) {
@@ -106,6 +110,26 @@ class PlatformWin {
RestoreConsoleLocked();
}
+
+ // Windows top-level unhandled exception handler function.
+ // See MSDN documentation for UnhandledExceptionFilter.
+ // https://msdn.microsoft.com/en-us/library/windows/desktop/ms681401(v=vs.85).aspx
+ static LONG WINAPI
+ DartExceptionHandler(struct _EXCEPTION_POINTERS* ExceptionInfo) {
+ if (ExceptionInfo->ExceptionRecord->ExceptionCode ==
+ EXCEPTION_ACCESS_VIOLATION) {
+ Dart_DumpNativeStackTrace(ExceptionInfo->ContextRecord);
+ RestoreConsole();
+ abort();
+ }
+ return EXCEPTION_CONTINUE_SEARCH;
+ }
+
+
+ static void SetExceptionHandler() {
+ SetUnhandledExceptionFilter(DartExceptionHandler);
+ }
+
private:
static Mutex* platform_win_mutex_;
static int saved_output_cp_;
« no previous file with comments | « no previous file | runtime/vm/profiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698