This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB 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]

[patch] Simulator stdin bug


Hi!

Some of the testcases in gcc libstdc++ testsuite fail for
(at least) cris-axis-elf with time out in the execution test.

The testcases in question all use freopen on stdin, here is
a pruned down C example:

#include <stdio.h>
#include <assert.h>

int
main (void)
{
   const char* name = "freopen.c";
   FILE* stream = freopen(name, "r", stdin);
   assert(stream != NULL);

   char c1 = getc(stream);
   printf("c1 = %x\n", c1);

   return 0;
}

When compiled with cris-axis-elf and run in simulator, the above
code does not read the first character of the file, but tries
to read one byte from stdin.

This is turns out to be because cb_syscall in
src/sim/common/callback.c does a simple check for "fd == 0",
not a real test if the associated (host) fd is actually stdin.

The below patch fixes this, and in so doing reduces the time
needed for a full run through the testsuite for gcc by a noticeable
amount.

For reference, here are the testcases which failed previously:

gcc/libstdc++-v3/testsuite/27_io/objects/char/10.cc
gcc/libstdc++-v3/testsuite/27_io/objects/char/12048-1.cc
gcc/libstdc++-v3/testsuite/27_io/objects/char/12048-2.cc
gcc/libstdc++-v3/testsuite/27_io/objects/char/12048-3.cc
gcc/libstdc++-v3/testsuite/27_io/objects/char/12048-4.cc


Tested with
make -k check 'RUNTESTFLAGS=--target_board=cris-sim\{,-march=v3,-march=v8,-march=v10\}'
in gcc for cris-axis-elf on i686-pc-linux-gnu with no new regressions.

Best regards,

/^Jesper Nilsson

sim/common/ChangeLog:

2007-10-08  Jesper Nilsson  <jesper.nilsson@axis.com>

	* callback.c (cb_is_stdin): Add.
	* syscall.c (cb_syscall): Test for stdin, not just fd 0.

include/gdb/ChangeLog:

2007-10-08  Jesper Nilsson  <jesper.nilsson@axis.com>

	* callback.h (cb_is_stdin): Add prototype.


Index: sim/common/callback.c
===================================================================
RCS file: /cvs/src/src/sim/common/callback.c,v
retrieving revision 1.20
diff -u -u -p -r1.20 callback.c
--- sim/common/callback.c	24 Aug 2007 14:28:35 -0000	1.20
+++ sim/common/callback.c	4 Oct 2007 06:18:09 -0000
@@ -1136,3 +1136,12 @@ sim_cb_eprintf (host_callback *p, const 
   p->evprintf_filtered (p, fmt, ap);
   va_end (ap);
 }
+
+int
+cb_is_stdin (cb, fd)
+      host_callback *cb;
+      int fd;
+{
+  return fdbad (cb, fd) ? 0 : fdmap (cb, fd) == 0;
+}
+
Index: sim/common/syscall.c
===================================================================
RCS file: /cvs/src/src/sim/common/syscall.c,v
retrieving revision 1.11
diff -u -u -p -r1.11 syscall.c
--- sim/common/syscall.c	24 Aug 2007 14:28:35 -0000	1.11
+++ sim/common/syscall.c	4 Oct 2007 06:18:10 -0000
@@ -291,7 +291,7 @@ cb_syscall (cb, sc)
 
 	while (count > 0)
 	  {
-	    if (fd == 0)
+	    if (cb_is_stdin(cb, fd))
 	      result = (int) (*cb->read_stdin) (cb, buf,
 						(count < FILE_XFR_SIZE
 						 ? count : FILE_XFR_SIZE));
Index: include/gdb/callback.h
===================================================================
RCS file: /cvs/src/src/include/gdb/callback.h,v
retrieving revision 1.11
diff -u -u -p -r1.11 callback.h
--- include/gdb/callback.h	23 Aug 2007 18:17:33 -0000	1.11
+++ include/gdb/callback.h	4 Oct 2007 06:18:09 -0000
@@ -315,6 +315,9 @@ int cb_host_to_target_stat PARAMS ((host
 /* Translate a value to target endian.  */
 void cb_store_target_endian PARAMS ((host_callback *, char *, int, long));
 
+/* Test if the fd is stdin. */
+int cb_is_stdin PARAMS ((host_callback *, int));
+
 /* Perform a system call.  */
 CB_RC cb_syscall PARAMS ((host_callback *, CB_SYSCALL *));
 

/^JN - Jesper Nilsson
--
               Jesper Nilsson -- jesper.nilsson@axis.com


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