diff options
author | Tom de Vries <tdevries@suse.de> | 2025-07-25 19:07:59 +0200 |
---|---|---|
committer | Tom de Vries <tdevries@suse.de> | 2025-07-25 19:07:59 +0200 |
commit | 3a7f7d0be3a2953fd110f084b34586ce9c649d66 (patch) | |
tree | b0616a332a8c3dece995d367cc29f445835f5124 | |
parent | 6d654864d9408d47dfac98358307796d4eade70b (diff) | |
download | binutils-3a7f7d0be3a2953fd110f084b34586ce9c649d66.zip binutils-3a7f7d0be3a2953fd110f084b34586ce9c649d66.tar.gz binutils-3a7f7d0be3a2953fd110f084b34586ce9c649d66.tar.bz2 |
[gdb/tui] Fix shell command terminal settings
In bash I have the following terminal settings:
...
$ stty
speed 38400 baud; line = 0;
-brkint -imaxbel iutf8
...
and then in gdb using the shell command likewise:
...
(gdb) shell stty
speed 38400 baud; line = 0;
-brkint -imaxbel iutf8
(gdb)
...
and likewise using a shell session:
...
(gdb) shell
$ stty
speed 38400 baud; line = 0;
-brkint -imaxbel iutf8
$
...
But in TUI, we get different settings (removed runaway indentation for
readability):
...
(gdb) shell sttyspeed 38400 baud; line = 0;
min = 1; time = 0;
-brkint -icrnl -imaxbel iutf8
-onlcr
-icanon -echo
(gdb)
...
and consequently the shell is not really usable. This is PR tui/18215.
The easiest way to fix this is to just temporarily leave TUI while in the shell,
leaving the output of the commands in CLI mode, but that's a bit confusing.
Fix this (as suggested in the PR) by restoring the initial terminal settings
while in the shell command, such that also in TUI we have:
...
(gdb) shell sttyspeed 38400 baud; line = 0;
-brkint -imaxbel iutf8
(gdb)
...
Tested on x86_64-linux.
Reported-By: Doug Evans <dje@google.com>
Approved-By: Tom Tromey <tom@tromey.com>
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=18215
-rw-r--r-- | gdb/cli/cli-cmds.c | 4 | ||||
-rw-r--r-- | gdb/inflow.c | 23 | ||||
-rw-r--r-- | gdb/terminal.h | 15 |
3 files changed, 42 insertions, 0 deletions
diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 868f12c..a15a04a 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -51,6 +51,7 @@ #include "cli/cli-cmds.h" #include "cli/cli-style.h" #include "cli/cli-utils.h" +#include "terminal.h" #include "extension.h" #include "gdbsupport/pathstuff.h" @@ -949,6 +950,9 @@ shell_escape (const char *arg, int from_tty) static void shell_command (const char *arg, int from_tty) { + scoped_gdb_ttystate save_restore_gdb_ttystate; + restore_initial_gdb_ttystate (); + shell_escape (arg, from_tty); } diff --git a/gdb/inflow.c b/gdb/inflow.c index 31e1565..4f1c8ef 100644 --- a/gdb/inflow.c +++ b/gdb/inflow.c @@ -55,6 +55,20 @@ static void child_terminal_ours_1 (target_terminal_state); static struct serial *stdin_serial; +/* See terminal.h. */ + +scoped_gdb_ttystate::scoped_gdb_ttystate () +{ + m_ttystate = serial_get_tty_state (stdin_serial); +} + +/* See terminal.h. */ + +scoped_gdb_ttystate::~scoped_gdb_ttystate () +{ + serial_set_tty_state (stdin_serial, m_ttystate); +} + /* Terminal related info we need to keep track of. Each inferior holds an instance of this structure --- we save it whenever the corresponding inferior stops, and restore it to the terminal when @@ -163,6 +177,15 @@ set_initial_gdb_ttystate (void) } } +/* See terminal.h. */ + +void +restore_initial_gdb_ttystate () +{ + if (initial_gdb_ttystate != nullptr) + serial_set_tty_state (stdin_serial, initial_gdb_ttystate); +} + /* Does GDB have a terminal (on stdin)? */ static int diff --git a/gdb/terminal.h b/gdb/terminal.h index 54e5e98..720fd4a 100644 --- a/gdb/terminal.h +++ b/gdb/terminal.h @@ -19,6 +19,8 @@ #ifndef GDB_TERMINAL_H #define GDB_TERMINAL_H +#include "serial.h" + struct inferior; extern void new_tty_prefork (std::string ttyname); @@ -43,4 +45,17 @@ extern void gdb_save_tty_state (void); have had a chance to alter it. */ extern void set_initial_gdb_ttystate (void); +/* Restore initial tty state. */ +extern void restore_initial_gdb_ttystate (void); + +/* An RAII-based object that saves the tty state, and then restores it again + when this object is destroyed. */ +class scoped_gdb_ttystate +{ +public: + scoped_gdb_ttystate (); + ~scoped_gdb_ttystate (); +private: + serial_ttystate m_ttystate; +}; #endif /* GDB_TERMINAL_H */ |