Fix Segmentation Fault in AIX during multi process debugging.

Message ID 20240514095141.6474-1-akamath996@gmail.com
State New
Headers
Series Fix Segmentation Fault in AIX during multi process debugging. |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm warning Patch is already merged
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 warning Patch is already merged

Commit Message

Aditya Vidyadhar Kamath May 14, 2024, 9:51 a.m. UTC
  From: Aditya Vidyadhar Kamath <Aditya.Kamath1@ibm.com>

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(-)
  

Comments

Ulrich Weigand May 14, 2024, 10:04 a.m. UTC | #1
Aditya Vidyadhar Kamath <akamath996@gmail.com> wrote:

>Due to the recent commit in aix-thread.c, we see a segmentation fault
>in AIX while debugging multiple process involving multiple threads.

This is OK.  I've applied the patch.

Bye,
Ulrich
  
Tom Tromey May 14, 2024, 12:28 p.m. UTC | #2
> From: Aditya Vidyadhar Kamath <Aditya.Kamath1@ibm.com>
> Due to the recent commit in aix-thread.c, we see a segmentation fault
> in AIX while debugging multiple process involving multiple threads.

I think it would probably be good for these patches to either mention
the existing test case that they fix, or to come with a new test.

thanks,
Tom
  

Patch

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);