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