From: Aditya Kamath1 <Aditya.Kamath1@ibm.com>
To: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>,
"simark@simark.ca" <simark@simark.ca>,
Aditya Kamath1 via Gdb-patches <gdb-patches@sourceware.org>
Cc: Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>
Subject: [PATCH] Enable multi process debugging for AIX
Date: Tue, 19 Jul 2022 15:53:52 +0000 [thread overview]
Message-ID: <CH2PR15MB354483D4F55BCF7DEB83D9B7D68F9@CH2PR15MB3544.namprd15.prod.outlook.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 2662 bytes --]
Hi,
The attached proposed patch adds multi process debugging feature in AIX.”
Till now AIX supported debugging only one inferior at a time, now we can be able to debug multi process.
Users can use set follow fork mode in child or parent and set detach on fork on or off to enable/disable simultaneous debugging of parent/child.
An example program is written below as follows with the gdb output:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
void hello_from_child(){
printf("Hello from child \n");
}
void hello_from_parent(){
printf("Hello from Parent \n");
}
int main(){
pid_t childpid;
printf("I should not be printed after fork as I am executed \n");
childpid = fork();
if (childpid == 0)
hello_from_child();
else
hello_from_parent();
return 0;
}
GDB Output:-
(gdb) b hello_from_child
Breakpoint 1 at 0x10000584: file test_fork.c, line 6.
(gdb) set follow-fork-mode child
(gdb) set detach-on-fork off
(gdb) r
Starting program: /home/test_fork
I should not be printed after fork as I am executed
[Attaching after process 23331156 fork to child process 23134700]
[New inferior 2 (process 23134700)]
[Switching to process 23134700]
Thread 2.1 hit Breakpoint 1, hello_from_child ()
at test_fork.c:6
6 printf("Hello from child \n");
(gdb) c
Continuing.
Hello from child
[Inferior 2 (process 23134700) exited normally]
(gdb)
The following are the results after running the "gdb.base" test suite:-
With patch
# of expected passes 26584
# of unexpected failures 3968
# of unexpected successes 1
# of expected failures 17
# of known failures 26
# of unresolved testcases 109
# of untested testcases 79
# of unsupported tests 62
# of paths in test names 1
# of duplicate test names 2
Without 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
Please find attached the patch [See file: 0001-Enable-multi-process-debugging-for-AIX.patch]
I have left comments in my patch to make it easy to understand and justify [code lines] the same. Let me know what you think.
Kindly give us feedback at the earliest.
Have a nice day ahead.
Thanks and regards,
Aditya.
Bye.
[-- Attachment #2: 0001-Enable-multi-process-debugging-for-AIX.patch --]
[-- Type: application/octet-stream, Size: 4303 bytes --]
From 1eab0bb05b1db09dfb98d31cc630722b40c081c4 Mon Sep 17 00:00:00 2001
From: Aditya Vidyadhar Kamath <Aditya.Kamath1@ibm.com>
Date: Tue, 19 Jul 2022 10:39:00 -0500
Subject: [PATCH] Enable multi process debugging for AIX
The attached proposed patch adds multi process debugging feature in AIX.
Till now AIX supported debugging only one inferior at a time,
now we can be able to debug multi process.
Users can use set follow fork mode in child or parent and
set detach on fork on or off to enable/disable simultaneous debugging of parent/child.
---
gdb/aix-thread.c | 4 ++++
gdb/rs6000-aix-nat.c | 48 +++++++++++++++++++++++++++++++++++++++++---
2 files changed, 49 insertions(+), 3 deletions(-)
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)
diff --git a/gdb/rs6000-aix-nat.c b/gdb/rs6000-aix-nat.c
index f604f7d503e..55844ca6dab 100644
--- a/gdb/rs6000-aix-nat.c
+++ b/gdb/rs6000-aix-nat.c
@@ -91,10 +91,16 @@ class rs6000_nat_target final : public inf_ptrace_target
ptid_t wait (ptid_t, struct target_waitstatus *, target_wait_flags) override;
+ /* Fork detection related functions, For adding multi process debugging
+ support. */
+ void follow_fork (inferior *, ptid_t, target_waitkind, bool, bool) override;
+
+ void mourn_inferior () override;
+
protected:
- void post_startup_inferior (ptid_t ptid) override
- { /* Nothing. */ }
+ void post_startup_inferior (ptid_t ptid) override;
+ //{ /* Nothing. */ }
private:
enum target_xfer_status
@@ -246,6 +252,22 @@ fetch_register (struct regcache *regcache, int regno)
}
}
+void rs6000_nat_target::post_startup_inferior(ptid_t ptid){
+ rs6000_ptrace64(PT_MULTI,ptid.pid(),NULL,1,NULL);
+}
+
+void
+rs6000_nat_target::follow_fork (inferior *child_inf, ptid_t child_ptid,
+ target_waitkind fork_kind, bool follow_child,
+ bool detach_fork)
+{
+ inf_ptrace_target::follow_fork(child_inf, child_ptid, fork_kind,
+ follow_child, detach_fork);
+}
+
+void rs6000_nat_target::mourn_inferior(){
+ inf_ptrace_target::mourn_inferior();
+}
/* Store register REGNO back into the inferior. */
static void
@@ -539,8 +561,28 @@ rs6000_nat_target::wait (ptid_t ptid, struct target_waitstatus *ourstatus,
if (status == 0x57c)
ourstatus->set_loaded ();
/* signal 0. I have no idea why wait(2) returns with this status word. */
- else if (status == 0x7f)
+ /* 0x17f and 0x137f in hexadecimal are status returned if
+ if we follow parent,
+ a switch is made to a child post parent execution
+ and child continues its execution [user switches to child and
+ presses continue]. */
+ else if (status == 0x7f || status == 0x17f || status == 0x137f)
ourstatus->set_spurious ();
+ /* When a process completes execution and any fork process exits status. */
+ else if (WIFEXITED(status))
+ ourstatus->set_exited(0);
+ /* 57e is the status number in AIX for fork event.
+ If a breakpoint is attached to a parent or child then on fork,
+ or after fork, once a breakpoint hits and the next or continue is
+ pressed, post breakpoint status is 1406 but we need not set status
+ to set_forked(), hence the condition find_inferior_pid() to set
+ fork status only if a child is born. */
+ else if (status == 0x57e && find_inferior_pid(this,pid)== nullptr)
+ {
+ ourstatus->set_forked (ptid_t(pid));
+ /* On a fork event return parent process ID to target wait */
+ return ptid_t(current_inferior()->pid);
+ }
/* A normal waitstatus. Let the usual macros deal with it. */
else
*ourstatus = host_status_to_waitstatus (status);
--
2.31.1
next reply other threads:[~2022-07-19 15:54 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-19 15:53 Aditya Kamath1 [this message]
2022-07-19 18:51 ` Simon Marchi
2022-07-22 16:56 ` Aditya Kamath1
2022-08-18 18:59 ` Aditya Kamath1
2022-08-21 17:15 ` Aditya Kamath1
2022-08-22 13:25 ` Ulrich Weigand
2022-08-22 14:19 ` Simon Marchi
2022-08-23 6:52 ` Aditya Kamath1
2022-10-19 10:57 ` Aditya Kamath1
2022-10-19 10:57 ` Aditya Kamath1
2022-10-28 10:59 ` Ulrich Weigand
2022-11-01 13:55 ` Aditya Kamath1
2022-11-02 8:56 ` Ulrich Weigand
2022-11-10 10:39 ` Aditya Kamath1
2022-11-14 18:24 ` Ulrich Weigand
2022-11-15 7:13 ` Aditya Kamath1
2022-11-15 10:53 ` Ulrich Weigand
2022-11-15 12:01 ` Aditya Kamath1
2022-11-15 12:43 ` Ulrich Weigand
2022-11-15 18:13 ` 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=CH2PR15MB354483D4F55BCF7DEB83D9B7D68F9@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).