public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Aditya Vidyadhar Kamath <ADITYA.VIDYADHAR.KAMATH@ibm.com>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>,
	Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>,
	Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Subject: RE: [PATCH] Use current_inferior ()->pid for AIX
Date: Fri, 10 Jun 2022 14:47:04 +0000	[thread overview]
Message-ID: <BN8PR15MB2867C6A305C104D2C8E2EB00B5A69@BN8PR15MB2867.namprd15.prod.outlook.com> (raw)
In-Reply-To: <0ad5c21e-60fa-e52d-f70c-d2bc62e0ac74@polymtl.ca>

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

Hi all,

While testing programs in AIX I noticed that GDB crashes when an
inferior exits, with this error:

  inferior.c:293: internal- error: inferior* find_inferior_pid(process_stratum_target*, int): Assertion `pid != 0' failed.

When a process exits inferior_ptid.pid is set to 0. Unfortunately, the rs6000-aix-nat target is still relying on the value of
inferior_ptid in the case where an inferior exits - we return the
value of inferior_ptid as the pid of the process that exited.

The waitpid() system call suspends execution of the calling process until a child specified by pid argument has changed state. Once the inferior [assuming there is only one inferior] dies, waitpid() has no child to return.

Due to this an ERRCHLD error is returned thereby returning an inferior_ptid.pid with 0 leading to this assertion failure.

This patch is a fix to the same where we use the pid returned by the beneath wait using waitpid and adjust our inferior_ptid so that the rest of the code will take in the right values of both inferior_ptid and current_inferior.

The following are the test results after running gdb.base test suite with the patch.
# of expected passes 26244
# of unexpected failures 4230
# of unexpected successes 1
# of expected failures 17
# of known failures 26
# of unresolved testcases 110
# of untested testcases 79
# of unsupported tests 62
# of paths in test names 1
# of duplicate test names 4

The following are test results after running gdb.base test suite without the patch.
# of expected passes 12935
# of unexpected failures 1988
# of unexpected successes 1
# of expected failures 3
# of known failures 6
# of unresolved testcases 159
# of untested testcases 77
# of unsupported tests 39
# of paths in test names 2
# of duplicate test names 13

Please find attached the patch. [See 0001-Fix-gdb_assert-pid-0-assertion-failure-in-AIX.patch].

Have a nice day ahead,

Thanks and regards,
Aditya.


________________________________
From: Simon Marchi <simon.marchi@polymtl.ca>
Sent: Monday, May 30, 2022 6:15 PM
To: Aditya Vidyadhar Kamath <ADITYA.VIDYADHAR.KAMATH@ibm.com>
Cc: Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>; Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Subject: [EXTERNAL] Re: [PATCH] Use current_inferior ()->pid for AIX

Hi,

Re-adding gdb-patches, since it's information useful to everybody.

On 2022-05-29 23:41, Aditya Vidyadhar Kamath wrote:
> Hi Simon,
>
> Thank you so much for the feedback. Yes it makes sense. As I was trying to fix this we need one more information that will help us.
>
> Once an inferior finishes its execution where is the inferior_ptid's pid variable set to 0. Or who is the one [file name or function name] that updates inferior_ptid class variable pid to 0.

This is done in the mourn_inferior target method.  Many targets call the
generic_mourn_inferior function, which calls switch_to_no_thread, which
sets current_thread_ to nullptr and inferior_ptid to null_ptid.

Simon

[-- Attachment #2: 0001-Fix-gdb_assert-pid-0-assertion-failure-in-AIX.patch --]
[-- Type: application/octet-stream, Size: 1703 bytes --]

From f8259070349b075f65a4b9fe0a888543a6864f6e Mon Sep 17 00:00:00 2001
From: "aditya@ibm" <aditya.vidyadhar.kamath@ibm.com>
Date: Fri, 10 Jun 2022 08:50:46 -0500
Subject: [PATCH] Fix gdb_assert (pid != 0); assertion failure in AIX

---
 gdb/aix-thread.c     | 5 +++++
 gdb/rs6000-aix-nat.c | 2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdb/aix-thread.c b/gdb/aix-thread.c
index ecd8200b692..3037d73c5c4 100644
--- a/gdb/aix-thread.c
+++ b/gdb/aix-thread.c
@@ -1079,6 +1079,7 @@ ptid_t
 aix_thread_target::wait (ptid_t ptid, struct target_waitstatus *status,
 			 target_wait_flags options)
 {
+  struct inferior *inf;
   {
     scoped_restore save_inferior_ptid = make_scoped_restore (&inferior_ptid);
 
@@ -1091,6 +1092,10 @@ aix_thread_target::wait (ptid_t ptid, struct target_waitstatus *status,
   if (ptid.pid () == -1)
     return ptid_t (-1);
 
+  inf = find_inferior_pid(current_inferior ()->process_target (),ptid.pid());
+  if(inf != NULL){
+   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)
diff --git a/gdb/rs6000-aix-nat.c b/gdb/rs6000-aix-nat.c
index 8563aea313a..8a0c074be8f 100644
--- a/gdb/rs6000-aix-nat.c
+++ b/gdb/rs6000-aix-nat.c
@@ -529,7 +529,7 @@ rs6000_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
 	}
 
       /* Ignore terminated detached child processes.  */
-      if (!WIFSTOPPED (status) && pid != inferior_ptid.pid ())
+      if (!WIFSTOPPED (status) && pid != inferior_ptid.pid () && inferior_ptid.pid () != 0)
 	pid = -1;
     }
   while (pid == -1);
-- 
2.31.1


  reply	other threads:[~2022-06-10 14:47 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29  6:58 Aditya Vidyadhar Kamath
2022-03-29 13:01 ` Simon Marchi
2022-03-30 13:04   ` Aditya Vidyadhar Kamath
2022-04-05 12:15     ` Aditya Vidyadhar Kamath
2022-04-05 12:47     ` Simon Marchi
2022-04-12 13:32       ` Aditya Vidyadhar Kamath
2022-04-18  6:33         ` Aditya Vidyadhar Kamath
2022-04-21 11:41         ` Aditya Vidyadhar Kamath
2022-04-21 14:51         ` Simon Marchi
     [not found]           ` <BN8PR15MB2867D6D625DD0B353C99D3A3B5DD9@BN8PR15MB2867.namprd15.prod.outlook.com>
2022-05-30 12:45             ` Simon Marchi
2022-06-10 14:47               ` Aditya Vidyadhar Kamath [this message]
2022-06-15  4:03                 ` Aditya Vidyadhar Kamath
2022-06-23 20:40                   ` Aditya Vidyadhar Kamath
2022-06-27 12:55                 ` Fw: " Aditya Vidyadhar Kamath
2022-06-27 15:11                   ` Simon Marchi
2022-07-04 19:28                   ` Simon Marchi
2022-07-06  4:25                     ` Fw: RE: [PATCH] Fix assert pid != 0 assertion failure in AIX Aditya Vidyadhar Kamath
2022-07-06 17:50                       ` Simon Marchi
2022-07-07  8:27                         ` Aditya Vidyadhar Kamath
2022-07-07 13:56                           ` Simon Marchi
     [not found] <BN6PR15MB13130BF943A019871F8F4E0EB5119@BN6PR15MB1313.namprd15.prod.outlook.com>
2022-05-02 14:50 ` [PATCH] Use current_inferior ()->pid for AIX Ulrich Weigand

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=BN8PR15MB2867C6A305C104D2C8E2EB00B5A69@BN8PR15MB2867.namprd15.prod.outlook.com \
    --to=aditya.vidyadhar.kamath@ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sangamesh.swamy@in.ibm.com \
    --cc=simon.marchi@polymtl.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).