[1/2] linux-nat: Callback for exec events
Commit Message
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(+)
@@ -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;
}
@@ -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 *)
{}