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]

[PATCH 01/14] Introduce current_inferior_ptid


This commit introduces a new function, current_inferior_ptid, that
allows shared code to obtain the ptid of the current inferior.

gdb/ChangeLog:

	* common/common-inferior.h: New file.
	* Makefile.in (HFILES_NO_SRCDIR): Add common/common-inferior.h.
	* inferior.h: Include common-inferior.h.
	* inferior.c (current_inferior_ptid): New function.
	* x86-linux-nat.c (x86_linux_dr_get_addr): Use the above.
	(x86_linux_dr_get_control): Likewise.
	(x86_linux_dr_get_status): Likewise.

gdb/gdbserver/ChangeLog:

	* inferiors.h: Include common-inferior.h.
	* inferiors.c (current_inferior_ptid): New function.
	* linux-x86-low.c (x86_dr_low_get_addr): Use the above.
	(x86_dr_low_get_control): Likewise.
	(x86_dr_low_get_status): Likewise.
---
 gdb/ChangeLog                 |   10 ++++++++++
 gdb/Makefile.in               |    2 +-
 gdb/common/common-inferior.h  |   28 ++++++++++++++++++++++++++++
 gdb/gdbserver/ChangeLog       |    8 ++++++++
 gdb/gdbserver/inferiors.c     |    8 ++++++++
 gdb/gdbserver/inferiors.h     |    2 ++
 gdb/gdbserver/linux-x86-low.c |   12 +++---------
 gdb/inferior.c                |    8 ++++++++
 gdb/inferior.h                |    2 ++
 gdb/x86-linux-nat.c           |    6 +++---
 10 files changed, 73 insertions(+), 13 deletions(-)
 create mode 100644 gdb/common/common-inferior.h

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index c394ea3..acea04b 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -939,7 +939,7 @@ common/print-utils.h common/rsp-low.h nat/x86-dregs.h x86-linux-nat.h \
 i386-linux-nat.h common/common-defs.h common/errors.h common/common-types.h \
 common/common-debug.h common/cleanups.h common/gdb_setjmp.h \
 common/common-exceptions.h target/target.h target/symbol.h \
-common/common-regcache.h
+common/common-regcache.h common/common-inferior.h
 
 # Header files that already have srcdir in them, or which are in objdir.
 
diff --git a/gdb/common/common-inferior.h b/gdb/common/common-inferior.h
new file mode 100644
index 0000000..fa23b22
--- /dev/null
+++ b/gdb/common/common-inferior.h
@@ -0,0 +1,28 @@
+/* Inferior process information.
+
+   Copyright (C) 2014 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef COMMON_INFERIOR_H
+#define COMMON_INFERIOR_H
+
+/* Return the ptid of the current inferior.  This function must be
+   provided by the client. */
+
+extern ptid_t current_inferior_ptid (void);
+
+#endif /* COMMON_INFERIOR_H */
diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c
index 29a07e0..c87de27 100644
--- a/gdb/gdbserver/inferiors.c
+++ b/gdb/gdbserver/inferiors.c
@@ -358,3 +358,11 @@ current_process (void)
   gdb_assert (current_inferior != NULL);
   return get_thread_process (current_inferior);
 }
+
+/* See common/common-inferior.h.  */
+
+ptid_t
+current_inferior_ptid (void)
+{
+  return ptid_of (current_inferior);
+}
diff --git a/gdb/gdbserver/inferiors.h b/gdb/gdbserver/inferiors.h
index f584339..10aa095 100644
--- a/gdb/gdbserver/inferiors.h
+++ b/gdb/gdbserver/inferiors.h
@@ -19,6 +19,8 @@
 #ifndef INFERIORS_H
 #define INFERIORS_H
 
+#include "common-inferior.h"
+
 /* Generic information for tracking a list of ``inferiors'' - threads,
    processes, etc.  */
 struct inferior_list
diff --git a/gdb/gdbserver/linux-x86-low.c b/gdb/gdbserver/linux-x86-low.c
index a66f61e..04f66aa 100644
--- a/gdb/gdbserver/linux-x86-low.c
+++ b/gdb/gdbserver/linux-x86-low.c
@@ -602,11 +602,9 @@ x86_dr_low_set_addr (int regnum, CORE_ADDR addr)
 static CORE_ADDR
 x86_dr_low_get_addr (int regnum)
 {
-  ptid_t ptid = ptid_of (current_inferior);
-
   gdb_assert (DR_FIRSTADDR <= regnum && regnum <= DR_LASTADDR);
 
-  return x86_linux_dr_get (ptid, regnum);
+  return x86_linux_dr_get (current_inferior_ptid (), regnum);
 }
 
 /* Update the inferior's DR7 debug control register from STATE.  */
@@ -625,9 +623,7 @@ x86_dr_low_set_control (unsigned long control)
 static unsigned long
 x86_dr_low_get_control (void)
 {
-  ptid_t ptid = ptid_of (current_inferior);
-
-  return x86_linux_dr_get (ptid, DR_CONTROL);
+  return x86_linux_dr_get (current_inferior_ptid (), DR_CONTROL);
 }
 
 /* Get the value of the DR6 debug status register from the inferior
@@ -636,9 +632,7 @@ x86_dr_low_get_control (void)
 static unsigned long
 x86_dr_low_get_status (void)
 {
-  ptid_t ptid = ptid_of (current_inferior);
-
-  return x86_linux_dr_get (ptid, DR_STATUS);
+  return x86_linux_dr_get (current_inferior_ptid (), DR_STATUS);
 }
 
 /* Low-level function vector.  */
diff --git a/gdb/inferior.c b/gdb/inferior.c
index 23da0c7..e19168d 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -68,6 +68,14 @@ set_current_inferior (struct inferior *inf)
   current_inferior_ = inf;
 }
 
+/* See common/common-inferior.h.  */
+
+ptid_t
+current_inferior_ptid (void)
+{
+  return inferior_ptid;
+}
+
 /* A cleanups callback, helper for save_current_program_space
    below.  */
 
diff --git a/gdb/inferior.h b/gdb/inferior.h
index 58557a4..72ecfda 100644
--- a/gdb/inferior.h
+++ b/gdb/inferior.h
@@ -21,6 +21,8 @@
 #if !defined (INFERIOR_H)
 #define INFERIOR_H 1
 
+#include "common-inferior.h"
+
 struct target_waitstatus;
 struct frame_info;
 struct ui_file;
diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c
index 67300d8..9370976 100644
--- a/gdb/x86-linux-nat.c
+++ b/gdb/x86-linux-nat.c
@@ -97,7 +97,7 @@ x86_linux_dr_get_addr (int regnum)
   /* DR6 and DR7 are retrieved with some other way.  */
   gdb_assert (DR_FIRSTADDR <= regnum && regnum <= DR_LASTADDR);
 
-  return x86_linux_dr_get (inferior_ptid, regnum);
+  return x86_linux_dr_get (current_inferior_ptid (), regnum);
 }
 
 /* Return the inferior's DR7 debug control register.  */
@@ -105,7 +105,7 @@ x86_linux_dr_get_addr (int regnum)
 static unsigned long
 x86_linux_dr_get_control (void)
 {
-  return x86_linux_dr_get (inferior_ptid, DR_CONTROL);
+  return x86_linux_dr_get (current_inferior_ptid (), DR_CONTROL);
 }
 
 /* Get DR_STATUS from only the one LWP of INFERIOR_PTID.  */
@@ -113,7 +113,7 @@ x86_linux_dr_get_control (void)
 static unsigned long
 x86_linux_dr_get_status (void)
 {
-  return x86_linux_dr_get (inferior_ptid, DR_STATUS);
+  return x86_linux_dr_get (current_inferior_ptid (), DR_STATUS);
 }
 
 /* Callback for iterate_over_lwps.  Update the debug registers of
-- 
1.7.1


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