2 # Copyright (C) 1999 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
4 # Contributed by Ulrich Drepper <drepper@gnu.org>, 1999.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Library General Public License as
8 # published by the Free Software Foundation; either version 2 of the
9 # License, or (at your option) any later version.
11 # The GNU C Library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Library General Public License for more details.
16 # You should have received a copy of the GNU Library General Public
17 # License along with the GNU C Library; see the file COPYING.LIB. If not,
18 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 # Boston, MA 02111-1307, USA.
21 pcprofileso=@LIBDIR@/libpcprofile.so
22 pcprofiledump=@BINDIR@/pcprofiledump
24 # Print usage message.
26 echo >&2 $"Try \`xtrace --help' for more information."
30 # Message for missing argument.
32 echo >&2 $"xtrace: option \`$1' requires an argument"
38 echo $"Usage: xtrace [OPTION]... PROGRAM [PROGRAMOPTION]...
39 Trace execution of program by printing currently executed function.
41 --data=FILE Don't run the program, just print the data from FILE.
43 -?,--help Print this help and exit
44 --usage Give a short usage message
45 -V,--version Print version information and exit
47 Mandatory arguments to long options are also mandatory for any corresponding
50 Report bugs using the \`glibcbug' script to <bugs@gnu.org>."
55 echo 'xtrace (GNU libc) @VERSION@'
56 echo $"Copyright (C) 1999 Free Software Foundation, Inc.
57 This is free software; see the source for copying conditions. There is NO
58 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
59 Written by Ulrich Drepper."
63 # Print out function name, file, and line number is a nice formatted way.
68 width=$(expr $COLUMNS - 30)
69 filelen=$(expr length $file)
70 if test "$filelen" -gt "$width"; then
71 rwidth=$(expr $width - 3)
72 file="...$(expr substr $file $(expr 1 + $filelen - $rwidth) $rwidth)"
74 printf '%-20s %-*s %6s\n' $fct $width $file $line
78 # If the variable COLUMNS is not set do this now.
79 COLUMNS=${COLUMNS:-80}
81 # If `TERM' is not set, set it to `xterm'.
84 # Process arguments. But stop as soon as the program name is found.
85 while test $# -gt 0; do
87 --d | --da | --dat | --data)
88 if test $# -eq 1; then
94 --d=* | --da=* | --dat=* | --data=*)
98 # Stop processing arguments.
103 echo >&2 $"memprof: unrecognized option \`$1'"
107 # Unknown option. This means the rest is the program name and parameters.
114 # See whether any arguments are left.
115 if test $# -eq 0; then
116 echo >&2 $"No program name given"
120 # Determine the program name and check whether it exists.
123 if test ! -f "$program"; then
124 echo >2& $"\executable \`$program' not found"
127 if test ! -x "$program"; then
128 echo >&2 $"\`$program' is no executable"
132 # We have two modes. If a data file is given simply print the included data.
133 printf "%-20s %-*s %6s\n" Function $(expr $COLUMNS - 30) File Line
134 for i in $(seq 1 $COLUMNS); do echo -n -; done; echo
135 if test -n "$data"; then
136 eval $pcprofiledump $data |
137 sed 's/this = \([^,]*\).*/\1/' |
138 addr2line -fC -e $program |
141 if test "$fct" != '??' -a "$file" != '??:0'; then
142 format_line $fct $file
146 fifo=$(mktemp -u ${TMPDIR:-/tmp}/xprof.XXXXXX)
147 mkfifo -m 0600 $fifo || exit 1
148 # Now start the program and let it write to the FIFO.
149 eval $TERM -T "'xtrace - $program $*'" -e /bin/sh -c "'LD_PRELOAD=$pcprofileso PCPROFILE_OUTPUT=$fifo $program $*; read $fifo'" &
151 eval $pcprofiledump $fifo |
152 sed 's/this = \([^,]*\).*/\1/' |
153 addr2line -fC -e $program |
156 if test "$fct" != '??' -a "$file" != '??:0'; then
157 format_line $fct $file
160 read -p "Press return to end the program."