This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFA 2/3] Change detach_breakpoints to take a ptid instead of a pid


> > gdb/ChangeLog:
> > 
> >         * breakpoint.h (detach_breakpoints): pid parameter is now a ptid.
> >         * breakpoint.c (detach_breakpoints): Change pid parameter into
> >         a ptid.  Adjust code accordingly.
> >         * infrun.c (handle_inferior_event): Delete variable child_pid.
> >         Update call to detach_breakpoints to pass the child ptid for
> >         fork events.
> >         * linux-nat.c (linux_nat_iterate_watchpoint_lwps): Remove
> >         assert that inferior_ptid's lwp is zero.
> >         (linux_handle_extended_wait): Update call to detach_breakpoints.
> > 
> > OK to apply?
> 
> 
> Looks fine to me.  One nit:

Thanks again.

Attached is revised version, which also includes the detach_breakpoints
calls from inf-ttrace, now that they here to stay...

-- 
Joel
>From ab57c818ceed0eb07c10cfba7436ee9f93e1b592 Mon Sep 17 00:00:00 2001
From: Joel Brobecker <brobecker@adacore.com>
Date: Sat, 9 Jun 2012 12:24:29 -0400
Subject: [PATCH 2/3] Change detach_breakpoints to take a ptid instead of a pid

Before this change, detach_breakpoints would take a pid, and then
set inferior_ptid to a ptid that it constructs using pid_to_ptid (pid).
Unfortunately, this ptid is not necessarily valid.  Consider for
instance the case of ia64-hpux, where ttrace refuses a register-read
operation if the LWP is not provided.

This problems shows up when GDB is trying to handle fork events.
Assuming GDB is configured to follow the parent, GDB will try to
detach from the child. But before doing so, it needs to remove
all breakpoints inside that child.  On ia64, this involves reading
inferior (the child's) memory. And on ia64-hpux, reading memory
requires us to read the bsp and bspstore registers, in order to
determine where that memory is relative to the value of those
registers, and thus to determine which ttrace operation to use in
order to fetch that memory (see ia64_hpux_xfer_memory).

This patch therefore changes detach_breakpoints to take a ptid instead
of a pid, and then updates all callers.

One of the consequences of this patch is that it trips an assert
on GNU/Linux targets.  But this assert appears to have not actual
purpose, and is thus removed.

gdb/ChangeLog:

        * breakpoint.h (detach_breakpoints): pid parameter is now a ptid.
        * breakpoint.c (detach_breakpoints): Change pid parameter into
        a ptid.  Adjust code accordingly.
        * infrun.c (handle_inferior_event): Delete variable child_pid.
        Update call to detach_breakpoints to pass the child ptid for
        fork events.
        * linux-nat.c (linux_nat_iterate_watchpoint_lwps): Remove
        assert that inferior_ptid's lwp is zero.
        (linux_handle_extended_wait): Update call to detach_breakpoints.
        * inf-ttrace.c (inf_ttrace_follow_fork): Update call to
        detach_breakpoints.
---
 gdb/breakpoint.c |    6 +++---
 gdb/breakpoint.h |    2 +-
 gdb/inf-ttrace.c |    4 ++--
 gdb/infrun.c     |    4 +---
 gdb/linux-nat.c  |    3 +--
 5 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 12ab271..eec939a 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -3272,18 +3272,18 @@ update_breakpoints_after_exec (void)
 }
 
 int
-detach_breakpoints (int pid)
+detach_breakpoints (ptid_t ptid)
 {
   struct bp_location *bl, **blp_tmp;
   int val = 0;
   struct cleanup *old_chain = save_inferior_ptid ();
   struct inferior *inf = current_inferior ();
 
-  if (pid == PIDGET (inferior_ptid))
+  if (PIDGET (ptid) == PIDGET (inferior_ptid))
     error (_("Cannot detach breakpoints of inferior_ptid"));
 
   /* Set inferior_ptid; remove_breakpoint_1 uses this global.  */
-  inferior_ptid = pid_to_ptid (pid);
+  inferior_ptid = ptid;
   ALL_BP_LOCATIONS (bl, blp_tmp)
   {
     if (bl->pspace != inf->pspace)
diff --git a/gdb/breakpoint.h b/gdb/breakpoint.h
index 68a9688..056f707 100644
--- a/gdb/breakpoint.h
+++ b/gdb/breakpoint.h
@@ -1273,7 +1273,7 @@ extern void update_breakpoints_after_exec (void);
 
    It is an error to use this function on the process whose id is
    inferior_ptid.  */
-extern int detach_breakpoints (int);
+extern int detach_breakpoints (ptid_t ptid);
 
 /* This function is called when program space PSPACE is about to be
    deleted.  It takes care of updating breakpoints to not reference
diff --git a/gdb/inf-ttrace.c b/gdb/inf-ttrace.c
index ddcbd42..2b9e7f5 100644
--- a/gdb/inf-ttrace.c
+++ b/gdb/inf-ttrace.c
@@ -457,7 +457,7 @@ inf_ttrace_follow_fork (struct target_ops *ops, int follow_child)
       inf->pspace = parent_inf->pspace;
       inf->aspace = parent_inf->aspace;
       copy_terminal_info (inf, parent_inf);
-      detach_breakpoints (pid);
+      detach_breakpoints (ptid_build (pid, lwpid, 0));
 
       target_terminal_ours ();
       fprintf_unfiltered (gdb_stdlog,
@@ -471,7 +471,7 @@ inf_ttrace_follow_fork (struct target_ops *ops, int follow_child)
 	 of fork events, we do not need to do this, because breakpoints
 	 should have already been removed earlier.  */
       if (tts.tts_event == TTEVT_VFORK)
-	detach_breakpoints (fpid);
+	detach_breakpoints (ptid_build (fpid, flwpid, 0));
 
       target_terminal_ours ();
       fprintf_unfiltered (gdb_stdlog,
diff --git a/gdb/infrun.c b/gdb/infrun.c
index 53db335..e13050b 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -3513,11 +3513,9 @@ handle_inferior_event (struct execution_control_state *ecs)
 	 vfork follow are detached.  */
       if (ecs->ws.kind != TARGET_WAITKIND_VFORKED)
 	{
-	  int child_pid = ptid_get_pid (ecs->ws.value.related_pid);
-
 	  /* This won't actually modify the breakpoint list, but will
 	     physically remove the breakpoints from the child.  */
-	  detach_breakpoints (child_pid);
+	  detach_breakpoints (ecs->ws.value.related_pid);
 	}
 
       if (singlestep_breakpoints_inserted_p)
diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 33b13fa..34cb57a 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -1305,7 +1305,6 @@ linux_nat_iterate_watchpoint_lwps
       pid_t child_pid = GET_PID (inferior_ptid);
       ptid_t child_ptid = ptid_build (child_pid, child_pid, 0);
 
-      gdb_assert (!is_lwp (inferior_ptid));
       gdb_assert (find_lwp_pid (child_ptid) == NULL);
       child_lp = add_lwp (child_ptid);
       child_lp->stopped = 1;
@@ -2296,7 +2295,7 @@ linux_handle_extended_wait (struct lwp_info *lp, int status,
 
 	  /* This won't actually modify the breakpoint list, but will
 	     physically remove the breakpoints from the child.  */
-	  detach_breakpoints (new_pid);
+	  detach_breakpoints (ptid_build (new_pid, new_pid, 0));
 
 	  /* Retain child fork in ptrace (stopped) state.  */
 	  if (!find_fork_pid (new_pid))
-- 
1.7.0.4


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]