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