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 03/14] Introduce current_inferior_pid


This commit introduces a new function, current_inferior_pid, that
shared code can use to obtain the PID of the current inferior.

gdb/ChangeLog:

	* common/common-inferior.c: New file.
	* Makefile.in (SFILES): Add common/common-inferior.c.
	(COMMON_OBS): Add common/common-inferior.o.
	(common-inferior.o): New rule.
	* common/common-inferior.h (current_inferior_pid): New function.
	* x86-linux-nat.c (x86_linux_dr_set_control): Use the above.
	(x86_linux_dr_set_addr): Likewise.

gdb/gdbserver/ChangeLog:

	* Makefile.in (SFILES): Add common-inferior.c.
	(OBS): Add common-inferior.o.
	(common-inferior.o): New rule.
---
 gdb/ChangeLog                |   10 ++++++++++
 gdb/Makefile.in              |    9 +++++++--
 gdb/common/common-inferior.c |   29 +++++++++++++++++++++++++++++
 gdb/common/common-inferior.h |    4 ++++
 gdb/gdbserver/ChangeLog      |    6 ++++++
 gdb/gdbserver/Makefile.in    |    8 ++++++--
 gdb/x86-linux-nat.c          |    4 ++--
 7 files changed, 64 insertions(+), 6 deletions(-)
 create mode 100644 gdb/common/common-inferior.c

diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index acea04b..c454503 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -851,7 +851,8 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.c \
 	common/ptid.c common/buffer.c gdb-dlfcn.c common/agent.c \
 	common/format.c common/filestuff.c btrace.c record-btrace.c ctf.c \
 	target/waitstatus.c common/print-utils.c common/rsp-low.c \
-	common/errors.c common/common-debug.c common/common-exceptions.c
+	common/errors.c common/common-debug.c common/common-exceptions.c \
+	common/common-inferior.c
 
 LINTFILES = $(SFILES) $(YYFILES) $(CONFIG_SRCS) init.c
 
@@ -1039,7 +1040,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
 	common-utils.o buffer.o ptid.o gdb-dlfcn.o common-agent.o \
 	format.o registry.o btrace.o record-btrace.o waitstatus.o \
 	print-utils.o rsp-low.o errors.o common-debug.o debug.o \
-	common-exceptions.o
+	common-exceptions.o common-inferior.o
 
 TSOBS = inflow.o
 
@@ -2173,6 +2174,10 @@ common-exceptions.o: ${srcdir}/common/common-exceptions.c
 	$(COMPILE) $(srcdir)/common/common-exceptions.c
 	$(POSTCOMPILE)
 
+common-inferior.o: ${srcdir}/common/common-inferior.c
+	$(COMPILE) $(srcdir)/common/common-inferior.c
+	$(POSTCOMPILE)
+
 #
 # gdb/target/ dependencies
 #
diff --git a/gdb/common/common-inferior.c b/gdb/common/common-inferior.c
new file mode 100644
index 0000000..a7a69c5
--- /dev/null
+++ b/gdb/common/common-inferior.c
@@ -0,0 +1,29 @@
+/* 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/>.  */
+
+#include "common-defs.h"
+#include "common-inferior.h"
+
+/* See common/common-inferior.h.  */
+
+int
+current_inferior_pid (void)
+{
+  return ptid_get_pid (current_inferior_ptid ());
+}
diff --git a/gdb/common/common-inferior.h b/gdb/common/common-inferior.h
index fa23b22..040630d 100644
--- a/gdb/common/common-inferior.h
+++ b/gdb/common/common-inferior.h
@@ -20,6 +20,10 @@
 #ifndef COMMON_INFERIOR_H
 #define COMMON_INFERIOR_H
 
+/* Return the pid of the current inferior.  */
+
+extern int current_inferior_pid (void);
+
 /* Return the ptid of the current inferior.  This function must be
    provided by the client. */
 
diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
index 074d93d..3b1c783 100644
--- a/gdb/gdbserver/Makefile.in
+++ b/gdb/gdbserver/Makefile.in
@@ -171,7 +171,8 @@ SFILES=	$(srcdir)/gdbreplay.c $(srcdir)/inferiors.c $(srcdir)/dll.c \
 	$(srcdir)/nat/mips-linux-watch.c $(srcdir)/common/print-utils.c \
 	$(srcdir)/common/rsp-low.c $(srcdir)/common/errors.c \
 	$(srcdir)/common/common-debug.c $(srcdir)/common/cleanups.c \
-	$(srcdir)/common/common-exceptions.c $(srcdir)/symbol.c
+	$(srcdir)/common/common-exceptions.c $(srcdir)/symbol.c \
+	$(srcdir)/common/common-inferior.c
 
 DEPFILES = @GDBSERVER_DEPFILES@
 
@@ -185,7 +186,7 @@ OBS = agent.o ax.o inferiors.o regcache.o remote-utils.o server.o signals.o \
       mem-break.o hostio.o event-loop.o tracepoint.o xml-utils.o \
       common-utils.o ptid.o buffer.o format.o filestuff.o dll.o notif.o \
       tdesc.o print-utils.o rsp-low.o errors.o common-debug.o cleanups.o \
-      common-exceptions.o symbol.o \
+      common-exceptions.o symbol.o common-inferior.o \
       $(XML_BUILTIN) $(DEPFILES) $(LIBOBJS)
 GDBREPLAY_OBS = gdbreplay.o version.o
 GDBSERVER_LIBS = @GDBSERVER_LIBS@
@@ -552,6 +553,9 @@ cleanups.o: ../common/cleanups.c
 common-exceptions.o: ../common/common-exceptions.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
+common-inferior.o: ../common/common-inferior.c
+	$(COMPILE) $<
+	$(POSTCOMPILE)
 waitstatus.o: ../target/waitstatus.c
 	$(COMPILE) $<
 	$(POSTCOMPILE)
diff --git a/gdb/x86-linux-nat.c b/gdb/x86-linux-nat.c
index 9370976..92bdfec 100644
--- a/gdb/x86-linux-nat.c
+++ b/gdb/x86-linux-nat.c
@@ -143,7 +143,7 @@ update_debug_registers_callback (struct lwp_info *lwp, void *arg)
 static void
 x86_linux_dr_set_control (unsigned long control)
 {
-  ptid_t pid_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
+  ptid_t pid_ptid = pid_to_ptid (current_inferior_pid ());
 
   iterate_over_lwps (pid_ptid, update_debug_registers_callback, NULL);
 }
@@ -154,7 +154,7 @@ x86_linux_dr_set_control (unsigned long control)
 static void
 x86_linux_dr_set_addr (int regnum, CORE_ADDR addr)
 {
-  ptid_t pid_ptid = pid_to_ptid (ptid_get_pid (inferior_ptid));
+  ptid_t pid_ptid = pid_to_ptid (current_inferior_pid ());
 
   gdb_assert (regnum >= 0 && regnum <= DR_LASTADDR - DR_FIRSTADDR);
 
-- 
1.7.1


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