From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19829 invoked by alias); 7 Jan 2015 13:39:47 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 19818 invoked by uid 89); 7 Jan 2015 13:39:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.0 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 07 Jan 2015 13:39:45 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t07Ddggn008875 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 7 Jan 2015 08:39:42 -0500 Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t07DdZAl006089; Wed, 7 Jan 2015 08:39:38 -0500 Message-ID: <54AD3716.7070209@redhat.com> Date: Wed, 07 Jan 2015 13:39:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Patrick Palka , gdb-patches@sourceware.org Subject: Re: [PATCH] [RFC] Don't propagate our current terminal state to the inferior References: <1416688748-20448-1-git-send-email-patrick@parcs.ath.cx> In-Reply-To: <1416688748-20448-1-git-send-email-patrick@parcs.ath.cx> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2015-01/txt/msg00103.txt.bz2 On 11/22/2014 08:39 PM, Patrick Palka wrote: > Currently when we start an inferior we have the inferior inherit our > terminal state. Under TUI, our terminal is highly modified by ncurses > and readline. So when starting an inferior under TUI, the inferior will > have a highly modified terminal state which will interfere with standard > I/O. For example, > > $ gdb gdb > (gdb) break main > (gdb) run > (gdb) print puts ("a\nb") > a > b > $1 = 4 > (gdb) [enter TUI mode] > (gdb) run > (gdb) [exit TUI mode] > (gdb) print puts ("a\nb") > a > b > $2 = 4 > (gdb) print puts ("a\r\nb\r") > a > b > $3 = 6 > > As you can see, when we start the inferior under the regular interface, > puts() prints the text properly. But when we start the inferior under > TUI, puts() does not print the text properly. This is because when we > start the inferior under TUI it inherits our current terminal state > which has been modified by ncurses to, among other things, require an > explicit \r\n to print a new line. As a result the inferior performs > standard I/O in an unexpected way. > > Because of this discrepancy, it doesn't seem like a good idea to have > the inferior inherit our _current_ terminal state for it may have been > modified by readline and/or ncurses. Instead, we should have the > inferior inherit a pristine snapshot of our terminal state taken before > readline or ncurses have had a chance to alter it. This enables the > inferior to run in a more accurate way, more closely mimicking its > behavior had the program run standalone. And it fixes the above > mentioned issue. > > I wonder, does this change make sense? What do others think? Thanks. This makes sense to me. > > +/* The initial tty state given to each new inferior. It is a snapshot of our > + own tty state taken during initialization of GDB. */ > +static serial_ttystate initial_inferior_ttystate; > + > static struct terminal_info *get_inflow_inferior_data (struct inferior *); > > #ifdef PROCESS_GROUP_TYPE > @@ -156,6 +160,13 @@ show_interactive_mode (struct ui_file *file, int from_tty, > fprintf_filtered (file, "Debugger's interactive mode is %s.\n", value); > } > > +/* Set the initial tty state that is to be inherited by new inferiors. */ > +void > +set_initial_inferior_ttystate (void) > +{ > + initial_inferior_ttystate = serial_get_tty_state (stdin_serial); > +} "initial inferior" reminded me of the initial inferior that GDB always creates. E.g., in main.c: /* Now that gdb_init has created the initial inferior, we're in position to set args for that inferior. */ Could you rename the function and the variable? Like: set_initial_gdb_ttystate (void) { initial_gdb_ttystate = serial_get_tty_state (stdin_serial); } ... /* Snapshot of our own tty state taken during initialization of GDB. This is used as tty state given to each new inferior. */ static serial_ttystate initial_gdb_ttystate; Calling the variable that way calls it for what it holds, not for how it is used, which is friendlier to reuse in other situations. This would be OK with me with that change. Thanks, Pedro Alves