[PATCH] Fix-for-multiple-thread-detection-in-AIX.patch
Simon Marchi
simark@simark.ca
Mon Jul 25 15:30:36 GMT 2022
On 2022-07-25 08:21, Ulrich Weigand wrote:
>
> Aditya Kamath1 <Aditya.Kamath1@ibm.com> wrote:
>
>> The cause of the bug :- Since, for the GDB core we are
>> switch_to_no_thread() i.e. we do not have a thread till we return the
>> pid from the wait() there is no thread. So, when a call is made from
>> pd_activate() in wait() of aix-thread.c, to pthdb_session_init() we are
>> going to recieve PTHDB_NOT_THREADED.
>
> Thanks for the explanation. I wasn't aware the use of
> inferior_ptid happens in some of callback routines used
> by the pthdb_session_init() library routine.
Thanks, me neither, but it makes sense.
> I still think the proposed fix isn't really ideal. Can you instead
> try to *temporarily* (i.e. using a scoped_restore) set up inferior_ptid
> in pd_activate() before calling pthdb_session_init(), with a comment
> explaining that this is needed for the callbacks?
That sounds like a good idea, this way, from the point of view of the
caller of pd_activate, pd_activate does not care about global state.
That's how we can do baby steps towards relying less on global state
implicitly. The next step could be to try to make each individual
callback switch to the right global context, based on what they need.
You just need to be careful, some parts of GDB expect inferior_ptid, the
current thread, the current inferior and the current program space to be
sync'ed. If you just set inferior_ptid, you need to make sure to only
call functions that use inferior_ptid, not the other current stuff.
There is not practical way to know this, you have to carefully inspect
what is called. To avoid this kind of problems, you can temporarily
switch thread (using scoped_restore_current_thread + switch_to_thread),
which will set all the current stuff mentioned above. But sometimes
this isn't possible, especially in thw wait method, because there isn't
always a thread_info for the ptid you are handling yet, so you can't
switch to it.
Given the AIX target only supports one inferior for now, the current
inferior and program space should be correct. But to support
multi-inferior, it will be important to keep that in mind. You might
have to switch to the right inferior in addition to setting
inferior_ptid in pd_acticate.
This hunk in the patch:
diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index 4c9195a7f12..91466a17647 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -976,7 +976,7 @@ pd_enable (void)
/* If we're debugging a core file or an attached inferior, the
pthread library may already have been initialized, so try to
activate thread debugging. */
- pd_activate (1);
+ pd_activate (inferior_ptid.pid());
}
looks right to me (except the missing space before the parenthesis). It
looks like an oversight in my "gdb: fix
{rs6000_nat_target,aix_thread_target}::wait to not use inferior_ptid"
patch, I forgot to update that call to pd_activate. Note that the old
parameter to pd_activate was SET_INFPID, and if set, pd_update would
change the current thread to reflect the thread ptid, if thread
debugging was enabled. The current code no longer does that. If that
was important, we can re-introduce it here: make pd_enable switch to the
thread with the ptid returned by pd_activate.
Simon
More information about the Gdb-patches
mailing list