aboutsummaryrefslogtreecommitdiff
path: root/gdb/gdbserver/linux-mips-low.c
diff options
context:
space:
mode:
authorDon Breazeal <donb@codesourcery.com>2015-05-12 09:52:44 -0700
committerDon Breazeal <donb@codesourcery.com>2015-05-12 09:52:44 -0700
commit3a8a0396bed4e9dd87c2df0f68386a0f04dfc824 (patch)
tree4fa6326b487196db58fe169e894d03edacaa2547 /gdb/gdbserver/linux-mips-low.c
parentde0d863ec3fda88e488cee568f943c7998b68862 (diff)
downloadgdb-3a8a0396bed4e9dd87c2df0f68386a0f04dfc824.zip
gdb-3a8a0396bed4e9dd87c2df0f68386a0f04dfc824.tar.gz
gdb-3a8a0396bed4e9dd87c2df0f68386a0f04dfc824.tar.bz2
Arch-specific remote follow fork
This patch implements the architecture-specific pieces of follow-fork for remote and extended-remote Linux targets, which in the current implementation copyies the parent's debug register state into the new child's data structures. This is required for x86, arm, aarch64, and mips. This follows the native implementation as closely as possible by implementing a new linux_target_ops function 'new_fork', which is analogous to 'linux_nat_new_fork' in linux-nat.c. In gdbserver, the debug registers are stored in the process list, instead of an architecture-specific list, so the function arguments are process_info pointers instead of an lwp_info and a pid as in the native implementation. In the MIPS implementation the debug register mirror is stored differently from x86, ARM, and aarch64, so instead of doing a simple structure assignment I had to clone the list of watchpoint structures. Tested using gdb.threads/watchpoint-fork.exp on x86, and ran manual tests on a MIPS board and an ARM board. Aarch64 hasn't been tested. gdb/gdbserver/ChangeLog: * linux-aarch64-low.c (aarch64_linux_new_fork): New function. (the_low_target) <new_fork>: Initialize new member. * linux-arm-low.c (arm_new_fork): New function. (the_low_target) <new_fork>: Initialize new member. * linux-low.c (handle_extended_wait): Call new target function new_fork. * linux-low.h (struct linux_target_ops) <new_fork>: New member. * linux-mips-low.c (mips_add_watchpoint): New function extracted from mips_insert_point. (the_low_target) <new_fork>: Initialize new member. (mips_linux_new_fork): New function. (mips_insert_point): Call mips_add_watchpoint. * linux-x86-low.c (x86_linux_new_fork): New function. (the_low_target) <new_fork>: Initialize new member.
Diffstat (limited to 'gdb/gdbserver/linux-mips-low.c')
-rw-r--r--gdb/gdbserver/linux-mips-low.c76
1 files changed, 64 insertions, 12 deletions
diff --git a/gdb/gdbserver/linux-mips-low.c b/gdb/gdbserver/linux-mips-low.c
index 7988d07..4601ad0 100644
--- a/gdb/gdbserver/linux-mips-low.c
+++ b/gdb/gdbserver/linux-mips-low.c
@@ -344,6 +344,68 @@ mips_linux_new_thread (struct lwp_info *lwp)
lwp->arch_private = info;
}
+/* Create a new mips_watchpoint and add it to the list. */
+
+static void
+mips_add_watchpoint (struct arch_process_info *private, CORE_ADDR addr,
+ int len, int watch_type)
+{
+ struct mips_watchpoint *new_watch;
+ struct mips_watchpoint **pw;
+
+ new_watch = xmalloc (sizeof (struct mips_watchpoint));
+ new_watch->addr = addr;
+ new_watch->len = len;
+ new_watch->type = watch_type;
+ new_watch->next = NULL;
+
+ pw = &private->current_watches;
+ while (*pw != NULL)
+ pw = &(*pw)->next;
+ *pw = new_watch;
+}
+
+/* Hook to call when a new fork is attached. */
+
+static void
+mips_linux_new_fork (struct process_info *parent,
+ struct process_info *child)
+{
+ struct arch_process_info *parent_private;
+ struct arch_process_info *child_private;
+ struct mips_watchpoint *wp;
+
+ /* These are allocated by linux_add_process. */
+ gdb_assert (parent->private != NULL
+ && parent->private->arch_private != NULL);
+ gdb_assert (child->private != NULL
+ && child->private->arch_private != NULL);
+
+ /* Linux kernel before 2.6.33 commit
+ 72f674d203cd230426437cdcf7dd6f681dad8b0d
+ will inherit hardware debug registers from parent
+ on fork/vfork/clone. Newer Linux kernels create such tasks with
+ zeroed debug registers.
+
+ GDB core assumes the child inherits the watchpoints/hw
+ breakpoints of the parent, and will remove them all from the
+ forked off process. Copy the debug registers mirrors into the
+ new process so that all breakpoints and watchpoints can be
+ removed together. The debug registers mirror will become zeroed
+ in the end before detaching the forked off process, thus making
+ this compatible with older Linux kernels too. */
+
+ parent_private = parent->private->arch_private;
+ child_private = child->private->arch_private;
+
+ child_private->watch_readback_valid = parent_private->watch_readback_valid;
+ child_private->watch_readback = parent_private->watch_readback;
+
+ for (wp = parent_private->current_watches; wp != NULL; wp = wp->next)
+ mips_add_watchpoint (child_private, wp->addr, wp->len, wp->type);
+
+ child_private->watch_mirror = parent_private->watch_mirror;
+}
/* This is the implementation of linux_target_ops method
prepare_to_resume. If the watch regs have changed, update the
thread's copies. */
@@ -397,8 +459,6 @@ mips_insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
struct process_info *proc = current_process ();
struct arch_process_info *priv = proc->priv->arch_private;
struct pt_watch_regs regs;
- struct mips_watchpoint *new_watch;
- struct mips_watchpoint **pw;
int pid;
long lwpid;
enum target_hw_bp_type watch_type;
@@ -425,16 +485,7 @@ mips_insert_point (enum raw_bkpt_type type, CORE_ADDR addr,
return -1;
/* It fit. Stick it on the end of the list. */
- new_watch = xmalloc (sizeof (struct mips_watchpoint));
- new_watch->addr = addr;
- new_watch->len = len;
- new_watch->type = watch_type;
- new_watch->next = NULL;
-
- pw = &priv->current_watches;
- while (*pw != NULL)
- pw = &(*pw)->next;
- *pw = new_watch;
+ mips_add_watchpoint (priv, addr, len, watch_type);
priv->watch_mirror = regs;
@@ -845,6 +896,7 @@ struct linux_target_ops the_low_target = {
NULL, /* siginfo_fixup */
mips_linux_new_process,
mips_linux_new_thread,
+ mips_linux_new_fork,
mips_linux_prepare_to_resume
};