From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8726 invoked by alias); 10 Oct 2009 05:20:00 -0000 Received: (qmail 8711 invoked by uid 22791); 10 Oct 2009 05:19:58 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL,BAYES_00,SARE_MSGID_LONG40,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail-pz0-f189.google.com (HELO mail-pz0-f189.google.com) (209.85.222.189) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 10 Oct 2009 05:19:53 +0000 Received: by pzk27 with SMTP id 27so1327250pzk.12 for ; Fri, 09 Oct 2009 22:19:52 -0700 (PDT) MIME-Version: 1.0 Received: by 10.143.25.40 with SMTP id c40mr288560wfj.265.1255151992076; Fri, 09 Oct 2009 22:19:52 -0700 (PDT) In-Reply-To: <200910090253.47934.pedro@codesourcery.com> References: <200910090253.47934.pedro@codesourcery.com> From: Hui Zhu Date: Sat, 10 Oct 2009 05:20:00 -0000 Message-ID: Subject: Re: Make linux_nat.c's target_wait always respect TARGET_WNOHANG. To: Pedro Alves Cc: gdb-patches@sourceware.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes 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 X-SW-Source: 2009-10/txt/msg00202.txt.bz2 Thanks for your patch, Pedro. Hui On Fri, Oct 9, 2009 at 09:53, Pedro Alves wrote: > Moving from . > > This patch fixes an issue Hui noticed. =A0linux_nat_wait_1 > wasn't respecting the TARGET_WNOHANG option in the case of waiting > for a specific lwpid. > > We have a related infrun bug. =A0If gdb is thread hoping, or other > situation when waiton_ptid is set (infwait_state !=3D infwait_normal_stat= e), > a TARGET_WAITKIND_IGNORE would reset infwait_state and waiton_ptid. > > Tested on x86_64-unknown-linux-gnu native sync and async modes. > > I'm checking this in. =A0Thanks Hui. > > -- > Pedro Alves > > 2009-10-09 =A0Pedro Alves =A0 > > =A0 =A0 =A0 =A0* linux-nat.c (linux_nat_wait_1): Bail out, if TARGET_WNOH= ANG and > =A0 =A0 =A0 =A0we found no event while waiting for a specific LWP. > =A0 =A0 =A0 =A0* infrun.c (handle_inferior_event): Handle TARGET_WAITKIND= _IGNORE > =A0 =A0 =A0 =A0before anything else. > > --- > =A0gdb/infrun.c =A0 =A0| =A0 62 +++++++++++++++++++++++++++--------------= --------------- > =A0gdb/linux-nat.c | =A0 11 +++++++++ > =A02 files changed, 41 insertions(+), 32 deletions(-) > > Index: src/gdb/linux-nat.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- src.orig/gdb/linux-nat.c =A0 =A02009-10-09 02:23:48.000000000 +0100 > +++ src/gdb/linux-nat.c 2009-10-09 02:42:37.000000000 +0100 > @@ -3255,6 +3255,17 @@ retry: > =A0 =A0 =A0 =A0 =A0 =A0 =A0sigsuspend (&suspend_mask); > =A0 =A0 =A0 =A0 =A0 =A0} > =A0 =A0 =A0 =A0} > + =A0 =A0 =A0else if (target_options & TARGET_WNOHANG) > + =A0 =A0 =A0 { > + =A0 =A0 =A0 =A0 /* No interesting event for PID yet. =A0*/ > + =A0 =A0 =A0 =A0 ourstatus->kind =3D TARGET_WAITKIND_IGNORE; > + > + =A0 =A0 =A0 =A0 if (debug_linux_nat_async) > + =A0 =A0 =A0 =A0 =A0 fprintf_unfiltered (gdb_stdlog, "LLW: exit (ignore)= \n"); > + > + =A0 =A0 =A0 =A0 restore_child_signals_mask (&prev_mask); > + =A0 =A0 =A0 =A0 return minus_one_ptid; > + =A0 =A0 =A0 } > > =A0 =A0 =A0 /* We shouldn't end up here unless we want to try again. =A0*/ > =A0 =A0 =A0 gdb_assert (lp =3D=3D NULL); > Index: src/gdb/infrun.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- src.orig/gdb/infrun.c =A0 =A0 =A0 2009-10-09 02:23:48.000000000 +0100 > +++ src/gdb/infrun.c =A0 =A02009-10-09 02:52:29.000000000 +0100 > @@ -2443,9 +2443,25 @@ handle_inferior_event (struct execution_ > =A0 struct symtab_and_line stop_pc_sal; > =A0 enum stop_kind stop_soon; > > + =A0if (ecs->ws.kind =3D=3D TARGET_WAITKIND_IGNORE) > + =A0 =A0{ > + =A0 =A0 =A0/* We had an event in the inferior, but we are not intereste= d in > + =A0 =A0 =A0 =A0handling it at this level. =A0The lower layers have alre= ady > + =A0 =A0 =A0 =A0done what needs to be done, if anything. > + > + =A0 =A0 =A0 =A0One of the possible circumstances for this is when the > + =A0 =A0 =A0 =A0inferior produces output for the console. =A0The inferio= r has > + =A0 =A0 =A0 =A0not stopped, and we are ignoring the event. =A0Another p= ossible > + =A0 =A0 =A0 =A0circumstance is any event which the lower level knows wi= ll be > + =A0 =A0 =A0 =A0reported multiple times without an intervening resume. = =A0*/ > + =A0 =A0 =A0if (debug_infrun) > + =A0 =A0 =A0 fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND_IG= NORE\n"); > + =A0 =A0 =A0prepare_to_wait (ecs); > + =A0 =A0 =A0return; > + =A0 =A0} > + > =A0 if (ecs->ws.kind !=3D TARGET_WAITKIND_EXITED > - =A0 =A0 =A0&& ecs->ws.kind !=3D TARGET_WAITKIND_SIGNALLED > - =A0 =A0 =A0&& ecs->ws.kind !=3D TARGET_WAITKIND_IGNORE) > + =A0 =A0 =A0&& ecs->ws.kind !=3D TARGET_WAITKIND_SIGNALLED) > =A0 =A0 { > =A0 =A0 =A0 struct inferior *inf =3D find_inferior_pid (ptid_get_pid (ecs= ->ptid)); > =A0 =A0 =A0 gdb_assert (inf); > @@ -2479,22 +2495,19 @@ handle_inferior_event (struct execution_ > =A0 /* Dependent on the current PC value modified by adjust_pc_after_brea= k. =A0*/ > =A0 reinit_frame_cache (); > > - =A0if (ecs->ws.kind !=3D TARGET_WAITKIND_IGNORE) > - =A0 =A0{ > - =A0 =A0 =A0breakpoint_retire_moribund (); > + =A0breakpoint_retire_moribund (); > > - =A0 =A0 =A0/* Mark the non-executing threads accordingly. =A0In all-sto= p, all > - =A0 =A0 =A0 =A0threads of all processes are stopped when we get any eve= nt > - =A0 =A0 =A0 =A0reported. =A0In non-stop mode, only the event thread sto= ps. =A0If > - =A0 =A0 =A0 =A0we're handling a process exit in non-stop mode, there's > - =A0 =A0 =A0 =A0nothing to do, as threads of the dead process are gone, = and > - =A0 =A0 =A0 =A0threads of any other process were left running. =A0*/ > - =A0 =A0 =A0if (!non_stop) > - =A0 =A0 =A0 set_executing (minus_one_ptid, 0); > - =A0 =A0 =A0else if (ecs->ws.kind !=3D TARGET_WAITKIND_SIGNALLED > - =A0 =A0 =A0 =A0 =A0 =A0 =A0&& ecs->ws.kind !=3D TARGET_WAITKIND_EXITED) > - =A0 =A0 =A0 set_executing (inferior_ptid, 0); > - =A0 =A0} > + =A0/* Mark the non-executing threads accordingly. =A0In all-stop, all > + =A0 =A0 threads of all processes are stopped when we get any event > + =A0 =A0 reported. =A0In non-stop mode, only the event thread stops. =A0= If > + =A0 =A0 we're handling a process exit in non-stop mode, there's nothing > + =A0 =A0 to do, as threads of the dead process are gone, and threads of > + =A0 =A0 any other process were left running. =A0*/ > + =A0if (!non_stop) > + =A0 =A0set_executing (minus_one_ptid, 0); > + =A0else if (ecs->ws.kind !=3D TARGET_WAITKIND_SIGNALLED > + =A0 =A0 =A0 =A0 =A0&& ecs->ws.kind !=3D TARGET_WAITKIND_EXITED) > + =A0 =A0set_executing (inferior_ptid, 0); > > =A0 switch (infwait_state) > =A0 =A0 { > @@ -2777,21 +2790,6 @@ handle_inferior_event (struct execution_ > =A0 =A0 =A0 print_stop_reason (NO_HISTORY, 0); > =A0 =A0 =A0 stop_stepping (ecs); > =A0 =A0 =A0 return; > - > - =A0 =A0 =A0/* We had an event in the inferior, but we are not interested > - =A0 =A0 =A0 =A0 in handling it at this level. The lower layers have alr= eady > - =A0 =A0 =A0 =A0 done what needs to be done, if anything. > - > - =A0 =A0 =A0 =A0 One of the possible circumstances for this is when the > - =A0 =A0 =A0 =A0 inferior produces output for the console. The inferior = has > - =A0 =A0 =A0 =A0 not stopped, and we are ignoring the event. =A0Another = possible > - =A0 =A0 =A0 =A0 circumstance is any event which the lower level knows w= ill be > - =A0 =A0 =A0 =A0 reported multiple times without an intervening resume. = =A0*/ > - =A0 =A0case TARGET_WAITKIND_IGNORE: > - =A0 =A0 =A0if (debug_infrun) > - =A0 =A0 =A0 =A0fprintf_unfiltered (gdb_stdlog, "infrun: TARGET_WAITKIND= _IGNORE\n"); > - =A0 =A0 =A0prepare_to_wait (ecs); > - =A0 =A0 =A0return; > =A0 =A0 } > > =A0 if (ecs->new_thread_event) >