Add sotruss program
[platform/upstream/glibc.git] / elf / sotruss.ksh
1 #! @KSH@
2 # Copyright (C) 2011 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
4
5 # The GNU C Library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9
10 # The GNU C Library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with the GNU C Library; if not, write to the Free
17 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 # 02111-1307 USA.
19
20 # We should be able to find the translation right at the beginning.
21 TEXTDOMAIN=libc
22 TEXTDOMAINDIR=@TEXTDOMAINDIR@
23
24 unset SOTRUSS_FROMLIST
25 unset SOTRUSS_TOLIST
26 unset SOTRUSS_OUTNAME
27 unset SOTRUSS_EXIT
28 unset SOTRUSS_NOINDENT
29 SOTRUSS_WHICH=$$
30 lib='@PREFIX@/$LIB/audit/sotruss-lib.so'
31
32 function do_help {
33   echo $"Usage: sotruss [OPTION...] [--] EXECUTABLE [EXECUTABLE-OPTION...]
34   -F, --from FROMLIST     trace calls from objects on FORMLIST
35   -T, --to TOLIST         trace calls to objects on TOLIST
36
37   -e, --exit              also show exits from the function calls
38   -f, --follow            trace child processes
39   -o, --output FILENAME   write output to FILENAME (or FILENAME.$PID in case
40                           -f is also used) instead of standard error
41
42       --help              print this help and exit
43       --version           print version information and exit"
44
45   echo
46   printf $"Mandatory arguments to long options are also mandatory for any corresponding\nshort options.\n"
47   echo
48
49   echo $"For bug reporting instructions, please see:
50 <http://www.gnu.org/software/libc/bugs.html>.
51 "
52   exit 0
53 }
54
55 function do_missing_arg {
56   printf >&2 $"%s: option requires an argument -- '%s'\n" sotruss "$1"
57   printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" sotruss sotruss
58   exit 1
59 }
60
61 function do_ambiguous {
62   printf >&2 $"%s: option is ambiguous; possibilities:"
63   while test $# -gt 0; do
64     printf >&2 " '%s'" $1
65     shift
66   done
67   printf >&2 "\n"
68   printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" sotruss sotruss
69   exit 1
70 }
71
72 while test $# -gt 0; do
73   case "$1" in
74   --v | --ve | --ver | --vers | --versi | --versio | --version)
75     echo "sotruss (GNU libc) @VERSION@"
76     printf $"Copyright (C) %s Free Software Foundation, Inc.
77 This is free software; see the source for copying conditions.  There is NO
78 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
79 " "2011"
80     printf $"Written by %s.\n" "Ulrich Drepper"
81     exit 0
82     ;;
83   --h | --he | --hel | --help)
84     do_help
85     ;;
86   --u | --us | --usa | --usag | --usage)
87     printf $"Usage: %s [-ef] [-F FROMLIST] [-o FILENAME] [-T TOLIST] [--exit]
88             [--follow] [--from FROMLIST] [--output FILENAME] [--to TOLIST]\n" sotruss
89     exit 0
90     ;;
91   -F | --fr | --fro | --from)
92     if test $# -eq 1; then
93       do_missing_arg "$1"
94     fi
95     shift
96     SOTRUSS_FROMLIST="$2"
97     ;;
98   -T | --t | --to)
99     if test $# -eq 1; then
100       do_missing_arg "$1"
101     fi
102     shift
103     SOTRUSS_TOLIST="$2"
104     ;;
105   -o | --o | --ou | --out | --outp | --outpu | --output)
106     if test $# -eq 1; then
107       do_missing_arg "$1"
108     fi
109     shift
110     SOTRUSS_OUTNAME="$1"
111     ;;
112   -f | --fo | --fol | --foll | --follo | --follow)
113     unset SOTRUSS_WHICH
114     ;;
115   -l | --l | --li | --lib)
116     if test $# -eq 1; then
117       do_missing_arg "$1"
118     fi
119     shift
120     lib="$1"
121     ;;
122   -e | --e | --ex | --exi | --exit)
123     SOTRUSS_EXIT=1
124     ;;
125   --f)
126     do_ambiguous '--from' '--follow'
127     ;;
128   --)
129     shift
130     break
131     ;;
132   -*)
133     printf >&2 $"%s: unrecognized option '%c%s'\n" sotruss '-' ${1#-}
134     printf >&2 $"Try \`%s --help' or \`%s --usage' for more information.\n" sotruss sotruss
135     exit 1
136     ;;
137   *)
138     break
139     ;;
140   esac
141   shift
142 done
143
144 export SOTRUSS_FROMLIST
145 export SOTRUSS_TOLIST
146 export SOTRUSS_OUTNAME
147 export SOTRUSS_WHICH
148 export SOTRUSS_EXIT
149 export LD_AUDIT="$lib"
150
151 exec "$@"
152 # Local Variables:
153 #  mode:ksh
154 # End: