duke@435: /* stefank@2314: * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "runtime/arguments.hpp" stefank@2314: #include "runtime/os.hpp" stefank@2314: #include "runtime/thread.hpp" stefank@2314: #include "utilities/vmError.hpp" duke@435: duke@435: duke@435: void VMError::show_message_box(char *buf, int buflen) { duke@435: bool yes; duke@435: do { duke@435: error_string(buf, buflen); duke@435: int len = (int)strlen(buf); duke@435: char *p = &buf[len]; duke@435: duke@435: jio_snprintf(p, buflen - len, duke@435: "\n\n" duke@435: "Do you want to debug the problem?\n\n" duke@435: "To debug, attach Visual Studio to process %d; then switch to thread 0x%x\n" duke@435: "Select 'Yes' to launch Visual Studio automatically (PATH must include msdev)\n" duke@435: "Otherwise, select 'No' to abort...", duke@435: os::current_process_id(), os::current_thread_id()); duke@435: duke@435: yes = os::message_box("Unexpected Error", buf) != 0; duke@435: duke@435: if (yes) { duke@435: // yes, user asked VM to launch debugger duke@435: // duke@435: // os::breakpoint() calls DebugBreak(), which causes a breakpoint duke@435: // exception. If VM is running inside a debugger, the debugger will duke@435: // catch the exception. Otherwise, the breakpoint exception will reach duke@435: // the default windows exception handler, which can spawn a debugger and duke@435: // automatically attach to the dying VM. duke@435: os::breakpoint(); duke@435: yes = false; duke@435: } duke@435: } while (yes); duke@435: } duke@435: duke@435: int VMError::get_resetted_sigflags(int sig) { duke@435: return -1; duke@435: } duke@435: duke@435: address VMError::get_resetted_sighandler(int sig) { duke@435: return NULL; duke@435: } duke@435: duke@435: LONG WINAPI crash_handler(struct _EXCEPTION_POINTERS* exceptionInfo) { duke@435: DWORD exception_code = exceptionInfo->ExceptionRecord->ExceptionCode; duke@435: VMError err(NULL, exception_code, NULL, duke@435: exceptionInfo->ExceptionRecord, exceptionInfo->ContextRecord); duke@435: err.report_and_die(); duke@435: return EXCEPTION_CONTINUE_SEARCH; duke@435: } duke@435: duke@435: void VMError::reset_signal_handlers() { duke@435: SetUnhandledExceptionFilter(crash_handler); duke@435: }