From 414aa6987f21a814851e5f3113388a3616993fa3 Mon Sep 17 00:00:00 2001 From: Aditya Vidyadhar Kamath Date: Tue, 14 May 2024 15:21:41 +0530 Subject: [PATCH] Fix Segmentation Fault in AIX during multi process debugging. Due to the recent commit in aix-thread.c, we see a segmentation fault in AIX while debugging multiple process involving multiple threads. One example is a thread that can fork. The GDB output in AIX for the same is Reading symbols from //gdb_tests/multi-thread-fork... (gdb) set detach-on-fork off (gdb) r Starting program: /gdb_tests/multi-thread-fork [New Thread 258 (tid 67110997)] [New Thread 515 (tid 127404289)] [New inferior 2 (process 16580940)] Hello from Parent! [process 16580940 exited] [New inferior 3 (process 14549318)] Hello from Parent! [process 14549318 exited] Fatal signal: Segmentation fault ----- Backtrace ----- This is because in sync_threadlists () in aix-thread.c there when we delete threads in unknown state we iterate through all the threads. When we have one or more threads with the same user thread ID but of different process then we delete a wrong thread. Since we just check only the pdtid in in_queue_threads.count (priv->pdtid) == 0 this happened. This patch is a fix for the same. The output after we apply this patch is: Reading symbols from //gdb_tests/multi-thread-fork... (gdb) set detach-on-fork off (gdb) r Starting program: /gdb_tests/multi-thread-fork [New Thread 258 (tid 75565441)] [New Thread 515 (tid 63244397)] [New inferior 2 (process 10813892)] Hello from Parent! [New inferior 3 (process 19005888)] Hello from Parent! Thread 1.1 received signal SIGINT, Interrupt. 0xd0611d70 in _p_nsleep () from /usr/lib/libpthread.a(_shr_xpg5.o) (gdb) info threads Id Target Id Frame * 1.1 Thread 1 (tid 66062355) ([running]) 0xd0611d70 in _p_nsleep () from /usr/lib/libpthread.a(_shr_xpg5.o) 1.2 Thread 258 (tid 75565441) ([running]) thread_function (arg=0x0) at //gdb_tests/multi-thread-fork.c:50 1.3 Thread 515 (tid 63244397) ([running]) thread_function (arg=0x0) at //gdb_tests/multi-thread-fork.c:50 2.1 Thread 515 (tid 32113089) ([running]) 0xd0610df0 in _sigsetmask () from /usr/lib/libpthread.a(_shr_xpg5.o) 3.1 Thread 258 (tid 64489699) ([running]) 0xd0610df0 in _sigsetmask () from /usr/lib/libpthread.a(_shr_xpg5.o) (gdb) q A debugging session is active. --- gdb/aix-thread.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c index c04a56ea342..327f5607d45 100644 --- a/gdb/aix-thread.c +++ b/gdb/aix-thread.c @@ -859,7 +859,8 @@ sync_threadlists (pid_t pid) { aix_thread_info *priv = get_aix_thread_info (it); if (in_queue_threads.count (priv->pdtid) == 0 - && in_thread_list (proc_target, it->ptid)) + && in_thread_list (proc_target, it->ptid) + && pid == it->ptid.pid ()) { delete_thread (it); data->exited_threads.insert (priv->pdtid); -- 2.11.4.GIT