From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id C8498385B536 for ; Mon, 28 Nov 2022 14:48:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C8498385B536 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=simark.ca Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=simark.ca Received: from [10.0.0.11] (unknown [217.28.27.60]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id 285AB1E0CB; Mon, 28 Nov 2022 09:48:03 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1669646884; bh=4h7bnnQtLSAaNEzefG9Ab6jMeoYxF/hJttntyQwRkR4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=py0HNsntbrR+3CFthO68Q4rckIuB026a6PBlmyQS3PR65OB+K11Uj6Ays7iUbkrA9 T289ieEVtLOUPbQLPk9sjSKFLKaqs9RDMwTwGW/n66SUUHIdt+ZoTql05l0yA7p78L lXBjabzbJNTF/f+Kt/KLenNhdfJN/qrz5CIZNin8= Message-ID: Date: Mon, 28 Nov 2022 09:48:03 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.2 Subject: Re: [PATCH v2 1/6] gdbserver: Add asserts in register_size and register_data functions Content-Language: en-US To: Thiago Jung Bauermann , gdb-patches@sourceware.org Cc: Luis Machado References: <20221126020452.1686509-1-thiago.bauermann@linaro.org> <20221126020452.1686509-2-thiago.bauermann@linaro.org> From: Simon Marchi In-Reply-To: <20221126020452.1686509-2-thiago.bauermann@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,SPF_HELO_PASS,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 11/25/22 21:04, Thiago Jung Bauermann via Gdb-patches wrote: > These helped me during development, catching bugs closer to when they > actually happened. > --- > gdbserver/regcache.cc | 4 ++++ > 1 file changed, 4 insertions(+) > > diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc > index 5cbcea978a05..14236069f712 100644 > --- a/gdbserver/regcache.cc > +++ b/gdbserver/regcache.cc > @@ -286,6 +286,8 @@ register_cache_size (const struct target_desc *tdesc) > int > register_size (const struct target_desc *tdesc, int n) > { > + gdb_assert (n >= 0 && n < tdesc->reg_defs.size ()); > + > return find_register_by_number (tdesc, n).size / 8; > } > > @@ -300,6 +302,8 @@ regcache_register_size (const struct regcache *regcache, int n) > static unsigned char * > register_data (const struct regcache *regcache, int n) > { > + gdb_assert(n >= 0 && n < regcache->tdesc->reg_defs.size()); Missing space before parenthesis. I don't know if that would have helped you, but given that find_register_by_number is implemented as an std::vector lookup, it would probably have been caught if building with -D_GLIBCXX_DEBUG. I recommend using that for development, it's really handy. https://gcc.gnu.org/onlinedocs/libstdc++/manual/debug_mode_using.html Approved-By: Simon Marchi Simon