From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id THwGAcOI2mOuRScAWB0awg (envelope-from ) for ; Wed, 01 Feb 2023 10:44:03 -0500 Received: by simark.ca (Postfix, from userid 112) id EEA591E128; Wed, 1 Feb 2023 10:44:02 -0500 (EST) Authentication-Results: simark.ca; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.a=rsa-sha256 header.s=default header.b=u+XKUl3m; dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,NICE_REPLY_A, RCVD_IN_DNSWL_MED,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 941341E110 for ; Wed, 1 Feb 2023 10:44:02 -0500 (EST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 19EA93858C5F for ; Wed, 1 Feb 2023 15:44:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 19EA93858C5F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675266241; bh=Ej6/+ILqgh9dL2ROYtwtzbxEgLsukpG0wJr1j65c85Q=; h=Date:Subject:To:Cc:References:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=u+XKUl3mepOZ0QnqoXV5YllLz7O8nCVHi9vnqoP/m7ZjGr7OhZV+1xFjsnMNTiXKE HhlGK7v0Bf2+Jkxj+mmgZUj42h1FgDPT2hJ8zEARIZNc3ADHE19xxAGiTBbNCgP6lJ 12f+dqBcUXFrQuNbvvBY3BVck3q6jw6AvgOc/llQ= Received: from simark.ca (simark.ca [158.69.221.121]) by sourceware.org (Postfix) with ESMTPS id 37D4C3858D33 for ; Wed, 1 Feb 2023 15:43:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37D4C3858D33 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) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id CDE841E110; Wed, 1 Feb 2023 10:43:40 -0500 (EST) Message-ID: Date: Wed, 1 Feb 2023 10:43:40 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 Subject: Re: [PATCH v3 1/8] gdbserver: Add assert in find_register_by_number To: Thiago Jung Bauermann , Simon Marchi Cc: gdb-patches@sourceware.org References: <20230130044518.3322695-1-thiago.bauermann@linaro.org> <20230130044518.3322695-2-thiago.bauermann@linaro.org> <87y1pilc0t.fsf@linaro.org> Content-Language: en-US In-Reply-To: <87y1pilc0t.fsf@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Simon Marchi via Gdb-patches Reply-To: Simon Marchi Errors-To: gdb-patches-bounces+public-inbox=simark.ca@sourceware.org Sender: "Gdb-patches" On 1/31/23 14:49, Thiago Jung Bauermann via Gdb-patches wrote: > > Hello Simon, > > Simon Marchi writes: > >> On 1/29/23 23:45, Thiago Jung Bauermann wrote: >>> 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 >>> --- >>> 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 ()); >> >> Since you're moving this assertion, I would suggest breaking it up in >> two. I general, I suggest avoiding multiple checks in a single >> gdb_assert. It makes it a little less obvious from the crash report >> which condition failed exactly. So: >> >> gdb_assert (n >= 0); >> gdb_assert (n < tdesc->reg_defs.size ()); > > Good point. I made this change. > >> The patch is fine to push right away in any case, it's good >> independently from the rest of the series: > > Indeed. I will do that. Is it OK if I push patch 2 as well? You approved > it in v2, and the only changes in v3 are to implement your review > comments. Probably, I will take a look (Andrew has left a comment already though). Simon