|
1 #!/bin/bash |
|
2 |
|
3 # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. |
|
4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
5 # |
|
6 # This code is free software; you can redistribute it and/or modify it |
|
7 # under the terms of the GNU General Public License version 2 only, as |
|
8 # published by the Free Software Foundation. |
|
9 # |
|
10 # This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 # version 2 for more details (a copy is included in the LICENSE file that |
|
14 # accompanied this code). |
|
15 # |
|
16 # You should have received a copy of the GNU General Public License version |
|
17 # 2 along with this work; if not, write to the Free Software Foundation, |
|
18 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 # |
|
20 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
21 # or visit www.oracle.com if you need additional information or have any |
|
22 # questions. |
|
23 |
|
24 |
|
25 # This script launches HotSpot. |
|
26 # |
|
27 # If the first parameter is either "-gdb" or "-gud", HotSpot will be |
|
28 # launched inside gdb. "-gud" means "open an Emacs window and run gdb |
|
29 # inside Emacs". |
|
30 # |
|
31 # If the first parameter is "-dbx", HotSpot will be launched inside dbx. |
|
32 # |
|
33 # If the first parameter is "-valgrind", HotSpot will be launched |
|
34 # inside Valgrind (http://valgrind.kde.org) using the Memcheck skin, |
|
35 # and with memory leak detection enabled. This currently (2005jan19) |
|
36 # requires at least Valgrind 2.3.0. -Xmx16m will also be passed as |
|
37 # the first parameter to HotSpot, since lowering HotSpot's memory |
|
38 # consumption makes execution inside of Valgrind *a lot* faster. |
|
39 # |
|
40 |
|
41 |
|
42 # |
|
43 # User changeable parameters ------------------------------------------------ |
|
44 # |
|
45 |
|
46 # This is the name of the gdb binary to use |
|
47 if [ ! "$GDB" ] |
|
48 then |
|
49 GDB=gdb |
|
50 fi |
|
51 |
|
52 # This is the name of the gdb binary to use |
|
53 if [ ! "$DBX" ] |
|
54 then |
|
55 DBX=dbx |
|
56 fi |
|
57 |
|
58 # This is the name of the Valgrind binary to use |
|
59 if [ ! "$VALGRIND" ] |
|
60 then |
|
61 VALGRIND=valgrind |
|
62 fi |
|
63 |
|
64 # This is the name of Emacs for running GUD |
|
65 EMACS=emacs |
|
66 |
|
67 # |
|
68 # End of user changeable parameters ----------------------------------------- |
|
69 # |
|
70 |
|
71 # Make sure the paths are fully specified, i.e. they must begin with /. |
|
72 SCRIPT=$(cd $(dirname $0) && pwd)/$(basename $0) |
|
73 RUNDIR=$(pwd) |
|
74 |
|
75 # Look whether the user wants to run inside gdb |
|
76 case "$1" in |
|
77 -gdb) |
|
78 MODE=gdb |
|
79 shift |
|
80 ;; |
|
81 -gud) |
|
82 MODE=gud |
|
83 shift |
|
84 ;; |
|
85 -dbx) |
|
86 MODE=dbx |
|
87 shift |
|
88 ;; |
|
89 -valgrind) |
|
90 MODE=valgrind |
|
91 shift |
|
92 ;; |
|
93 *) |
|
94 MODE=run |
|
95 ;; |
|
96 esac |
|
97 |
|
98 if [ "${ALT_JAVA_HOME}" = "" ]; then |
|
99 if [ "${JAVA_HOME}" = "" ]; then |
|
100 echo "Neither ALT_JAVA_HOME nor JAVA_HOME is set. Aborting."; |
|
101 exit 1; |
|
102 else |
|
103 JDK=${JAVA_HOME%%/jre}; |
|
104 fi |
|
105 else |
|
106 JDK=${ALT_JAVA_HOME%%/jre}; |
|
107 fi |
|
108 |
|
109 # We will set the LD_LIBRARY_PATH as follows: |
|
110 # o $JVMPATH (directory portion only) |
|
111 # o $JRE/lib/$ARCH |
|
112 # followed by the user's previous effective LD_LIBRARY_PATH, if |
|
113 # any. |
|
114 JRE=$JDK/jre |
|
115 JAVA_HOME=$JDK |
|
116 ARCH=@@LIBARCH@@ |
|
117 |
|
118 # Find out the absolute path to this script |
|
119 MYDIR=$(cd $(dirname $SCRIPT) && pwd) |
|
120 |
|
121 SBP=${MYDIR}:${JRE}/lib/${ARCH} |
|
122 |
|
123 # Set up a suitable LD_LIBRARY_PATH |
|
124 |
|
125 if [ -z "$LD_LIBRARY_PATH" ] |
|
126 then |
|
127 LD_LIBRARY_PATH="$SBP" |
|
128 else |
|
129 LD_LIBRARY_PATH="$SBP:$LD_LIBRARY_PATH" |
|
130 fi |
|
131 |
|
132 export LD_LIBRARY_PATH |
|
133 export JAVA_HOME |
|
134 |
|
135 JPARMS="$@ $JAVA_ARGS"; |
|
136 |
|
137 # Locate the gamma development launcher |
|
138 LAUNCHER=${MYDIR}/gamma |
|
139 if [ ! -x $LAUNCHER ] ; then |
|
140 echo Error: Cannot find the gamma development launcher \"$LAUNCHER\" |
|
141 exit 1 |
|
142 fi |
|
143 |
|
144 GDBSRCDIR=$MYDIR |
|
145 BASEDIR=$(cd $MYDIR/../../.. && pwd) |
|
146 |
|
147 init_gdb() { |
|
148 # Create a gdb script in case we should run inside gdb |
|
149 GDBSCR=/tmp/hsl.$$ |
|
150 rm -f $GDBSCR |
|
151 cat >>$GDBSCR <<EOF |
|
152 cd `pwd` |
|
153 handle SIGUSR1 nostop noprint |
|
154 handle SIGUSR2 nostop noprint |
|
155 set args $JPARMS |
|
156 file $LAUNCHER |
|
157 directory $GDBSRCDIR |
|
158 # Get us to a point where we can set breakpoints in libjvm.so |
|
159 break InitializeJVM |
|
160 run |
|
161 # Stop in InitializeJVM |
|
162 delete 1 |
|
163 # We can now set breakpoints wherever we like |
|
164 EOF |
|
165 } |
|
166 |
|
167 |
|
168 case "$MODE" in |
|
169 gdb) |
|
170 init_gdb |
|
171 $GDB -x $GDBSCR |
|
172 rm -f $GDBSCR |
|
173 ;; |
|
174 gud) |
|
175 init_gdb |
|
176 # First find out what emacs version we're using, so that we can |
|
177 # use the new pretty GDB mode if emacs -version >= 22.1 |
|
178 case $($EMACS -version 2> /dev/null) in |
|
179 *GNU\ Emacs\ 2[23]*) |
|
180 emacs_gud_cmd="gdba" |
|
181 emacs_gud_args="--annotate=3" |
|
182 ;; |
|
183 *) |
|
184 emacs_gud_cmd="gdb" |
|
185 emacs_gud_args= |
|
186 ;; |
|
187 esac |
|
188 $EMACS --eval "($emacs_gud_cmd \"$GDB $emacs_gud_args -x $GDBSCR\")"; |
|
189 rm -f $GDBSCR |
|
190 ;; |
|
191 dbx) |
|
192 $DBX -s $MYDIR/.dbxrc $LAUNCHER $JPARAMS |
|
193 ;; |
|
194 valgrind) |
|
195 echo Warning: Defaulting to 16Mb heap to make Valgrind run faster, use -Xmx for larger heap |
|
196 echo |
|
197 $VALGRIND --tool=memcheck --leak-check=yes --num-callers=50 $LAUNCHER -Xmx16m $JPARMS |
|
198 ;; |
|
199 run) |
|
200 LD_PRELOAD=$PRELOADING exec $LAUNCHER $JPARMS |
|
201 ;; |
|
202 *) |
|
203 echo Error: Internal error, unknown launch mode \"$MODE\" |
|
204 exit 1 |
|
205 ;; |
|
206 esac |
|
207 RETVAL=$? |
|
208 exit $RETVAL |