Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Pedro Alves <palves@redhat.com>
To: Patrick Palka <patrick@parcs.ath.cx>, gdb-patches@sourceware.org
Subject: Re: [PATCH] Make sure terminal settings are restored before exiting
Date: Wed, 29 Jul 2015 00:09:00 -0000	[thread overview]
Message-ID: <55B819B5.5070800@redhat.com> (raw)
In-Reply-To: <1438053504-21507-1-git-send-email-patrick@parcs.ath.cx>

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


  parent reply	other threads:[~2015-07-29  0:09 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-28  3:18 Patrick Palka
2015-07-28 22:20 ` Patrick Palka
2015-07-28 23:53   ` Pedro Alves
2015-07-29 11:39     ` Patrick Palka
2015-07-29  0:09 ` Pedro Alves [this message]
2015-07-29 11:38   ` Patrick Palka
2015-07-29 12:15     ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55B819B5.5070800@redhat.com \
    --to=palves@redhat.com \
    --cc=gdb-patches@sourceware.org \
    --cc=patrick@parcs.ath.cx \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox