PowerPC: Reserve TCB space for EBB framework
[glibc.git] / debug / catchsegv.sh
blob0ff5a8a047e95f13b5eca9292430117c197f5f49
1 #! /bin/sh
2 # Copyright (C) 1998,1999,2001,2003,2004,2006,2007,2008,2009,2010,2011,2012
3 # Free Software Foundation, Inc.
4 # This file is part of the GNU C Library.
5 # Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
7 # The GNU C Library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
12 # The GNU C Library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 # Lesser General Public License for more details.
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with the GNU C Library; if not, see
19 # <http://www.gnu.org/licenses/>.
21 if test $# -eq 0; then
22 echo "$0: missing program 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 'For bug reporting instructions, please see:'
37 cat <<\EOF
38 @REPORT_BUGS_TO@.
39 EOF
40 exit 0
42 --v | --ve | --ver | --vers | --versi | --versio | --version)
43 echo 'catchsegv @PKGVERSION@@VERSION@'
44 echo 'Copyright (C) 2012 Free Software Foundation, Inc.
45 This is free software; see the source for copying conditions. There is NO
46 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
47 Written by Ulrich Drepper.'
48 exit 0
52 esac
55 segv_output=`mktemp ${TMPDIR:-/tmp}/segv_output.XXXXXX` || exit
57 # Redirect stderr to avoid termination message from shell.
58 (exec 3>&2 2>/dev/null
59 LD_PRELOAD=${LD_PRELOAD:+${LD_PRELOAD}:}@SLIB@/libSegFault.so \
60 SEGFAULT_USE_ALTSTACK=1 \
61 SEGFAULT_OUTPUT_NAME=$segv_output \
62 "$prog" ${1+"$@"} 2>&3 3>&-)
63 exval=$?
65 # Check for output. Even if the program terminated correctly it might
66 # be that a minor process (clone) failed. Therefore we do not check the
67 # exit code.
68 if test -s "$segv_output"; then
69 # The program caught a signal. The output is in the file with the
70 # name we have in SEGFAULT_OUTPUT_NAME. In the output the names of
71 # functions in shared objects are available, but names in the static
72 # part of the program are not. We use addr2line to get this information.
73 case $prog in
74 */*) ;;
76 old_IFS=$IFS
77 IFS=:
78 for p in $PATH; do
79 test -n "$p" || p=.
80 if test -f "$p/$prog"; then
81 prog=$p/$prog
82 break
84 done
85 IFS=$old_IFS
87 esac
88 sed '/Backtrace/q' "$segv_output"
89 sed '1,/Backtrace/d' "$segv_output" |
90 (while read line; do
91 line=`echo $line | sed "s@^$prog\\(\\[.*\\)@\1@"`
92 case "$line" in
93 \[*) addr=`echo "$line" | sed 's/^\[\(.*\)\]$/\1/'`
94 complete=`addr2line -f -e "$prog" $addr 2>/dev/null`
95 if test $? -eq 0; then
96 echo "`echo "$complete"|sed 'N;s/\(.*\)\n\(.*\)/\2(\1)/;'`$line"
97 else
98 echo "$line"
101 *) echo "$line"
103 esac
104 done)
106 rm -f "$segv_output"
108 exit $exval