From patchwork Tue Dec 8 14:07:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antoine Tremblay X-Patchwork-Id: 9936 Received: (qmail 40655 invoked by alias); 8 Dec 2015 14:07:57 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 40581 invoked by uid 89); 8 Dec 2015 14:07:56 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 X-HELO: usplmg21.ericsson.net Received: from usplmg21.ericsson.net (HELO usplmg21.ericsson.net) (198.24.6.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 08 Dec 2015 14:07:40 +0000 Received: from EUSAAHC001.ericsson.se (Unknown_Domain [147.117.188.75]) by usplmg21.ericsson.net (Symantec Mail Security) with SMTP id 11.48.32102.E14E6665; Tue, 8 Dec 2015 15:07:26 +0100 (CET) Received: from elxa4wqvvz1.dyn.mo.ca.am.ericsson.se (147.117.188.8) by smtps-am.internal.ericsson.com (147.117.188.75) with Microsoft SMTP Server (TLS) id 14.3.248.2; Tue, 8 Dec 2015 09:07:30 -0500 From: Antoine Tremblay To: CC: Antoine Tremblay Subject: [PATCH v7 5/8] Share regcache function regcache_raw_read_unsigned. Date: Tue, 8 Dec 2015 09:07:18 -0500 Message-ID: <1449583641-18156-6-git-send-email-antoine.tremblay@ericsson.com> In-Reply-To: <1449583641-18156-1-git-send-email-antoine.tremblay@ericsson.com> References: <1449583641-18156-1-git-send-email-antoine.tremblay@ericsson.com> MIME-Version: 1.0 X-IsSubscribed: yes 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/Makefile.in | 8 +++++++- gdb/common/common-regcache.c | 36 ++++++++++++++++++++++++++++++++++++ gdb/common/common-regcache.h | 24 ++++++++++++++++++++++++ gdb/gdbserver/Makefile.in | 7 +++++-- gdb/gdbserver/regcache.c | 26 ++++++++++++++++++++++++-- gdb/gdbserver/regcache.h | 7 ------- gdb/regcache.c | 15 --------------- gdb/regcache.h | 24 ------------------------ 8 files changed, 96 insertions(+), 51 deletions(-) create mode 100644 gdb/common/common-regcache.c diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 14ad405..0306770 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -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 index 0000000..9ee1102 --- /dev/null +++ b/gdb/common/common-regcache.c @@ -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 . */ + +#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; +} diff --git a/gdb/common/common-regcache.h b/gdb/common/common-regcache.h index c470603..97c186c 100644 --- a/gdb/common/common-regcache.h +++ b/gdb/common/common-regcache.h @@ -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 */ diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in index f18243b..82af44c 100644 --- a/gdb/gdbserver/Makefile.in +++ b/gdb/gdbserver/Makefile.in @@ -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 diff --git a/gdb/gdbserver/regcache.c b/gdb/gdbserver/regcache.c index b9311fe..c608bf3 100644 --- a/gdb/gdbserver/regcache.c +++ b/gdb/gdbserver/regcache.c @@ -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 diff --git a/gdb/gdbserver/regcache.h b/gdb/gdbserver/regcache.h index a0be95e..f4b798b 100644 --- a/gdb/gdbserver/regcache.h +++ b/gdb/gdbserver/regcache.h @@ -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. */ diff --git a/gdb/regcache.c b/gdb/regcache.c index 7fb9d18..5ee31fb 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -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) { diff --git a/gdb/regcache.h b/gdb/regcache.h index c9d9a7d..36bfef8 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -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);