public inbox for gdb-cvs@sourceware.org
help / color / mirror / Atom feed
From: Thiago Bauermann <bauermann@sourceware.org>
To: gdb-cvs@sourceware.org
Subject: [binutils-gdb] gdbserver: Add assert in find_register_by_number
Date: Wed,  1 Feb 2023 21:33:02 +0000 (GMT)	[thread overview]
Message-ID: <20230201213302.708A43858D37@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=cbd02f9fa521a6cb21c04b15ee7671c8bb4be55b

commit cbd02f9fa521a6cb21c04b15ee7671c8bb4be55b
Author: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
Date:   Tue Aug 16 17:18:47 2022 +0000

    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 <simon.marchi@efficios.com>
    Approved-By: Simon Marchi <simon.marchi@efficios.com>

Diff:
---
 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);

                 reply	other threads:[~2023-02-01 21:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230201213302.708A43858D37@sourceware.org \
    --to=bauermann@sourceware.org \
    --cc=gdb-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).