From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oi1-x236.google.com (mail-oi1-x236.google.com [IPv6:2607:f8b0:4864:20::236]) by sourceware.org (Postfix) with ESMTPS id 303ED3858D28 for ; Tue, 29 Nov 2022 02:43:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 303ED3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-oi1-x236.google.com with SMTP id h132so13786809oif.2 for ; Mon, 28 Nov 2022 18:43:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=tQXSlqH+/L/8Dvef1SFHQoAFPKZ8c+4M07haspwhGrg=; b=Uqhadf5cbcTWwWcuNWi7LulKtkHhYx6IosA00KRl2LCGC+xHGT12Eh20aU5Pms1lCf B7gPb9qjEBP0NxKpxIOEB/txpbhsUVfY0QxmT3/9BFeqiSymmqEK+8bqKnod3Azd/+dy kBXICY+q31AyFey4zSXLCmwqWRz3z0YJVQ2Ku5c9oaBN4E82XiJRHPF16FfFmsA/oT9H h9YzVZdl/cp8HfxeRuN1gmqcLdJIwdofSL8ShFhT7K5bNBk8Y9NmpQIvjwJJBT6jmsfj Lb57hypBDBIgn90MiJworxzq6uYt0JfgIMATSvOP5NnStyA8Ua4uuy9sHtCwPszwlBA4 jobg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=tQXSlqH+/L/8Dvef1SFHQoAFPKZ8c+4M07haspwhGrg=; b=hc6Rad/7tqzGjHXjMKcn4v+31AVwNeLRncJuBX1avR9nPUKBWwnzAFP32TWGJbnWvp izC6BgB3is+MlP9fTy6b6rdXbtlsGGNw+B1CUsP3vQ3czfVO72Nh65VJXScyzu+Bt4az WGFhfZtmu1dqi3u6c9rHTGiBmUiTeh+occGwRZvFtupzVB5WWZ7Z2Y9Nict98CqZ3xud EvkYLjhBtdpowh+s5v3keW1LTMIw8xuNAmkecpWl9DerfkWn8UODEM8DL6rAEjwsTUJS hR/rgsMEpyvDBKT0fMmb/BkRtwmfX/PMNK5NuTsl5zPoKPOxNdMDseUG/NnohqXlyTZG ouxA== X-Gm-Message-State: ANoB5pkDLy0o1AIAP6TJJdnBYT8tGIIoAWaE5fRNx6DcYis15bf+BG87 rERnTO/gLFhUBG4UO2myFV90XA== X-Google-Smtp-Source: AA0mqf6wJN/NTr/CpQEU5S4Hj9QBu4C+IwTMHybadDvehU7bE/T3sx0Vv62ajynVOKkLU5tW7mRJZg== X-Received: by 2002:aca:5c03:0:b0:35a:c6da:965d with SMTP id q3-20020aca5c03000000b0035ac6da965dmr17891205oib.196.1669689812482; Mon, 28 Nov 2022 18:43:32 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:201c:ea26:41ce:5eb]) by smtp.gmail.com with ESMTPSA id l13-20020a056870f14d00b0013b911d5960sm6780015oac.49.2022.11.28.18.43.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Nov 2022 18:43:31 -0800 (PST) References: <20221126020452.1686509-1-thiago.bauermann@linaro.org> <20221126020452.1686509-2-thiago.bauermann@linaro.org> User-agent: mu4e 1.8.11; emacs 28.2 From: Thiago Jung Bauermann To: Simon Marchi Cc: gdb-patches@sourceware.org, Luis Machado Subject: Re: [PATCH v2 1/6] gdbserver: Add asserts in register_size and register_data functions In-reply-to: Date: Tue, 29 Nov 2022 02:43:29 +0000 Message-ID: <87iliyiipa.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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: Hello Simon, Thank you for your review! Simon Marchi writes: > 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 Nice, I will start using that flag on my development builds. Thank you for the hint! -- Thiago