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