]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Share regcache function regcache_raw_read_unsigned
authorAntoine Tremblay <antoine.tremblay@ericsson.com>
Fri, 18 Dec 2015 16:33:59 +0000 (11:33 -0500)
committerAntoine Tremblay <antoine.tremblay@ericsson.com>
Fri, 18 Dec 2015 16:39:21 +0000 (11:39 -0500)
This patch is in preparation for software single step support on ARM in
GDBServer. It adds a new shared function regcache_raw_read_unsigned and
regcache_raw_get_unsigned so that GDB and GDBServer can use the same call
to fetch a raw register into an integer.

No regressions, tested on ubuntu 14.04 ARMv7 and x86.
With gdbserver-{native,extended} / { -marm -mthumb }

gdb/ChangeLog:

* Makefile.in (SFILES): Append common/common-regcache.c.
(COMMON_OBS): Append common/common-regcache.o.
(common-regcache.o): New rule.
* common/common-regcache.h (register_status) New enum.
(regcache_raw_read_unsigned): New declaration.
* common/common-regcache.c: New file.
* regcache.h (enum register_status): Move to common-regcache.h.
(regcache_raw_read_unsigned): Likewise.
(regcache_raw_get_unsigned): Likewise.

gdb/gdbserver/ChangeLog:

* Makefile.in (SFILES): Append common/common-regcache.c.
(OBS): Append common-regcache.o.
(common-regcache.o): New rule.
* regcache.c (init_register_cache): Initialize cache to
REG_UNAVAILABLE.
(regcache_raw_read_unsigned): New function.
* regcache.h (REG_UNAVAILABLE, REG_VALID): Replaced by shared
register_status enum.

gdb/ChangeLog
gdb/Makefile.in
gdb/common/common-regcache.c [new file with mode: 0644]
gdb/common/common-regcache.h
gdb/gdbserver/ChangeLog
gdb/gdbserver/Makefile.in
gdb/gdbserver/regcache.c
gdb/gdbserver/regcache.h
gdb/regcache.c
gdb/regcache.h

index a590a0d7f30aa3b46c096ec2b0a4747b44a907f9..8f078c2fc77aae7c6e3b063e48ab1e9ef37d80a1 100644 (file)
@@ -1,3 +1,15 @@
+2015-12-18  Antoine Tremblay  <antoine.tremblay@ericsson.com>
+
+       * Makefile.in (SFILES): Append common/common-regcache.c.
+       (COMMON_OBS): Append common/common-regcache.o.
+       (common-regcache.o): New rule.
+       * common/common-regcache.h (register_status) New enum.
+       (regcache_raw_read_unsigned): New declaration.
+       * common/common-regcache.c: New file.
+       * regcache.h (enum register_status): Move to common-regcache.h.
+       (regcache_raw_read_unsigned): Likewise.
+       (regcache_raw_get_unsigned): Likewise.
+
 2015-12-18  Antoine Tremblay  <antoine.tremblay@ericsson.com>
 
        * arm-linux-tdep.c (arm_linux_sigreturn_next_pc_offset): New function.
index 3eadbbcf437c908c020b8b8fe54192fc9e2c763d..014df44544c2c8d3a6c7501ecb8e812c810b193d 100644 (file)
@@ -894,7 +894,7 @@ SFILES = ada-exp.y ada-lang.c ada-typeprint.c ada-valprint.c ada-tasks.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/btrace-common.c common/fileio.c \
+       common/btrace-common.c common/fileio.c common/common-regcache.c \
        $(SUBDIR_GCC_COMPILE_SRCS)
 
 LINTFILES = $(SFILES) $(YYFILES) $(CONFIG_SRCS) init.c
@@ -1085,6 +1085,7 @@ COMMON_OBS = $(DEPFILES) $(CONFIG_OBS) $(YYOBJ) \
        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 btrace-common.o fileio.o \
+       common-regcache.o \
        $(SUBDIR_GCC_COMPILE_OBS)
 
 TSOBS = inflow.o
@@ -2266,6 +2267,11 @@ btrace-common.o: ${srcdir}/common/btrace-common.c
 fileio.o: ${srcdir}/common/fileio.c
        $(COMPILE) $(srcdir)/common/fileio.c
        $(POSTCOMPILE)
+
+common-regcache.o: ${srcdir}/common/common-regcache.c
+       $(COMPILE) $(srcdir)/common/common-regcache.c
+       $(POSTCOMPILE)
+
 #
 # gdb/target/ dependencies
 #
diff --git a/gdb/common/common-regcache.c b/gdb/common/common-regcache.c
new file mode 100644 (file)
index 0000000..9ee1102
--- /dev/null
@@ -0,0 +1,36 @@
+/* Cache and manage the values of registers for GDB, the GNU debugger.
+
+   Copyright (C) 2015 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-regcache.h"
+
+/* Return the register's value or throw if it's not available.  */
+
+ULONGEST
+regcache_raw_get_unsigned (struct regcache *regcache, int regnum)
+{
+  ULONGEST value;
+  enum register_status status;
+
+  status = regcache_raw_read_unsigned (regcache, regnum, &value);
+  if (status == REG_UNAVAILABLE)
+    throw_error (NOT_AVAILABLE_ERROR,
+                _("Register %d is not available"), regnum);
+  return value;
+}
index c47060374a3e827316b7ae1af736512b0e121bd7..97c186c5596395cddb3382a020267ce0ddc1d94c 100644 (file)
 
 /* This header is a stopgap until we have an independent regcache.  */
 
+enum register_status
+  {
+    /* The register value is not in the cache, and we don't know yet
+       whether it's available in the target (or traceframe).  */
+    REG_UNKNOWN = 0,
+
+    /* The register value is valid and cached.  */
+    REG_VALID = 1,
+
+    /* The register value is unavailable.  E.g., we're inspecting a
+       traceframe, and this register wasn't collected.  Note that this
+       is different a different "unavailable" from saying the register
+       does not exist in the target's architecture --- in that case,
+       the target should have given us a target description that does
+       not include the register in the first place.  */
+    REG_UNAVAILABLE = -1
+  };
+
 /* Return a pointer to the register cache associated with the
    thread specified by PTID.  This function must be provided by
    the client.  */
@@ -38,4 +56,10 @@ extern int regcache_register_size (const struct regcache *regcache, int n);
 
 extern CORE_ADDR regcache_read_pc (struct regcache *regcache);
 
+/* Read a raw register into a unsigned integer.  */
+extern enum register_status regcache_raw_read_unsigned
+  (struct regcache *regcache, int regnum, ULONGEST *val);
+
+ULONGEST regcache_raw_get_unsigned (struct regcache *regcache, int regnum);
+
 #endif /* COMMON_REGCACHE_H */
index eebc12e251fbe857685da124bc0c5385a36f9b11..eab693038b3d8ad1a2646d873da96a6e97d9a527 100644 (file)
@@ -1,3 +1,14 @@
+2015-12-18  Antoine Tremblay  <antoine.tremblay@ericsson.com>
+
+       * Makefile.in (SFILES): Append common/common-regcache.c.
+       (OBS): Append common-regcache.o.
+       (common-regcache.o): New rule.
+       * regcache.c (init_register_cache): Initialize cache to
+       REG_UNAVAILABLE.
+       (regcache_raw_read_unsigned): New function.
+       * regcache.h (REG_UNAVAILABLE, REG_VALID): Replaced by shared
+       register_status enum.
+
 2015-12-18  Antoine Tremblay  <antoine.tremblay@ericsson.com>
 
        * linux-aarch64-low.c (the_low_targets): Rename
index f18243baef7b2ad0936f5db3aa6cbcd83241add5..82af44c81868b06bad2e0e84aab5d66504c8e5c4 100644 (file)
@@ -181,7 +181,7 @@ SFILES=     $(srcdir)/gdbreplay.c $(srcdir)/inferiors.c $(srcdir)/dll.c \
        $(srcdir)/common/common-exceptions.c $(srcdir)/symbol.c \
        $(srcdir)/common/btrace-common.c \
        $(srcdir)/common/fileio.c $(srcdir)/nat/linux-namespaces.c \
-       $(srcdir)/arch/arm.c
+       $(srcdir)/arch/arm.c $(srcdir)/common/common-regcache.c
 
 DEPFILES = @GDBSERVER_DEPFILES@
 
@@ -195,7 +195,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 btrace-common.o fileio.o \
+      common-exceptions.o symbol.o btrace-common.o fileio.o common-regcache.o \
       $(XML_BUILTIN) $(DEPFILES) $(LIBOBJS)
 GDBREPLAY_OBS = gdbreplay.o version.o
 GDBSERVER_LIBS = @GDBSERVER_LIBS@
@@ -583,6 +583,9 @@ waitstatus.o: ../target/waitstatus.c
 fileio.o: ../common/fileio.c
        $(COMPILE) $<
        $(POSTCOMPILE)
+common-regcache.o: ../common/common-regcache.c
+       $(COMPILE) $<
+       $(POSTCOMPILE)
 
 # Arch object files rules form ../arch
 
index b9311fe4f27ffc5ec7810edd6843fe0a7f18a543..c608bf35783b24cda24d3da276fbf9ee4530c93c 100644 (file)
@@ -145,8 +145,9 @@ init_register_cache (struct regcache *regcache,
        = (unsigned char *) xcalloc (1, tdesc->registers_size);
       regcache->registers_owned = 1;
       regcache->register_status
-       = (unsigned char *) xcalloc (1, tdesc->num_registers);
-      gdb_assert (REG_UNAVAILABLE == 0);
+       = (unsigned char *) xmalloc (tdesc->num_registers);
+      memset ((void *) regcache->register_status, REG_UNAVAILABLE,
+             tdesc->num_registers);
 #else
       gdb_assert_not_reached ("can't allocate memory from the heap");
 #endif
@@ -435,6 +436,27 @@ collect_register (struct regcache *regcache, int n, void *buf)
          register_size (regcache->tdesc, n));
 }
 
+enum register_status
+regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
+                           ULONGEST *val)
+{
+  int size;
+
+  gdb_assert (regcache != NULL);
+  gdb_assert (regnum >= 0 && regnum < regcache->tdesc->num_registers);
+
+  size = register_size (regcache->tdesc, regnum);
+
+  if (size > (int) sizeof (ULONGEST))
+    error (_("That operation is not available on integers of more than"
+            "%d bytes."),
+          (int) sizeof (ULONGEST));
+
+  collect_register (regcache, regnum, val);
+
+  return REG_VALID;
+}
+
 #ifndef IN_PROCESS_AGENT
 
 void
index a0be95eb8bdce9fff3b3751bd9acc66ac8b404ac..f4b798bbfd3b4c25240cee77bc8a3b50dc8c6657 100644 (file)
 struct thread_info;
 struct target_desc;
 
-/* The register exists, it has a value, but we don't know what it is.
-   Used when inspecting traceframes.  */
-#define REG_UNAVAILABLE 0
-
-/* We know the register's value (and we have it cached).  */
-#define REG_VALID 1
-
 /* The data for the register cache.  Note that we have one per
    inferior; this is primarily for simplicity, as the performance
    benefit is minimal.  */
index 7fb9d181e79b38615142a11b8c850203b36a0ecb..5ee31fb20df6adcaa67a1ff3bc0c4e6e052087aa 100644 (file)
@@ -715,21 +715,6 @@ regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
   return status;
 }
 
-/* Return the register's value or throw if it's not available.  */
-
-ULONGEST
-regcache_raw_get_unsigned (struct regcache *regcache, int regnum)
-{
-  ULONGEST value;
-  enum register_status status;
-
-  status = regcache_raw_read_unsigned (regcache, regnum, &value);
-  if (status == REG_UNAVAILABLE)
-    throw_error (NOT_AVAILABLE_ERROR,
-                _("Register %d is not available"), regnum);
-  return value;
-}
-
 void
 regcache_raw_write_signed (struct regcache *regcache, int regnum, LONGEST val)
 {
index c9d9a7df0f4cd94727dbba5820181f64ac250a8a..36bfef88ea3762125e909db9c6f6e2f8ceac954e 100644 (file)
@@ -47,24 +47,6 @@ extern struct gdbarch *get_regcache_arch (const struct regcache *regcache);
 
 extern struct address_space *get_regcache_aspace (const struct regcache *);
 
-enum register_status
-  {
-    /* The register value is not in the cache, and we don't know yet
-       whether it's available in the target (or traceframe).  */
-    REG_UNKNOWN = 0,
-
-    /* The register value is valid and cached.  */
-    REG_VALID = 1,
-
-    /* The register value is unavailable.  E.g., we're inspecting a
-       traceframe, and this register wasn't collected.  Note that this
-       is different a different "unavailable" from saying the register
-       does not exist in the target's architecture --- in that case,
-       the target should have given us a target description that does
-       not include the register in the first place.  */
-    REG_UNAVAILABLE = -1
-  };
-
 enum register_status regcache_register_status (const struct regcache *regcache,
                                               int regnum);
 
@@ -78,12 +60,6 @@ void regcache_raw_write (struct regcache *regcache, int rawnum,
 extern enum register_status
   regcache_raw_read_signed (struct regcache *regcache,
                            int regnum, LONGEST *val);
-extern enum register_status
-  regcache_raw_read_unsigned (struct regcache *regcache,
-                             int regnum, ULONGEST *val);
-
-ULONGEST regcache_raw_get_unsigned (struct regcache *regcache,
-                                   int regnum);
 
 extern void regcache_raw_write_signed (struct regcache *regcache,
                                       int regnum, LONGEST val);