2 # Copyright (C) 1999, 2001 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) 2001 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 `TERMINAL_PROG' is not set, set it to `xterm'.
82 TERMINAL_PROG
=${TERMINAL_PROG:-xterm}
84 # The data file to process, if any.
87 # Process arguments. But stop as soon as the program name is found.
88 while test $# -gt 0; do
90 --d |
--da |
--dat |
--data)
91 if test $# -eq 1; then
97 --d=* |
--da=* |
--dat=* |
--data=*)
100 -? |
--h |
--he |
--hel |
--help)
103 --v |
--ve |
--ver |
--vers |
--versi |
--versio |
--version)
107 # Stop processing arguments.
118 echo >&2 $
"memprof: unrecognized option \`$1'"
122 # Unknown option. This means the rest is the program name and parameters.
129 # See whether any arguments are left.
130 if test $# -eq 0; then
131 echo >&2 $
"No program name given"
135 # Determine the program name and check whether it exists.
138 if test ! -f "$program"; then
139 echo >2& $
"executable \`$program' not found"
142 if test ! -x "$program"; then
143 echo >&2 $
"\`$program' is no executable"
147 # We have two modes. If a data file is given simply print the included data.
148 printf "%-20s %-*s %6s\n" Function $
(expr $COLUMNS - 30) File Line
149 for i
in $
(seq 1 $COLUMNS); do echo -n -; done; echo
150 if test -n "$data"; then
151 $pcprofiledump "$data" |
152 sed 's/this = \([^,]*\).*/\1/' |
153 addr2line
-fC -e "$program" |
156 if test "$fct" != '??' -a "$file" != '??:0'; then
157 format_line
$fct $file
161 fifo
=$
(mktemp
-u ${TMPDIR:-/tmp}/xprof.XXXXXX
)
162 mkfifo -m 0600 $fifo ||
exit 1
163 # Now start the program and let it write to the FIFO.
164 $TERMINAL_PROG -T "xtrace - $program $*" -e /bin
/sh
-c "LD_PRELOAD=$pcprofileso PCPROFILE_OUTPUT=$fifo $program $*; read $fifo" &
166 $pcprofiledump $fifo |
167 sed 's/this = \([^,]*\).*/\1/' |
168 addr2line
-fC -e $program |
171 if test "$fct" != '??' -a "$file" != '??:0'; then
172 format_line
$fct $file
175 read -p "Press return to end the program."