[1/2] linux-nat: Callback for exec events

Message ID 20190516201218.29403-2-pedromfc@linux.ibm.com
State New, archived
Headers

Commit Message

Pedro Franco de Carvalho May 16, 2019, 8:12 p.m. UTC
  This patch adds a new virtual low method to the linux native target,
called when an exec event is detected (PTRACE_EVENT_EXEC).

The main motivation for this is for arch-specific code to be able to
update its debug register state, since infrun assumes that an exec
will cause the hardware watchpoints in the inferior to be cleared.

Because this callback is called before infrun and other GDB layers
become aware of the exec event, care must be taken when overriding it.

2019-05-16  Pedro Franco de Carvalho  <pedromfc@linux.ibm.com>

	* linux-nat.h (class linux_nat_target) <low_post_exec>: New
	method.
	* linux-nat.c (linux_handle_extended_wait): Call low_post_exec.
---
 gdb/linux-nat.c |  4 ++++
 gdb/linux-nat.h | 13 +++++++++++++
 2 files changed, 17 insertions(+)
  

Patch

diff --git a/gdb/linux-nat.c b/gdb/linux-nat.c
index 65165a2d46..188b1696a8 100644
--- a/gdb/linux-nat.c
+++ b/gdb/linux-nat.c
@@ -2092,6 +2092,10 @@  linux_handle_extended_wait (struct lwp_info *lp, int status)
 	 thread execs, it changes its tid to the tgid, and the old
 	 tgid thread might have not been resumed.  */
       lp->resumed = 1;
+
+      /* Let the arch know that lp called exec.  */
+      linux_target->low_post_exec (lp);
+
       return 0;
     }
 
diff --git a/gdb/linux-nat.h b/gdb/linux-nat.h
index 0c1695ad10..569683ba33 100644
--- a/gdb/linux-nat.h
+++ b/gdb/linux-nat.h
@@ -168,6 +168,19 @@  public:
   virtual void low_forget_process (pid_t pid)
   {}
 
+  /* The method to call, if any, when an exec event is detected on
+     LWP.
+
+     This is meant to be used by the low target to update its own
+     internal state of debug registers, given that infrun assumes that
+     watchpoints are cleared accross an exec.
+
+     For other needs, be careful of assumptions about the state of
+     other layers of GDB, which haven't been notified of the exec
+     event at this point.  */
+  virtual void low_post_exec (struct lwp_info * lwp)
+  {}
+
   /* Hook to call prior to resuming a thread.  */
   virtual void low_prepare_to_resume (struct lwp_info *)
   {}