blob: 61738a135a7d7160e6fde745bb5116644acbd97e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#! /bin/sh
#
# Run the command we're passed in a subshell, so that said subshell will
# catch any signals from it and report it.
#
# This is done for commands that aren't the last command in the
# pipeline, as, given that the exit status of a pipeline is the exit
# status of the last command in the pipeline, there's no guarantee that
# the shell will bother to pick up the exit status of earlier commands
# in the pipeline.
#
# XXX - on OS X, core dumps are in /cores/core.{PID}; would they appear
# elsewhere on any other UN*X?
#
rm -f core
"$@"
if [ -r core ]
then
#
# Core dumped - try to get a stack trace.
#
# First, find the executable.
#
if [ -x "$1" ]
then
executable="$1"
else
executable=`which "$1"`
fi
if [ ! -z "$executable" ]
then
#
# Found the executable.
#
# Now, look for a debugger.
# XXX - lldb?
#
dbx=`which dbx`
if [ ! -z "$dbx" ]
then
#
# Found dbx. Run it to get a stack trace;
# cause the stack trace to go to the standard
# error.
#
dbx "$executable" core 1>&2 <<EOF
where
quit
EOF
else
gdb=`which gdb`
if [ ! -z "$gdb" ]
then
#
# Found gdb. Run it to get a stack trace;
# cause the stack trace to go to the standard
# error.
#
gdb "$executable" core 1>&2 <<EOF
backtrace
quit
EOF
fi
fi
fi
fi
|