public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Simon Marchi <simon.marchi@ericsson.com>
To: Pedro Alves <palves@redhat.com>, <gdb-patches@sourceware.org>
Subject: Re: [PATCH v2] Restore terminal state in mi_thread_exit (PR gdb/17627)
Date: Fri, 05 Dec 2014 16:12:00 -0000	[thread overview]
Message-ID: <5481D97B.3040408@ericsson.com> (raw)
In-Reply-To: <54807F25.9040506@redhat.com>

> That doesn't follow though.  We have a ton of places that call
> target_terminal_our that don't need to put back the terminal in
> whatever state is was before.  The reason is that usually we'll
> be printing after the inferior stopped for some event.  If we end
> up re-resuming it, we'll call target_terminal_inferior then.

I am not sure I understand that part. The thread exit is noticed because
of a breakpoint being hit (a breakpoint in libthread-db). In all-stop, I
would expect that when the thread-exit breakpoint is hit, we stop all
threads, then process the event (display the message). After that, we
would need to resume the remaining threads, so the application continues
executing. If so, we would call target_terminal_inferior there.

But, I also remember you mentioning that these thread-db breakpoints are
not handled the same way as regular breakpoints. If I inspect the
target-stack when debugging a threaded program:

    The current target stack is:
      - multi-thread (multi-threaded child process.)
      - native (Native process)
      - exec (Local exec file)
      - None (None)

I would guess that the layer responsible for the all-stop behavior (stop
all the threads when one is stopped) is the native process one. The
thread-db breakpoint handling, however, is done in the multi-thread layer,
so the native target is not reached for handling these. So when the
message is printed, the other threads are actually still running.

Is this last explanation correct?

> But in the thread exit case, there's nothing to be re-resumed,
> so we need to care about it "manually".  If you take a backtrace
> at the point the thread exit event is printed, we should be
> still deep within the target backend code.
> 
> Please update the commit log to clarify this.

I would write this:

We need to manually restore the terminal setting in this particular observer.
In the case of the other observers that call target_terminal_ours, gdb will end
up resuming the inferior later in the execution and call
target_terminal_inferior. In the case of the thread exit event, we still need
to call target_terminal_ours to be able to print something, but there is nothing
that gdb will need to resume after that. We therefore need to call
target_terminal_inferior ourselves.

is this correct?

>>  extern int target_supports_terminal_ours (void);
>>  
>> +/* Make a cleanup that restores the state of the terminal to the current
>> +   value.  */
> 
> Should be "to the current state", I think.

Done.

Thanks, I will push if the clarification above is OK.

Simon

  reply	other threads:[~2014-12-05 16:12 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-02 22:10 Simon Marchi
2014-12-03  0:09 ` Patrick Palka
2014-12-03 14:29   ` Simon Marchi
2014-12-04 15:40     ` Pedro Alves
2014-12-04 15:35 ` Pedro Alves
2014-12-05 16:12   ` Simon Marchi [this message]
2014-12-10 17:20     ` Pedro Alves
2014-12-10 18:06       ` Simon Marchi

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=5481D97B.3040408@ericsson.com \
    --to=simon.marchi@ericsson.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).