From 91be783a0ede9fd1fd6f55315cd59803d2910d78 Mon Sep 17 00:00:00 2001 From: Aditya Vidyadhar Kamath Date: Fri, 29 Jul 2022 03:36:21 -0500 Subject: [PATCH] Fix-for-multiple-thread-detection-in-AIX --- gdb/aix-thread.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index 4c9195a7f12..68aad282ee7 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -887,8 +887,15 @@ pd_update (int pid) status = pthdb_session_update (pd_session); if (status != PTHDB_SUCCESS) return ptid_t (pid); - - sync_threadlists (pid); + + /* This is needed to eliminate the dependency of current thread + which is null so that thread lists sync with the correct current + thread. */ + { + scoped_restore_current_thread restore_current_thread; + switch_to_thread (current_inferior ()->process_target () ,ptid_t(pid)); + sync_threadlists (pid); + } /* Define "current thread" as one that just received a trap signal. */ @@ -911,10 +918,17 @@ static ptid_t pd_activate (int pid) { int status; - - status = pthdb_session_init (PD_USER, arch64 ? PEM_64BIT : PEM_32BIT, - PTHDB_FLAG_REGS, &pd_callbacks, - &pd_session); + + /* This is needed to eliminate the dependency of callbacks on current + thread and inferior_ptid. */ + + { + scoped_restore_current_thread restore_current_thread; + switch_to_thread (current_inferior ()->process_target () ,ptid_t(pid)); + status = pthdb_session_init (PD_USER, arch64 ? PEM_64BIT : PEM_32BIT, + PTHDB_FLAG_REGS, &pd_callbacks, + &pd_session); + } if (status != PTHDB_SUCCESS) { return ptid_t (pid); @@ -976,7 +990,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 ()); } /* Undo the effects of pd_enable(). */ -- 2.31.1