Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Joel Brobecker <brobecker@adacore.com>
Cc: palves@redhat.com, gdb-patches@sourceware.org
Subject: Re: [PATCH] Fix "PC register is not available" issue
Date: Thu, 27 Mar 2014 17:41:00 -0000	[thread overview]
Message-ID: <83k3bfy1ws.fsf@gnu.org> (raw)
In-Reply-To: <20140327125646.GA4030@adacore.com>

> Date: Thu, 27 Mar 2014 05:56:46 -0700
> From: Joel Brobecker <brobecker@adacore.com>
> Cc: Pedro Alves <palves@redhat.com>, gdb-patches@sourceware.org
> 
> > My theory is that we get those Access Denied (winerr = 5) errors when
> > we try to suspend these threads when they are about to exit.  That's
> > because I normally see a "Thread exited" message immediately after the
> > warning with the error code.  However, testing whether the thread
> > exited, and avoiding the SuspendThread call if it did, didn't stop the
> > warnings, so I guess the issue is more subtle.  E.g., it could be that
> > during the final stages of thread shutdown, the thread runs some
> > privileged code or something, which precludes suspension.
> 
> Perhaps a simpler theory is that these threads are typically
> short-lived, and so you'd be always be seeing their exit soon
> after they are created.

They live for several minutes, so not so short-lived.

> > In addition, I tried to solve warnings like these:
> > 
> >   error return windows-nat.c:1306 was 5
> >   [Thread 15492.0x68a0 exited with code 0]
> >   (gdb) q
> >   A debugging session is active.
> > 
> > 	  Inferior 1 [process 15492] will be killed.
> > 
> >   Quit anyway? (y or n) y
> >   error return windows-nat.c:1306 was 5
> 
> Yay! :)
> 
> > These come from SetThreadContext in windows_continue.  The second
> > occurrence is because we already killed the inferior by calling
> > TerminateProcess, so its threads begin to shut down, and trying to set
> > their context might indeed fail.  The first warning is about one of
> > those same threads, and again happens just before the thread exit is
> > announced.
> > 
> > My solution, which you can see below, is (a) pass an additional
> > parameter to windows_continue telling it that the inferior was killed,
> > in which case it doesn't bother checking errors from the
> > SetThreadContext call; and (b) check if the thread already exited, and
> > if so, avoid calling SetThreadContext on it.  This completely avoids
> > the warning when killing the inferior, and removes most (but not all)
> > of the warnings for the other threads.
> 
> I am missing the command that caused the first error. From what you
> are saying, was it "kill"?

No, it was "continue", which caused the inferior to run until a
breakpoint, at which point I typed "q".  The thread exit event
happened while the inferior was running.

> it'd be interesting to understand why we send a TerminateProcess
> first, and then try to SetThreadContext later on. It does not seem
> to make sense.

That happens because windows_kill_inferior does this:

  static void
  windows_kill_inferior (struct target_ops *ops)
  {
    CHECK (TerminateProcess (current_process_handle, 0));

    for (;;)
      {
	if (!windows_continue (DBG_CONTINUE, -1, 1))
	  break;
	if (!WaitForDebugEvent (&current_event, INFINITE))
	  break;
	if (current_event.dwDebugEventCode == EXIT_PROCESS_DEBUG_EVENT)
	  break;
      }

    target_mourn_inferior ();	/* Or just windows_mourn_inferior?  */
  }

IOW, we resume the inferior (perhaps to collect all the debug
events?).

> Perhaps one way to address the problem more globally is to have
> a version of the CHECK macro that ignores access-denied errors,
> and use this one on operations where we know we might get that
> error?

We only have one or 2 places for that right now, so I wouldn't think a
separate macro is justified.

> > Finally, here's the full patch.  I hope this research answered all the
> > questions, and we can now get the patch in.
> 
> I'm good with the first half of the patch that handles SuspendThread
> more gracefully. For the additional argument to windows_continue,
> I propose we handle that as a separate patch. It's the right thing
> to do procedurally anyway, and it'll give us a chance to investigate
> more without holding the first half up.

Given what I told above, what additional investigations are needed?

Note that the second part is not entirely separate: those phantom
threads hit the problem with SetThreadContext as well, and checking
whether the thread already exited does let through fewer of those
warnings.


  reply	other threads:[~2014-03-27 17:41 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-17 19:43 Eli Zaretskii
2014-03-18 16:16 ` Joel Brobecker
2014-03-18 16:35   ` Eli Zaretskii
2014-03-18 16:54     ` Joel Brobecker
2014-03-18 17:13       ` Eli Zaretskii
2014-03-18 17:33         ` Pedro Alves
2014-03-19  3:41           ` Eli Zaretskii
2014-03-19 10:07             ` Pedro Alves
2014-03-19 16:24               ` Eli Zaretskii
2014-03-19 16:41                 ` Pedro Alves
2014-03-26 18:49       ` Eli Zaretskii
2014-03-27 12:56         ` Joel Brobecker
2014-03-27 17:41           ` Eli Zaretskii [this message]
2014-03-28 13:00             ` Joel Brobecker
2014-03-28 17:29               ` Eli Zaretskii
2014-03-28 14:50         ` Pedro Alves
2014-03-28 17:35           ` Eli Zaretskii
2014-03-28 17:49             ` Pedro Alves
2014-03-28 18:30               ` Eli Zaretskii
2014-03-31 15:31                 ` Eli Zaretskii
2014-04-05  9:06                   ` Eli Zaretskii
2014-04-07 16:58                     ` Joel Brobecker
2014-04-07 17:09                   ` Pedro Alves
2014-04-07 18:25                     ` Eli Zaretskii
2014-04-07 21:39                       ` Joel Brobecker
2014-04-08  2:44                         ` Eli Zaretskii
2014-04-08  4:23                           ` Joel Brobecker
2014-04-08 15:17                             ` Eli Zaretskii
2014-04-08 11:32                       ` Pedro Alves
2014-04-08 16:43                         ` Pedro Alves
2014-04-08 17:10                           ` Eli Zaretskii
2014-04-08 17:36                             ` Pedro Alves
2014-04-08 17:54                               ` Eli Zaretskii
2014-04-11 20:06                                 ` Joel Brobecker
2014-04-19  8:33                                   ` Eli Zaretskii
2014-04-21 15:43                                     ` Joel Brobecker
2014-04-21 15:59                                       ` Eli Zaretskii

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=83k3bfy1ws.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=brobecker@adacore.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