[11/13,v2] Introduce x86_linux_update_debug_registers

Message ID 1412848358-9958-12-git-send-email-gbenson@redhat.com
State Committed
Headers

Commit Message

Gary Benson Oct. 9, 2014, 9:52 a.m. UTC
  This commit moves the entire body of both GDB's and gdbserver's
x86_linux_prepare_to_resume functions into new functions,
x86_linux_update_debug_registers.  This reorganisation allows
all Linux x86 low-level debug register code to be placed in one
shared file, separate from general Linux x86 shared code.

gdb/ChangeLog:

	* x86-linux-nat.c (x86_linux_update_debug_registers):
	New function.
	(x86_linux_prepare_to_resume): Call the above.

gdb/gdbserver/ChangeLog:

	* linux-x86-low.c (x86_linux_update_debug_registers):
	New function.
	(x86_linux_prepare_to_resume): Call the above.
---
 gdb/ChangeLog                 |    6 ++++++
 gdb/gdbserver/ChangeLog       |    6 ++++++
 gdb/gdbserver/linux-x86-low.c |   16 +++++++++++++---
 gdb/x86-linux-nat.c           |   16 +++++++++++++---
 4 files changed, 38 insertions(+), 6 deletions(-)
  

Comments

Pedro Alves Oct. 28, 2014, 12:59 p.m. UTC | #1
On 10/09/2014 10:52 AM, Gary Benson wrote:
> This commit moves the entire body of both GDB's and gdbserver's
> x86_linux_prepare_to_resume functions into new functions,
> x86_linux_update_debug_registers.  This reorganisation allows
> all Linux x86 low-level debug register code to be placed in one
> shared file, separate from general Linux x86 shared code.
> 
> gdb/ChangeLog:
> 
> 	* x86-linux-nat.c (x86_linux_update_debug_registers):
> 	New function.
> 	(x86_linux_prepare_to_resume): Call the above.

I'd prefer making it a little clearer that this is code being
factored out, instead of being really new code, like:

 	* x86-linux-nat.c (x86_linux_update_debug_registers):
 	New function, factored out from ...
 	(x86_linux_prepare_to_resume): ... this.

> gdb/gdbserver/ChangeLog:
> 
> 	* linux-x86-low.c (x86_linux_update_debug_registers):
> 	New function.
> 	(x86_linux_prepare_to_resume): Call the above.

OK.

Thanks,
Pedro Alves
  

Patch

diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index f4d6437..bb8e1a7 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -763,15 +763,17 @@  x86_debug_reg_state (pid_t pid)
   return &proc->private->arch_private->debug_reg_state;
 }
 
-/* Called prior to resuming a thread.  Updates the thread's debug
-   registers if the values in our local mirror have been changed.  */
+/* Update the thread's debug registers if the values in our local
+   mirror have been changed.  */
 
 static void
-x86_linux_prepare_to_resume (struct lwp_info *lwp)
+x86_linux_update_debug_registers (struct lwp_info *lwp)
 {
   ptid_t ptid = ptid_of_lwp (lwp);
   int clear_status = 0;
 
+  gdb_assert (lwp_is_stopped (lwp));
+
   if (lwp_debug_registers_changed (lwp))
     {
       struct x86_debug_reg_state *state
@@ -807,6 +809,14 @@  x86_linux_prepare_to_resume (struct lwp_info *lwp)
   if (clear_status || lwp_is_stopped_by_watchpoint (lwp))
     x86_linux_dr_set (ptid, DR_STATUS, 0);
 }
+
+/* Called prior to resuming a thread.  */
+
+static void
+x86_linux_prepare_to_resume (struct lwp_info *lwp)
+{
+  x86_linux_update_debug_registers (lwp);
+}
 
 /* When GDBSERVER is built as a 64-bit application on linux, the
    PTRACE_GETSIGINFO data is always presented in 64-bit layout.  Since
diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c
index d806474..55c3bd3 100644
--- a/gdb/x86-linux-nat.c
+++ b/gdb/x86-linux-nat.c
@@ -162,15 +162,17 @@  x86_linux_dr_set_addr (int regnum, CORE_ADDR addr)
   iterate_over_lwps (pid_ptid, update_debug_registers_callback, NULL);
 }
 
-/* Called prior to resuming a thread.  Updates the thread's debug
-   registers if the values in our local mirror have been changed.  */
+/* Update the thread's debug registers if the values in our local
+   mirror have been changed.  */
 
 static void
-x86_linux_prepare_to_resume (struct lwp_info *lwp)
+x86_linux_update_debug_registers (struct lwp_info *lwp)
 {
   ptid_t ptid = ptid_of_lwp (lwp);
   int clear_status = 0;
 
+  gdb_assert (lwp_is_stopped (lwp));
+
   if (lwp_debug_registers_changed (lwp))
     {
       struct x86_debug_reg_state *state
@@ -207,6 +209,14 @@  x86_linux_prepare_to_resume (struct lwp_info *lwp)
     x86_linux_dr_set (ptid, DR_STATUS, 0);
 }
 
+/* Called prior to resuming a thread.  */
+
+static void
+x86_linux_prepare_to_resume (struct lwp_info *lwp)
+{
+  x86_linux_update_debug_registers (lwp);
+}
+
 /* Called when a new thread is detected.  */
 
 static void