Message ID | 20221126020452.1686509-2-thiago.bauermann@linaro.org |
---|---|
State | New |
Headers |
Return-Path: <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D2513887F5B for <patchwork@sourceware.org>; Sat, 26 Nov 2022 02:05:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D2513887F5B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1669428340; bh=AsprGWoNf7eKHygJV85RKVoDXmOCFsW3sIHXe1eg9Pw=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=wln1fADZy0q0SHtlHrPZbZOmgmz6PEUpL09tE7uKS9F+Y41aZb6YuTjZvtE2RB+ol SuzTp5jiZF7jiJIwSnc7IcxOHapYuqrhtgrXeZkzrSgBKMztClBaAN2OIKm3O2i+G3 1BNf4OqfypPXC7BN7Ql2H84jD6ziha0ZFZRhbNlA= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-oi1-x232.google.com (mail-oi1-x232.google.com [IPv6:2607:f8b0:4864:20::232]) by sourceware.org (Postfix) with ESMTPS id 3F6AD38451B3 for <gdb-patches@sourceware.org>; Sat, 26 Nov 2022 02:05:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3F6AD38451B3 Received: by mail-oi1-x232.google.com with SMTP id n186so6096734oih.7 for <gdb-patches@sourceware.org>; Fri, 25 Nov 2022 18:05:16 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=AsprGWoNf7eKHygJV85RKVoDXmOCFsW3sIHXe1eg9Pw=; b=h6AIQdjsTaJD5roicaDDY7eTAzfIqoZryEKKXHRNG/jEecweoM3pyqvxHG/eb5UjDS PSnIpcw6V43T3PVKmLdvAv0tPXSSBiIXkKenDZDnj8MXIR6UQ5yR0sGP/H8GLsurzV1J xQf4foHjg+vg86MyTnkOP6g2mcVyoaAklpachTqZnrF0o/cKkedVYR3AVsw1oWAT1E3C Mhe0Eahz9j+k6Dgj+kr7BueEU2SQZPWGbVzLRmxxX2xwcqzPAx7fizwZ8+s77PiKqsKd PDKeXYszHDhFyxdwCiaD217P8jnbPTyBJpE0S7pOPcvQn8PQfET/w651V92+PIVPug6n AKEQ== X-Gm-Message-State: ANoB5pnT8fKBTxBHKUSKnWh+lIwXhx0kuzH+8wPJfsnmpt99kohWAW2N aVzOOV6yIEfcyWViERVFEnWbpQPf51iApQ== X-Google-Smtp-Source: AA0mqf6tdpMlBXlFaztJhw2EgFyONjVPnGrMIs8aTDydbBSwkn22WI0hB6MHACmXEnb7yJmJATqDcw== X-Received: by 2002:a05:6808:3096:b0:355:ebd:8b3a with SMTP id bl22-20020a056808309600b003550ebd8b3amr19293408oib.117.1669428315692; Fri, 25 Nov 2022 18:05:15 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:41ee:c7fc:c991:eee6]) by smtp.gmail.com with ESMTPSA id k17-20020a4ae291000000b004805b00b2cdsm2142450oot.28.2022.11.25.18.05.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 18:05:15 -0800 (PST) To: gdb-patches@sourceware.org Cc: Luis Machado <luis.machado@arm.com>, Thiago Jung Bauermann <thiago.bauermann@linaro.org> Subject: [PATCH v2 1/6] gdbserver: Add asserts in register_size and register_data functions Date: Sat, 26 Nov 2022 02:04:47 +0000 Message-Id: <20221126020452.1686509-2-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221126020452.1686509-1-thiago.bauermann@linaro.org> References: <20221126020452.1686509-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list <gdb-patches.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/gdb-patches/> List-Post: <mailto:gdb-patches@sourceware.org> List-Help: <mailto:gdb-patches-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/gdb-patches>, <mailto:gdb-patches-request@sourceware.org?subject=subscribe> From: Thiago Jung Bauermann via Gdb-patches <gdb-patches@sourceware.org> Reply-To: Thiago Jung Bauermann <thiago.bauermann@linaro.org> Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" <gdb-patches-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
gdbserver improvements for AArch64 SVE support
|
|
Commit Message
Thiago Jung Bauermann
Nov. 26, 2022, 2:04 a.m. UTC
These helped me during development, catching bugs closer to when they actually happened. --- gdbserver/regcache.cc | 4 ++++ 1 file changed, 4 insertions(+)
Comments
On 11/26/22 02:04, Thiago Jung Bauermann 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()); > + > return (regcache->registers > + find_register_by_number (regcache->tdesc, n).offset / 8); > } LGTM. Reviewed-by: Luis Machado <luis.machado@arm.com>
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.marchi@efficios.com> Simon
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 <simon.marchi@efficios.com> 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
Hello Simon, Thank you for your review! Simon Marchi <simark@simark.ca> 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!
Simon Marchi <simark@simark.ca> writes: > On 11/28/22 09:48, Simon Marchi wrote: >> >> Approved-By: Simon Marchi <simon.marchi@efficios.com> > > Actually, I would perhaps suggest moving the assertion checks to > find_register_by_number, the place that actually accesses reg_defs. Good idea. I'll do that in v3. > And we could perhaps remove the equivalent gdb_assert in > regcache_raw_read_unsigned, since it's checking the same a few frames > above. Good point. Will do.
Hello Luis, Thank you for the quick review! Luis Machado <luis.machado@arm.com> writes: > On 11/26/22 02:04, Thiago Jung Bauermann 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()); >> + >> return (regcache->registers >> + find_register_by_number (regcache->tdesc, n).offset / 8); >> } > > LGTM. > > Reviewed-by: Luis Machado <luis.machado@arm.com> With Simon's suggestion, this patch will be different in v3 so unfortunately I won't be able to add this Reviewed-by.
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()); + return (regcache->registers + find_register_by_number (regcache->tdesc, n).offset / 8); }