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

Message ID 20231108051222.1275306-5-simon.marchi@polymtl.ca
State New
Headers
Series Fix reading and writing pseudo registers in non-current frames |

Commit Message

Simon Marchi Nov. 8, 2023, 5 a.m. UTC
  From: Simon Marchi <simon.marchi@efficios.com>

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
---
 gdb/regcache.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)
  

Patch

diff --git a/gdb/regcache.c b/gdb/regcache.c
index 11a6ecc3469e..ae5411ba5563 100644
--- a/gdb/regcache.c
+++ b/gdb/regcache.c
@@ -891,16 +891,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);
@@ -928,16 +928,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);
@@ -958,16 +958,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);
@@ -997,16 +997,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);