1 #!/bin/ksh
   2 #
   3 # Copyright 2002-2003 Sun Microsystems, Inc.  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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
  21 # CA 95054 USA or visit www.sun.com if you need additional information or
  22 # have any questions.
  23 #  
  24 #
  25 
  26 
  27 # This jdk must be hopper or better; it must have the 
  28 # SA connectors in VirtualMachineManagerImpl.
  29 jdk=/java/re/jdk/1.4.1/promoted/latest/binaries/solaris-sparc
  30 #jdk=/net/mmm/export/mmm/jdk1.4fcs.sa
  31 
  32 doUsage()
  33 {
  34     cat <<EOF
  35     Run sagclient.class using Serviceability Agent to talk to a corefile/pid/debugserver.
  36     Usage:  runsa.sh [-jdk <jdk-pathname>] [-jdb] [ -jdbx ] [ -d64 ] [ -remote ] [ pid | corefile | debugserver ]
  37 
  38     -jdk means to use that jdk.  Default is 1.4.1/latest.
  39     -jdbx means to run it under jdbx
  40     -jdb means to connect using jdb instead of the sagclient program.
  41     -remote debugserver means you want to connect to a remote debug server
  42 
  43     The corefile must have been produced by the same java as is running SA.
  44 
  45 EOF
  46 }
  47 
  48 if [ $# = 0 ] ; then
  49     doUsage
  50     exit 1
  51 fi
  52 
  53 # License file for development version of dbx
  54 #LM_LICENSE_FILE=7588@extend.eng:/usr/dist/local/config/sparcworks/license.dat:7588@setlicense
  55 #export LM_LICENSE_FILE
  56 
  57 do=
  58 args=
  59 theClass=sagclient
  60 javaArgs=
  61 
  62 while [ $# != 0 ] ; do
  63     case $1 in
  64       -vv)
  65         set -x
  66         ;;
  67      -jdk)
  68         jdk=$2
  69         shift
  70         ;;
  71      -jdbx)
  72         do=jdbx
  73         ;;
  74      -jdb)
  75         do=jdb
  76         ;;
  77      -help | help)
  78         doUsage
  79         exit
  80         ;;
  81      -d64) 
  82         d64=-d64
  83         ;;
  84      -remote)
  85         shift 
  86         args="$1"
  87         do=remote
  88         ;;
  89      -*)
  90         javaArgs="$javaArgs $1"
  91         ;;
  92      *)
  93         echo "$1" | grep -s '^[0-9]*$' > /dev/null
  94         if [ $? = 0 ] ; then
  95             # it is a pid
  96             args="$args $1"
  97         else
  98             # It is a core.        
  99             # We have to pass the name of the program that produced the
 100             # core, and the core file itself.
 101             args="$jdk/bin/java $1"
 102         fi
 103         ;;
 104    esac
 105    shift
 106 done
 107 
 108 if [ -z "$jdk" ] ; then
 109     error "--Error: runsa.sh:  Must specify -jdk <jdk-pathname>."
 110     error "         Do runsa.sh -help for more info"
 111     exit 1
 112 fi
 113 
 114 set -x
 115 #setenv USE_LIBPROC_DEBUGGER "-Dsun.jvm.hotspot.debugger.useProcDebugger -Djava.library.path=$saprocdir"
 116 
 117 # If jjh makes this, then the classes are in .../build/agent.
 118 # if someone else does, they are in  .
 119 classesDir=../../../../../../build/agent
 120 if [ ! -r $classesDir ] ; then
 121     classesDir=.
 122     if [ ! -r $classesDir ] ; then
 123         echo "-- Error: runsa.sh can't find the SA classes"
 124         exit 1
 125     fi
 126 fi
 127 #javacp="/net/mmm/export/mmm/ws/sabaseline/build/solaris/solaris_sparc_compiler1/generated/sa-jdi.jar:$classesDir:$jdk/lib/tools.jar:$jdk/classes:./workdir"
 128 
 129 javacp="$jdk/lib/sa-jdi.jar:$classesDir:$jdk/lib/tools.jar:$jdk/classes:./workdir"
 130 
 131 
 132 extraArgs="-showversion $javaArgs"
 133 #extraArgs="-DdbxSvcAgentDSOPathName=/net/mmm/export/mmm/ws/m/b2/sa/src/os/solaris/agent/64bit/libsvc_agent_dbx.so $extraArgs"
 134 #extraArgs="-DdbxSvcAgentDSOPathName=/net/jano.eng/export/disk05/hotspot/sa/solaris/sparcv9/lib/libsvc_agent_dbx.so $extraArgs"
 135 
 136 mkdir -p workdir
 137 if [ sagclient.java -nt ./workdir/sagclient.class ] ; then
 138     $jdk/bin/javac -d ./workdir -classpath $javacp sagclient.java
 139     if [ $? != 0 ] ; then
 140         exit 1
 141     fi
 142 fi
 143 if [ sagdoit.java -nt ./workdir/sagdoit.class ] ; then
 144     $jdk/bin/javac -d ./workdir -classpath $javacp sagdoit.java
 145     if [ $? != 0 ] ; then
 146         exit 1
 147     fi
 148 fi
 149 
 150 if [ "$do" = jdbx ] ; then
 151     set -x
 152     dbx=/net/sparcworks.eng/export/set/sparcworks2/dbx_70_nightly/dev/buildbin/Derived-sparc-S2-opt/bin/dbx
 153 
 154     # Have to do this export for jdbx to work.  -cp and -classpath don't work.
 155     CLASSPATH=$javacp
 156     export CLASSPATH
 157     #extraArgs="-Djava.class.path=$mhs/../sa/build/agent sun.jvm.hotspot.HSDB $*"
 158     jvm_invocation="$jdk/bin/java -Xdebug \
 159                -Dsun.boot.class.path=$jdk/classes \
 160                $extraArgs"
 161     #export jvm_invocation
 162     
 163     JAVASRCPATH=$mhs/../sa/src/share/vm/agent
 164     export JAVASRCPATH
 165 
 166     #operand is pathname of .class file, eg ./jj.class.
 167     echo run $args
 168     clss=`echo $theClass | sed -e 's@\.@/@'`
 169     if [ -r ./workdir/$clss.class ] ; then
 170         # kludge for running sagclient
 171         $dbx  ./workdir/$clss.class
 172     else
 173         # kludge for running HSDB
 174         $dbx  $mhs/../sa/build/agent/$clss.class
 175     fi
 176 elif [ "$do" = jdb ] ; then
 177     # This hasn't been tested.
 178     $jdk/bin/jdb -J-Xbootclasspath/a:$classesDir -connect sun.jvm.hotspot.jdi.SACoreAttachingConnector:core=sagcore
 179 elif [ "$do" = remote ] ; then
 180     $jdk/bin/java $d64 -Djava.class.path=$javacp $extraArgs $theClass $args
 181 else
 182     $jdk/bin/java $d64 -Djava.class.path=$javacp $extraArgs $theClass $args
 183 
 184 fi