xref: /netbsd-src/external/gpl3/gcc/dist/contrib/repro_fail (revision 4d5abbe83f525258eb479e5fca29f25cb943f379)
148fb7bfaSmrg#!/bin/bash -eu
248fb7bfaSmrg#
348fb7bfaSmrg# Script to reproduce a test failure from a dejagnu .log file.
448fb7bfaSmrg#
548fb7bfaSmrg# Contributed by Diego Novillo <dnovillo@google.com>
648fb7bfaSmrg#
7*4d5abbe8Smrg# Copyright (C) 2011, 2012, 2013 Free Software Foundation, Inc.
848fb7bfaSmrg#
948fb7bfaSmrg# This file is part of GCC.
1048fb7bfaSmrg#
1148fb7bfaSmrg# GCC is free software; you can redistribute it and/or modify
1248fb7bfaSmrg# it under the terms of the GNU General Public License as published by
1348fb7bfaSmrg# the Free Software Foundation; either version 3, or (at your option)
1448fb7bfaSmrg# any later version.
1548fb7bfaSmrg#
1648fb7bfaSmrg# GCC is distributed in the hope that it will be useful,
1748fb7bfaSmrg# but WITHOUT ANY WARRANTY; without even the implied warranty of
1848fb7bfaSmrg# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1948fb7bfaSmrg# GNU General Public License for more details.
2048fb7bfaSmrg#
2148fb7bfaSmrg# You should have received a copy of the GNU General Public License
2248fb7bfaSmrg# along with GCC; see the file COPYING.  If not, write to
2348fb7bfaSmrg# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
2448fb7bfaSmrg# Boston, MA 02110-1301, USA.
2548fb7bfaSmrg
2648fb7bfaSmrg# This script will search a line starting with 'spawn' that includes the
2748fb7bfaSmrg# pattern you are looking for (typically a source file name).
2848fb7bfaSmrg#
2948fb7bfaSmrg# Once it finds that pattern, it re-executes the whole command
3048fb7bfaSmrg# in the spawn line.  If the pattern matches more than one spawn
3148fb7bfaSmrg# command, it asks which one you want.
3248fb7bfaSmrg
3348fb7bfaSmrgif [ $# -lt 2 ] ; then
3448fb7bfaSmrg    echo "usage: $0 [--debug|--debug-tui] pattern file.log [additional-args]"
3548fb7bfaSmrg    echo
3648fb7bfaSmrg    echo "Finds the 'spawn' line matching PATTERN in FILE.LOG and executes"
3748fb7bfaSmrg    echo "the command with any arguments in ADDITIONAL-ARGS."
3848fb7bfaSmrg    echo
3948fb7bfaSmrg    echo "If --debug is used, the compiler is invoked with -wrapper gdb,--args"
4048fb7bfaSmrg    echo "If --debug-tui is used, the compiler is invoked with -wrapper "\
4148fb7bfaSmrg         "gdb,--tui,--args"
4248fb7bfaSmrg    exit 1
4348fb7bfaSmrgfi
4448fb7bfaSmrg
4548fb7bfaSmrgif [ "$1" == "--debug" ] ; then
4648fb7bfaSmrg    debug_args="-wrapper gdb,--args"
4748fb7bfaSmrg    shift
4848fb7bfaSmrgelif [ "$1" == "--debug-tui" ] ; then
4948fb7bfaSmrg    debug_args="-wrapper gdb,--tui,--args"
5048fb7bfaSmrg    shift
5148fb7bfaSmrgelse
5248fb7bfaSmrg    debug_args=""
5348fb7bfaSmrgfi
5448fb7bfaSmrgpattern="$1"
5548fb7bfaSmrglogf="$2"
5648fb7bfaSmrgshift 2
5748fb7bfaSmrg
5848fb7bfaSmrg# Find the commands in LOGF that reference PATTERN.
59*4d5abbe8Smrglines=$(grep -E "^spawn .*$pattern" $logf \
60*4d5abbe8Smrg        | sed -e 's/^spawn -ignore SIGHUP //' \
61*4d5abbe8Smrg        | sed -e 's/^spawn //')
6248fb7bfaSmrgif [ -z "$lines" ] ; then
6348fb7bfaSmrg    echo "Could not find a spawn command for pattern $pattern"
6448fb7bfaSmrg    exit 1
6548fb7bfaSmrgfi
6648fb7bfaSmrg
6748fb7bfaSmrg# Collect all the command lines into the COMMANDS array.
6848fb7bfaSmrgold_IFS="$IFS"
6948fb7bfaSmrgIFS="
7048fb7bfaSmrg"
7148fb7bfaSmrgnum_lines=0
7248fb7bfaSmrgfor line in $lines ; do
7348fb7bfaSmrg    num_lines=$[$num_lines + 1]
7448fb7bfaSmrg    echo "[$num_lines] $line"
7548fb7bfaSmrg    commands[$num_lines]=$line
7648fb7bfaSmrgdone
7748fb7bfaSmrg
7848fb7bfaSmrg# If we found more than one line for PATTERN, ask which one we should run.
7948fb7bfaSmrgcmds_to_run='0'
8048fb7bfaSmrgif [ $num_lines -gt 1 ] ; then
8148fb7bfaSmrg    echo
8248fb7bfaSmrg    echo
8348fb7bfaSmrg    echo -n "Enter the list of commands to run or '0' to run them all: "
8448fb7bfaSmrg    read cmds_to_run
8548fb7bfaSmrgfi
8648fb7bfaSmrgif [ "$cmds_to_run" = "0" ] ; then
8748fb7bfaSmrg    cmds_to_run=$(seq 1 $num_lines)
8848fb7bfaSmrgfi
8948fb7bfaSmrgIFS="$old_IFS"
9048fb7bfaSmrg
9148fb7bfaSmrg# Finally, execute all the commands we were told to execute.
9248fb7bfaSmrgfor cmd_num in $cmds_to_run ; do
9348fb7bfaSmrg    cmd=${commands[$cmd_num]}
9448fb7bfaSmrg    set -x +e
9548fb7bfaSmrg    $cmd $debug_args "$@"
9648fb7bfaSmrg    set +x -e
97done
98