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