]>
Commit | Line | Data |
---|---|---|
23d11384 DN |
1 | #!/bin/bash -eu |
2 | # | |
3 | # Script to reproduce a test failure from a dejagnu .log file. | |
4 | # | |
5 | # Contributed by Diego Novillo <dnovillo@google.com> | |
6 | # | |
f3e4f44c | 7 | # Copyright (C) 2011, 2012, 2013 Free Software Foundation, Inc. |
23d11384 DN |
8 | # |
9 | # This file is part of GCC. | |
10 | # | |
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. | |
15 | # | |
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. | |
20 | # | |
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. | |
25 | ||
26 | # This script will search a line starting with 'spawn' that includes the | |
27 | # pattern you are looking for (typically a source file name). | |
28 | # | |
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. | |
32 | ||
33 | if [ $# -lt 2 ] ; then | |
a8fc9855 | 34 | echo "usage: $0 [--debug|--debug-tui] pattern file.log [additional-args]" |
23d11384 DN |
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 | |
a8fc9855 DN |
39 | echo "If --debug is used, the compiler is invoked with -wrapper gdb,--args" |
40 | echo "If --debug-tui is used, the compiler is invoked with -wrapper "\ | |
41 | "gdb,--tui,--args" | |
23d11384 DN |
42 | exit 1 |
43 | fi | |
44 | ||
a8fc9855 DN |
45 | if [ "$1" == "--debug" ] ; then |
46 | debug_args="-wrapper gdb,--args" | |
47 | shift | |
48 | elif [ "$1" == "--debug-tui" ] ; then | |
49 | debug_args="-wrapper gdb,--tui,--args" | |
50 | shift | |
51 | else | |
52 | debug_args="" | |
53 | fi | |
23d11384 DN |
54 | pattern="$1" |
55 | logf="$2" | |
56 | shift 2 | |
57 | ||
58 | # Find the commands in LOGF that reference PATTERN. | |
f3e4f44c DM |
59 | lines=$(grep -E "^spawn .*$pattern" $logf \ |
60 | | sed -e 's/^spawn -ignore SIGHUP //' \ | |
61 | | sed -e 's/^spawn //') | |
23d11384 DN |
62 | if [ -z "$lines" ] ; then |
63 | echo "Could not find a spawn command for pattern $pattern" | |
64 | exit 1 | |
65 | fi | |
66 | ||
67 | # Collect all the command lines into the COMMANDS array. | |
68 | old_IFS="$IFS" | |
69 | IFS="\r" | |
70 | num_lines=0 | |
71 | for line in $lines ; do | |
72 | num_lines=$[$num_lines + 1] | |
73 | echo "[$num_lines] $line" | |
74 | commands[$num_lines]=$line | |
75 | done | |
76 | ||
77 | # If we found more than one line for PATTERN, ask which one we should run. | |
78 | cmds_to_run='0' | |
79 | if [ $num_lines -gt 1 ] ; then | |
80 | echo | |
81 | echo | |
82 | echo -n "Enter the list of commands to run or '0' to run them all: " | |
83 | read cmds_to_run | |
84 | fi | |
85 | if [ "$cmds_to_run" = "0" ] ; then | |
86 | cmds_to_run=$(seq 1 $num_lines) | |
87 | fi | |
88 | IFS="$old_IFS" | |
89 | ||
90 | # Finally, execute all the commands we were told to execute. | |
91 | for cmd_num in $cmds_to_run ; do | |
92 | cmd=${commands[$cmd_num]} | |
93 | set -x +e | |
a8fc9855 | 94 | $cmd $debug_args "$@" |
23d11384 DN |
95 | set +x -e |
96 | done |