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	cat 1>&2 << 'EOF'
31usage: whocalls [sl:] <funcname> <utility> [utility arguments]
32
33  whocalls will audit all function bindings between <utility> and any library
34  it utilizes.  Each time the function <funcname> is called, a stack
35  backtrace is displayed
36
37	-l <wholib>
38		specify an alternate who.so to use.
39
40	-s	When available, examine and use the .symtab symbol table
41		for local symbols (more expensive).
42EOF
43}
44
45optlet="sl:"
46
47if [[ $# -lt 2 ]]; then
48	usage
49	exit 1
50fi
51
52wholib32="/usr/lib/link_audit/32/who.so.1"
53wholib64="/usr/lib/link_audit/64/who.so.1"
54detail=""
55
56while getopts $optlet c
57do
58	case $c in
59	l)
60		wholib32="$OPTARG"
61		wholib64="$OPTARG"
62		;;
63	s)
64		detail="1"
65		;;
66	\?)
67		usage
68		exit 1
69		;;
70	esac
71done
72
73shift `expr $OPTIND - 1`
74func=$1
75shift 1
76
77LD_AUDIT_32="$wholib32" \
78LD_AUDIT_64="$wholib64" \
79WHO_DETAIL="$detail" \
80WHOCALLS="$func" \
81"$@"
82exit 0
83