xref: /titanic_41/usr/src/cmd/sgs/link_audit/common/sotruss.ksh (revision 40db2e2b777b79f3dd0d6d9629593a07f86b9c0a)
1#!/bin/ksh -p
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# ident	"%Z%%M%	%I%	%E% SMI"
25#
26# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
27# Use is subject to license terms.
28
29usage() {
30	echo "usage: sotruss [-F:-T:-o:-f] utility [utility arguments]"
31	echo "	-F <bindfromlist>"
32	echo "		A colon seperated list of libraries that are to be"
33	echo "		traced.  Only calls from these libraries will be"
34	echo "		traced.  The default is to trace calls from the"
35	echo "		main executable."
36	echo "	-T <bindtolist>"
37	echo "		A colon seperated list of libraries that are to be"
38	echo "		traced.  Only calls to these libraries will be"
39	echo "		traced.  The default is to trace all calls."
40	echo "	-o <outputfile>"
41	echo "		sotruss output will be directed to 'outputfile'."
42	echo "		by default it is placed on stdout."
43	echo "	-f"
44	echo "		Follow all children created by fork() and also"
45	echo "		print truss output for the children.  This also"
46	echo "		causes a 'pid' to be added to each truss output line."
47}
48
49bindto=""
50bindfrom=""
51outfile=""
52noindentopt=""
53trusslib32="/usr/lib/link_audit/32/truss.so.1"
54trusslib64="/usr/lib/link_audit/64/truss.so.1"
55pidopt=""
56noexitopt="1"
57
58optlet="eF:T:o:fl:i"
59
60if [[ $# -lt 1 ]]; then
61	usage
62	exit 1
63fi
64
65while getopts $optlet c
66do
67	case $c in
68	F)
69		bindfrom="$OPTARG"
70		;;
71	T)
72		bindto="$OPTARG"
73		;;
74	o)
75		outfile="$OPTARG"
76		;;
77	l)
78		trusslib32="$OPTARG"
79		trusslib64="$OPTARG"
80		;;
81	f)
82		pidopt="1"
83		;;
84	i)
85		noindentopt="1"
86		;;
87	e)
88		noexitopt=""
89		;;
90	\?)
91		usage
92		exit 1
93		;;
94	esac
95done
96shift `expr $OPTIND - 1`
97
98#
99# Build environment variables
100#
101
102TRUSS_BINDTO="$bindto" \
103TRUSS_BINDFROM="$bindfrom" \
104TRUSS_OUTPUT="$outfile" \
105TRUSS_PID="$pidopt" \
106TRUSS_NOINDENT="$noindentopt" \
107TRUSS_NOEXIT="$noexitopt" \
108LD_AUDIT_32="$trusslib32" \
109LD_AUDIT_64="$trusslib64" \
110"$@"
111
112exit 0
113