src/os/aix/vm/vmError_aix.cpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #include "precompiled.hpp"
aoqi@0 26 #include "runtime/arguments.hpp"
aoqi@0 27 #include "runtime/os.hpp"
aoqi@0 28 #include "runtime/thread.hpp"
aoqi@0 29 #include "utilities/vmError.hpp"
aoqi@0 30
aoqi@0 31 #include <sys/types.h>
aoqi@0 32 #include <sys/wait.h>
aoqi@0 33 #include <unistd.h>
aoqi@0 34 #include <signal.h>
aoqi@0 35
aoqi@0 36 void VMError::show_message_box(char *buf, int buflen) {
aoqi@0 37 bool yes;
aoqi@0 38 do {
aoqi@0 39 error_string(buf, buflen);
aoqi@0 40 int len = (int)strlen(buf);
aoqi@0 41 char *p = &buf[len];
aoqi@0 42
aoqi@0 43 jio_snprintf(p, buflen - len,
aoqi@0 44 "\n\n"
aoqi@0 45 "Do you want to debug the problem?\n\n"
aoqi@0 46 "To debug, run 'dbx -a %d'; then switch to thread tid " INTX_FORMAT ", k-tid " INTX_FORMAT "\n"
aoqi@0 47 "Enter 'yes' to launch dbx automatically (PATH must include dbx)\n"
aoqi@0 48 "Otherwise, press RETURN to abort...",
aoqi@0 49 os::current_process_id(),
aoqi@0 50 os::current_thread_id(), thread_self());
aoqi@0 51
aoqi@0 52 yes = os::message_box("Unexpected Error", buf);
aoqi@0 53
aoqi@0 54 if (yes) {
aoqi@0 55 // yes, user asked VM to launch debugger
aoqi@0 56 jio_snprintf(buf, buflen, "dbx -a %d", os::current_process_id());
aoqi@0 57
aoqi@0 58 os::fork_and_exec(buf);
aoqi@0 59 yes = false;
aoqi@0 60 }
aoqi@0 61 } while (yes);
aoqi@0 62 }
aoqi@0 63
aoqi@0 64 // Handle all synchronous signals which may happen during signal handling,
aoqi@0 65 // not just SIGSEGV and SIGBUS.
aoqi@0 66 static const int SIGNALS[] = { SIGSEGV, SIGBUS, SIGILL, SIGFPE, SIGTRAP }; // add more if needed
aoqi@0 67 static const int NUM_SIGNALS = sizeof(SIGNALS) / sizeof(int);
aoqi@0 68
aoqi@0 69 // Space for our "saved" signal flags and handlers
aoqi@0 70 static int resettedSigflags[NUM_SIGNALS];
aoqi@0 71 static address resettedSighandler[NUM_SIGNALS];
aoqi@0 72
aoqi@0 73 static void save_signal(int idx, int sig) {
aoqi@0 74 struct sigaction sa;
aoqi@0 75 sigaction(sig, NULL, &sa);
aoqi@0 76 resettedSigflags[idx] = sa.sa_flags;
aoqi@0 77 resettedSighandler[idx] = (sa.sa_flags & SA_SIGINFO)
aoqi@0 78 ? CAST_FROM_FN_PTR(address, sa.sa_sigaction)
aoqi@0 79 : CAST_FROM_FN_PTR(address, sa.sa_handler);
aoqi@0 80 }
aoqi@0 81
aoqi@0 82 int VMError::get_resetted_sigflags(int sig) {
aoqi@0 83 // Handle all program errors.
aoqi@0 84 for (int i = 0; i < NUM_SIGNALS; i++) {
aoqi@0 85 if (SIGNALS[i] == sig) {
aoqi@0 86 return resettedSigflags[i];
aoqi@0 87 }
aoqi@0 88 }
aoqi@0 89 return -1;
aoqi@0 90 }
aoqi@0 91
aoqi@0 92 address VMError::get_resetted_sighandler(int sig) {
aoqi@0 93 // Handle all program errors.
aoqi@0 94 for (int i = 0; i < NUM_SIGNALS; i++) {
aoqi@0 95 if (SIGNALS[i] == sig) {
aoqi@0 96 return resettedSighandler[i];
aoqi@0 97 }
aoqi@0 98 }
aoqi@0 99 return NULL;
aoqi@0 100 }
aoqi@0 101
aoqi@0 102 static void crash_handler(int sig, siginfo_t* info, void* ucVoid) {
aoqi@0 103 // Unmask current signal.
aoqi@0 104 sigset_t newset;
aoqi@0 105 sigemptyset(&newset);
aoqi@0 106 sigaddset(&newset, sig);
aoqi@0 107
aoqi@0 108 Unimplemented();
aoqi@0 109 }
aoqi@0 110
aoqi@0 111 void VMError::reset_signal_handlers() {
aoqi@0 112 sigset_t newset;
aoqi@0 113 sigemptyset(&newset);
aoqi@0 114
aoqi@0 115 for (int i = 0; i < NUM_SIGNALS; i++) {
aoqi@0 116 save_signal(i, SIGNALS[i]);
aoqi@0 117 os::signal(SIGNALS[i], CAST_FROM_FN_PTR(void *, crash_handler));
aoqi@0 118 sigaddset(&newset, SIGNALS[i]);
aoqi@0 119 }
aoqi@0 120
aoqi@0 121 sigthreadmask(SIG_UNBLOCK, &newset, NULL);
aoqi@0 122 }

mercurial