From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22467 invoked by alias); 14 Nov 2008 05:12:32 -0000 Received: (qmail 22410 invoked by uid 22791); 14 Nov 2008 05:12:30 -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; Fri, 14 Nov 2008 05:11:54 +0000 Received: (qmail 3187 invoked from network); 14 Nov 2008 05:11:52 -0000 Received: from unknown (HELO wind.localnet) (vladimir@127.0.0.2) by mail.codesourcery.com with ESMTPA; 14 Nov 2008 05:11:52 -0000 From: Vladimir Prus To: Pedro Alves Subject: Re: [RFA] Implement 'detach pid'. Date: Fri, 14 Nov 2008 12:57:00 -0000 User-Agent: KMail/1.10.90 (Linux/2.6.24-21-generic; KDE/4.1.73; i686; svn-883826; 2008-11-13) Cc: gdb-patches@sourceware.org References: <200811122339.02463.vladimir@codesourcery.com> <200811140058.49275.vladimir@codesourcery.com> <200811132249.18018.pedro@codesourcery.com> In-Reply-To: <200811132249.18018.pedro@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200811140811.46025.vladimir@codesourcery.com> 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/msg00322.txt.bz2 On Friday 14 November 2008 01:49:17 Pedro Alves wrote: > 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 iterat= ion, > > + =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_= func, > > 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 > * 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. Ok, I'll drop this part. I can never get accustomed to the practice to documenting interface inside implementation files :-) > > +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 threa= d group id '%s'"), argv[0]); > > + > > + =C2=A0 =C2=A0 =C2=A0/* Pick any thread in the desired process. =C2=A0= Current > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 target_detach deteches from= the parent of inferior_ptid. =C2=A0*/ > > ^ detaches. > > > + =C2=A0 =C2=A0 =C2=A0tp =3D iterate_over_threads (find_thread_of_proce= ss, &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 em= pty")); > > Yep, something like that. > > I take that it's OK then to not revert back to the > previous thread? Yes, --thread work the same way. - Volodya