Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Cagney <ac131313@ges.redhat.com>
To: Mark Kettenis <kettenis@chello.nl>, gdb-patches@sources.redhat.com
Subject: [PATCH] regcache raw read/write partial; Was: [PATCH] Remove some write_register_bytes occurences from i386-tdep.c
Date: Sun, 18 Aug 2002 13:35:00 -0000	[thread overview]
Message-ID: <3D60050F.3020508@ges.redhat.com> (raw)
In-Reply-To: <200208182019.g7IKJGLp000325@elgar.kettenis.dyndns.org>

[-- Attachment #1: Type: text/plain, Size: 762 bytes --]

>    Date: Sun, 18 Aug 2002 16:08:06 -0400
>    From: Andrew Cagney <ac131313@ges.redhat.com>
> 
>    > As for write_register_bytes() can it be avoided?  I've just posted ``regcache_cooked_write_with_offset_hack().  But I don't think that hack is right here.  Perhaphs a single register read - modify - write function is needed?
> 
>    Hmm,
> 
>    I just hit a need for the same operation while implementing some pseudo 
>    registers.  Just adding:
> 
>    regcache_raw_read_part(regcache,regnum,offset,length,buf)
>    regcache_raw_write_part(regcache,regnum,offset,length,buf)
> 
> Where OFFSET would be the byte offset into the register I suppose.
> 
> Seems like a good idea to me.

Yes, something like the attached.

I'll commit in a few hours,
Andrew


[-- Attachment #2: diffs --]
[-- Type: text/plain, Size: 2813 bytes --]

2002-08-18  Andrew Cagney  <ac131313@redhat.com>

	* regcache.c (regcache_raw_xfer_part): New function.

	* regcache.h (regcache_raw_read_part): Declare.
	(regcache_raw_write_part): Declare.
	

Index: regcache.c
===================================================================
RCS file: /cvs/src/src/gdb/regcache.c,v
retrieving revision 1.53
diff -u -r1.53 regcache.c
--- regcache.c	13 Aug 2002 23:06:40 -0000	1.53
+++ regcache.c	18 Aug 2002 20:27:18 -0000
@@ -916,6 +916,46 @@
     }
 }
 
+/* Perform a partial register transfer using a read, modify, write
+   operation.  */
+
+void
+regcache_raw_xfer_part (struct regcache *regcache, int regnum,
+			int offset, int len, void *in, const void *out)
+{
+  struct regcache_descr *descr = regcache->descr;
+  bfd_byte *reg = alloca (descr->max_register_size);
+  gdb_assert (regnum >= 0 && regnum < descr->nr_raw_registers);
+  gdb_assert (offset >= 0 && offset < descr->sizeof_register[regnum]);
+  gdb_assert (len >= 0 && len + offset < descr->sizeof_register[regnum]);
+  /* Read (when needed) ... */
+  if (in != NULL
+      || offset > 0
+      || offset + len < descr->sizeof_register[regnum])
+    regcache_raw_read (regcache, regnum, reg);
+  /* ... modify ... */
+  if (in != NULL)
+    memcpy (in, reg + offset, len);
+  if (out != NULL)
+    memcpy (reg + offset, out, len);
+  /* ... write (when needed).  */
+  if (out != NULL)
+    regcache_raw_write (regcache, regnum, reg);
+}
+
+void
+regcache_raw_read_part (struct regcache *regcache, int regnum,
+			int offset, int len, void *buf)
+{
+  regcache_raw_xfer_part (regcache, regnum, offset, len, buf, NULL);
+}
+
+void
+regcache_raw_write_part (struct regcache *regcache, int regnum,
+			 int offset, int len, const void *buf)
+{
+  regcache_raw_xfer_part (regcache, regnum, offset, len, NULL, buf);
+}
 
 /* Return the contents of register REGNUM as an unsigned integer.  */
 
Index: regcache.h
===================================================================
RCS file: /cvs/src/src/gdb/regcache.h,v
retrieving revision 1.14
diff -u -r1.14 regcache.h
--- regcache.h	13 Aug 2002 14:32:28 -0000	1.14
+++ regcache.h	18 Aug 2002 20:27:18 -0000
@@ -44,6 +44,13 @@
 					int regnum, ULONGEST *val);
 int regcache_valid_p (struct regcache *regcache, int regnum);
 
+/* Raw partial transfers.  These perform read, modify, write style
+   operations.  */
+void regcache_raw_read_part (struct regcache *regcache, int regnum,
+			     int offset, int len, void *buf);
+void regcache_raw_write_part (struct regcache *regcache, int regnum,
+			      int offset, int len, const void *buf);
+
 /* Transfer a cooked register [0..NUM_REGS+NUM_PSEUDO_REGS).  */
 void regcache_cooked_read (struct regcache *regcache, int rawnum, void *buf);
 void regcache_cooked_write (struct regcache *regcache, int rawnum,

  reply	other threads:[~2002-08-18 20:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-08-18 10:18 Mark Kettenis
2002-08-18 10:46 ` Andrew Cagney
2002-08-18 13:08   ` Andrew Cagney
2002-08-18 13:19     ` Mark Kettenis
2002-08-18 13:35       ` Andrew Cagney [this message]
2002-08-18 17:38         ` [PATCH] regcache raw read/write partial; Was: " Andrew Cagney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3D60050F.3020508@ges.redhat.com \
    --to=ac131313@ges.redhat.com \
    --cc=gdb-patches@sources.redhat.com \
    --cc=kettenis@chello.nl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox