public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix Segmentation Fault in AIX during multi process debugging.
@ 2024-05-14  9:51 Aditya Vidyadhar Kamath
  2024-05-14 10:04 ` Ulrich Weigand
  2024-05-14 12:28 ` Tom Tromey
  0 siblings, 2 replies; 4+ messages in thread
From: Aditya Vidyadhar Kamath @ 2024-05-14  9:51 UTC (permalink / raw)
  To: tom; +Cc: ulrich.weigand, gdb-patches, Aditya.Kamath1, sangamesh.swamy

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

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.41.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix Segmentation Fault in AIX during multi process debugging.
  2024-05-14  9:51 [PATCH] Fix Segmentation Fault in AIX during multi process debugging Aditya Vidyadhar Kamath
@ 2024-05-14 10:04 ` Ulrich Weigand
  2024-05-14 12:28 ` Tom Tromey
  1 sibling, 0 replies; 4+ messages in thread
From: Ulrich Weigand @ 2024-05-14 10:04 UTC (permalink / raw)
  To: akamath996, tom; +Cc: gdb-patches, Aditya Kamath1, Sangamesh Mallayya

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Fix Segmentation Fault in AIX during multi process debugging.
  2024-05-14  9:51 [PATCH] Fix Segmentation Fault in AIX during multi process debugging Aditya Vidyadhar Kamath
  2024-05-14 10:04 ` Ulrich Weigand
@ 2024-05-14 12:28 ` Tom Tromey
  2024-05-15  5:44   ` Aditya Kamath1
  1 sibling, 1 reply; 4+ messages in thread
From: Tom Tromey @ 2024-05-14 12:28 UTC (permalink / raw)
  To: Aditya Vidyadhar Kamath
  Cc: tom, ulrich.weigand, gdb-patches, Aditya.Kamath1, sangamesh.swamy

> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH] Fix Segmentation Fault in AIX during multi process debugging.
  2024-05-14 12:28 ` Tom Tromey
@ 2024-05-15  5:44   ` Aditya Kamath1
  0 siblings, 0 replies; 4+ messages in thread
From: Aditya Kamath1 @ 2024-05-15  5:44 UTC (permalink / raw)
  To: Tom Tromey, Aditya Vidyadhar Kamath
  Cc: tom, Ulrich Weigand, gdb-patches, Sangamesh Mallayya

[-- Attachment #1: Type: text/plain, Size: 1072 bytes --]

>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.

Hi Tom,

Sure 😊

I am coming up with this test case.

Have a nice day ahead.

Thanks and regards,
Aditya.

From: Tom Tromey <tom@tromey.com>
Date: Tuesday, 14 May 2024 at 5:59 PM
To: Aditya Vidyadhar Kamath <akamath996@gmail.com>
Cc: tom@tromey.com <tom@tromey.com>, Ulrich Weigand <Ulrich.Weigand@de.ibm.com>, gdb-patches@sourceware.org <gdb-patches@sourceware.org>, Aditya Kamath1 <Aditya.Kamath1@ibm.com>, Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>
Subject: [EXTERNAL] Re: [PATCH] Fix Segmentation Fault in AIX during multi process debugging.
> 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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-05-15  5:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-14  9:51 [PATCH] Fix Segmentation Fault in AIX during multi process debugging Aditya Vidyadhar Kamath
2024-05-14 10:04 ` Ulrich Weigand
2024-05-14 12:28 ` Tom Tromey
2024-05-15  5:44   ` Aditya Kamath1

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).