From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20692 invoked by alias); 28 Aug 2003 22:02:39 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 20659 invoked from network); 28 Aug 2003 22:02:32 -0000 Received: from unknown (HELO walton.kettenis.dyndns.org) (213.93.115.144) by sources.redhat.com with SMTP; 28 Aug 2003 22:02:32 -0000 Received: from elgar.kettenis.dyndns.org (elgar.kettenis.dyndns.org [192.168.0.2]) by walton.kettenis.dyndns.org (8.12.6p2/8.12.5) with ESMTP id h7SM2QFd005229 for ; Fri, 29 Aug 2003 00:02:26 +0200 (CEST) (envelope-from kettenis@elgar.kettenis.dyndns.org) Received: from elgar.kettenis.dyndns.org (localhost [127.0.0.1]) by elgar.kettenis.dyndns.org (8.12.6p2/8.12.6) with ESMTP id h7SM2QSr032447 for ; Fri, 29 Aug 2003 00:02:26 +0200 (CEST) (envelope-from kettenis@elgar.kettenis.dyndns.org) Received: (from kettenis@localhost) by elgar.kettenis.dyndns.org (8.12.6p2/8.12.6/Submit) id h7SM2Q2k032444; Fri, 29 Aug 2003 00:02:26 +0200 (CEST) Date: Thu, 28 Aug 2003 22:02:00 -0000 Message-Id: <200308282202.h7SM2Q2k032444@elgar.kettenis.dyndns.org> From: Mark Kettenis To: gdb-patches@sources.redhat.com Subject: [PATCH/RFC/RFA] Add regcache_raw_{supply,collect} X-SW-Source: 2003-08/txt/msg00519.txt.bz2 With this path I propose the addition of two new regcache interfaces to replace supply_register() and regcache_collect(). My work on debugging 32-bit code on AMD64 and unifying ELF core file support will be touching several places where we transfer registers to and from the register cache. The current functions aren't named very consistently. Moreover, somewhere in the future we want to get rid of the single register cache, so we should be able to specify a register cache. That's why I think we need the following functions: /* Supply register REGNUM, whose contents are stored in BUF, to REGCACHE. */ void regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf); /* Collect register REGNUM from REGCACHE and store its contents in BUF. */ void regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf); For now, these will only be called with CURRENT_REGCACHE as their first argument, but if we start to use these functions now it will be easier to start using multiple register caches in the future. Opinions? Mark Index: ChangeLog from Mark Kettenis * regcache.c (register_buffer): Consitify first argument. (regcache_raw_supply, regcache_raw_collect): New functions. Index: regcache.c =================================================================== RCS file: /cvs/src/src/gdb/regcache.c,v retrieving revision 1.94 diff -u -p -r1.94 regcache.c --- regcache.c 4 Aug 2003 22:24:44 -0000 1.94 +++ regcache.c 28 Aug 2003 22:01:55 -0000 @@ -345,7 +345,7 @@ make_cleanup_regcache_xfree (struct regc /* Return a pointer to register REGNUM's buffer cache. */ static char * -register_buffer (struct regcache *regcache, int regnum) +register_buffer (const struct regcache *regcache, int regnum) { return regcache->registers + regcache->descr->register_offset[regnum]; } @@ -1201,6 +1201,10 @@ write_register_pid (int regnum, CORE_ADD inferior_ptid = save_ptid; } +/* FIXME: kettenis/20030828: We should get rid of supply_register and + regcache_collect in favour of regcache_raw_supply and + regcache_raw_collect. */ + /* SUPPLY_REGISTER() Record that register REGNUM contains VAL. This is used when the @@ -1250,6 +1254,55 @@ regcache_collect (int regnum, void *buf) { memcpy (buf, register_buffer (current_regcache, regnum), REGISTER_RAW_SIZE (regnum)); +} + +/* Supply register REGNUM, whose contents are store in BUF, to REGCACHE. */ + +void +regcache_raw_supply (struct regcache *regcache, int regnum, const void *buf) +{ + void *regbuf; + size_t size; + + gdb_assert (regcache != NULL && buf != NULL); + gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); + gdb_assert (!regcache->readonly_p); + + /* FIXME: kettenis/20030828: It shouldn't be necessary to handle + CURRENT_REGCACHE specially here. */ + if (regcache == current_regcache + && !ptid_equal (registers_ptid, inferior_ptid)) + { + registers_changed (); + registers_ptid = inferior_ptid; + } + + regbuf = register_buffer (regcache, regnum); + size = regcache->descr->sizeof_register[regnum]; + + if (buf) + memcpy (regbuf, buf, size); + else + memset (regbuf, 0, size); + + /* Mark the register as cached. */ + regcache->register_valid_p[regnum] = 1; +} + +/* Collect register REGNUM from REGCACHE and store its contents in BUF. */ + +void +regcache_raw_collect (const struct regcache *regcache, int regnum, void *buf) +{ + const void *regbuf; + size_t size; + + gdb_assert (regcache != NULL && buf != NULL); + gdb_assert (regnum >= 0 && regnum < regcache->descr->nr_raw_registers); + + regbuf = register_buffer (regcache, regnum); + size = regcache->descr->sizeof_register[regnum]; + memcpy (buf, regbuf, size); } Index: regcache.h =================================================================== RCS file: /cvs/src/src/gdb/regcache.h,v retrieving revision 1.35 diff -u -p -r1.35 regcache.h --- regcache.h 15 May 2003 18:01:50 -0000 1.35 +++ regcache.h 28 Aug 2003 22:01:56 -0000 @@ -94,6 +94,10 @@ void regcache_cooked_write_part (struct extern void supply_register (int regnum, const void *val); extern void regcache_collect (int regnum, void *buf); +extern void regcache_raw_supply (struct regcache *regcache, + int regnum, const void *buf); +extern void regcache_raw_collect (const struct regcache *regcache, + int regnum, void *buf); /* The register's ``offset''.