From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 6E3CC3858D38 for ; Mon, 30 Jan 2023 04:45:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6E3CC3858D38 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-ot1-x329.google.com with SMTP id 70-20020a9d084c000000b0068bccf754f1so722294oty.7 for ; Sun, 29 Jan 2023 20:45:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=T556B1qDxApN1W5PgdX1i1AUoiIe1HwTGpyed7z3xJs=; b=OiGVats6xdPK0BWycwqO4N5Ae8poasyERaycJ3oHJckUpPMyjpUkYA3uftq3TdDHmM H0aY6/sz0dzKJ6aHfXKsLiKy93kEPOfivPF+yM2IEFSnE6Zh7bI+yqOzM4xXSmcbFTGQ XNZuHJrwjCr2+cjdIUGuJQJwsGEidJZ529glM9cTLa0n87i4rOhcK1CW/EdfxYKH7aWF 0ZLu7QH37W5JmMPh2c0qf28BpG+1YYK2662pyn7j2w8APapjU6ss8Si9jNDh6ULxlGG5 jx0qDZRCy7Uchy6Pr4EJGak7g2lzyQzc2qe8UCHU0bM7pBZNAmpUaLT74HlKzxZOq4g0 oH7A== 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=T556B1qDxApN1W5PgdX1i1AUoiIe1HwTGpyed7z3xJs=; b=MggqA/9ChqQW2HSIdandLfA8BY358xqxOtKU3xfcISBz7w2q5IglhP/WjipDkggYvg lH37+khhw3fDZ30u6U9SODh+0BiJLyUSud+DhjEpyKBX/V5uI/Vg9qSmXv5W4MCYpZgF 7jUbIh2b72lVccazWe5jRVeUgTlTu1YHvdodSrTHJHp1GqFVGIEt+MY+XTZPX3sLH3gb 8PkXAnAvPk+tpuQR3U40fqJXXj0K9JbiDEtRN7W5u+eYfVfa/m7B1ymc+NWsXzi3Gt7U nDsP8ThtrmOySCA54Ev+3Qiah/Tm5mu9wPJijI7XbVKWhg6JaICV9XqiLTKi0h0pBfTL cvXQ== X-Gm-Message-State: AO0yUKX2l7sF5OMQkaJ0r9bnfM+faTshFP0H0WwB75H3AEVu0zUC038x KHXUgLaAbSk2GkptqCcxXn5ALPVqtngeRAZN X-Google-Smtp-Source: AK7set/XX8snF8Y9m6rL3FIRuSiuTIgscBymbTgms+lPrlvF4s75OZz9DypIAHXx/5OskR0ZbmtDvA== X-Received: by 2002:a9d:7190:0:b0:68b:c44a:b616 with SMTP id o16-20020a9d7190000000b0068bc44ab616mr701544otj.19.1675053939728; Sun, 29 Jan 2023 20:45:39 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:df99:10bd:7dca:b2e9]) by smtp.gmail.com with ESMTPSA id j9-20020a056830270900b0068b6bcaa037sm4005484otu.40.2023.01.29.20.45.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 29 Jan 2023 20:45:39 -0800 (PST) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Thiago Jung Bauermann , Simon Marchi Subject: [PATCH v3 1/8] gdbserver: Add assert in find_register_by_number Date: Mon, 30 Jan 2023 04:45:11 +0000 Message-Id: <20230130044518.3322695-2-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230130044518.3322695-1-thiago.bauermann@linaro.org> References: <20230130044518.3322695-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.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 List-Id: 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 ()); + return tdesc->reg_defs[n]; } @@ -440,8 +442,6 @@ regcache_raw_read_unsigned (struct regcache *regcache, int regnum, int size; gdb_assert (regcache != NULL); - gdb_assert (regnum >= 0 - && regnum < regcache->tdesc->reg_defs.size ()); size = register_size (regcache->tdesc, regnum);