[PATCH v3 1/8] gdbserver: Add assert in find_register_by_number

Thiago Jung Bauermann via Gdb-patches
2023-01-30T04:46:06Z

It helped me during development, catching bugs closer to when they actually
happened.

Also remove the equivalent gdb_assert in regcache_raw_read_unsigned, since
it's checking the same condition a few frames above.

Suggested-By: Simon Marchi <simon.marchi@efficios.com>
---
gdbserver/regcache.cc | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc
index 3aeefcc79a37..7b896a19767d 100644
--- a/gdbserver/regcache.cc
+++ b/gdbserver/regcache.cc
@@ -199,6 +199,8 @@ regcache_cpy (struct regcache *dst, struct regcache *src)
static const struct gdb::reg &
find_register_by_number (const struct target_desc *tdesc, int n)
{
+ gdb_assert (n >= 0 && n < tdesc->reg_defs.size ());
+
return tdesc->reg_defs[n];
}

@@ -440,8 +442,6 @@ regcache_raw_read_unsigned (struct regcache *regcache, int regnum,
int size;

gdb_assert (regcache != NULL);
- gdb_assert (regnum >= 0
- && regnum < regcache->tdesc->reg_defs.size ());

size = register_size (regcache->tdesc, regnum);