]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
New '--binary-output' command line option, fix gdb.mi/ testing on Windows
authorPedro Alves <pedro@palves.net>
Mon, 8 Sep 2025 19:10:22 +0000 (20:10 +0100)
committerPedro Alves <pedro@palves.net>
Fri, 19 Sep 2025 18:54:13 +0000 (19:54 +0100)
MI testcases currently all fail on native Windows with:

 Running /c/gdb/src/gdb/testsuite/gdb.mi/mi-simplerun.exp ...
 ERROR: (timeout) GDB never initialized after 10 seconds.

This is because when GDB is started in MI mode, it prints info to the
terminal before -iex options are processed.  I.e., before the "maint
set console-translation-mode binary" command in

 gdb -nw -nx -q -iex "set height 0" -iex "set width 0" \
    -iex "set interactive-mode on" \
    -iex "maint set console-translation-mode binary" \
    -i=mi

... is processed.  This results in GDB printing early output with
\r\r\n, like can be easily seen by passing --debug to runtest:

  expect: does "=thread-group-added,id="i1"\r\r\n=cmd-param-changed,param="width",value="4294967295"\r\r\n=cmd-param-changed,param="interactive-mode",value="on"\r\r\n(gdb) \r\n" (spawn_id exp10) match regular expression "~"GNU.*\r\n~".*[(]gdb[)] \r\n$"? Gate "~"GNU*\r\n~"*gdb? \r\n"? gate=no

Fix this by adding a new Windows-only --binary-output command line
option to GDB, which is processed much earlier than -iex, and making
the testsuite pass that instead of "maint set console-translation-mode
binary".

Remove "maint set console-translation-mode" completely, since the only
reason it existed was for the testsuite, and it was never included in
any release.

Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Reviewed-By: Tom de Vries <tdevries@suse.de>
Change-Id: I4632707bb7c8ca573cffff9641ddeb33a0e150af

gdb/NEWS
gdb/doc/gdb.texinfo
gdb/main.c
gdb/mingw-hdep.c
gdb/terminal.h
gdb/testsuite/lib/gdb.exp

index 2f3a26048d88370908e9b35a57156e4628cce01b..87c72cb3d9fc9b288ccda4a3f254248d08e92ef0 100644 (file)
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -86,6 +86,10 @@ single-inf-arg in qSupported
 * Debugging Linux programs that use AArch64 Guarded Control Stacks is now
   supported.
 
+* New "--binary-output" command line option instructs GDB to set the
+  translation mode of its stdout/stderr to binary mode.  This disables
+  Line Feed translation.  MS-Windows only.
+
 * New commands
 
 maintenance check psymtabs
@@ -97,12 +101,6 @@ maintenance check symtabs
 maintenance canonicalize
   Show the canonical form of a C++ name.
 
-maintenance set console-translation-mode <binary|text>
-maintenance show console-translation-mode
-  Controls the translation mode of GDB stdout/stderr.  MS-Windows only.  In
-  binary mode, no translation is done.  In text mode, a Line Feed is
-  translated into a Carriage Return-Line Feed combination.
-
 set riscv numeric-register-names on|off
 show riscv numeric-register-names
   Controls whether GDB refers to risc-v registers by their numeric names
index 6b0cfec26ebad2820bf157cb158823ee39188a44..462b86c87e6c3d02855c3a3c1cfb89ff757ff9ae 100644 (file)
@@ -1215,6 +1215,17 @@ Run @value{GDBN} using @var{directory} as its data directory.
 The data directory is where @value{GDBN} searches for its
 auxiliary files.  @xref{Data Files}.
 
+@item -binary-output
+@cindex @code{--binary-output}
+
+Instructs @value{GDBN} to set the translation mode of its
+@code{stdout}/@code{stderr} to binary.  MS-Windows only.  Useful for
+running the @value{GDBN} testsuite.  By default, @value{GDBN} opens
+@code{stdout}/@code{stderr} in text mode, and translates @samp{\n}
+(LF, a single Line Feed) into @samp{\r\n} (CR-LF, a Carriage
+Return-Line Feed combination).  If this option is set, no translation
+is done.
+
 @item -fullname
 @itemx -f
 @cindex @code{--fullname}
@@ -42899,22 +42910,6 @@ reports and error and the command is aborted.
 @item show watchdog
 Show the current setting of the target wait timeout.
 
-@kindex maint set console-translation-mode
-@kindex maint show console-translation-mode
-@item maint set console-translation-mode @r{[}binary|text@r{]}
-@itemx maint show console-translation-mode
-Controls the translation mode of @value{GDBN} stdout/stderr.  MS-Windows
-only.  Useful for running the @value{GDBN} testsuite.
-
-The translation mode values are as follows:
-@table @code
-@item binary
-No translation.
-@item text
-Translate @samp{\n} (LF, a single Line Feed) into @samp{\r\n} (CR-LF, a
-Carriage Return-Line Feed combination).
-@end table
-
 @end table
 
 @node Remote Protocol
index f3049600a06a86a075e237ff026df8a622f6406c..3d56a31eb0c1d38cba0a7aafb16402088195a08f 100644 (file)
@@ -59,6 +59,7 @@
 #include "serial.h"
 #include "cli-out.h"
 #include "bt-utils.h"
+#include "terminal.h"
 
 /* The selected interpreter.  */
 std::string interpreter_p;
@@ -783,6 +784,9 @@ captured_main_1 (struct captured_main_args *context)
       OPT_READNEVER,
       OPT_SET_ESC_ARGS,
       OPT_SET_NO_ESC_ARGS,
+#ifdef USE_WIN32API
+      OPT_BINARY_OUTPUT,
+#endif
     };
     /* This struct requires int* in the struct, but write_files is a bool.
        So use this temporary int that we write back after argument parsing.  */
@@ -859,6 +863,9 @@ captured_main_1 (struct captured_main_args *context)
       {"no-escape-args", no_argument, nullptr, OPT_SET_NO_ESC_ARGS},
       {"l", required_argument, 0, 'l'},
       {"return-child-result", no_argument, &return_child_result, 1},
+#ifdef USE_WIN32API
+      {"binary-output", no_argument, 0, OPT_BINARY_OUTPUT},
+#endif
       {0, no_argument, 0, 0}
     };
 
@@ -1043,6 +1050,12 @@ captured_main_1 (struct captured_main_args *context)
            }
            break;
 
+#ifdef USE_WIN32API
+         case OPT_BINARY_OUTPUT:
+           set_output_translation_mode_binary ();
+           break;
+#endif
+
          case '?':
            error (_("Use `%s --help' for a complete list of options."),
                   gdb_program_name);
@@ -1482,8 +1495,13 @@ Remote debugging options:\n\n\
 Other options:\n\n\
   --cd=DIR           Change current directory to DIR.\n\
   --data-directory=DIR, -D\n\
-                    Set GDB's data-directory to DIR.\n\
-"), stream);
+                    Set GDB's data-directory to DIR.\n"
+#ifdef USE_WIN32API
+"\
+  --binary-output    Set the translation mode of stdout/stderr to binary,\n\
+                    disabling CRLF translation.\n"
+#endif
+), stream);
   gdb_puts (_("\n\
 At startup, GDB reads the following early init files and executes their\n\
 commands:\n\
index a4e9cf5005f0401fd5218b7092374132e68a614f..f24d2f533a9e0786b7337fe1cb12d0e73283923e 100644 (file)
@@ -25,6 +25,7 @@
 #include "cli/cli-style.h"
 #include "command.h"
 #include "cli/cli-cmds.h"
+#include "terminal.h"
 
 #include <windows.h>
 #include <signal.h>
@@ -448,61 +449,11 @@ install_sigint_handler (c_c_handler_ftype *fn)
   return result;
 }
 
-/* Set stdout and stderr handles to translation mode MODE.  */
+/* See terminal.h.  */
 
-static void
-set_console_translation_mode (int mode)
-{
-  setmode (fileno (stdout), mode);
-  setmode (fileno (stderr), mode);
-}
-
-/* Arg in "maint set console-translation-mode <arg>.  */
-
-static std::string maint_console_translation_mode;
-
-/* Current value of "maint set/show console-translation-mode".  */
-
-static std::string console_translation_mode = "unknown";
-
-/* Sets the console translation mode.  */
-
-static void
-set_maint_console_translation_mode (const char *args, int from_tty,
-                                   struct cmd_list_element *c)
-{
-  if (maint_console_translation_mode == "binary")
-    set_console_translation_mode (O_BINARY);
-  else if (maint_console_translation_mode == "text")
-    set_console_translation_mode (O_TEXT);
-  else
-    error (_("Invalid console translation mode: %s"),
-          maint_console_translation_mode.c_str ());
-
-  console_translation_mode = maint_console_translation_mode;
-}
-
-/* Shows the console translation mode.  */
-
-static void
-show_maint_console_translation_mode (struct ui_file *file, int from_tty,
-                                    struct cmd_list_element *c,
-                                    const char *value)
-{
-  gdb_printf (file, _("Console translation mode is %s.\n"),
-             console_translation_mode.c_str ());
-}
-
-INIT_GDB_FILE (mingw_hdep)
+void
+set_output_translation_mode_binary ()
 {
-  add_setshow_string_cmd ("console-translation-mode",
-                         class_maintenance,
-                         &maint_console_translation_mode, _("\
-Set the translation mode of stdout/stderr."), _("\
-Show the translation mode of stdout/stderr."), _("\
-Use \"binary\", or \"text\""),
-                          set_maint_console_translation_mode,
-                          show_maint_console_translation_mode,
-                          &maintenance_set_cmdlist,
-                          &maintenance_show_cmdlist);
+  setmode (fileno (stdout), O_BINARY);
+  setmode (fileno (stderr), O_BINARY);
 }
index 720fd4a7cbc939c85c4395ece0f0042a7c8254aa..87a1aee37fb90631618d8ca22b8fd4d618f35d86 100644 (file)
@@ -58,4 +58,10 @@ public:
 private:
   serial_ttystate m_ttystate;
 };
+
+#ifdef USE_WIN32API
+/* Set translation mode of stdout/stderr to binary.  */
+extern void set_output_translation_mode_binary ();
+#endif
+
 #endif /* GDB_TERMINAL_H */
index 36bd3b48dbc8c277f5a5e0faed2a2407e50559c7..f05e1c84d5b37dcb1de89a668683ca7977db4d85 100644 (file)
@@ -276,7 +276,7 @@ if ![info exists INTERNAL_GDBFLAGS] {
     append INTERNAL_GDBFLAGS { -iex "set interactive-mode on"}
 
     if { [ishost "*-*-mingw*"] } {
-       append INTERNAL_GDBFLAGS { -iex "maint set console-translation-mode binary"}
+       append INTERNAL_GDBFLAGS { --binary-output}
     }
 }