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 "-valgrind", HotSpot will be launched 32 # inside Valgrind (http://valgrind.kde.org) using the Memcheck skin, 33 # and with memory leak detection enabled. This currently (2005jan19) 34 # requires at least Valgrind 2.3.0. -Xmx16m will also be passed as 35 # the first parameter to HotSpot, since lowering HotSpot's memory 36 # consumption makes execution inside of Valgrind *a lot* faster. 37 # 38 39 javahome= 40 41 get_javahome() 42 { 43 for p in $*; do 44 local v=${p##-Djava.home=}; 45 if [ "$v" != "$p" ] 46 then 47 javahome=$v 48 fi 49 done 50 } 51 52 # 53 # User changeable parameters ------------------------------------------------ 54 # 55 56 # This is the name of the gdb binary to use 57 if [ ! "$GDB" ] 58 then 59 GDB=gdb 60 fi 61 62 # This is the name of the Valgrind binary to use 63 if [ ! "$VALGRIND" ] 64 then 65 VALGRIND=valgrind 66 fi 67 68 # This is the name of Emacs for running GUD 69 EMACS=emacs 70 71 # 72 # End of user changeable parameters ----------------------------------------- 73 # 74 75 # Make sure the paths are fully specified, i.e. they must begin with /. 76 SCRIPT=$(cd $(dirname $0) && pwd)/$(basename $0) 77 RUNDIR=$(pwd) 78 79 # Look whether the user wants to run inside gdb 80 case "$1" in 81 -gdb) 82 MODE=gdb 83 shift 84 ;; 85 -gud) 86 MODE=gud 87 shift 88 ;; 89 -valgrind) 90 MODE=valgrind 91 shift 92 ;; 93 *) 94 MODE=run 95 ;; 96 esac 97 98 get_javahome $*; 99 100 if [ "$javahome" != "" ]; then 101 JDK=${javahome%%/jre}; 102 else 103 if [ "${ALT_JAVA_HOME}" = "" ]; then 104 if [ "${JAVA_HOME}" = "" ]; then 105 echo "Neither ALT_JAVA_HOME nor JAVA_HOME is set. Aborting."; 106 exit 1; 107 else 108 JDK=${JAVA_HOME%%/jre}; 109 fi 110 else 111 JDK=${ALT_JAVA_HOME%%/jre}; 112 fi 113 fi 114 115 # We will set the LD_LIBRARY_PATH as follows: 116 # o $JVMPATH (directory portion only) 117 # o $JRE/lib/$ARCH 118 # followed by the user's previous effective LD_LIBRARY_PATH, if 119 # any. 120 JRE=$JDK/jre 121 JAVA_HOME=$JDK 122 ARCH=@@LIBARCH@@ 123 124 # Find out the absolute path to this script 125 MYDIR=$(cd $(dirname $SCRIPT) && pwd) 126 127 SBP=${MYDIR}:${JRE}/lib/${ARCH} 128 129 # Set up a suitable LD_LIBRARY_PATH 130 131 if [ -z "$LD_LIBRARY_PATH" ] 132 then 133 LD_LIBRARY_PATH="$SBP" 134 else 135 LD_LIBRARY_PATH="$SBP:$LD_LIBRARY_PATH" 136 fi 137 138 export LD_LIBRARY_PATH 139 export JAVA_HOME 140 141 JPARMS="$@ $JAVA_ARGS"; 142 143 # Locate the gamma development launcher 144 LAUNCHER=${MYDIR}/gamma 145 if [ ! -x $LAUNCHER ] ; then 146 echo Error: Cannot find the gamma development launcher \"$LAUNCHER\" 147 exit 1 148 fi 149 150 GDBSRCDIR=$MYDIR 151 BASEDIR=$(cd $MYDIR/../../.. && pwd) 152 153 init_gdb() { 154 # Create a gdb script in case we should run inside gdb 155 GDBSCR=/tmp/hsl.$$ 156 rm -f $GDBSCR 157 cat >>$GDBSCR <<EOF 158 cd `pwd` 159 handle SIGUSR1 nostop noprint 160 handle SIGUSR2 nostop noprint 161 set args $JPARMS 162 file $LAUNCHER 163 directory $GDBSRCDIR 164 # Get us to a point where we can set breakpoints in libjvm.so 165 break InitializeJVM 166 run 167 # Stop in InitializeJVM 168 delete 1 169 # We can now set breakpoints wherever we like 170 EOF 171 } 172 173 case "$MODE" in 174 gdb) 175 init_gdb 176 $GDB -x $GDBSCR 177 rm -f $GDBSCR 178 ;; 179 gud) 180 init_gdb 181 # First find out what emacs version we're using, so that we can 182 # use the new pretty GDB mode if emacs -version >= 22.1 183 case $($EMACS -version 2> /dev/null) in 184 *GNU\ Emacs\ 2[23]*) 185 emacs_gud_cmd="gdba" 186 emacs_gud_args="--annotate=3" 187 ;; 188 *) 189 emacs_gud_cmd="gdb" 190 emacs_gud_args= 191 ;; 192 esac 193 $EMACS --eval "($emacs_gud_cmd \"$GDB $emacs_gud_args -x $GDBSCR\")"; 194 rm -f $GDBSCR 195 ;; 196 valgrind) 197 echo Warning: Defaulting to 16Mb heap to make Valgrind run faster, use -Xmx for larger heap 198 echo 199 $VALGRIND --tool=memcheck --leak-check=yes --num-callers=50 $LAUNCHER -Xmx16m $JPARMS 200 ;; 201 run) 202 LD_PRELOAD=$PRELOADING exec $LAUNCHER $JPARMS 203 ;; 204 *) 205 echo Error: Internal error, unknown launch mode \"$MODE\" 206 exit 1 207 ;; 208 esac 209 RETVAL=$? 210 exit $RETVAL