Hi Ulrich and community, Please find attached the patch. {See: : 0001-Fix-Assertion-pid-0-failure-in-AIX.patch} >Ah, right. There's indeed no inf argument (unfortunately), but you can >just use "current_inferior ()" instead. This is guaranteed to be >set correctly at this point. This makes it easy. Thanks Ulrich. It fixes the issue and no memory leaks. Kindly push this small patch if there are no further changes. >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. [snip] >>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. >I'm not aware of anything. But if you noticed this when updating the >GDB sources recently, you might be able to find the specific commit >that introduced the breakage via bisect (binary search). I will dig this deeper and figure out. Thanks. Thanks and regards, Aditya. ---------------------------- Output after patch application:- 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) r Starting program: /home/aditya/latest_gdb/binutils-gdb/gdb/foll-fork-other-thread [New Thread 258] [Detaching after fork from child process 20906416] [Inferior 1 (process 21365186) exited normally] (gdb) Output without applying the patch:- (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 ??? The code :- 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 */ } From: Ulrich Weigand Date: Tuesday, 2 May 2023 at 6:23 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: >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?? ::detach() is called when you detach from an inferior that GDB attached to (i.e. when using the "detach" command). It is not called for an inferior that was actually started under GDB; ::mourn_inferior() is used in those cases. >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.. Ah, right. There's indeed no inf argument (unfortunately), but you can just use "current_inferior ()" instead. This is guaranteed to be set correctly at this point. >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. [snip] >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. I'm not aware of anything. But if you noticed this when updating the GDB sources recently, you might be able to find the specific commit that introduced the breakage via bisect (binary search). Bye, Ulrich