Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Pierre Muller" <muller@ics.u-strasbg.fr>
To: "'Pedro Alves'" <pedro_alves@portugalmail.pt>
Cc: <gdb-patches@sourceware.org>
Subject: RE: [win32] Fix suspend count handling
Date: Thu, 22 Nov 2007 09:19:00 -0000	[thread overview]
Message-ID: <002401c82ce8$c82f7f90$588e7eb0$@u-strasbg.fr> (raw)
In-Reply-To: <4744BCCE.60705@portugalmail.pt>

  I checked again the new patch and
the testsuite results are exactly the
same as I already reported for the hardware watchpoint fix
alone.
  I think that this patch is good,
but only Christopher can approve it.

Pierre

> -----Original Message-----
> From: gdb-patches-owner@sourceware.org [mailto:gdb-patches-
> owner@sourceware.org] On Behalf Of Pedro Alves
> Sent: Thursday, November 22, 2007 12:19 AM
> To: Pierre Muller
> Cc: gdb-patches@sourceware.org
> Subject: Re: [win32] Fix suspend count handling
> 
> Pedro Alves wrote:
> > Pedro Alves wrote:
> >> On Nov 21, 2007 2:13 PM, Pierre Muller wrote:
> >> That's not what I see here.  Can you show me a run where you get 4
> >> only this patch applied?
> >>
> >
> > I did try that, but posted a log of not doing it :-).
> >
> > I've just tried about 30 times, and only once I did see a 4 coming
> out
> > ...  oh, well, one of those things.
> >
> 
> OK.  Back at my home laptop, I can reproduce that with no problems.
> Let me clarify what the 4 problem really is.
> It's a race between gdb and the inferior.
> 
> Take this slightly changed test case.  The only difference to the
> original version is the extra Sleep call.
> 
> #include <windows.h>
> 
> HANDLE started;
> HANDLE stop;
> 
> DWORD WINAPI
> thread_start (void *arg)
> {
>      SetEvent (started);
>      WaitForSingleObject (stop, INFINITE);
>      return 0;
> }
> 
> int
> main (int argc, char **argv)
> {
>      int i;
>      DWORD suspend_count;
>      started = CreateEvent (NULL, TRUE, FALSE, NULL);
>      stop = CreateEvent (NULL, TRUE, FALSE, NULL);
> 
>      HANDLE h = CreateThread (NULL, 0, thread_start, NULL,
> 			   0, NULL);
> 
>      WaitForSingleObject (started, INFINITE);
> 
>      for (i = 0; i < 3; i++)
>        if (SuspendThread (h) == (DWORD) -1)
>          {
> 	printf ("SuspendThreadFailed\n");
> 	return 1;
>          }
> 
>      Sleep (300);
> 
>      suspend_count = ResumeThread (h); /* set breakpoint here */
> 
>      printf ("%lu\n", suspend_count); /* should be 3 */
> 
>      while ((suspend_count = ResumeThread (h)) != 0
> 	 && suspend_count != -1)
>        ;
>      SetEvent (stop);
>      WaitForSingleObject (h, INFINITE);
>      CloseHandle (h);
>      CloseHandle (started);
>      CloseHandle (stop);
>      return 0;
> }
> 
> If you do the "break at ...", "run", "thread 3", "continue"
> sequence, and "..." is the "Sleep" line, you'll get 3, but if you put
> the break at the /* set breakpoint here */ line, you'll get 4 (if
> you're (un)lucky).
> 
> The race happens due to the fact that gdb is doing something similar to
> this:
> 
> win32_continue()
> {
>     ContinueDebugEvent (...);  /* Resumes all non suspended
>                                   threads of the process.  */
> 
>     /* At this point, gdb is running concurrently with
>        the inferior threads that were not suspended - which
>        included the main thread of the testcase.  */
>     foreach t in threads do
>        if t is suspended
>           ResumeThread t
>        fi
>     done
> }
> 
> If you break at the Sleep call, when we resume, gdb will have a bit of
> time to call ResumeThread on the suspended thread of the testcase.  If
> you instead break at the ResumeThread line, you'll have a good chance
> that the inferior wins the race, hence the "4" result (remember that
> ResumeThread returns the previous suspend count).
> If we put something like this after the ResumeThread call:
> 
>      (...)
>      suspend_count = ResumeThread (h); /* set breakpoint here */
> 
> +  Sleep (300);
> +  SuspendThread (h);
> +  suspend_count = ResumeThread (h);
> 
>      printf ("%lu\n", suspend_count); /* should be 3 */
>      (...)
> 
> ... you'll see that eventually gdb will bring the suspend count back to
> 3.  (A SuspendThread, ResumeThread pair is the way to get at the
> suspend count.)
> 
> > Since the watchpoint patch should fix this, what shall I do?  Shall I
> > merge the two and resubmit, or leave it at that ?  They've already
> > been tested together without regressions.
> >
> 
> Here is the merge from the patch I posted at the start of the thread
> with this patch:
>     [win32] Fix watchpoint support
>     http://sourceware.org/ml/gdb-patches/2007-11/msg00390.html
> 
> This patch fixes both the suspend_count
> handling, and the watchpoint support.
> 
> Thanks Pierre, for looking at it.
> 
> OK ?
> 
> --
> Pedro Alves



  reply	other threads:[~2007-11-22  9:19 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-11-21  0:35 Pedro Alves
2007-11-21 11:25 ` Pierre Muller
2007-11-21 13:43   ` Pedro Alves
2007-11-21 14:13     ` Pierre Muller
2007-11-21 15:08       ` Pedro Alves
2007-11-21 15:32         ` Pierre Muller
2007-11-21 18:19         ` Pedro Alves
2007-11-21 23:33           ` Pedro Alves
2007-11-22  9:19             ` Pierre Muller [this message]
2007-11-23  1:07             ` Christopher Faylor
2007-11-23 10:19               ` Lerele
2007-11-23 18:30                 ` Lerele
2007-11-24 12:43                   ` Pedro Alves
2007-11-24 14:21                     ` Lerele
2007-11-24  5:33                 ` Christopher Faylor
2007-11-24 14:18                   ` Lerele
2007-11-24 15:49                     ` Pedro Alves
2007-11-24 17:50                       ` Lerele
2007-11-24 20:49                         ` Christopher Faylor
2007-11-24 20:48                     ` Christopher Faylor
2007-11-25 14:44                       ` Lerele
2007-11-25 18:13                         ` Christopher Faylor
2007-11-25 18:56                           ` Pedro Alves
2007-11-25 22:05                             ` Christopher Faylor
2007-11-25 22:13                               ` Lerele
2007-11-25 20:34                           ` Lerele
2007-11-24 12:16               ` Pedro Alves
2007-11-24 20:51                 ` Christopher Faylor

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='002401c82ce8$c82f7f90$588e7eb0$@u-strasbg.fr' \
    --to=muller@ics.u-strasbg.fr \
    --cc=gdb-patches@sourceware.org \
    --cc=pedro_alves@portugalmail.pt \
    /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