]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
[gdb/tdep] Add "maint set console-translation-mode <binary|text>" command
authorTom de Vries <tdevries@suse.de>
Sat, 28 Jun 2025 11:03:14 +0000 (13:03 +0200)
committerTom de Vries <tdevries@suse.de>
Sat, 28 Jun 2025 11:03:14 +0000 (13:03 +0200)
commitf9e9e263f5d8aa60f34207c056fd3c6d8bd5d8ff
tree07b57b1af87a2ed109ee40cc7732a9f15c54461a
parentd62eaecf2e6fc2bce3a0d3a711666c700e79a51a
[gdb/tdep] Add "maint set console-translation-mode <binary|text>" command

On MSYS2, say we record a brief gdb session using TERM=dumb script:
...
$ gdb -q
(gdb) print 1
$1 = 1
(gdb) q
...

When looking at the resulting typescript, we notice something odd:
...
$ gdb -q^M
(gdb) print 1^M
$1 = 1^M^M
(gdb) q^M
...

For some reason, we have "$1 = 1\r\r\n(gdb) ".

Looking at the documentation of _setmode [1], it mentions translation mode
_O_TEXT as a mode in which "\n" is translated into "\r\n" on output.

So, it looks like this translation happens twice.

Add a command "maint set console-translation-mode <binary|text>" command that
allows us to set the translation mode of stdout/stderr to binary, such that we
get instead:
...
$ gdb -q -ex "maint set console-translation-mode binary"^M
(gdb) print 1^M
$1 = 1^M
(gdb) q^M
...

Since we run into this in the testsuite, add
"maint set console-translation-mode binary" to INTERNAL_GDBFLAGS.

Based on "maint set testsuite-mode on/off" from these patches [2][3] by Pierre
Muller.

Compared to that proposal, I dropped the name testsuite-mode, because the
behaviour is not specific to the testsuite.

Also I chose values binary/text instead of on/off because eventually there may
be other translation mode values that we need [4].

Co-Authored-By: Pierre Muller <muller@sourceware.org>
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
[1] https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/setmode
[2] https://sourceware.org/legacy-ml/gdb-patches/2013-09/msg00939.html
[3] https://sourceware.org/legacy-ml/gdb-patches/2013-09/msg00940.html
[4] https://learn.microsoft.com/en-us/cpp/c-runtime-library/translation-mode-constants
gdb/NEWS
gdb/doc/gdb.texinfo
gdb/mingw-hdep.c
gdb/testsuite/lib/gdb.exp