]> sourceware.org Git - glibc.git/blame - debug/catchsegv.sh
Update copyright year.
[glibc.git] / debug / catchsegv.sh
CommitLineData
6ce7ab19 1#! /bin/sh
e56bad6c 2# Copyright (C) 1998,1999,2001,2003,2004,2006 Free Software Foundation, Inc.
6ce7ab19
UD
3# This file is part of the GNU C Library.
4# Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
5
6# The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
6ce7ab19
UD
10
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
41bdb6e2 14# Lesser General Public License for more details.
6ce7ab19 15
41bdb6e2
AJ
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.
6ce7ab19 20
a9ddb793 21if test $# -eq 0; then
432cf458 22 echo "$0: missing program name" >&2
a9ddb793
UD
23 echo "Try \`$0 --help' for more information." >&2
24 exit 1
25fi
26
6ce7ab19
UD
27prog="$1"
28shift
6ce7ab19
UD
29
30if test $# -eq 0; then
07435eb4 31 case "$prog" in
6ce7ab19
UD
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'
d40eb37a
UD
36 echo "For bug reporting instructions, please see:"
37 echo "<http://www.gnu.org/software/libc/bugs.html>."
6ce7ab19
UD
38 exit 0
39 ;;
40 --v | --ve | --ver | --vers | --versi | --versio | --version)
41 echo 'catchsegv (GNU libc) @VERSION@'
e56bad6c 42 echo 'Copyright (C) 2006 Free Software Foundation, Inc.
6ce7ab19
UD
43This is free software; see the source for copying conditions. There is NO
44warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
45Written by Ulrich Drepper.'
46 exit 0
47 ;;
48 *)
49 ;;
50 esac
51fi
52
347b6d62 53segv_output=`mktemp ${TMPDIR:-/tmp}/segv_output.XXXXXX` || exit
6ce7ab19 54
997a4165
UD
55# Redirect stderr to avoid termination message from shell.
56(exec 3>&2 2>/dev/null
a9ddb793
UD
57LD_PRELOAD=${LD_PRELOAD:+${LD_PRELOAD}:}@SLIB@/libSegFault.so \
58SEGFAULT_USE_ALTSTACK=1 \
59SEGFAULT_OUTPUT_NAME=$segv_output \
997a4165 60"$prog" ${1+"$@"} 2>&3 3>&-)
6ce7ab19
UD
61exval=$?
62
e503270c 63# Check for output. Even if the program terminated correctly it might
1e02536f 64# be that a minor process (clone) failed. Therefore we do not check the
e503270c 65# exit code.
347b6d62 66if test -s "$segv_output"; then
997a4165 67 # The program caught a signal. The output is in the file with the
6ce7ab19
UD
68 # name we have in SEGFAULT_OUTPUT_NAME. In the output the names of
69 # functions in shared objects are available, but names in the static
70 # part of the program are not. We use addr2line to get this information.
a9ddb793
UD
71 case $prog in
72 */*) ;;
73 *)
74 old_IFS=$IFS
75 IFS=:
76 for p in $PATH; do
77 test -n "$p" || p=.
78 if test -f "$p/$prog"; then
79 prog=$p/$prog
80 break
81 fi
82 done
83 IFS=$old_IFS
84 ;;
85 esac
c2228a51
UD
86 sed '/Backtrace/q' "$segv_output"
87 sed '1,/Backtrace/d' "$segv_output" |
88 (while read line; do
4a10c7fe 89 line=`echo $line | sed "s@^$prog\\(\\[.*\\)@\1@"`
6ce7ab19 90 case "$line" in
4a10c7fe
UD
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"
97 fi
98 ;;
99 *) echo "$line"
100 ;;
6ce7ab19 101 esac
c2228a51 102 done)
6ce7ab19 103fi
347b6d62 104rm -f "$segv_output"
6ce7ab19
UD
105
106exit $exval
This page took 0.199335 seconds and 5 git commands to generate.