Fix comment typo.
[glibc.git] / debug / catchsegv.sh
blob8e32ed44232c3e798a2dabe23a779c34d3e85b14
1 #! /bin/sh
2 # Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
4 # Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
6 # The GNU C Library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Lesser General Public
8 # License as published by the Free Software Foundation; either
9 # version 2.1 of the 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 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, write to the Free
18 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 # 02111-1307 USA.
21 if test $# -eq 0; then
22 echo "$0: missing programm name" >&2
23 echo "Try \`$0 --help' for more information." >&2
24 exit 1
27 prog="$1"
28 shift
30 if test $# -eq 0; then
31 case "$prog" in
32 --h | --he | --hel | --help)
33 echo 'Usage: catchsegv PROGRAM ARGS...'
34 echo ' --help print this help, then exit'
35 echo ' --version print version number, then exit'
36 echo "Report bugs using the \`glibcbug' script to <bugs@gnu.org>."
37 exit 0
39 --v | --ve | --ver | --vers | --versi | --versio | --version)
40 echo 'catchsegv (GNU libc) @VERSION@'
41 echo 'Copyright (C) 2001 Free Software Foundation, Inc.
42 This is free software; see the source for copying conditions. There is NO
43 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
44 Written by Ulrich Drepper.'
45 exit 0
49 esac
52 segv_output=`basename "$prog"`.segv.$$
53 # Make sure this output file does not exist.
54 rm -f "$segv_output"
56 # Redirect stderr to avoid termination message from shell.
57 (exec 3>&2 2>/dev/null
58 LD_PRELOAD=${LD_PRELOAD:+${LD_PRELOAD}:}@SLIB@/libSegFault.so \
59 SEGFAULT_USE_ALTSTACK=1 \
60 SEGFAULT_OUTPUT_NAME=$segv_output \
61 "$prog" ${1+"$@"} 2>&3 3>&-)
62 exval=$?
64 # Check for output. Even if the program terminated correctly it might
65 # be that a minor process (clone) failed. Therefore we do not check the
66 # exit code.
67 if test -f "$segv_output"; then
68 # The program caught a signal. The output is in the file with the
69 # name we have in SEGFAULT_OUTPUT_NAME. In the output the names of
70 # functions in shared objects are available, but names in the static
71 # part of the program are not. We use addr2line to get this information.
72 case $prog in
73 */*) ;;
75 old_IFS=$IFS
76 IFS=:
77 for p in $PATH; do
78 test -n "$p" || p=.
79 if test -f "$p/$prog"; then
80 prog=$p/$prog
81 break
83 done
84 IFS=$old_IFS
86 esac
87 sed '/Backtrace/q' "$segv_output"
88 sed '1,/Backtrace/d' "$segv_output" |
89 (while read line; do
90 case "$line" in
91 [*) addr=`echo "$line" | sed 's/^\[\(.*\)\]$/\1/'`
92 complete=`addr2line -f -e "$prog" $addr 2>/dev/null`
93 if test $? -eq 0; then
94 echo "`echo "$complete"|sed 'N;s/\(.*\)\n\(.*\)/\2(\1)/;'`$line"
95 else
96 echo "$line"
99 *) echo "$line"
101 esac
102 done)
103 rm -f "$segv_output"
106 exit $exval