public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pph contrib] Add support for multiple spawn patterns in repro_fail (issue4571061)
@ 2011-06-10 23:52 Diego Novillo
  2011-06-21 18:50 ` Alexandre Oliva
  0 siblings, 1 reply; 3+ messages in thread
From: Diego Novillo @ 2011-06-10 23:52 UTC (permalink / raw)
  To: reply, lxo, crowl, gchare, gcc-patches


So I had to go back to grep|sed instead of just sed because I want
to use extended regexps supported by grep -E.  In pph this is useful
so that you can specify patterns that match both the writing and the
reading of the PPH files.

I'm thinking that this script is better written in python, but that
may make it less generic and I don't know whether we accept python in
gcc/contrib.  Alex?

Committed to pph branch.


Diego.


	* repro_fail: Add support for patterns matching multiple spawns.

diff --git a/contrib/repro_fail b/contrib/repro_fail
index d5bce04..8100456 100755
--- a/contrib/repro_fail
+++ b/contrib/repro_fail
@@ -1,6 +1,6 @@
-#!/bin/bash
+#!/bin/bash -eu
 #
-# Script to reproduce a test failure from a dejagnu .log file
+# Script to reproduce a test failure from a dejagnu .log file.
 #
 # Contributed by Diego Novillo <dnovillo@google.com>
 #
@@ -23,6 +23,13 @@
 # the Free Software Foundation, 51 Franklin Street, Fifth Floor,
 # Boston, MA 02110-1301, USA.
 
+# This script will search a line starting with 'spawn' that includes the
+# pattern you are looking for (typically a source file name).
+#
+# Once it finds that pattern, it re-executes the whole command
+# in the spawn line.  If the pattern matches more than one spawn
+# command, it asks which one you want.
+
 if [ $# -lt 2 ] ; then
     echo "usage: $0 pattern file.log [additional-args]"
     echo
@@ -32,18 +39,44 @@ if [ $# -lt 2 ] ; then
     exit 1
 fi
 
-set -e
-pattern=$1
-logf=$2
+pattern="$1"
+logf="$2"
 shift 2
-args="$@"
-line=$(grep "^spawn .*$pattern" $logf | sed -e "s:^spawn ::")
 
-if [ "$line" = "" ] ; then
-    echo "Could not find a spawn command for pattern $1"
+# Find the commands in LOGF that reference PATTERN.
+lines=$(grep -E "^spawn .*$pattern" $logf | sed -e 's/^spawn //')
+if [ -z "$lines" ] ; then
+    echo "Could not find a spawn command for pattern $pattern"
     exit 1
 fi
 
-set -x +e
-$line $args
-exit $?
+# Collect all the command lines into the COMMANDS array.
+old_IFS="$IFS"
+IFS="\r"
+num_lines=0
+for line in $lines ; do
+    num_lines=$[$num_lines + 1]
+    echo "[$num_lines] $line"
+    commands[$num_lines]=$line
+done
+
+# If we found more than one line for PATTERN, ask which one we should run.
+cmds_to_run='0'
+if [ $num_lines -gt 1 ] ; then
+    echo
+    echo
+    echo -n "Enter the list of commands to run or '0' to run them all: "
+    read cmds_to_run
+fi
+if [ "$cmds_to_run" = "0" ] ; then
+    cmds_to_run=$(seq 1 $num_lines)
+fi
+IFS="$old_IFS"
+
+# Finally, execute all the commands we were told to execute.
+for cmd_num in $cmds_to_run ; do
+    cmd=${commands[$cmd_num]}
+    set -x +e
+    $cmd "$@"
+    set +x -e
+done

--
This patch is available for review at http://codereview.appspot.com/4571061

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pph contrib] Add support for multiple spawn patterns in repro_fail (issue4571061)
  2011-06-10 23:52 [pph contrib] Add support for multiple spawn patterns in repro_fail (issue4571061) Diego Novillo
@ 2011-06-21 18:50 ` Alexandre Oliva
  2011-06-24 13:30   ` Diego Novillo
  0 siblings, 1 reply; 3+ messages in thread
From: Alexandre Oliva @ 2011-06-21 18:50 UTC (permalink / raw)
  To: Diego Novillo; +Cc: reply, lxo, crowl, gchare, gcc-patches

On Jun 10, 2011, dnovillo@google.com (Diego Novillo) wrote:

> I'm thinking that this script is better written in python, but that
> may make it less generic and I don't know whether we accept python in
> gcc/contrib.  Alex?

I guess anything goes in gcc/contrib, so it could be rewritten in
Python, but the bash script you checked in looks good enough to me.
Thanks,

-- 
Alexandre Oliva, freedom fighter    http://FSFLA.org/~lxoliva/
You must be the change you wish to see in the world. -- Gandhi
Be Free! -- http://FSFLA.org/   FSF Latin America board member
Free Software Evangelist      Red Hat Brazil Compiler Engineer

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pph contrib] Add support for multiple spawn patterns in repro_fail (issue4571061)
  2011-06-21 18:50 ` Alexandre Oliva
@ 2011-06-24 13:30   ` Diego Novillo
  0 siblings, 0 replies; 3+ messages in thread
From: Diego Novillo @ 2011-06-24 13:30 UTC (permalink / raw)
  To: Alexandre Oliva; +Cc: reply, lxo, crowl, gchare, gcc-patches

On Tue, Jun 21, 2011 at 14:36, Alexandre Oliva <aoliva@redhat.com> wrote:
> On Jun 10, 2011, dnovillo@google.com (Diego Novillo) wrote:
>
>> I'm thinking that this script is better written in python, but that
>> may make it less generic and I don't know whether we accept python in
>> gcc/contrib.  Alex?
>
> I guess anything goes in gcc/contrib, so it could be rewritten in
> Python, but the bash script you checked in looks good enough to me.

Thanks.  I committed the script to trunk r175374.


Diego.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-06-24 13:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-10 23:52 [pph contrib] Add support for multiple spawn patterns in repro_fail (issue4571061) Diego Novillo
2011-06-21 18:50 ` Alexandre Oliva
2011-06-24 13:30   ` Diego Novillo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).