Re: [PATCH v2 18/24] Multi-target support

Simon Marchi
2020-01-17T15:49:31Z

On 2020-01-16 10:47 p.m., Simon Marchi wrote:
> On 2019-10-17 6:50 p.m., Pedro Alves wrote:
>> This commit adds multi-target support to GDB. What this means is that
>> with this commit, GDB can now be connected to different targets at the
>> same time. E.g., you can debug a live native process and a core dump
>> at the same time, connect to multiple gdbservers, etc.
>
> Hi Pedro,
>
> I think I found something odd happening starting with this commit. When
> the test gdb.threads/tid-reuse.exp runs, we are adding a thread_info to the
> inferior's thread list when a thread_info object with the same ptid is
> already present. I don't think this is ever supposed to happen, right?
>
> This can be observed by applying the following diff and running
> gdb.threads/tid-reuse.exp. Note that some distributions are starting to bump
> pid_max to a really large value, so make sure it's not that on your system.
>
> diff --git a/gdb/thread.c b/gdb/thread.c
> index 4959f938c7f3..8909e371e2ce 100644
> --- a/gdb/thread.c
> +++ b/gdb/thread.c
> @@ -254,7 +254,10 @@ new_thread (struct inferior *inf, ptid_t ptid)
> struct thread_info *last;
>
> for (last = inf->thread_list; last->next != NULL; last = last->next)
> - ;
> + gdb_assert (ptid != last->ptid);
> +
> + gdb_assert (ptid != last->ptid);
> +
> last->next = tp;
> }
>
>
> What I have found so far, by breaking at thread.c:274 and stepping into
> the "delete_thread" call, is that `inferior_ptid == ptid` is false
> (inferior_ptid is (0,0,0)). In delete_thread, we are actually not
> deleting the thread because ->deletable () returns false, because
> the refcount is 2.
>
> Before this patch, we would enter the `if (inferior_ptid == ptid)`.
>
> If it can help, here is the command line I'm using to debug this, which is
> mimicking the test:
>
> ./gdb -nx --data-directory=data-directory testsuite/outputs/gdb.threads/tid-reuse/tid-reuse -iex "set confirm off" -iex "set pagination off" -ex start -ex "set print thread-events off" -ex "b after_count" -ex c -ex "b do_nothing_thread_func" -ex c -ex d -ex "b after_reuse_time" -ex c
>
> Simon
>

I filed this in bugzilla, so we can track it better:

https://sourceware.org/bugzilla/show_bug.cgi?id=25412

Simon