From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 82135 invoked by alias); 29 Jul 2015 00:09:30 -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 82126 invoked by uid 89); 29 Jul 2015 00:09:29 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS 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, 29 Jul 2015 00:09:28 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (Postfix) with ESMTPS id 8988D19F259; Wed, 29 Jul 2015 00:09:27 +0000 (UTC) Received: from [127.0.0.1] (ovpn01.gateway.prod.ext.ams2.redhat.com [10.39.146.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t6T09QWR021611; Tue, 28 Jul 2015 20:09:26 -0400 Message-ID: <55B819B5.5070800@redhat.com> Date: Wed, 29 Jul 2015 00:09:00 -0000 From: Pedro Alves User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 MIME-Version: 1.0 To: Patrick Palka , gdb-patches@sourceware.org Subject: Re: [PATCH] Make sure terminal settings are restored before exiting References: <1438053504-21507-1-git-send-email-patrick@parcs.ath.cx> In-Reply-To: <1438053504-21507-1-git-send-email-patrick@parcs.ath.cx> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2015-07/txt/msg00852.txt.bz2 On 07/28/2015 04:18 AM, Patrick Palka wrote: > When exiting GDB -- whether it's via the "quit" command, via a SIGTERM, > or otherwise -- we should leave the terminal in the state we acquired > it. To that end, we have to undo any modifications that may have been > made by the TUI (ncurses) or by the CLI (readline). > > [ Note that we already take a snapshot of the original tty state and save > it to inflow.c:initial_gdb_ttystate. Using this variable we can > define a new function restore_initial_gdb_ttystate and use it here. > We can replace the call to rl_deprep_terminal with such a function, > though it wouldn't hurt to have both around either. Is this a good > idea? > > As far as testing goes, I am having trouble figuring out how to > retrieve the pid of the GDB subprocess in order to kill it via SIGTERM > with the subshell/stty approach used in > batch-preserve-term-settings.exp. Seems non-trivial. Any ideas? ] A few ideas: #0 - We're starting it under a shell we control, so make use of that. Start gdb in the background "gdb &" and follow it with "echo $!" to get the pid, followed by "fg". Starting the background might be tricky, so alternatively start it as usual and then send a C-z to background it, then "echo $!". #1 - Run "shell ps" in gdb and extract the PID from the first column that has a line that matches *gdb*. #2 - Do like gdb.server/server-kill.c, and the test's program store the parent's process id in a global variable with getppid(). You'll need to disable "set startup-with-shell", so that the process's direct parent is GDB. Read the global variable from gdb. #3 - add a "maint print pid" command ... #0 seems preferred. #1 is hacky, but ... i've seen worse. #2 only works with native testing. #3 could be the most reliable... Thanks, Pedro Alves