8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / mdb / tools / scripts / mdb.sh
blob1e53f55bfb6dc64cd46d60ae26a396de1633b891
1 #!/bin/sh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License, Version 1.0 only
7 # (the "License"). You may not use this file except in compliance
8 # with the License.
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
21 # CDDL HEADER END
24 # Copyright (c) 1998-2001 by Sun Microsystems, Inc.
25 # All rights reserved.
27 #ident "%Z%%M% %I% %E% SMI"
29 mdb_lib=/net/mdb.eng/mdb/archives # Archive library path
30 mdb_ws=/net/mdb.eng/mdb/snapshot/latest # Snapshot of latest workspace
31 mdb_args= # Debugger argument string
33 os_name='s81' # Default OS name prefix
34 os_rel='5.9' # Default OS release number
36 mach=`/usr/bin/uname -p` # Machine type
37 unset mdb_exec build root # Local variables
40 # Attempt to locate a suitable mdb binary to execute, first on the local
41 # machine, then in the user's workspace, and finally on the MDB server.
42 # If we select the user's workspace, we also set $root to their proto area
43 # to force MDB to use shared libraries installed there as well.
45 if [ -n "$CODEMGR_WS" -a -x $CODEMGR_WS/proto/root_$mach/usr/bin/mdb ]; then
46 mdb_exec=$CODEMGR_WS/proto/root_$mach/usr/bin/mdb
47 root=$CODEMGR_WS/proto/root_$mach
48 elif [ -x /usr/bin/mdb -a ! -d /mdb ]; then
49 mdb_exec=/usr/bin/mdb
50 root=$mdb_lib/$mach/%R/%V
51 elif [ -x /usr/bin/mdb -a -d /mdb ]; then
52 for isa in `isalist`; do
53 if [ -x /usr/bin/$isa/mdb ]; then
54 mdb_exec=/usr/bin/$isa/mdb
55 break
57 done
58 if [ -z "$mdb_exec" ]; then
59 echo "$0: cannot find mdb binary in ISA subdirectories" >& 2
60 exit 1
62 root=$mdb_lib/$mach/%R/%V
63 elif [ -x $mdb_ws/proto/root_$mach/usr/bin/mdb ]; then
64 mdb_exec=$mdb_ws/proto/root_$mach/usr/bin/mdb
65 root=$mdb_lib/$mach/%R/%V
69 # Abort if we were not able to locate a copy of mdb to execute.
71 if [ -z "$mdb_exec" ]; then
72 echo "$0: failed to locate mdb executable" >& 2
73 exit 1
77 # The wrapper script handles several special command-line arguments that are
78 # used to select a desired set of MDB macros, modules, and a libkvm binary.
80 if [ $# -gt 0 ]; then
81 case "$1" in
82 -s[0-9]*)
83 build=`echo "$1" | tr -d -`
84 shift
87 -[0-9]|-[0-9][0-9])
88 build=`echo "$1" | tr -d -`
89 if [ $build -lt 10 ]; then
90 build=${os_name}_0$build
91 else
92 build=${os_name}_$build
94 shift
97 -[0-9][0-9]-|-[0-9][0-9][A-Za-z])
98 build=${os_name}_`echo "$1" | cut -c2- | tr '[A-Z]' '[a-z]'`
99 shift
102 -B) build=$os_rel/Beta; shift ;;
103 -U) build=$os_rel/Beta_Update; shift ;;
104 -G) build=$os_rel/Generic; shift ;;
106 -\?)
107 echo "Usage: $0" \
108 "[ -s<rel> | -s<bld> | -[0-9]+ | -B | -G | -U ] args ..."
110 echo "\t-s<rel> Use proto area for specified release"
111 echo "\t e.g. -${os_name}"
112 echo "\t-s<bld> Use proto area for specified build"
113 echo "\t e.g. -${os_name}_01"
114 echo "\t-[0-9]+ Use proto area for specified build of $os_name"
115 echo "\t-B Use proto area for $os_rel Beta build"
116 echo "\t-G Use proto area for $os_rel Generic build\n"
117 echo "\t-U Use proto area for $os_rel Beta_Update build"
119 esac
123 # If a build was specified, using the corresponding proto area from $mdb_lib.
124 # Note that this will override the $root setting determined above.
126 [ -n "$build" ] && root=$mdb_lib/$mach/$build
129 # If a proto area was set either by specifying a build number, or by using
130 # mdb from $CODEMGR_WS, set LD_LIBRARY_PATH accordingly. This allows mdb to
131 # pick up the appropriate libkvm.so to examine dumps from that build.
132 # We also add the -R flag to the mdb command line so that mdb will modify
133 # its default macro include and module library paths to use the build root.
135 if [ -n "$build" -o "$root" = "$CODEMGR_WS/proto/root_$mach" ]; then
136 if [ -n "$build" -a ! -d $root ]; then
137 echo "mdb: $root is missing or not a directory" >& 2
138 exit 1
141 [ -n "$LD_LIBRARY_PATH" ] && LD_LIBRARY_PATH=$LD_LIBRARY_PATH:
142 LD_LIBRARY_PATH="$LD_LIBRARY_PATH$root/usr/lib"
144 [ -n "$LD_LIBRARY_PATH_64" ] && LD_LIBRARY_PATH_64=$LD_LIBRARY_PATH_64:
145 LD_LIBRARY_PATH_64="$LD_LIBRARY_PATH_64$root/usr/lib/sparcv9"
147 export LD_LIBRARY_PATH LD_LIBRARY_PATH_64
149 elif [ $mdb_exec = $mdb_ws/proto/root_$mach/usr/bin/mdb ]; then
151 # We also need to set LD_LIBRARY_PATH if we're using mdb.eng's mdb
152 # binary -- it requires the new libproc.so to work properly.
154 usrlib=$mdb_ws/proto/root_$mach/usr/lib
156 [ -n "$LD_LIBRARY_PATH" ] && LD_LIBRARY_PATH=$LD_LIBRARY_PATH:
157 LD_LIBRARY_PATH="$LD_LIBRARY_PATH$usrlib"
159 [ -n "$LD_LIBRARY_PATH_64" ] && LD_LIBRARY_PATH_64=$LD_LIBRARY_PATH_64:
160 LD_LIBRARY_PATH_64="$LD_LIBRARY_PATH_64$usrlib/sparcv9"
162 export LD_LIBRARY_PATH LD_LIBRARY_PATH_64
165 exec $mdb_exec -R $root $mdb_args "$@"