Chris Lattner | 03efbe6 | 2003-01-19 18:07:38 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Program: RunSafely.sh |
| 4 | # |
| 5 | # Synopsis: This script simply runs another program. If the program works |
| 6 | # correctly, this script has no effect, otherwise it will do things |
| 7 | # like print a stack trace of a core dump. It always returns |
| 8 | # "successful" so that tests will continue to be run. |
| 9 | # |
Chris Lattner | 75e05a9 | 2003-05-11 17:34:14 +0000 | [diff] [blame] | 10 | # This script funnels stdout and stderr from the program into the |
| 11 | # first argument specified, and outputs a <outputfile>.time file which |
| 12 | # contains a timing of the program. |
Chris Lattner | 03efbe6 | 2003-01-19 18:07:38 +0000 | [diff] [blame] | 13 | # |
Chris Lattner | b8f52ba | 2003-05-31 23:16:10 +0000 | [diff] [blame] | 14 | # Syntax: ./RunSafely.sh <ulimit> <stdinfile> <stdoutfile> <program> <args...> |
Chris Lattner | 75e05a9 | 2003-05-11 17:34:14 +0000 | [diff] [blame] | 15 | # |
Chris Lattner | 062b428 | 2003-05-17 22:32:43 +0000 | [diff] [blame] | 16 | ULIMIT=$1 |
| 17 | shift |
Chris Lattner | b8f52ba | 2003-05-31 23:16:10 +0000 | [diff] [blame] | 18 | INFILE=$1 |
| 19 | shift |
Chris Lattner | 75e05a9 | 2003-05-11 17:34:14 +0000 | [diff] [blame] | 20 | OUTFILE=$1 |
| 21 | shift |
Chris Lattner | 03efbe6 | 2003-01-19 18:07:38 +0000 | [diff] [blame] | 22 | PROGRAM=$1 |
| 23 | shift |
| 24 | |
Chris Lattner | 062b428 | 2003-05-17 22:32:43 +0000 | [diff] [blame] | 25 | ulimit -t $ULIMIT |
Chris Lattner | 75e05a9 | 2003-05-11 17:34:14 +0000 | [diff] [blame] | 26 | rm -f core core.* |
Chris Lattner | 3d28352 | 2003-05-11 18:55:29 +0000 | [diff] [blame] | 27 | ulimit -c unlimited |
John Criswell | 5438cb6 | 2003-07-02 20:42:05 +0000 | [diff] [blame] | 28 | |
| 29 | # |
John Criswell | c335feb | 2003-07-03 17:50:57 +0000 | [diff] [blame^] | 30 | # If we are on a sun4u machine (UltraSparc), then the code we're generating |
| 31 | # is 64 bit code. In that case, use gdb-64 instead of gdb. |
| 32 | # |
| 33 | myarch=`uname -m` |
| 34 | if [ "$myarch" = "sun4u" ] |
| 35 | then |
| 36 | GDB="gdb-64" |
| 37 | else |
| 38 | GDB=gdb |
| 39 | fi |
| 40 | |
| 41 | # |
John Criswell | 5438cb6 | 2003-07-02 20:42:05 +0000 | [diff] [blame] | 42 | # Run the command, timing its execution. |
| 43 | # The standard output and standard error of $PROGRAM should go in $OUTFILE, |
| 44 | # and the standard error of time should go in $OUTFILE.time. |
| 45 | # |
| 46 | # Ah, the joys of shell programming! |
| 47 | # To get the time program and the specified program different output filenames, |
| 48 | # we tell time to launch a shell which in turn executes $PROGRAM with the |
| 49 | # necessary I/O redirection. |
| 50 | # |
John Criswell | c335feb | 2003-07-03 17:50:57 +0000 | [diff] [blame^] | 51 | (time sh -c "$PROGRAM $* > $OUTFILE 2>&1 < $INFILE") > $OUTFILE.time 2>&1 |
John Criswell | 5438cb6 | 2003-07-02 20:42:05 +0000 | [diff] [blame] | 52 | |
Chris Lattner | ad1959c | 2003-07-01 18:04:43 +0000 | [diff] [blame] | 53 | if test $? -eq 0 |
| 54 | then |
| 55 | touch $OUTFILE.exitok |
| 56 | fi |
| 57 | |
Chris Lattner | 03efbe6 | 2003-01-19 18:07:38 +0000 | [diff] [blame] | 58 | if ls | egrep "^core" > /dev/null |
| 59 | then |
| 60 | corefile=`ls core* | head -1` |
| 61 | echo "where" > StackTrace.$$ |
John Criswell | c335feb | 2003-07-03 17:50:57 +0000 | [diff] [blame^] | 62 | $GDB -q -batch --command=StackTrace.$$ --core=$corefile $PROGRAM < /dev/null |
Chris Lattner | 03efbe6 | 2003-01-19 18:07:38 +0000 | [diff] [blame] | 63 | rm -f StackTrace.$$ $corefile |
| 64 | fi |
| 65 | |
John Criswell | 5438cb6 | 2003-07-02 20:42:05 +0000 | [diff] [blame] | 66 | exit 0 |