[01/14] Introduce current_inferior_ptid
Commit Message
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
@@ -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.
new file mode 100644
@@ -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 */
@@ -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);
+}
@@ -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
@@ -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. */
@@ -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. */
@@ -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;
@@ -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