public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix AIX watchpoint warning during fork () event.
@ 2024-01-10  2:57 Aditya Kamath1
  2024-01-10 16:41 ` Ulrich Weigand
  0 siblings, 1 reply; 3+ messages in thread
From: Aditya Kamath1 @ 2024-01-10  2:57 UTC (permalink / raw)
  To: Ulrich Weigand, Aditya Kamath1 via Gdb-patches; +Cc: Sangamesh Mallayya


[-- Attachment #1.1: Type: text/plain, Size: 3045 bytes --]

Respected community members,

Hi,

This is a patch to fix the warnings appearing while setting a catchpoint in AIX for a fork () event.

Please find attached the patch.(See: 0001-Fix-AIX-catchpoint-warning-during-fork-event.patch)

Consider a simple program pasted below this email named as fork-print-inferior-events.c.

When we run GDB and have a catchpoint at fork () we get:

Reading symbols from //gdb_tests/fork-print-inferior-events...
(gdb) b main
Breakpoint 1 at 0x10000694: file //gdb_tests/fork-print-inferior-events.c, line 26.
(gdb) r
Starting program: /gdb_tests/fork-print-inferior-events

Breakpoint 1, main (argc=1, argv=0x2ff229a0) at //gdb_tests/fork-print-inferior-events.c:26
26        child = fork ();
(gdb) catch fork
Catchpoint 2 (fork)
(gdb) c
Continuing.
warning: Error inserting catchpoint 2: Your system does not support this type
of catchpoint.
[Detaching after fork from child process 8782104]
[Inferior 1 (process 12059130) exited normally]

So, we get this warning that our system does not this type.

When I tried to debug the reason for the same here is my analysis. We hit the breakpoint.c file where we fail the condition if (val). A short code snippet I have pasted below.

if (bl->owner->type == bp_catchpoint)
    {
      int val;

      val = bl->owner->insert_location (bl);
      if (val)
    {
      bl->owner->enable_state = bp_disabled;

      if (val == 1)
        warning (_("\
Error inserting catchpoint %d: Your system does not support this type\n\
of catchpoint."), bl->owner->number);
      else
        warning (_("Error inserting catchpoint %d."), bl->owner->number);
    }

This insert_location () will lead to fork_catchpoint::insert_location () and then to target_insert_fork_catchpoint (). In Linux, this insert_fork_catchpoint is doing a return 0 only, which we in AIX were missing. We did not have these functions defined.

After we define them in rs6000-aix-nat.c (as done in this patch) we get,

Reading symbols from //gdb_tests/fork-print-inferior-events...
(gdb) b main
Breakpoint 1 at 0x10000694: file //gdb_tests/fork-print-inferior-events.c, line 26.
(gdb) r
Starting program: /gdb_tests/fork-print-inferior-events

Breakpoint 1, main (argc=1, argv=0x2ff229a0) at //gdb_tests/fork-print-inferior-events.c:26
26        child = fork ();
(gdb) catch fork
Catchpoint 2 (fork)
(gdb) c
Continuing.
Catchpoint 2 (forked process 23068956), 0xd028b3f0 in fork () from /usr/lib/libc.a(_shr.o)
(gdb) c
Continuing.
[Detaching after fork from child process 23068956]
[Inferior 1 (process 8782214) exited normally]
(gdb)


So, this fixed the issue. Kindly let me know what you think and give me feedback.

Have a nice day ahead.

Thanks and regards,
Aditya.

#include <stdlib.h>
#include <unistd.h>

int
main (int argc, char *argv[])
{
  pid_t child;

  child = fork ();
  switch (child)
    {
      case -1:
        abort ();
      case 0:
      default:
        break;
    }

  return 0;
}

[-- Attachment #2: 0001-Fix-AIX-catchpoint-warning-during-fork-event.patch --]
[-- Type: application/octet-stream, Size: 1354 bytes --]

From b3d536a7aad5c78583325e004d5e8753c7bdd3db Mon Sep 17 00:00:00 2001
From: Aditya Vidyadhar Kamath <Aditya.Kamath1@ibm.com>
Date: Tue, 9 Jan 2024 20:50:37 -0600
Subject: [PATCH] Fix AIX catchpoint warning during fork () event

In AIX we were missing some hooks needed to catch a fork () event
in rs6000-aix-nat.c. Due to their absence we were returning 1 while we
insert the breakpoint/catchpoint location. This patch is a fix to the same.
---
 gdb/rs6000-aix-nat.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/gdb/rs6000-aix-nat.c b/gdb/rs6000-aix-nat.c
index 771fef407a7..74cc4879729 100644
--- a/gdb/rs6000-aix-nat.c
+++ b/gdb/rs6000-aix-nat.c
@@ -104,6 +104,9 @@ class rs6000_nat_target final : public inf_ptrace_target
 
   const struct target_desc *read_description ()  override;
 
+  int insert_fork_catchpoint (int) override;
+  int remove_fork_catchpoint (int) override;
+
 protected:
 
   void post_startup_inferior (ptid_t ptid) override;
@@ -477,6 +480,19 @@ rs6000_nat_target::follow_fork (inferior *child_inf, ptid_t child_ptid,
   }
 }
 
+/* Functions for catchpoint in AIX.  */
+int
+rs6000_nat_target::insert_fork_catchpoint (int pid)
+{
+  return 0;
+}
+
+int
+rs6000_nat_target::remove_fork_catchpoint (int pid)
+{
+  return 0;
+}
+
 /* Fetch register REGNO from the inferior.  */
 
 static void
-- 
2.41.0


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix AIX watchpoint warning during fork () event.
  2024-01-10  2:57 [PATCH] Fix AIX watchpoint warning during fork () event Aditya Kamath1
@ 2024-01-10 16:41 ` Ulrich Weigand
  2024-01-11  5:51   ` Aditya Kamath1
  0 siblings, 1 reply; 3+ messages in thread
From: Ulrich Weigand @ 2024-01-10 16:41 UTC (permalink / raw)
  To: gdb-patches, Aditya Kamath1; +Cc: Sangamesh Mallayya

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

>This is a patch to fix the warnings appearing while setting a catchpoint in AIX for a fork () event.

This is OK.  I've applied the patch.

Thanks,
Ulrich


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix AIX watchpoint warning during fork () event.
  2024-01-10 16:41 ` Ulrich Weigand
@ 2024-01-11  5:51   ` Aditya Kamath1
  0 siblings, 0 replies; 3+ messages in thread
From: Aditya Kamath1 @ 2024-01-11  5:51 UTC (permalink / raw)
  To: Ulrich Weigand, gdb-patches; +Cc: Sangamesh Mallayya

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

Thank you

From: Ulrich Weigand <Ulrich.Weigand@de.ibm.com>
Date: Wednesday, 10 January 2024 at 10:11 PM
To: gdb-patches@sourceware.org <gdb-patches@sourceware.org>, Aditya Kamath1 <Aditya.Kamath1@ibm.com>
Cc: Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>
Subject: Re: [PATCH] Fix AIX watchpoint warning during fork () event.
Aditya Kamath1 <Aditya.Kamath1@ibm.com> wrote:

>This is a patch to fix the warnings appearing while setting a catchpoint in AIX for a fork () event.

This is OK.  I've applied the patch.

Thanks,
Ulrich

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-01-11  5:51 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-10  2:57 [PATCH] Fix AIX watchpoint warning during fork () event Aditya Kamath1
2024-01-10 16:41 ` Ulrich Weigand
2024-01-11  5:51   ` Aditya Kamath1

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