Fix Segmentation Fault in AIX during multi process debugging.
commit414aa6987f21a814851e5f3113388a3616993fa3
authorAditya Vidyadhar Kamath <Aditya.Kamath1@ibm.com>
Tue, 14 May 2024 09:51:41 +0000 (14 15:21 +0530)
committerUlrich Weigand <ulrich.weigand@de.ibm.com>
Tue, 14 May 2024 10:02:31 +0000 (14 12:02 +0200)
tree342a0708fcb0bd71a6e9cff776c26b82d459de4f
parent30d57f2e41b168dcce23e5e63fae28685920077e
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