Hi Ulrich and community, Please find attached the patch. {See: : 0001-Fix-Assertion-pid-0-failure-in-AIX.patch} Ideally this patch should have worked and it is. But I see some problems. >I'm not sure this is quite right. Can this now cause leaks e.g. >because we did not properly call pthdb_session_destroy? >Also, I'm starting to wonder if using inferior_ptid is right here >in the first place. For example, aix_thread_target::detach >actually gets an "inferior *" argument, which it then completely >ignores and instead tries to re-create an inferior from >inferior_ptid - this doesn't look right. >I guess pd_enable and pd_disable should be getting inferior * >arguments and use those, whenever available. Yes it does cause leaks. Currently there are two places from where pd_disable () is called. One from aix_thread_tarhet::detach () where we have the inferior. Unfortunately this is not getting called at all and hence we are never actually detaching. We can take the case of the program pasted in this mail below. But even in complex programs detach has never been called. This makes me worried that I am missing something major. Am I?? And when pd_disable () is called it is from the mourn inferior (). Here we do not have the inferior_ptid.pid nor the inf to catch hold of the exited thread/process.. So in AIX, thread exits are not captured properly. I have missed something in my analysis. This patch is only an adjustment that fixes the problem, but not correctly. Also I begin to see these warnings… Starting program: /home/aditya/latest_gdb/binutils-gdb/gdb/foll-fork-other-thread [New Thread 258] [New inferior 2 (process 30278140)] warning: "/usr/lib/libpthreads.a": member "shr_comm.o" missing. warning: "/usr/lib/libpthread.a": member "shr_xpg5.o" missing. warning: "/usr/lib/libc.a": member "shr.o" missing. warning: Could not load shared library symbols for 3 libraries, e.g. /usr/lib/libpthreads.a(shr_comm.o). Use the "info sharedlibrary" command to see the complete listing. Do you need "set solib-search-path" or "set sysroot"? [New process 29229422] This indicates my shared libraries are not loaded. When I checked in my solib-aix.c I figured out that the function gdb_bfd_ref_ptr object_bfd (gdb_bfd_openr_next_archived_file (archive_bfd.get (), NULL)); is returning NULL for object_bfd and hence it does not enter that while loop in search of the library and this happens for every new forked process that is attached. And what’s worse is libc is getting loaded properly. The other three are not. You can see it in the ouput pasted below named as problematic output. Did this API change in the last few days?? Until Thursday all was fine and I was not seeing these warnings. I updated my GDB to the latest development branch today. So I have these problems and I am missing a trick. I have shared the details of my analysis. Kindly let me know where I have gone wrong and where we can correct this. Have a nice day ahead. Thanks and regards, Aditya. ---------------------------------------------- Code:- { Program Credits: GDB threads testsuite} #include #include #include #include #include #include #include /* Set by GDB. */ volatile int stop_looping = 0; static void * gdb_forker_thread (void *arg) { int ret; int stat; pid_t pid = FORK_FUNC (); if (pid == 0) _exit (0); assert (pid > 0); /* Wait for child to exit. */ do { ret = waitpid (pid, &stat, 0); } while (ret == -1 && errno == EINTR); assert (ret == pid); assert (WIFEXITED (stat)); assert (WEXITSTATUS (stat) == 0); stop_looping = 1; return NULL; } static void sleep_a_bit (void) { usleep (1000 * 50); } int main (void) { int i; int ret; pthread_t thread; alarm (60); ret = pthread_create (&thread, NULL, gdb_forker_thread, NULL); assert (ret == 0); while (!stop_looping) /* while loop */ { sleep_a_bit (); /* break here */ sleep_a_bit (); /* other line */ } pthread_join (thread, NULL); return 0; /* exiting here */ } ---------------------------------------- Output before patch:- ./gdb ~/gdb_tests/foll-fork-other-thread GNU gdb (GDB) 14.0.50.20230327-git Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "powerpc64-ibm-aix7.2.0.0". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from /home/aditya/gdb_tests/foll-fork-other-thread... (gdb) r Starting program: /home/aditya/gdb_tests/foll-fork-other-thread [New Thread 258] [Detaching after fork from child process 10944778] [Inferior 1 (process 7209300) exited normally] inferior.c:350: internal-error: find_inferior_pid: Assertion `pid != 0' failed. A problem internal to GDB has been detected, further debugging may prove unreliable. ----- Backtrace ----- 0x100f7d307 ??? 0x100f7d4cf ??? -------------------------------------------------------- Output after applying patch:- bash-5.1$ ./gdb ~/gdb_tests/foll-fork-other-thread GNU gdb (GDB) 14.0.50.20230327-git Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "powerpc64-ibm-aix7.2.0.0". Type "show configuration" for configuration details. For bug reporting instructions, please see: . Find the GDB manual and other documentation resources online at: . For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from /home/aditya/gdb_tests/foll-fork-other-thread... (gdb) r Starting program: /home/aditya/gdb_tests/foll-fork-other-thread [New Thread 258] [Detaching after fork from child process 7209320] [Inferior 1 (process 10944912) exited normally] (gdb) Problematic case:- bash-5.1$ ./gdb foll-fork-other-thread GNU gdb (GDB) 14.0.50.20230502-git Copyright (C) 2023 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "powerpc64-ibm-aix7.2.0.0". Type "show configuration" for configuration details. For bug reporting instructions, please see: https://www.gnu.org/software/gdb/bugs/. Find the GDB manual and other documentation resources online at: http://www.gnu.org/software/gdb/documentation/. For help, type "help". Type "apropos word" to search for commands related to "word"... Reading symbols from foll-fork-other-thread... (gdb) set detach-on-fork off (gdb) r Starting program: /home/aditya/latest_gdb/binutils-gdb/gdb/foll-fork-other-thread [New Thread 258] [New inferior 2 (process 29295030)] warning: "/usr/lib/libpthreads.a": member "shr_comm.o" missing. warning: "/usr/lib/libpthread.a": member "shr_xpg5.o" missing. warning: "/usr/lib/libc.a": member "shr.o" missing. warning: Could not load shared library symbols for 3 libraries, e.g. /usr/lib/libpthreads.a(shr_comm.o). Use the "info sharedlibrary" command to see the complete listing. Do you need "set solib-search-path" or "set sysroot"? [New process 20251106] Thread 1.3 received signal SIGINT, Interrupt. [Switching to process 20251106] 0xd02390e0 in waitpid () from /usr/lib/libc.a(shr.o) (gdb) inferior 2 [Switching to inferior 2 [process 29295030] (/home/aditya/latest_gdb/binutils-gdb/gdb/foll-fork-other-thread)] [Switching to thread 2.1 (process 29295030)] #0 0xd058f948 in ?? () (gdb) info sharedlibrary From To Syms Read Shared Object Library No /usr/lib/libpthreads.a(shr_comm.o) 0xd05b5240 0xd05b59a1 Yes (*) /usr/lib/libcrypt.a(shr.o) No /usr/lib/libpthread.a(shr_xpg5.o) No /usr/lib/libc.a(shr.o) (*): Shared library is missing debugging information. (gdb) From: Ulrich Weigand Date: Thursday, 27 April 2023 at 5:50 PM To: gdb-patches@sourceware.org , Aditya Kamath1 Cc: Sangamesh Mallayya Subject: Re: [Patch] Fix Assertion pid 0 failure in AIX while running gdb.threads/foll-fork-other-thread Aditya Kamath1 wrote: >Once the thread completes execution and goes to pd_disable () in >aix-thread.c , since the process exits, the inferior_ptid.pid () is 0. >Hence in pd_disable () when GDB goes to fetch the aix thread data for >process 0, this assertion failure occurs. I'm not sure this is quite right. Can this now cause leaks e.g. because we did not properly call pthdb_session_destroy? Also, I'm starting to wonder if using inferior_ptid is right here in the first place. For example, aix_thread_target::detach actually gets an "inferior *" argument, which it then completely ignores and instead tries to re-create an inferior from inferior_ptid - this doesn't look right. I guess pd_enable and pd_disable should be getting inferior * arguments and use those, whenever available. Bye, Ulrich