blob: b756d6a236f098f0124fa366b31852008289c4a6 [file] [log] [blame]
Chris Lattner03efbe62003-01-19 18:07:38 +00001#!/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 Lattner75e05a92003-05-11 17:34:14 +000010# 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 Lattner03efbe62003-01-19 18:07:38 +000013#
Chris Lattnerb8f52ba2003-05-31 23:16:10 +000014# Syntax: ./RunSafely.sh <ulimit> <stdinfile> <stdoutfile> <program> <args...>
Chris Lattner75e05a92003-05-11 17:34:14 +000015#
Chris Lattner062b4282003-05-17 22:32:43 +000016ULIMIT=$1
17shift
Chris Lattnerb8f52ba2003-05-31 23:16:10 +000018INFILE=$1
19shift
Chris Lattner75e05a92003-05-11 17:34:14 +000020OUTFILE=$1
21shift
Chris Lattner03efbe62003-01-19 18:07:38 +000022PROGRAM=$1
23shift
24
Chris Lattner062b4282003-05-17 22:32:43 +000025ulimit -t $ULIMIT
Chris Lattner75e05a92003-05-11 17:34:14 +000026rm -f core core.*
Chris Lattner3d283522003-05-11 18:55:29 +000027ulimit -c unlimited
John Criswell5438cb62003-07-02 20:42:05 +000028
29#
John Criswellc335feb2003-07-03 17:50:57 +000030# 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#
33myarch=`uname -m`
34if [ "$myarch" = "sun4u" ]
35then
36 GDB="gdb-64"
37else
38 GDB=gdb
39fi
40
41#
John Criswell5438cb62003-07-02 20:42:05 +000042# 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 Criswellc335feb2003-07-03 17:50:57 +000051(time sh -c "$PROGRAM $* > $OUTFILE 2>&1 < $INFILE") > $OUTFILE.time 2>&1
John Criswell5438cb62003-07-02 20:42:05 +000052
Chris Lattnerad1959c2003-07-01 18:04:43 +000053if test $? -eq 0
54then
55 touch $OUTFILE.exitok
56fi
57
Chris Lattner03efbe62003-01-19 18:07:38 +000058if ls | egrep "^core" > /dev/null
59then
60 corefile=`ls core* | head -1`
61 echo "where" > StackTrace.$$
John Criswellc335feb2003-07-03 17:50:57 +000062 $GDB -q -batch --command=StackTrace.$$ --core=$corefile $PROGRAM < /dev/null
Chris Lattner03efbe62003-01-19 18:07:38 +000063 rm -f StackTrace.$$ $corefile
64fi
65
John Criswell5438cb62003-07-02 20:42:05 +000066exit 0