public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Aditya Kamath1 <Aditya.Kamath1@ibm.com>
To: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
	"simark@simark.ca" <simark@simark.ca>,
	"gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
Cc: Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>
Subject: Re: [PATCH] 0001-Fix-multi-thread-debug-bug-in-AIX.patch
Date: Wed, 23 Nov 2022 16:03:11 +0000	[thread overview]
Message-ID: <CH2PR15MB35441FE8F8E1FECD83202EF6D60C9@CH2PR15MB3544.namprd15.prod.outlook.com> (raw)
In-Reply-To: <0dba07cfad3da44c0281c53702d73f807bca7d06.camel@de.ibm.com>

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

Hi Ulrich,

I'm confused why this is the correct place.  From what I can see,
in this scenario, we have:

- libpthdebug reports some threads using a thread ID, i.e. pbuf has
   ptid_t (pid, 0, pthid1)
    ..
   ptid_t (pid, 0, pthidN)
with pcount >= 1.

- GDB only has one single thread in unthreaded mode, i.e. gbuf has
   ptid_t (pid, 0, 0)
with gcount == 1.

So when running the loop, during the first iteration, we should compare
   ptid_cmp (ptid_t (pid, 0, pthid1), ptid_t (pid, 0, 0))
which should be > 0 since pthid1 > 0.  Right?

This means we'll get into the branch that just does:
              delete_thread (gbuf[gi]);
thereby deleting the original thread.  Does this not happen for you?
What is going on instead?

[ Note that this is a simplified case with only a single process; in the
multi-process scenario, this may be more complex.



>What is going on instead?
The one I highlighted in bold does not happen. In our first iteration pcount is 1 but gcount is 0. That is why when gi =0 == gcount becomes true and control enters into that block instead of going into the else block..

>[ Note that this is a simplified case with only a single process; in the
multi-process scenario, this may be more complex.

This I agree. I just checked now..

Hmm. So, something is going wrong here..

gcount = 0;

  iterate_over_threads (giter_count, &gcount);

  g = gbuf = XNEWVEC (struct thread_info *, gcount);

  iterate_over_threads (giter_accum, &g);

  qsort (gbuf, gcount, sizeof *gbuf, gcmp);

Let's me check these lines. Hope I answered why I was doing it..

The rest of the changes you mentioned I will do it..
________________________________
From: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
Sent: 23 November 2022 19:45
To: simark@simark.ca <simark@simark.ca>; Aditya Kamath1 <Aditya.Kamath1@ibm.com>; gdb-patches@sourceware.org <gdb-patches@sourceware.org>
Cc: Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>
Subject: Re: [PATCH] 0001-Fix-multi-thread-debug-bug-in-AIX.patch

Aditya Kamath1 <Aditya.Kamath1@ibm.com> wrote:

>@@ -514,8 +514,16 @@ pdc_read_data (pthdb_user_t user_current_pid, void *buf,
>        during first initialisation.  In the rest of the callbacks the
>        current thread needs to be correct.  */
>     if (user_current_pid != 0)
>-      switch_to_thread (current_inferior ()->process_target (),
>-                      ptid_t (user_current_pid));
>+    {
>+      inferior *inf = find_inferior_ptid (current_inferior ()-> process_target (),
>+                                          ptid_t (user_current_pid));
This would be simpler using find_inferior_pid.
>+        for (thread_info *tp: inf->threads ())
>+        if (tp != NULL)
This would be simpler using any_thread_of_inferior.
>+          {
>+            switch_to_thread (tp);
>+            break;
>+          }
>+    }
>     status = target_read_memory (addr, (gdb_byte *) buf, len);

However, switching to just any random thread of the process seems odd.

Looking at sol-thread.c, they don't switch to a thread at all
in the equivalent place, but rather do this:

  scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);

  if (inferior_ptid.tid_p () || !target_thread_alive (inferior_ptid))
    {
      /* It's either a thread or an LWP that isn't alive.  Any live
         LWP will do so use the first available.

         NOTE: We don't need to call switch_to_thread; we're just
         reading memory.  */
      inferior_ptid = procfs_first_available ();
    }

Since your xfer_partial routine only ever looks at the PID
component of the ptid, I'm wondering if we couldn't similarly
just switch inferior_ptid, without actually switching theads.
Something along the lines of

  scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
  if (user_current_pid != 0)
    inferior_ptid = ptid_t (user_current_pid);

Does this work for you?

>-      if (thrinf.ti_cursig == SIGTRAP)
>+      /* In a multi threaded application user can interrupt the main
>+       thread as well. This function should return the tid in this
>+         case apart from threads that can trap or be interrupted.  */
Whitespace problem.
>+
>+      if (thrinf.ti_cursig == SIGTRAP || thrinf.ti_cursig == SIGINT)
>        return thrinf.ti_tid;

This seems an unrelated change?  If this is actually necessary,
then all the comments (e.g. at the top of this function, or at
the call site) likewise need to be updated - they only refer to
trap signals currently.

>          process_stratum_target *proc_target
>            = current_inferior ()->process_target ();
>-        thread = add_thread_with_info (proc_target,
>-                                       ptid_t (pid, 0, pbuf[pi].pthid),
>-                                       priv);
>+
>+        thread_info *tp = find_thread_ptid (proc_target, ptid_t (pid));
>+
>+        /* If the pthread library is used then we replace the main
>+           with the thread having the main thread ID and process ID.
>+           Otherwise this is a new thread and we need to add it.  */
>+        if (tp != NULL && tp->priv == NULL)
>+          {
>+          thread_change_ptid (proc_target, tp->ptid,
>+                              ptid_t (pid, 0, pbuf[pi].pthid));
>+          tp->priv.reset (priv);
>+          }
>+        else
>+          thread = add_thread_with_info (proc_target,
>+                                         ptid_t (pid, 0, pbuf[pi].pthid),
>+                                         priv);

I'm confused why this is the correct place.  From what I can see,
in this scenario, we have:

- libpthdebug reports some threads using a thread ID, i.e. pbuf has
   ptid_t (pid, 0, pthid1)
    ..
   ptid_t (pid, 0, pthidN)
with pcount >= 1.

- GDB only has one single thread in unthreaded mode, i.e. gbuf has
   ptid_t (pid, 0, 0)
with gcount == 1.

So when running the loop, during the first iteration, we should compare
   ptid_cmp (ptid_t (pid, 0, pthid1), ptid_t (pid, 0, 0))
which should be > 0 since pthid1 > 0.  Right?

This means we'll get into the branch that just does:
              delete_thread (gbuf[gi]);
thereby deleting the original thread.  Does this not happen for you?
What is going on instead?

[ Note that this is a simplified case with only a single process; in the
multi-process scenario, this may be more complex. ]


Bye,
Ulrich


  reply	other threads:[~2022-11-23 16:03 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25  6:47 Aditya Kamath1
2022-10-28  9:49 ` Ulrich Weigand
2022-11-08 12:00   ` Aditya Kamath1
2022-11-08 12:17     ` Ulrich Weigand
2022-11-13 18:15       ` Aditya Kamath1
2022-11-15 18:16         ` Ulrich Weigand
2022-11-21  8:27           ` Aditya Kamath1
2022-11-23 14:15             ` Ulrich Weigand
2022-11-23 16:03               ` Aditya Kamath1 [this message]
2022-11-23 17:09                 ` Ulrich Weigand
2022-11-23 18:45                   ` Aditya Kamath1
2022-11-29  8:18                     ` Aditya Kamath1
2022-11-30 14:57                       ` Ulrich Weigand
2022-12-02  7:50                         ` Aditya Kamath1
2022-12-05 18:33                           ` Ulrich Weigand
2022-12-08 10:28                             ` Aditya Kamath1
2022-12-08 10:46                               ` Aditya Kamath1
2022-12-08 16:29                               ` Ulrich Weigand
2022-12-15 12:58                                 ` Aditya Kamath1
2022-12-15 15:53                                   ` Ulrich Weigand
2022-12-19  6:30                                     ` Aditya Kamath1
2022-12-22 12:50                                       ` Ulrich Weigand
2022-12-26 13:18                                         ` Aditya Kamath1
2023-01-09 14:04                                           ` Ulrich Weigand
2023-01-10 12:23                                             ` Aditya Kamath1
2023-01-11 13:31                                               ` Ulrich Weigand
2023-01-13 14:06                                                 ` Aditya Kamath1
2023-01-20 14:44                                                   ` Ulrich Weigand
2023-01-27 14:40                                                     ` Aditya Kamath1
2023-01-30 19:54                                                       ` Tom Tromey
2023-02-02  6:24                                                       ` Aditya Kamath1
2023-02-02  6:35                                                         ` Aditya Kamath1
2023-02-02 17:43                                                           ` Ulrich Weigand
2023-02-03 11:10                                                             ` Aditya Kamath1
2023-02-06 19:07                                                               ` Ulrich Weigand
2023-02-07 11:57                                                                 ` Aditya Kamath1
2023-02-08 18:44                                                                   ` Ulrich Weigand
2023-02-10 16:33                                                                     ` Aditya Kamath1
2023-02-10 16:46                                                                       ` Aditya Kamath1
2023-02-13 19:01                                                                       ` Ulrich Weigand
2023-02-14 14:13                                                                         ` Aditya Kamath1
2023-02-16 19:46                                                                           ` Ulrich Weigand
2023-02-17 11:26                                                                             ` Aditya Kamath1
2023-02-17 12:04                                                                               ` Ulrich Weigand
2023-02-17 13:22                                                                                 ` Aditya Kamath1
2023-02-17 14:18                                                                                   ` Ulrich Weigand
2023-02-17 15:15                                                                                     ` Aditya Kamath1
2023-02-17 19:14                                                                                       ` Ulrich Weigand
2022-11-08 12:00 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=CH2PR15MB35441FE8F8E1FECD83202EF6D60C9@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).