Share regcache function regcache_raw_read_unsigned

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.
This commit is contained in:
Antoine Tremblay 2015-12-18 11:33:59 -05:00
parent d0e59a6888
commit 68ce205943
10 changed files with 119 additions and 51 deletions

View 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.

View 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
#

View File

@ -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;
}

View File

@ -22,6 +22,24 @@
/* 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 */

View 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

View 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

View 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

View File

@ -24,13 +24,6 @@
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. */

View 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)
{

View 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);