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