From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 18398 invoked by alias); 13 Nov 2008 22:49:49 -0000 Received: (qmail 18320 invoked by uid 22791); 13 Nov 2008 22:49:47 -0000 X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 13 Nov 2008 22:49:10 +0000 Received: (qmail 17145 invoked from network); 13 Nov 2008 22:49:08 -0000 Received: from unknown (HELO orlando.local) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 13 Nov 2008 22:49:08 -0000 From: Pedro Alves To: Vladimir Prus Subject: Re: [RFA] Implement 'detach pid'. Date: Fri, 14 Nov 2008 05:12:00 -0000 User-Agent: KMail/1.9.10 Cc: gdb-patches@sourceware.org References: <200811122339.02463.vladimir@codesourcery.com> <200811122319.57637.pedro@codesourcery.com> <200811140058.49275.vladimir@codesourcery.com> In-Reply-To: <200811140058.49275.vladimir@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200811132249.18018.pedro@codesourcery.com> 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: 2008-11/txt/msg00308.txt.bz2 On Thursday 13 November 2008 21:58:49, Vladimir Prus wrote: > =C2=A0/* Iterator function to call a user-provided callback function > - =C2=A0 once for each known thread. =C2=A0*/ > + =C2=A0 once for each known thread. =C2=A0Returns 0 to continue iteratio= n, > + =C2=A0 and 1 to stop -- which causes iterate_over_threads to return > + =C2=A0 the current thread_info. =C2=A0*/ To be honest, this sounds a bit confusing to me: the iterator function, which is what was being described in the first sentence isn't the same subject of the second sentence, "returns 0 ..." is now talking about the callback. > =C2=A0typedef int (*thread_callback_func) (struct thread_info *, void *); > =C2=A0extern struct thread_info *iterate_over_threads (thread_callback_fu= nc, void *); Notice that a few gdbthread.h exported functions are also documented in thread.c. In this case: /* * Thread iterator function. * * Calls a callback function once for each thread, so long as * the callback function returns false. If the callback function * returns true, the iteration will end and the current thread * will be returned. This can be useful for implementing a=20 * search for a thread with arbitrary attributes, or for applying * some operation to every thread. * */ If we're moving the descriptions around, please, let's do that as a separate patch. > +void > +mi_cmd_target_detach (char *command, char **argv, int argc) > +{ > + =C2=A0if (argc !=3D 0 && argc !=3D 1) > + =C2=A0 =C2=A0error ("Usage: -target-detach [thread-group]"); > + > + =C2=A0if (argc =3D=3D 1) > + =C2=A0 =C2=A0{ > + =C2=A0 =C2=A0 =C2=A0struct thread_info *tp; > + =C2=A0 =C2=A0 =C2=A0char *end =3D argv[0]; > + =C2=A0 =C2=A0 =C2=A0int pid =3D strtol (argv[0], &end, 10); > + =C2=A0 =C2=A0 =C2=A0if (*end !=3D '\0') > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0error (_("Cannot parse thread = group id '%s'"), argv[0]); > + > + =C2=A0 =C2=A0 =C2=A0/* Pick any thread in the desired process. =C2=A0Cu= rrent > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 target_detach deteches from t= he parent of inferior_ptid. =C2=A0*/ ^ detaches. > + =C2=A0 =C2=A0 =C2=A0tp =3D iterate_over_threads (find_thread_of_process= , &pid); > + =C2=A0 =C2=A0 =C2=A0if (!tp) > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0error (_("Thread group is empt= y")); Yep, something like that. I take that it's OK then to not revert back to the previous thread? Thanks! --=20 Pedro Alves