From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1158) id 3C74D385703C; Tue, 9 Aug 2022 13:33:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3C74D385703C Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ulrich Weigand To: gdb-cvs@sourceware.org Subject: [binutils-gdb] Fix-for-multiple-thread-detection-in-AIX. X-Act-Checkin: binutils-gdb X-Git-Author: Aditya Vidyadhar Kamath X-Git-Refname: refs/heads/master X-Git-Oldrev: a8a882968a6cd3bfe64d789b6e914521c74498c2 X-Git-Newrev: 80d362484999634e11d2b9f9e6d69e2cd4fdba12 Message-Id: <20220809133355.3C74D385703C@sourceware.org> Date: Tue, 9 Aug 2022 13:33:55 +0000 (GMT) X-BeenThere: gdb-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Aug 2022 13:33:55 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dbinutils-gdb.git;h=3D80d362484999= 634e11d2b9f9e6d69e2cd4fdba12 commit 80d362484999634e11d2b9f9e6d69e2cd4fdba12 Author: Aditya Vidyadhar Kamath Date: Fri Aug 5 09:07:37 2022 -0500 Fix-for-multiple-thread-detection-in-AIX. =20 In AIX multiple threads were not added. This patch is a fix for the same =20 When we create a pthread debug session we have callbacks to read symbols and memory. One of those call backs is pdc_read_data. =20 Before we come into aix-thread wait() we switch to no thread and therefore the current thread is null. =20 When we get into pdc_read_data we have a dependency that we need to be in the correct current thread that has caused an event of new thread, inorder to read memory. =20 Hence we switch to the correct thread. =20 This is done by passing the pid in the pthdb_user_t user_current_pid parameter in every call back. Diff: --- gdb/aix-thread.c | 63 +++++++++++++++++++++++++++++++---------------------= ---- 1 file changed, 35 insertions(+), 28 deletions(-) diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index 4c9195a7f12..57e5756e144 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -72,11 +72,6 @@ static bool debug_aix_thread; =20 #define PD_TID(ptid) (pd_active && ptid.tid () !=3D 0) =20 -/* pthdb_user_t value that we pass to pthdb functions. 0 causes - PTHDB_BAD_USER errors, so use 1. */ - -#define PD_USER 1 - /* Success and failure values returned by pthdb callbacks. */ =20 #define PDC_SUCCESS PTHDB_SUCCESS @@ -331,7 +326,7 @@ pid_to_prc (ptid_t *ptidp) the address of SYMBOLS[].name. */ =20 static int -pdc_symbol_addrs (pthdb_user_t user, pthdb_symbol_t *symbols, int count) +pdc_symbol_addrs (pthdb_user_t user_current_pid, pthdb_symbol_t *symbols, = int count) { struct bound_minimal_symbol ms; int i; @@ -339,8 +334,8 @@ pdc_symbol_addrs (pthdb_user_t user, pthdb_symbol_t *sy= mbols, int count) =20 if (debug_aix_thread) gdb_printf (gdb_stdlog, - "pdc_symbol_addrs (user =3D %ld, symbols =3D 0x%lx, count =3D %d)\n", - user, (long) symbols, count); + "pdc_symbol_addrs (user_current_pid =3D %ld, symbols =3D 0x%lx, count = =3D %d)\n", + user_current_pid, (long) symbols, count); =20 for (i =3D 0; i < count; i++) { @@ -378,7 +373,7 @@ pdc_symbol_addrs (pthdb_user_t user, pthdb_symbol_t *sy= mbols, int count) If successful return 0, else non-zero is returned. */ =20 static int -pdc_read_regs (pthdb_user_t user,=20 +pdc_read_regs (pthdb_user_t user_current_pid, pthdb_tid_t tid, unsigned long long flags, pthdb_context_t *context) @@ -450,7 +445,7 @@ pdc_read_regs (pthdb_user_t user, If successful return 0, else non-zero is returned. */ =20 static int -pdc_write_regs (pthdb_user_t user, +pdc_write_regs (pthdb_user_t user_current_pid, pthdb_tid_t tid, unsigned long long flags, pthdb_context_t *context) @@ -500,17 +495,29 @@ pdc_write_regs (pthdb_user_t user, /* pthdb callback: read LEN bytes from process ADDR into BUF. */ =20 static int -pdc_read_data (pthdb_user_t user, void *buf,=20 +pdc_read_data (pthdb_user_t user_current_pid, void *buf, pthdb_addr_t addr, size_t len) { int status, ret; =20 if (debug_aix_thread) gdb_printf (gdb_stdlog, - "pdc_read_data (user =3D %ld, buf =3D 0x%lx, addr =3D %s, len =3D %ld)\n= ", - user, (long) buf, hex_string (addr), len); + "pdc_read_data (user_current_pid =3D %ld, buf =3D 0x%lx, addr =3D %s, le= n =3D %ld)\n", + user_current_pid, (long) buf, hex_string (addr), len); =20 - status =3D target_read_memory (addr, (gdb_byte *) buf, len); + /* This is needed to eliminate the dependency of current thread + which is null so that thread reads the correct target memory. */ + { + scoped_restore_current_thread restore_current_thread; + /* Before the first inferior is added, we pass inferior_ptid.pid () + from pd_enable () which is 0. There is no need to switch threads + during first initialisation. In the rest of the callbacks the + current thread needs to be correct. */ + if (user_current_pid !=3D 0) + switch_to_thread (current_inferior ()->process_target (), + ptid_t (user_current_pid)); + status =3D target_read_memory (addr, (gdb_byte *) buf, len); + } ret =3D status =3D=3D 0 ? PDC_SUCCESS : PDC_FAILURE; =20 if (debug_aix_thread) @@ -522,15 +529,15 @@ pdc_read_data (pthdb_user_t user, void *buf, /* pthdb callback: write LEN bytes from BUF to process ADDR. */ =20 static int -pdc_write_data (pthdb_user_t user, void *buf,=20 +pdc_write_data (pthdb_user_t user_current_pid, void *buf, pthdb_addr_t addr, size_t len) { int status, ret; =20 if (debug_aix_thread) gdb_printf (gdb_stdlog, - "pdc_write_data (user =3D %ld, buf =3D 0x%lx, addr =3D %s, len =3D %ld)\= n", - user, (long) buf, hex_string (addr), len); + "pdc_write_data (user_current_pid =3D %ld, buf =3D 0x%lx, addr =3D %s, l= en =3D %ld)\n", + user_current_pid, (long) buf, hex_string (addr), len); =20 status =3D target_write_memory (addr, (gdb_byte *) buf, len); ret =3D status =3D=3D 0 ? PDC_SUCCESS : PDC_FAILURE; @@ -545,12 +552,12 @@ pdc_write_data (pthdb_user_t user, void *buf, in BUFP. */ =20 static int -pdc_alloc (pthdb_user_t user, size_t len, void **bufp) +pdc_alloc (pthdb_user_t user_current_pid, size_t len, void **bufp) { if (debug_aix_thread) gdb_printf (gdb_stdlog, - "pdc_alloc (user =3D %ld, len =3D %ld, bufp =3D 0x%lx)\n", - user, len, (long) bufp); + "pdc_alloc (user_current_pid =3D %ld, len =3D %ld, bufp =3D 0x%lx)\n", + user_current_pid, len, (long) bufp); *bufp =3D xmalloc (len); if (debug_aix_thread) gdb_printf (gdb_stdlog,=20 @@ -567,12 +574,12 @@ pdc_alloc (pthdb_user_t user, size_t len, void **bufp) pointer to the result in BUFP. */ =20 static int -pdc_realloc (pthdb_user_t user, void *buf, size_t len, void **bufp) +pdc_realloc (pthdb_user_t user_current_pid, void *buf, size_t len, void **= bufp) { if (debug_aix_thread) gdb_printf (gdb_stdlog, - "pdc_realloc (user =3D %ld, buf =3D 0x%lx, len =3D %ld, bufp =3D 0x%lx)\= n", - user, (long) buf, len, (long) bufp); + "pdc_realloc (user_current_pid =3D %ld, buf =3D 0x%lx, len =3D %ld, bufp= =3D 0x%lx)\n", + user_current_pid, (long) buf, len, (long) bufp); *bufp =3D xrealloc (buf, len); if (debug_aix_thread) gdb_printf (gdb_stdlog,=20 @@ -584,11 +591,11 @@ pdc_realloc (pthdb_user_t user, void *buf, size_t len= , void **bufp) realloc callback. */ =20 static int -pdc_dealloc (pthdb_user_t user, void *buf) +pdc_dealloc (pthdb_user_t user_current_pid, void *buf) { if (debug_aix_thread) gdb_printf (gdb_stdlog,=20 - "pdc_free (user =3D %ld, buf =3D 0x%lx)\n", user, + "pdc_free (user_current_pid =3D %ld, buf =3D 0x%lx)\n", user_current_pid, (long) buf); xfree (buf); return PDC_SUCCESS; @@ -912,7 +919,7 @@ pd_activate (int pid) { int status; =09 - status =3D pthdb_session_init (PD_USER, arch64 ? PEM_64BIT : PEM_32BIT, + status =3D pthdb_session_init (pid, arch64 ? PEM_64BIT : PEM_32BIT, PTHDB_FLAG_REGS, &pd_callbacks,=20 &pd_session); if (status !=3D PTHDB_SUCCESS) @@ -955,7 +962,7 @@ pd_enable (void) =20 /* Check whether the application is pthreaded. */ stub_name =3D NULL; - status =3D pthdb_session_pthreaded (PD_USER, PTHDB_FLAG_REGS, + status =3D pthdb_session_pthreaded (inferior_ptid.pid (), PTHDB_FLAG_REG= S, &pd_callbacks, &stub_name); if ((status !=3D PTHDB_SUCCESS && status !=3D PTHDB_NOT_PTHREADED) || !stub_name) @@ -976,7 +983,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 ()); } =20 /* Undo the effects of pd_enable(). */