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 74F09385B536 for ; Mon, 28 Nov 2022 14:53:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 74F09385B536 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 DC4BB1E0CB; Mon, 28 Nov 2022 09:53:09 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1669647190; bh=fgy9tbuvkRTBx6qBzV483vwWJz+bQaPXO4Qzy5f3y8M=; h=Date:Subject:From:To:Cc:References:In-Reply-To:From; b=pXTVaey10BQWQ+n5naw31tMgEKp+Hx9PWSQc6OM9VhIxIcbzjSlwZthI6agj9ln3n cqDlZE5xDJWf6p5rWrwowQPcQ9T37mUdNnhE7lp0GmjL1czdPlu53yGXu5l6YdaIXw 6lOQRDEguYjgjUSa22ALYAyPasVQsowf4iaGlr3o= Message-ID: <0250c717-43a4-304b-5926-5b85c225c352@simark.ca> Date: Mon, 28 Nov 2022 09:53:09 -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 From: Simon Marchi 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> In-Reply-To: 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/28/22 09:48, Simon Marchi wrote: > > > 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 Actually, I would perhaps suggest moving the assertion checks to find_register_by_number, the place that actually accesses reg_defs. And we could perhaps remove the equivalent gdb_assert in regcache_raw_read_unsigned, since it's checking the same a few frames above. Simon