xref: /illumos-gate/usr/src/cmd/mdb/tools/scripts/mdb.sh (revision 7c478bd9)
1#!/bin/sh
2#
3# CDDL HEADER START
4#
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.
9#
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.
14#
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]
20#
21# CDDL HEADER END
22#
23#
24# Copyright (c) 1998-2001 by Sun Microsystems, Inc.
25# All rights reserved.
26#
27#ident	"%Z%%M%	%I%	%E% SMI"
28
29mdb_lib=/net/mdb.eng/mdb/archives	# Archive library path
30mdb_ws=/net/mdb.eng/mdb/snapshot/latest	# Snapshot of latest workspace
31mdb_args=				# Debugger argument string
32
33os_name='s81'				# Default OS name prefix
34os_rel='5.9'				# Default OS release number
35
36mach=`/usr/bin/uname -p`		# Machine type
37unset mdb_exec build root		# Local variables
38
39#
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.
44#
45if [ -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
48elif [ -x /usr/bin/mdb -a ! -d /mdb ]; then
49	mdb_exec=/usr/bin/mdb
50	root=$mdb_lib/$mach/%R/%V
51elif [ -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
56		fi
57	done
58	if [ -z "$mdb_exec" ]; then
59		echo "$0: cannot find mdb binary in ISA subdirectories" >& 2
60		exit 1
61	fi
62	root=$mdb_lib/$mach/%R/%V
63elif [ -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
66fi
67
68#
69# Abort if we were not able to locate a copy of mdb to execute.
70#
71if [ -z "$mdb_exec" ]; then
72	echo "$0: failed to locate mdb executable" >& 2
73	exit 1
74fi
75
76#
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.
79#
80if [ $# -gt 0 ]; then
81	case "$1" in
82	-s[0-9]*)
83		build=`echo "$1" | tr -d -`
84		shift
85		;;
86
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
93		fi
94		shift
95		;;
96
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
100		;;
101
102	-B) build=$os_rel/Beta; shift ;;
103	-U) build=$os_rel/Beta_Update; shift ;;
104	-G) build=$os_rel/Generic; shift ;;
105
106	-\?)
107		echo "Usage: $0" \
108		     "[ -s<rel> | -s<bld> | -[0-9]+ | -B | -G | -U ] args ..."
109
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"
118		;;
119	esac
120fi
121
122#
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.
125#
126[ -n "$build" ] && root=$mdb_lib/$mach/$build
127
128#
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.
134#
135if [ -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
139	fi
140
141	[ -n "$LD_LIBRARY_PATH" ] && LD_LIBRARY_PATH=$LD_LIBRARY_PATH:
142	LD_LIBRARY_PATH="$LD_LIBRARY_PATH$root/usr/lib"
143
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"
146
147	export LD_LIBRARY_PATH LD_LIBRARY_PATH_64
148
149elif [ $mdb_exec = $mdb_ws/proto/root_$mach/usr/bin/mdb ]; then
150	#
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.
153	#
154	usrlib=$mdb_ws/proto/root_$mach/usr/lib
155
156	[ -n "$LD_LIBRARY_PATH" ] && LD_LIBRARY_PATH=$LD_LIBRARY_PATH:
157	LD_LIBRARY_PATH="$LD_LIBRARY_PATH$usrlib"
158
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"
161
162	export LD_LIBRARY_PATH LD_LIBRARY_PATH_64
163fi
164
165exec $mdb_exec -R $root $mdb_args "$@"
166