RE: [PATCH v7 5/5] gdb/infrun: handle already-exited threads when attempting to stop

Aktemur, Tankut Baris
2020-04-22T16:07:23Z

On Wednesday, April 22, 2020 5:01 PM, Aktemur, Tankut Baris wrote:
> diff --git a/gdb/infrun.c b/gdb/infrun.c
> index 167d50ff3ab..93169269553 100644
> --- a/gdb/infrun.c
> +++ b/gdb/infrun.c
> @@ -4781,7 +4781,47 @@ stop_all_threads (void)
> {
> int need_wait = 0;
>
> - update_thread_list ();
> + for (inferior *inf : all_non_exited_inferiors ())
> + {

Sorry. There is a 'switch_to_inferior_no_thread (inf);', here.

> + update_thread_list ();
> +
> + /* After updating the thread list, it's possible to end
> + up with pid != 0 but no threads, if the inf's process
> + has exited but we have not processed that event yet.
> + The exit event must be waiting somewhere in the queue
> + to be processed. Silently add a thread so that we do
> + a wait_one() below to pick the pending event. */
> +
> + bool has_threads = false;
> + for (thread_info *tp ATTRIBUTE_UNUSED
> + : inf->non_exited_threads ())
> + {
> + has_threads = true;
> + break;
> + }
> +
> + if (has_threads)
> + continue;
> +
> + ptid_t ptid (inf->pid, inf->pid, 0);
> +
> + /* Re-surrect the thread, if not physically deleted.
> + Add a new one otherwise. */
> + thread_info *t = find_thread_ptid (inf->process_target (), ptid);
> + gdb_assert (t == nullptr || t->state == THREAD_EXITED);
> +
> + if (debug_infrun)
> + fprintf_unfiltered (gdb_stdlog, "infrun: stop_all_threads,"
> + " inf (pid %d): %s a thread", inf->pid,
> + (t == nullptr)
> + ? "adding" : "resurrecting");
> +
> + if (t == nullptr)
> + t = add_thread_silent (inf->process_target (), ptid);
> +
> + set_executing (inf->process_target (), ptid, true);
> + t->state = THREAD_STOPPED;
> + }

Thanks.
-Baris

Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Gary Kershaw
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928