]>
Commit | Line | Data |
---|---|---|
48d0341c | 1 | #!/bin/sh |
04277e02 | 2 | # Copyright (C) 1998-2019 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 | 16 | # You should have received a copy of the GNU Lesser General Public |
59ba27a6 PE |
17 | # License along with the GNU C Library; if not, see |
18 | # <http://www.gnu.org/licenses/>. | |
6ce7ab19 | 19 | |
a9ddb793 | 20 | if test $# -eq 0; then |
432cf458 | 21 | echo "$0: missing program name" >&2 |
a9ddb793 UD |
22 | echo "Try \`$0 --help' for more information." >&2 |
23 | exit 1 | |
24 | fi | |
25 | ||
6ce7ab19 UD |
26 | prog="$1" |
27 | shift | |
6ce7ab19 UD |
28 | |
29 | if test $# -eq 0; then | |
07435eb4 | 30 | case "$prog" in |
6ce7ab19 UD |
31 | --h | --he | --hel | --help) |
32 | echo 'Usage: catchsegv PROGRAM ARGS...' | |
33 | echo ' --help print this help, then exit' | |
34 | echo ' --version print version number, then exit' | |
8b748aed JM |
35 | echo 'For bug reporting instructions, please see:' |
36 | cat <<\EOF | |
37 | @REPORT_BUGS_TO@. | |
38 | EOF | |
6ce7ab19 UD |
39 | exit 0 |
40 | ;; | |
41 | --v | --ve | --ver | --vers | --versi | --versio | --version) | |
8b748aed | 42 | echo 'catchsegv @PKGVERSION@@VERSION@' |
09533208 | 43 | echo 'Copyright (C) 2018 Free Software Foundation, Inc. |
6ce7ab19 UD |
44 | This is free software; see the source for copying conditions. There is NO |
45 | warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
46 | Written by Ulrich Drepper.' | |
47 | exit 0 | |
48 | ;; | |
49 | *) | |
50 | ;; | |
51 | esac | |
52 | fi | |
53 | ||
347b6d62 | 54 | segv_output=`mktemp ${TMPDIR:-/tmp}/segv_output.XXXXXX` || exit |
6ce7ab19 | 55 | |
997a4165 UD |
56 | # Redirect stderr to avoid termination message from shell. |
57 | (exec 3>&2 2>/dev/null | |
a9ddb793 UD |
58 | LD_PRELOAD=${LD_PRELOAD:+${LD_PRELOAD}:}@SLIB@/libSegFault.so \ |
59 | SEGFAULT_USE_ALTSTACK=1 \ | |
60 | SEGFAULT_OUTPUT_NAME=$segv_output \ | |
997a4165 | 61 | "$prog" ${1+"$@"} 2>&3 3>&-) |
6ce7ab19 UD |
62 | exval=$? |
63 | ||
e503270c | 64 | # Check for output. Even if the program terminated correctly it might |
1e02536f | 65 | # be that a minor process (clone) failed. Therefore we do not check the |
e503270c | 66 | # exit code. |
347b6d62 | 67 | if test -s "$segv_output"; then |
997a4165 | 68 | # The program caught a signal. The output is in the file with the |
6ce7ab19 UD |
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. | |
a9ddb793 UD |
72 | case $prog in |
73 | */*) ;; | |
74 | *) | |
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 | |
82 | fi | |
83 | done | |
84 | IFS=$old_IFS | |
85 | ;; | |
86 | esac | |
c2228a51 UD |
87 | sed '/Backtrace/q' "$segv_output" |
88 | sed '1,/Backtrace/d' "$segv_output" | | |
89 | (while read line; do | |
4a10c7fe | 90 | line=`echo $line | sed "s@^$prog\\(\\[.*\\)@\1@"` |
6ce7ab19 | 91 | case "$line" in |
4a10c7fe UD |
92 | \[*) addr=`echo "$line" | sed 's/^\[\(.*\)\]$/\1/'` |
93 | complete=`addr2line -f -e "$prog" $addr 2>/dev/null` | |
94 | if test $? -eq 0; then | |
95 | echo "`echo "$complete"|sed 'N;s/\(.*\)\n\(.*\)/\2(\1)/;'`$line" | |
96 | else | |
97 | echo "$line" | |
98 | fi | |
99 | ;; | |
561470e0 | 100 | *) echo "$line" |
4a10c7fe | 101 | ;; |
6ce7ab19 | 102 | esac |
c2228a51 | 103 | done) |
6ce7ab19 | 104 | fi |
347b6d62 | 105 | rm -f "$segv_output" |
6ce7ab19 UD |
106 | |
107 | exit $exval |