This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[vta, vta4.4] cope with missing GDB in guality testsuite


Jakub mentioned guality tests took forever on a build chroot that didn't
have GDB installed.

This patch adds a short time-out for GDB to attach, and also checks that
the pipe to it doesn't die too early.  This should cut down the time in
test runs without GDB.  It's expected that one of the writes to the pipe
will detect that GDB didn't start and fail early, but if GDB misbehaves
(say GUALITY_GDB='sleep 300' :-) it will still give up quickly, and
(hopefully) not *too* quickly.

I'm installing this in VTA and VTA4.4.  This is the last patch in
today's batch, and most likely the last before I post an updated
consolidated VTA patchset for the merge.  However, I'll merge trunk and
4.4 into the corresponding VTA branches first.

for  gcc/ChangeLog.vta
from  Alexandre Oliva  <aoliva@redhat.com>

	* testsuite/gcc.dg/guality/guality.h (main): Error-check GDB pipe
	operations.
	(guality_check): Likewise.  Update comment.  Time-out GDB attach.

Index: gcc/testsuite/gcc.dg/guality/guality.h
===================================================================
--- gcc/testsuite/gcc.dg/guality/guality.h.orig	2009-05-07 16:37:50.000000000 -0300
+++ gcc/testsuite/gcc.dg/guality/guality.h	2009-08-18 14:44:05.000000000 -0300
@@ -190,15 +190,21 @@ main (int argc, char *argv[])
   if (!guality_skip)
     {
       guality_gdb_input = popen (guality_gdb_command, "w");
+      /* This call sets guality_breakpoint_line.  */
       guality_check (NULL, 0, 0);
-      fprintf (guality_gdb_input, "\
+      if (!guality_gdb_input
+	  || fprintf (guality_gdb_input, "\
 set height 0\n\
 attach %i\n\
-b %i\n\
 set guality_attached = 1\n\
+b %i\n\
 continue\n\
-", (int)getpid (), guality_breakpoint_line);
-      fflush (guality_gdb_input);
+", (int)getpid (), guality_breakpoint_line) <= 0
+	  || fflush (guality_gdb_input))
+	{
+	  perror ("gdb");
+	  abort ();
+	}
     }
 
   argv[--i] = argv0;
@@ -217,10 +223,9 @@ continue\n\
 
 #define main guality_main
 
-/* Fork a child process and attach a debugger to the parent to
-   evaluate NAME in the caller.  If it matches VALUE, we have a PASS;
-   if it's unknown and UNKNOWN_OK, we have an UNRESOLVED.  Otherwise,
-   it's a FAIL.  */
+/* Tell the GDB child process to evaluate NAME in the caller.  If it
+   matches VALUE, we have a PASS; if it's unknown and UNKNOWN_OK, we
+   have an UNRESOLVED.  Otherwise, it's a FAIL.  */
 
 static void __attribute__((noinline))
 guality_check (const char *name, long long value, int unknown_ok)
@@ -237,7 +242,7 @@ guality_check (const char *name, long lo
       {
 	/* The sequence below cannot distinguish an optimized away
 	   variable from one mapped to a non-lvalue zero.  */
-	fprintf (guality_gdb_input, "\
+	if (fprintf (guality_gdb_input, "\
 up\n\
 set $value1 = 0\n\
 set $value1 = (%s)\n\
@@ -251,10 +256,29 @@ down\n\
 set xvalue = $value1\n\
 set unavailable = $value1 != $value2 ? -1 : $value3 != $value4 ? 1 : 0\n\
 continue\n\
-", name, name, name, name);
-	fflush (guality_gdb_input);
-	while (!guality_attached)
-	  ;
+", name, name, name, name) <= 0
+	    || fflush (guality_gdb_input))
+	  {
+	    perror ("gdb");
+	    abort ();
+	  }
+	else if (!guality_attached)
+	  {
+	    unsigned int timeout = 0;
+
+	    /* Give GDB some more time to attach.  Wrapping around a
+	       32-bit counter takes some seconds, it should be plenty
+	       of time for GDB to get a chance to start up and attach,
+	       but not long enough that, if GDB is unavailable or
+	       broken, we'll take far too long to give up.  */
+	    while (--timeout && !guality_attached)
+	      ;
+	    if (!timeout && !guality_attached)
+	      {
+		fprintf (stderr, "gdb: took too long to attach\n");
+		abort ();
+	      }
+	  }
       }
     else
       {
-- 
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]