[RFA] Implement 'detach pid'.

Pedro Alves pedro@codesourcery.com
Fri Nov 14 05:12:00 GMT 2008


On Thursday 13 November 2008 21:58:49, Vladimir Prus wrote:

>  /* Iterator function to call a user-provided callback function
> -   once for each known thread.  */
> +   once for each known thread.  Returns 0 to continue iteration,
> +   and 1 to stop -- which causes iterate_over_threads to return
> +   the current thread_info.  */

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.

>  typedef int (*thread_callback_func) (struct thread_info *, void *);
>  extern 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.

> +void
> +mi_cmd_target_detach (char *command, char **argv, int argc)
> +{
> +  if (argc != 0 && argc != 1)
> +    error ("Usage: -target-detach [thread-group]");
> +
> +  if (argc == 1)
> +    {
> +      struct thread_info *tp;
> +      char *end = argv[0];
> +      int pid = strtol (argv[0], &end, 10);
> +      if (*end != '\0')
> +       error (_("Cannot parse thread group id '%s'"), argv[0]);
> +
> +      /* Pick any thread in the desired process.  Current
> +        target_detach deteches from the parent of inferior_ptid.  */
                            ^ detaches.

> +      tp = iterate_over_threads (find_thread_of_process, &pid);
> +      if (!tp)
> +       error (_("Thread group is empty"));

Yep, something like that.

I take that it's OK then to not revert back to the
previous thread?

Thanks!

-- 
Pedro Alves



More information about the Gdb-patches mailing list