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 37D4C3858D33 for ; Wed, 1 Feb 2023 15:43:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 37D4C3858D33 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) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPSA id CDE841E110; Wed, 1 Feb 2023 10:43:40 -0500 (EST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=simark.ca; s=mail; t=1675266220; bh=djWOujAebu+FD6bOeAq2z8R2AupccGem3xzvJLTzmlw=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=Z+Sryq/DgOpGpM3LUzlOSLPuYnuQFPsKfkVV3DwAnpVySVGJoUVD4/k6b7gQC+5E7 Hb/lkKmlrwkPzpOO5aDtuAGFqPkXakHHZU8w8Xb1iYosZDzb+M7CYP7OBcGskXTRN0 Uxy8Binu1DIlLco88Edo1VXE8zpnoa4378y8h8dA= 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 From: Simon Marchi In-Reply-To: <87y1pilc0t.fsf@linaro.org> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,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 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