This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
[RFC] Testsuite: Avoid \r\r\n problem of *-*-mingw* host
- From: "Pierre Muller" <pierre dot muller at ics-cnrs dot unistra dot fr>
- To: <gdb-patches at sourceware dot org>
- Date: Wed, 18 Sep 2013 01:14:06 +0200
- Subject: [RFC] Testsuite: Avoid \r\r\n problem of *-*-mingw* host
- Authentication-results: sourceware.org; auth=none
Here is an alternate proposal to get rid of that double \r
problem encountered when running the testsuite with mingw host GDB.
maint set testsuite-mode on
force stdout and stderr to use binary mode.
maint set testsuite-mode off
restores stdout and stderr "normal" text mode behavior.
Comments welcome,
Pierre Muller
GDB pascal language maintainer
2013-09-18 Pierre Muller <muller@sourceware.org>
* mingw-hdep.c (set_output_binary_mode): New function.
(set_output_normal_mode, set_maint_testsuite_mode): New functions.
(show_maint_testsuite_mode): New function.
(_initialize_mingw_hdep): Add new command,
"maintenance set testsuite-mode on/off".
testsuite/ChangeLog:
* testsuite/lib/gdb.exp (*-*-mingw* hosts): Add
"maint set testsuite-mode" and "set interacitve-mode on"
startup command.
Index: src/gdb/mingw-hdep.c
===================================================================
RCS file: /cvs/src/src/gdb/mingw-hdep.c,v
retrieving revision 1.16
diff -u -p -r1.16 mingw-hdep.c
--- src/gdb/mingw-hdep.c 6 Apr 2013 06:52:06 -0000 1.16
+++ src/gdb/mingw-hdep.c 17 Sep 2013 23:00:49 -0000
@@ -21,6 +21,8 @@
#include "main.h"
#include "serial.h"
#include "event-loop.h"
+#include "command.h"
+#include "gdbcmd.h"
#include "gdb_assert.h"
#include "gdb_select.h"
@@ -265,6 +267,50 @@ gdb_call_async_signal_handler (struct as
SetEvent (sigint_event);
}
+/* Set stdout and stderr handles to binary unbuffered mode. */
+
+static void
+set_output_binary_mode (void)
+{
+ /* In textmode, a '\n' is automatically expanded into "\r\n". This
+ results in expect seeing "\r\r\n". The tests aren't prepared
+ currently for other forms of eol. As a workaround, we force the
+ output to binary mode. */
+ setmode (fileno (stdout), O_BINARY);
+ setmode (fileno (stderr), O_BINARY);
+}
+
+/* Restore stdout and stderr handles to "normal" mode. */
+
+static void
+set_output_normal_mode (void)
+{
+ setmode (fileno (stdout), O_TEXT);
+ setmode (fileno (stderr), O_TEXT);
+}
+
+static int maint_testsuite_mode = 0;
+
+/* Sets the maintenance testsuite mode using the static global
+ testuite_mode. */
+
+static void
+set_maint_testsuite_mode (char *args, int from_tty,
+ struct cmd_list_element *c)
+{
+ if (maint_testsuite_mode)
+ set_output_binary_mode ();
+ else
+ set_output_normal_mode ();
+}
+
+static void
+show_maint_testsuite_mode (struct ui_file *file, int from_tty,
+ struct cmd_list_element *c, const char *value)
+{
+ fprintf_filtered (file, _("Testsuite mode is %s.\n"), value);
+}
+
/* -Wmissing-prototypes */
extern initialize_file_ftype _initialize_mingw_hdep;
@@ -272,4 +318,16 @@ void
_initialize_mingw_hdep (void)
{
sigint_event = CreateEvent (0, FALSE, FALSE, 0);
+ add_setshow_boolean_cmd ("testsuite-mode", class_maintenance,
+ &maint_testsuite_mode, _("\
+Set to adapt to dejagnu testsuite runs."), _("\
+Show whether GDB is adapted to run testsuite."), _("\
+Use \"on\" to enable, \"off\" to disable.\n\
+If enabled, stdout and stderr are set to binary mode,\n\
+to allow better testing."),
+ set_maint_testsuite_mode,
+ show_maint_testsuite_mode,
+ &maintenance_set_cmdlist,
+ &maintenance_show_cmdlist);
+
}
Index: src/gdb/testsuite/lib/gdb.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/lib/gdb.exp,v
retrieving revision 1.245
diff -u -p -r1.245 gdb.exp
--- src/gdb/testsuite/lib/gdb.exp 16 Sep 2013 23:59:02 -0000
1.245
+++ src/gdb/testsuite/lib/gdb.exp 17 Sep 2013 23:01:48 -0000
@@ -61,6 +61,10 @@ global INTERNAL_GDBFLAGS
if ![info exists INTERNAL_GDBFLAGS] {
set INTERNAL_GDBFLAGS "-nw -nx -data-directory $BUILD_DATA_DIRECTORY"
}
+if [ishost "*-*-mingw*"] {
+ verbose "mingw host, needs testsuite-mode"
+# append INTERNAL_GDBFLAGS " -iex {maint set testsuite-mode on} -iex
{set interactive-mode on}"
+}
# The variable gdb_prompt is a regexp which matches the gdb prompt.
# Set it if it is not already set.