Hi Ulrich and Simon, Please find attached the patch [See: 0001-Enable-multi-process-debugging-for-AIX.patch] I have taken care of parent child relationship. See find_my_aix_parent () function. You can refer the link https://www.ibm.com/docs/en/aix/7.2?topic=g-getprocs-subroutine for the documentation of the same. I have also taken care of what if break points hit in other threads while only a child or a parent event is reported in another thread as you mentioned Ulrich or any other event. [You can refer the output I have pasted below]. The while loop will take care. getprocs Subroutine - IBM Note: The ProcessBuffer parameter of getprocs subroutine contains two struct rusage fields named pi_ru and pi_cru.Each of these fields contains two struct timeval fields named ru_utime and ru_stime.The tv_usec field in both of the struct timeval contain nanoseconds instead of microseconds. These values cone from the struct user fields named U_ru and U_cru. www.ibm.com >I understand W_SFWTED is not a bit mask, but simply a value. >So shouldn't you just test for "status == W_SFWTED"? Also, >I'm not sure where the "& 0xff" comes into play. What are >the contents of the high bits? The AIX documentation doesn't >seem to say ... So, if there is a fork event then my W_SFWTED = 0x7e = 0x01111110 bits is set in my status flag. The other bits represent other things in the status flag. Therefore, I eliminate other bits with AND operation with 0xff and see only if my first 8 bits are set.. You were right with this "status == W_SFWTED". I corrected it. Let me know what you think.. Hope this patch works.. Have a nice day ahead. Thanks and regards, Aditya. -------------------------------------------------------------- Consider the program #include #include #include #include #include pthread_barrier_t barrier; #define NUM_THREADS 2 void * thread_function (void *arg) { /* This ensures that the breakpoint is only hit after both threads are created, so the test can always switch to the non-event thread when the breakpoint triggers. */ pthread_barrier_wait (&barrier); pid_t child; child = fork (); if (child > 0) printf ("I am parent \n"); else{ printf (" Iam child \n"); child = fork (); if (child > 0) printf ("From child I became a parent \n"); else printf ("I am grandchild \n"); } while (1); /* break here */ } int main (void) { int i; alarm (300); pthread_barrier_init (&barrier, NULL, NUM_THREADS); for (i = 0; i < NUM_THREADS; i++) { pthread_t thread; int res; res = pthread_create (&thread, NULL, thread_function, NULL); assert (res == 0); } while (1) sleep (1); return 0; } Output:- Reading symbols from /home/XYZ/gdb_tests/ultimate-multi-thread-fork... (gdb) b thread_function Breakpoint 1 at 0x100006f8: file /home/XYZ/gdb_tests/ultimate-multi-thread-fork.c, line 18. (gdb) set detach-on-fork off (gdb) r Starting program: /home/XYZ/gdb_tests/ultimate-multi-thread-fork [New Thread 1] [New Thread 258] [Switching to Thread 258] Thread 3 hit Breakpoint 1, thread_function (arg=0x0) at /home/aditya/gdb_tests/ultimate-multi-thread-fork.c:18 18 pthread_barrier_wait (&barrier); (gdb) c Continuing. [New Thread 515] [Switching to Thread 515] Thread 4 hit Breakpoint 1, thread_function (arg=warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.) 0x0) at /home/XYZ/gdb_tests/ultimate-multi-thread-fork.c:18 18 pthread_barrier_wait (&barrier); (gdb) c Continuing. [New inferior 2 (process 18612656)] warning: "/usr/lib/libpthreads.a": member "shr_comm.o" missing. warning: "/usr/lib/libcrypt.a": member "shr.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 4 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"? I am parent [New inferior 3 (process 8454632)] warning: "/usr/lib/libpthreads.a": member "shr_comm.o" missing. warning: "/usr/lib/libcrypt.a": member "shr.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 4 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"? I am parent ^C Thread 1.1 received signal SIGINT, Interrupt. [Switching to process 23462236] 0xd0595fb0 in _p_nsleep () from /usr/lib/libpthread.a(shr_xpg5.o) (gdb) ________________________________ From: Ulrich Weigand Sent: 02 November 2022 14:26 To: simark@simark.ca ; Aditya Kamath1 ; gdb-patches@sourceware.org Cc: Sangamesh Mallayya Subject: Re: [PATCH] Enable multi process debugging for AIX Aditya Kamath1 wrote: >>Is there any other way of figuring out what the parent process of >>the new child is? Maybe you should just do that when you get the >>child event. > >I fully did not get the above suggestion " Maybe you should just do that when you get the >child event ". Kindly let me know what you are trying to tell me in this context. The last iteration of you patch simply has a list of "pending parent" and "pending child" PIDs. If you get a fork event for the child, and there is *any* parent PID in the "pending" list, you automatically assume that this is the parent of *this* child. I'm concerned that this may not always be true. For example, if you are already debugging multiple processes, and *two* of those fork at the same time, you'll be getting four ptrace events in GDB - two events for the two parent processes, and two events for the two new child processes. If this happens, you'll need to verify which child is actually associated with *which* parent. As you note, on other platforms this relationship is reported as part of the ptrace event directly, and this is apparently not the case on AIX. However, the OS of course still knows what the parent process of each of the child processes is - so I guess there should be *some* way to find this out from within GDB. (E.g. in Linux you could get at that information by reading some /proc files.) Bye, Ulrich