gcc/
[official-gcc.git] / contrib / repro_fail
blob8100456ac6295e450316864d70bd4f5914a9cff6
1 #!/bin/bash -eu
3 # Script to reproduce a test failure from a dejagnu .log file.
5 # Contributed by Diego Novillo <dnovillo@google.com>
7 # Copyright (C) 2011 Free Software Foundation, Inc.
9 # This file is part of GCC.
11 # GCC is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 3, or (at your option)
14 # any later version.
16 # GCC is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with GCC; see the file COPYING. If not, write to
23 # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
24 # Boston, MA 02110-1301, USA.
26 # This script will search a line starting with 'spawn' that includes the
27 # pattern you are looking for (typically a source file name).
29 # Once it finds that pattern, it re-executes the whole command
30 # in the spawn line. If the pattern matches more than one spawn
31 # command, it asks which one you want.
33 if [ $# -lt 2 ] ; then
34 echo "usage: $0 pattern file.log [additional-args]"
35 echo
36 echo "Finds the 'spawn' line matching PATTERN in FILE.LOG and executes"
37 echo "the command with any arguments in ADDITIONAL-ARGS."
38 echo
39 exit 1
42 pattern="$1"
43 logf="$2"
44 shift 2
46 # Find the commands in LOGF that reference PATTERN.
47 lines=$(grep -E "^spawn .*$pattern" $logf | sed -e 's/^spawn //')
48 if [ -z "$lines" ] ; then
49 echo "Could not find a spawn command for pattern $pattern"
50 exit 1
53 # Collect all the command lines into the COMMANDS array.
54 old_IFS="$IFS"
55 IFS=" "
56 num_lines=0
57 for line in $lines ; do
58 num_lines=$[$num_lines + 1]
59 echo "[$num_lines] $line"
60 commands[$num_lines]=$line
61 done
63 # If we found more than one line for PATTERN, ask which one we should run.
64 cmds_to_run='0'
65 if [ $num_lines -gt 1 ] ; then
66 echo
67 echo
68 echo -n "Enter the list of commands to run or '0' to run them all: "
69 read cmds_to_run
71 if [ "$cmds_to_run" = "0" ] ; then
72 cmds_to_run=$(seq 1 $num_lines)
74 IFS="$old_IFS"
76 # Finally, execute all the commands we were told to execute.
77 for cmd_num in $cmds_to_run ; do
78 cmd=${commands[$cmd_num]}
79 set -x +e
80 $cmd "$@"
81 set +x -e
82 done