public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Aditya Vidyadhar Kamath <ADITYA.VIDYADHAR.KAMATH@ibm.com>
To: Joel Brobecker via Gdb-patches <gdb-patches@sourceware.org>
Cc: Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>
Subject: [PATCH] Use current_inferior ()->pid for AIX
Date: Tue, 29 Mar 2022 06:58:25 +0000	[thread overview]
Message-ID: <BN8PR15MB2867D1D3A166739CBAE8C9E1B51E9@BN8PR15MB2867.namprd15.prod.outlook.com> (raw)

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

Hi all,



Attaching the patch for fetching the inferior process ID using current_inferior() function in AIX.



AIX is still using inferior_ptid.pid() to get the inferior pid instead of the new object current_inferior().With this it is not possible to debug any sample program as the it fails with assertion check for pid!=0.

In the gdb to access the process id of the debugged inferior process, a function current_inferior is used which returns the struct type variable inferior. As current_inferior() holds the inferior pid one must use this object to hold the inferior pid. The attached patch is to the current_inferior() object to get the inferior pid and continue debugging.



This can be demonstrated using the below sample program.



#include <stdio.h>

#include <stdlib.h>

int main()

{

   int i = 1;

   return 0;

}



Sample output without patch:

(gdb) b main

Breakpoint 1 at 0x1000070c: file test.cc, line 3.

(gdb) r

Starting program: /home/gdb_tests/test

inferior.c:303: internal-error: find_inferior_pid: Assertion `pid != 0' failed.

A problem internal to GDB has been detected,

further debugging may prove unreliable.

----- Backtrace -----

0x100e874a3 ???

0x100e8766b ???

0x10003724b ???

0x100037697 ???

0x1000363f3 ???

0x1000593a3 ???

0x1000594ff ???

0x10053aa5b ???

0x1002f6e37 ???

0x1002f2e7f ???

0x100b26ca3 ???

0x1003029bf ???

0x10077e373 ???

0x10077b107 ???

0x100001dff ???

0x100002007 ???

0x10000421b ???

0x1000042ef ???

0x100000a9f ???

0x100000583 ???

---------------------

inferior.c:303: internal-error: find_inferior_pid: Assertion `pid != 0' failed.



Output with patch:

(gdb) b main

Breakpoint 1 at 0x1000070c: file test.cc, line 3.

(gdb) r

Starting program: /home/gdb_tests/test

Breakpoint 1, main () at test.cc:3

3 int i = 1;



----------------------------------------------------------------------------------



Summary of the gdb.base testsuites.



Without Patch
------------------------

# of expected passes

8096

# of unexpected failures

2160

# of unexpected successes

1

# of expected failures

4

# of known failures

5

# of unresolved testcases

113

# of untested testcases

83

# of unsupported tests

40

# of paths in test names

2

# of duplicate test names

13

With Patch
-------------------

# of expected passes

13831

# of unexpected failures

7397

# of unexpected successes

1

# of expected failures

11

# of known failures

6

# of unresolved testcases

78

# of untested testcases

88

# of unsupported tests

63

# of paths in test names

1

# of duplicate test names

2

(See attached file: ChangeLog)(See attached file: current_inferior.patch).



Thanks and regards,

Aditya.


[-- Attachment #2: ChangeLog --]
[-- Type: application/octet-stream, Size: 386 bytes --]

2022-03-15  Aditya Vidyadhar Kamath <ADITYA.VIDYADHAR.KAMATH@ibm.com>

	*aix-thread.c (get_signaled_thread): Use current_inferior->pid() instead of
	inferior_ptid.pid() in AIX.
	(sync_threadlists): Likewise.
	(pd_update) : Likewise.
	(pd_activate): Likewise.
	(pd_deactivate): Likewise.
	*rs6000-aix-nat.c (xfer_partial): Likewise.
	(wait): Likewise.
	(xfer_shared_libraries): Likewise.

[-- Attachment #3: current_inferior.patch --]
[-- Type: application/octet-stream, Size: 2806 bytes --]

--- ./gdb/aix-thread.c_orig	2022-03-15 02:26:39 +0000
+++ ./gdb/aix-thread.c	2022-03-03 07:21:16 +0000
@@ -708,7 +708,7 @@
 
   while (1)
     {
-      if (getthrds (inferior_ptid.pid (), &thrinf,
+      if (getthrds ( current_inferior ()->pid, &thrinf,
 		    sizeof (thrinf), &ktid, 1) != 1)
 	break;
 
@@ -791,7 +791,7 @@
 
   /* Apply differences between the two arrays to GDB's thread list.  */
 
-  infpid = inferior_ptid.pid ();
+  infpid = current_inferior ()->pid;
   for (pi = gi = 0; pi < pcount || gi < gcount;)
     {
       if (pi == pcount)
@@ -883,11 +883,11 @@
   struct thread_info *thread = NULL;
 
   if (!pd_active)
-    return inferior_ptid;
+    return ptid_t (current_inferior ()->pid);
 
   status = pthdb_session_update (pd_session);
   if (status != PTHDB_SUCCESS)
-    return inferior_ptid;
+   return ptid_t (current_inferior ()->pid);
 
   sync_threadlists ();
 
@@ -897,7 +897,7 @@
   if (tid != 0)
     thread = iterate_over_threads (iter_tid, &tid);
   if (!thread)
-    ptid = inferior_ptid;
+    ptid = ptid_t (current_inferior ()->pid); 
   else
     {
       ptid = thread->ptid;
@@ -921,7 +921,7 @@
 			       &pd_session);
   if (status != PTHDB_SUCCESS)
     {
-      return inferior_ptid;
+      return ptid_t (current_inferior ()->pid);
     }
   pd_active = 1;
   return pd_update (set_infpid);
@@ -932,11 +932,12 @@
 static void
 pd_deactivate (void)
 {
+  ptid_t ptdrtn = ptid_t (current_inferior ()->pid);
   if (!pd_active)
     return;
   pthdb_session_destroy (pd_session);
   
-  pid_to_prc (&inferior_ptid);
+  pid_to_prc (&ptdrtn); 
   pd_active = 0;
 }
 
--- gdb/rs6000-aix-nat.c_orig	2022-03-15 02:27:22 +0000
+++ gdb/rs6000-aix-nat.c	2022-03-11 05:37:57 +0000
@@ -397,7 +397,7 @@
 				 ULONGEST offset, ULONGEST len,
 				 ULONGEST *xfered_len)
 {
-  pid_t pid = inferior_ptid.pid ();
+  pid_t pid =  current_inferior ()->pid;
   int arch64 = ARCH64 ();
 
   switch (object)
@@ -525,15 +525,14 @@
 
 	  /* Claim it exited with unknown signal.  */
 	  ourstatus->set_signalled (GDB_SIGNAL_UNKNOWN);
-	  return inferior_ptid;
+	  return ptid_t (current_inferior ()->pid);
 	}
 
       /* Ignore terminated detached child processes.  */
-      if (!WIFSTOPPED (status) && pid != inferior_ptid.pid ())
+      if (!WIFSTOPPED (status) && pid != pid_t(current_inferior ()->pid))
 	pid = -1;
     }
   while (pid == -1);
   /* AIX has a couple of strange returns from wait().  */
 
   /* stop after load" status.  */
@@ -658,7 +657,7 @@
   if (writebuf)
     return TARGET_XFER_E_IO;
 
-  gdb::byte_vector ldi_buf = rs6000_ptrace_ldinfo (inferior_ptid);
+   gdb::byte_vector ldi_buf = rs6000_ptrace_ldinfo (ptid_t (current_inferior ()->pid)); 
   result = rs6000_aix_ld_info_to_xml (target_gdbarch (), ldi_buf.data (),
 				      readbuf, offset, len, 1);
 

             reply	other threads:[~2022-03-29  6:58 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29  6:58 Aditya Vidyadhar Kamath [this message]
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
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=BN8PR15MB2867D1D3A166739CBAE8C9E1B51E9@BN8PR15MB2867.namprd15.prod.outlook.com \
    --to=aditya.vidyadhar.kamath@ibm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sangamesh.swamy@in.ibm.com \
    /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).