Re: Cell multi-arch broken (Re: [PATCH 2/2] GNU/Linux: Stop using libthread_db/td_ta_thr_iter)

Doug Evans
2015-09-19T06:21:27Z

Doug Evans <xdje42@gmail.com> writes:
> "Ulrich Weigand" <uweigand@de.ibm.com> writes:
>> Ah, indeed that works for me. The attached patch also fixes the
>> problem for me.
>>
>> Bye,
>> Ulrich
>>
>> Index: binutils-gdb/gdb/linux-thread-db.c
>> ===================================================================
>> --- binutils-gdb.orig/gdb/linux-thread-db.c
>> +++ binutils-gdb/gdb/linux-thread-db.c
>> @@ -1851,13 +1851,16 @@ thread_db_get_thread_local_address (stru
>> struct thread_info *thread_info;
>> struct target_ops *beneath;
>>
>> - /* If we have not discovered any threads yet, check now. */
>> - if (!have_threads (ptid))
>> - thread_db_find_new_threads_1 (ptid);
>> -
>> /* Find the matching thread. */
>> thread_info = find_thread_ptid (ptid);
>>
>> + /* We may not have discovered the thread yet. */
>> + if (thread_info != NULL && thread_info->priv == NULL)
>> + {
>> + thread_from_lwp (ptid);
>> + thread_info = find_thread_ptid (ptid);
>> + }
>> +
>> if (thread_info != NULL && thread_info->priv != NULL)
>> {
>> td_err_e err;
>
> Hi.
>
> Just a thought.
>
> It's kinda clumsy that thread_from_lwp ends with this:
>
> /* Fill the cache. */
> tp = find_thread_ptid (ptid);
> record_thread (info, tp, ptid, &th, &ti);
>
> and then we just call find_thread_ptid again after it returns:
>
>> + thread_from_lwp (ptid);
>> + thread_info = find_thread_ptid (ptid);
>
> One might ask "Why doesn't thread_from_lwp just return thread_info?"
>
> From record_thread things seem to be a be more subtle.
> Even if we pass in a non-NULL TP we may still create a new one.
>
> /* Add the thread to GDB's thread list. If we already know about a
> thread with this PTID, but it's marked exited, then the kernel
> reused the tid of an old thread. */
> if (tp == NULL || tp->state == THREAD_EXITED)
> tp = add_thread_with_info (ptid, priv);
> else
> tp->priv = priv;
>
> So it'd be helpful if record_thread also returned tp.
> Sound about right?
>
> 2015-08-27 Doug Evans <xdje42@gmail.com>
>
> * linux-thread-db.c (record_thread): Return the created thread.
> (thread_from_lwp): Likewise.
> (thread_db_get_thread_local_address): Update.

Committed.