From cbd02f9fa521a6cb21c04b15ee7671c8bb4be55b Mon Sep 17 00:00:00 2001 From: Thiago Jung Bauermann Date: Tue, 16 Aug 2022 17:18:47 +0000 Subject: [PATCH] gdbserver: Add assert in find_register_by_number 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 Approved-By: Simon Marchi --- gdbserver/regcache.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc index 3aeefcc79a3..0b1141662ac 100644 --- a/gdbserver/regcache.cc +++ b/gdbserver/regcache.cc @@ -199,6 +199,9 @@ 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); + gdb_assert (n < tdesc->reg_defs.size ()); + return tdesc->reg_defs[n]; } @@ -440,8 +443,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); -- 2.30.2