From patchwork Wed May 24 13:45:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom de Vries X-Patchwork-Id: 69955 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9DD9D3858418 for ; Wed, 24 May 2023 13:45:49 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DD9D3858418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1684935949; bh=LIQwBQ5kycvAxG+Tn2Z1MFRXk1C2WHaB1MXWXKQujps=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=u9f5/JOIlfmDbqrzYLHvCg4f1FxD+tsFY/SPrfgNQrnmMoj2KBRQTr67ldCp40CGe JtTKedc3zZadxhKjR42WHoxA4qMgp5gY/qzUDmD+LVlodiydWK/ncLHYz+04fnhkbt fYSKMiQDOQRT9XbGSXeIKhttr+JXWE/zuqTyiqsU= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 591243858D28 for ; Wed, 24 May 2023 13:45:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 591243858D28 Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 8B5FC22171; Wed, 24 May 2023 13:45:24 +0000 (UTC) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 6CC62133E6; Wed, 24 May 2023 13:45:24 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id bYY3GfQUbmS6EQAAMHmgww (envelope-from ); Wed, 24 May 2023 13:45:24 +0000 To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] [gdb/tui] Fix shell command terminal settings Date: Wed, 24 May 2023 15:45:31 +0200 Message-Id: <20230524134531.16083-1-tdevries@suse.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tom de Vries via Gdb-patches From: Tom de Vries Reply-To: Tom de Vries Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" 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. Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=18215 Reported-By: Doug Evans --- gdb/cli/cli-cmds.c | 4 ++++ gdb/inflow.c | 23 +++++++++++++++++++++++ gdb/terminal.h | 14 ++++++++++++++ 3 files changed, 41 insertions(+) base-commit: ea33730dfa4b2e639f99bb4c1f4f8f073ef5b937 diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index b7b65303a0b..5d86e2842bd 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -53,6 +53,7 @@ #include "cli/cli-style.h" #include "cli/cli-utils.h" #include "cli/cli-style.h" +#include "terminal.h" #include "extension.h" #include "gdbsupport/pathstuff.h" @@ -970,6 +971,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 767cfd02c48..9a2ec623b61 100644 --- a/gdb/inflow.c +++ b/gdb/inflow.c @@ -52,6 +52,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 @@ -160,6 +174,15 @@ set_initial_gdb_ttystate (void) } } +/* See terminal.h. */ + +void +restore_initial_gdb_ttystate (void) +{ + 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 34ce2281c4f..6e474cd98c0 100644 --- a/gdb/terminal.h +++ b/gdb/terminal.h @@ -19,6 +19,8 @@ #if !defined (TERMINAL_H) #define TERMINAL_H 1 +#include "serial.h" + struct inferior; extern void new_tty_prefork (std::string ttyname); @@ -43,4 +45,16 @@ 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 /* !defined (TERMINAL_H) */