public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Aditya Kamath1 <Aditya.Kamath1@ibm.com>
To: Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
	Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
	"simark@simark.ca" <simark@simark.ca>
Subject: [PATCH] Fix-for-multiple-thread-detection-in-AIX.patch
Date: Fri, 15 Jul 2022 15:51:39 +0000	[thread overview]
Message-ID: <CH2PR15MB3544221B808DE441B42A6518D68B9@CH2PR15MB3544.namprd15.prod.outlook.com> (raw)

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

Hi,

Folks using AIX are not able to debug multiple threads.

The reason:- Since a new thread addition causes a thread target to wait, in AIX once the event ptid is got with the waitpid(), we need to set the inferior_ptid variable. Every time we come into aix_thread_target::wait() we check if libpthdebug might be ready to be initialized.In doing so we call pd_activate(). Here the session needs to be successfully initialised failing to which just a pid is returned. We do not enter pd_update() in the former case to take care of the rest of the thread addition process. The pthdb_session_init() is dependent on inferior_ptid variable as per our observations to return PTHDB_SUCCESS.

Please find attached the patch. [See: Fix-for-multiple-thread-detection-in-AIX.patch]

This can be shown by the following program:-


#include <stdio.h>

#include <unistd.h>

#include <stdlib.h>

#include <pthread.h>

#include <assert.h>


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


  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 without patch:-

(gdb) r

Starting program: /home/aditya/gdb_tests/continue-pending-status

^C

Program received signal SIGINT, Interrupt.

0xd0595fb0 in _p_nsleep () from /usr/lib/libpthread.a(shr_xpg5.o)

(gdb) info threads

  Id   Target Id         Frame

* 1    process 29557240  0xd0595fb0 in _p_nsleep () from /usr/lib/libpthread.a(shr_xpg5.o)

(gdb)



Output with patch:-


Reading symbols from /home/aditya/gdb_tests/continue-pending-status...

(gdb) r

Starting program: /home/aditya/gdb_tests/continue-pending-status

[New Thread 1]

^C[New Thread 258]

[New Thread 515]


Thread 1 received signal SIGINT, Interrupt.

0xd0595fb0 in _p_nsleep () from /usr/lib/libpthread.a(shr_xpg5.o)

(gdb) info threads

  Id   Target Id                           Frame

* 1    process 29557210                    0xd0595fb0 in _p_nsleep ()

   from /usr/lib/libpthread.a(shr_xpg5.o)

  2    Thread 1 (tid 120197499, running)   0xd0595fb0 in _p_nsleep ()

   from /usr/lib/libpthread.a(shr_xpg5.o)

  3    Thread 258 (tid 130486575, running) thread_function (arg=0x0)

    at continue-pending-status.c:36

  4    Thread 515 (tid 131666371, running) thread_function (arg=warning: (Internal error: pc 0x0 in read in psymtab, but not in symtab.)


0x0)

    at continue-pending-status.c:36

(gdb)

The gdb base test suite numbers with patch:-

# of expected passes            14094

# of unexpected failures        8770

# of unexpected successes       1

# of expected failures          10

# of known failures             46

# of unresolved testcases       121

# of untested testcases         84

# of unsupported tests          61

# of paths in test names        2

# of duplicate test names       5


Kindly let me know what you think.

Thanks and regards,
Aditya.



[-- Attachment #2: 0001-Fix-for-multiple-thread-detection-in-AIX.patch --]
[-- Type: application/octet-stream, Size: 928 bytes --]

From 7e8abe258f67abd3854fedf54e43da2b13541986 Mon Sep 17 00:00:00 2001
From: Aditya Vidyadhar Kamath <Aditya.Kamath1@ibm.com>
Date: Fri, 15 Jul 2022 08:40:25 -0500
Subject: [PATCH] Fix for multiple thread detection in AIX

---
 gdb/aix-thread.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index d47f5132592..f66b5904ae8 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -1088,6 +1088,10 @@ aix_thread_target::wait (ptid_t ptid, struct target_waitstatus *status,
      pid-only ptids.  */
   gdb_assert (ptid.is_pid ());
 
+  /* In pd_activate to get PTHB_SUCCESS in pthread debug session init
+     we need inferior_ptid set to update multiple threads. */
+  inferior_ptid = ptid;
+
   /* Check whether libpthdebug might be ready to be initialized.  */
   if (!pd_active && status->kind () == TARGET_WAITKIND_STOPPED
       && status->sig () == GDB_SIGNAL_TRAP)
-- 
2.31.1


             reply	other threads:[~2022-07-15 15:51 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-15 15:51 Aditya Kamath1 [this message]
2022-07-16  3:57 ` Aditya Kamath1
2022-07-19 12:21   ` Ulrich Weigand
2022-07-22 17:03     ` Aditya Kamath1
2022-07-25 12:04       ` Aditya Kamath1
2022-07-25 12:21         ` Ulrich Weigand
2022-07-25 15:30           ` Simon Marchi
2022-07-29  9:23             ` Aditya Kamath1
2022-08-01 17:25               ` Aditya Kamath1
2022-08-03 16:22               ` Ulrich Weigand
2022-08-04 15:15                 ` Aditya Kamath1
2022-08-05  5:01                   ` Aditya Kamath1
2022-08-05 11:53                     ` Ulrich Weigand
2022-08-05 14:11                       ` Aditya Kamath1
2022-08-05 14:18                         ` Ulrich Weigand
2022-08-05 14:24                           ` Aditya Kamath1
2022-08-09  2:36                             ` Aditya Kamath1
2022-08-09 13:41                               ` Ulrich Weigand
2022-08-10  6:57                                 ` Aditya Kamath1

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CH2PR15MB3544221B808DE441B42A6518D68B9@CH2PR15MB3544.namprd15.prod.outlook.com \
    --to=aditya.kamath1@ibm.com \
    --cc=Ulrich.Weigand@de.ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sangamesh.swamy@in.ibm.com \
    --cc=simark@simark.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).