[v2,04/24] gdb: simplify conditions in regcache::{read, write, raw_collect, raw_supply}_part

Message ID 20231124212656.96801-5-simon.marchi@efficios.com
State New
Headers
Series Fix reading and writing pseudo registers in non-current frames |

Commit Message

Simon Marchi Nov. 24, 2023, 9:26 p.m. UTC
  Make a few simplifications in these functions.

1. When checking if we need to do nothing, if the length is 0, we don't
   need to do anything, regardless of the value of offset.  Remove the
   offset check.

2. When check if transferring the whole register, if the length is equal
   to the register size, then we transfer the whole register, no need to
   check the offset.  Remove the offset check.

3. In the gdb_asserts, it is unnecessary to check for:

     offset <= reg_size

   given that right after we check for:

     len >= 0 && offset + len <= reg_size

   If `offset + len` is <= reg_size and len is >= 0, then necessarily
   offset is <= reg_size.  Remove the `offset <= reg_size` check.

Change-Id: I30a73acdc7bf432c45a07f5f177224d1cdc298e8
Reviewed-By: John Baldwin <jhb@FreeBSD.org>
---
 gdb/regcache.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
  

Patch

diff --git a/gdb/regcache.c b/gdb/regcache.c
index 7f1f07694d8a..abea211627c4 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -873,16 +873,16 @@  readable_regcache::read_part (int regnum, int offset, int len,
   int reg_size = register_size (arch (), regnum);
 
   gdb_assert (out != NULL);
-  gdb_assert (offset >= 0 && offset <= reg_size);
+  gdb_assert (offset >= 0);
   gdb_assert (len >= 0 && offset + len <= reg_size);
 
-  if (offset == 0 && len == 0)
+  if (len == 0)
     {
       /* Nothing to do.  */
       return REG_VALID;
     }
 
-  if (offset == 0 && len == reg_size)
+  if (len == reg_size)
     {
       /* Read the full register.  */
       return (is_raw) ? raw_read (regnum, out) : cooked_read (regnum, out);
@@ -910,16 +910,16 @@  reg_buffer::raw_collect_part (int regnum, int offset, int len,
   int reg_size = register_size (arch (), regnum);
 
   gdb_assert (out != nullptr);
-  gdb_assert (offset >= 0 && offset <= reg_size);
+  gdb_assert (offset >= 0);
   gdb_assert (len >= 0 && offset + len <= reg_size);
 
-  if (offset == 0 && len == 0)
+  if (len == 0)
     {
       /* Nothing to do.  */
       return;
     }
 
-  if (offset == 0 && len == reg_size)
+  if (len == reg_size)
     {
       /* Collect the full register.  */
       return raw_collect (regnum, out);
@@ -940,16 +940,16 @@  regcache::write_part (int regnum, int offset, int len,
   int reg_size = register_size (arch (), regnum);
 
   gdb_assert (in != NULL);
-  gdb_assert (offset >= 0 && offset <= reg_size);
+  gdb_assert (offset >= 0);
   gdb_assert (len >= 0 && offset + len <= reg_size);
 
-  if (offset == 0 && len == 0)
+  if (len == 0)
     {
       /* Nothing to do.  */
       return REG_VALID;
     }
 
-  if (offset == 0 && len == reg_size)
+  if (len == reg_size)
     {
       /* Write the full register.  */
       (is_raw) ? raw_write (regnum, in) : cooked_write (regnum, in);
@@ -979,16 +979,16 @@  reg_buffer::raw_supply_part (int regnum, int offset, int len,
   int reg_size = register_size (arch (), regnum);
 
   gdb_assert (in != nullptr);
-  gdb_assert (offset >= 0 && offset <= reg_size);
+  gdb_assert (offset >= 0);
   gdb_assert (len >= 0 && offset + len <= reg_size);
 
-  if (offset == 0 && len == 0)
+  if (len == 0)
     {
       /* Nothing to do.  */
       return;
     }
 
-  if (offset == 0 && len == reg_size)
+  if (len == reg_size)
     {
       /* Supply the full register.  */
       return raw_supply (regnum, in);