diff mbox

Remove MAX_REGISTER_SIZE from regcache.c

Message ID B40E247A-422D-426A-8E17-74811D0DFFD7@arm.com
State New
Headers show

Commit Message

Alan Hayward April 26, 2017, 2:03 p.m. UTC
> On 21 Apr 2017, at 15:01, Yao Qi <qiyaoltc@gmail.com> wrote:

> 

> On Mon, Apr 10, 2017 at 9:59 AM, Yao Qi <qiyaoltc@gmail.com> wrote:

>> 

>> This patches removes the 2nd argument of regcache_restore, because it

>> is only called by regcache_cpy.  In regcache_cpy, if regcache_restore

>> is called, dst is not readonly, but src is readonly.  So this patch

>> adds an assert that src is readonly in regcache_restore.

>> regcache_cook_read read everything from a readonly regcache cache

>> (src)'s register_buffer, and register status is from src->register_status.

>> 

>> gdb:

>> 

>> 2017-04-07  Yao Qi  <yao.qi@linaro.org>

>> 

>>        * regcache.c (regcache_restore): Remove argument 2.  Replace

>>        argument 3 with regcache.  Get register status from

>>        src->register_status and get register contents from

>>        register_buffer (src, regnum).

>>        (regcache_cpy): Update.

>> 

> 

> Tested it again on x86_64-linux.  Pushed it in.

> 

> -- 

> Yao (齐尧)


Ok, this leaves the following in regcache.c.

Tested on a --enable-targets=all using make check with board files
unix and native-gdbserver.

Ok to commit?

Alan.

2017-04-26  Alan Hayward  <alan.hayward@arm.com>

	* regcache.c (regcache_save): Avoid buffer use.
	(regcache_dump): Avoid buffer use.

Comments

Yao Qi April 27, 2017, 9:43 a.m. UTC | #1
Alan Hayward <Alan.Hayward@arm.com> writes:

> Ok to commit?
>
> Alan.
>
> 2017-04-26  Alan Hayward  <alan.hayward@arm.com>
>
> 	* regcache.c (regcache_save): Avoid buffer use.
> 	(regcache_dump): Avoid buffer use.

Hi Alan,
Patch is good to me, but it has conflict with my patches

  [PATCH 0/6] Class-fy regcache in GDB
  https://sourceware.org/ml/gdb-patches/2017-04/msg00684.html

Can you postpone pushing this patch until my patches are committed?  You
then need to rebase your patch.  I've rebased my patch sets twice before
I posted them.  Considering the size of your patch, it takes less
effort to rebase yours.
Alan Hayward April 27, 2017, 9:52 a.m. UTC | #2
> On 27 Apr 2017, at 10:43, Yao Qi <qiyaoltc@gmail.com> wrote:

> 

> Alan Hayward <Alan.Hayward@arm.com> writes:

> 

>> Ok to commit?

>> 

>> Alan.

>> 

>> 2017-04-26  Alan Hayward  <alan.hayward@arm.com>

>> 

>> 	* regcache.c (regcache_save): Avoid buffer use.

>> 	(regcache_dump): Avoid buffer use.

> 

> Hi Alan,

> Patch is good to me, but it has conflict with my patches

> 

>  [PATCH 0/6] Class-fy regcache in GDB

>  https://sourceware.org/ml/gdb-patches/2017-04/msg00684.html

> 

> Can you postpone pushing this patch until my patches are committed?  You

> then need to rebase your patch.  I've rebased my patch sets twice before

> I posted them.  Considering the size of your patch, it takes less

> effort to rebase yours.

> 


That’s fine. My rebase should be easy enough.
If you remember, could you let me know when you have pushed your patch.


Alan.
Yao Qi May 3, 2017, 8:21 a.m. UTC | #3
Alan Hayward <Alan.Hayward@arm.com> writes:

> That’s fine. My rebase should be easy enough.
> If you remember, could you let me know when you have pushed your patch.

Hi Alan,
My patch set is pushed in.  You can rebase your patch.
diff mbox

Patch

diff --git a/gdb/regcache.c b/gdb/regcache.c
index f9bf992197b8e7bdc3cfc6fc3bafbcf928c49df9..6c1c8b9ee373d8998f771d756542f59e2adde8ff 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -337,7 +337,6 @@  regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
 	       void *src)
 {
   struct gdbarch *gdbarch = dst->descr->gdbarch;
-  gdb_byte buf[MAX_REGISTER_SIZE];
   int regnum;

   /* The DST should be `read-only', if it wasn't then the save would
@@ -356,17 +355,13 @@  regcache_save (struct regcache *dst, regcache_cooked_read_ftype *cooked_read,
     {
       if (gdbarch_register_reggroup_p (gdbarch, regnum, save_reggroup))
 	{
-	  enum register_status status = cooked_read (src, regnum, buf);
+	  gdb_byte *dst_buf = register_buffer (dst, regnum);
+	  enum register_status status = cooked_read (src, regnum, dst_buf);

-	  if (status == REG_VALID)
-	    memcpy (register_buffer (dst, regnum), buf,
-		    register_size (gdbarch, regnum));
-	  else
+	  if (status != REG_VALID)
 	    {
 	      gdb_assert (status != REG_UNKNOWN);
-
-	      memset (register_buffer (dst, regnum), 0,
-		      register_size (gdbarch, regnum));
+	      memset (dst_buf, 0, register_size (gdbarch, regnum));
 	    }
 	  dst->register_status[regnum] = status;
 	}
@@ -1334,7 +1329,6 @@  regcache_dump (struct regcache *regcache, struct ui_file *file,
   int footnote_register_offset = 0;
   int footnote_register_type_name_null = 0;
   long register_offset = 0;
-  gdb_byte buf[MAX_REGISTER_SIZE];

 #if 0
   fprintf_unfiltered (file, "nr_raw_registers %d\n",
@@ -1461,8 +1455,8 @@  regcache_dump (struct regcache *regcache, struct ui_file *file,
 	    fprintf_unfiltered (file, "<unavailable>");
 	  else
 	    {
-	      regcache_raw_read (regcache, regnum, buf);
-	      print_hex_chars (file, buf,
+	      regcache_raw_update (regcache, regnum);
+	      print_hex_chars (file, register_buffer (regcache, regnum),
 			       regcache->descr->sizeof_register[regnum],
 			       gdbarch_byte_order (gdbarch));
 	    }
@@ -1475,9 +1469,30 @@  regcache_dump (struct regcache *regcache, struct ui_file *file,
 	    fprintf_unfiltered (file, "Cooked value");
 	  else
 	    {
+	      const gdb_byte *buf = NULL;
 	      enum register_status status;
+	      struct value *value = NULL;
+
+	      if (regnum < regcache->descr->nr_raw_registers)
+		{
+		  regcache_raw_update (regcache, regnum);
+		  status = regcache_register_status (regcache, regnum);
+		  buf = register_buffer (regcache, regnum);
+		}
+	      else
+		{
+		  value = regcache_cooked_read_value (regcache, regnum);
+
+		  if (!value_optimized_out (value)
+		      && value_entirely_available (value))
+		    {
+		      status = REG_VALID;
+		      buf = value_contents_all (value);
+		    }
+		  else
+		    status = REG_UNAVAILABLE;
+		}

-	      status = regcache_cooked_read (regcache, regnum, buf);
 	      if (status == REG_UNKNOWN)
 		fprintf_unfiltered (file, "<invalid>");
 	      else if (status == REG_UNAVAILABLE)
@@ -1486,6 +1501,12 @@  regcache_dump (struct regcache *regcache, struct ui_file *file,
 		print_hex_chars (file, buf,
 				 regcache->descr->sizeof_register[regnum],
 				 gdbarch_byte_order (gdbarch));
+
+	      if (value != NULL)
+		{
+		  release_value (value);
+		  value_free (value);
+		}
 	    }
 	}