From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 98522 invoked by alias); 29 Jul 2015 11:38:03 -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 98511 invoked by uid 89); 29 Jul 2015 11:38:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 X-HELO: mail-oi0-f51.google.com Received: from mail-oi0-f51.google.com (HELO mail-oi0-f51.google.com) (209.85.218.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Wed, 29 Jul 2015 11:38:01 +0000 Received: by oixx19 with SMTP id x19so3431066oix.0 for ; Wed, 29 Jul 2015 04:37:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=ausaBoEPBHWhfwnLwe22hZPgA8vIhujBeZzc/MBa+9s=; b=f89zZWsIOfKnXxn5aEb3nsxc72qpJ4aVI5XSmgQ2/VYFaJRGzl7HGxpSZqhcG4O05/ 6wQpALcynWlNoaTftPf9BSnqRUzSDcLamrsNUyaU6aw+jCblJIj0i7uVhzP6R7o9ZA1Q nH3pGYU3DvfiUcU0N2aE6XgHBPZD7baOyOMiKKpOFDXop4BKb3xXPiHFgPH0ag9G+hxI gkFFNNgdQDukibBHNv+FGCrRnvV5cRJM/fzx+zYtYncJYCzEqx+MtsdGu5ijus66AF5F +L9fZ99zedB6oMkcpqlL1amY9LCEQtKKQz8/jlrwHb8/UVJRXx/UY4cPH0cKtfHEgunb 7kJA== X-Gm-Message-State: ALoCoQlHoi5pojwrDCHpGyma5o+yBiCtjVAp9vv6lk9bjG1UY3AzzlAHqK3KW6j2fFbj9vdU2KwW X-Received: by 10.202.75.13 with SMTP id y13mr38535729oia.92.1438169878859; Wed, 29 Jul 2015 04:37:58 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.56.202 with HTTP; Wed, 29 Jul 2015 04:37:39 -0700 (PDT) In-Reply-To: <55B819B5.5070800@redhat.com> References: <1438053504-21507-1-git-send-email-patrick@parcs.ath.cx> <55B819B5.5070800@redhat.com> From: Patrick Palka Date: Wed, 29 Jul 2015 11:38:00 -0000 Message-ID: Subject: Re: [PATCH] Make sure terminal settings are restored before exiting To: Pedro Alves Cc: "gdb-patches@sourceware.org" Content-Type: text/plain; charset=UTF-8 X-SW-Source: 2015-07/txt/msg00863.txt.bz2 On Tue, Jul 28, 2015 at 8:09 PM, Pedro Alves wrote: > 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... Nice list. The #0 approach does not work for me. When I suspend GDB with ^Z, the shell variable $! remains empty. It looks like you have to start the process in the background to populate the $! variable, and starting GDB in the background does not work too well. Just very recently I discovered the $PPID environment variable, a standardized (thus hopefully portable) variable that should contain the pid of the parent process. With it we can do "shell echo $PPID" to print the gdb pid and then capture the output of this command with expect. I'll try this approach.