From patchwork Sat Nov 2 02:56:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 840272 Delivered-To: patch@linaro.org Received: by 2002:adf:a38c:0:b0:37d:45d0:187 with SMTP id l12csp1158177wrb; Fri, 1 Nov 2024 19:57:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUQcFXRwnOvrxzOIaEmFA010M6Lz89j1fTw4ssteoLlAmaC2ABDsYLaZJ4WraGYWiN9IrruQQ==@linaro.org X-Google-Smtp-Source: AGHT+IGy+UiyfgVmvLt5k7g77M7LBUPO/l288dBWBnD0Pt+w9wZW5g6r7r7MPQ84iaMNECaFqtTm X-Received: by 2002:a05:620a:2956:b0:7ac:9b07:dbd3 with SMTP id af79cd13be357-7b2fa60b808mr1046363385a.5.1730516229838; Fri, 01 Nov 2024 19:57:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1730516229; cv=pass; d=google.com; s=arc-20240605; b=c6yW3mRAryHsQGzdQJfiduxUG9JfaB7GTjlCz+WYITpjV6bj4P8a/ZSlmN4TCgBBbJ YmsyHNPeyYegeTQfTOyXz/AeG0cUfaliRqFy/hqahj671S5SU/kw82e35oZG3jarimYR aaTVd2ZalnH07cmC11geADTSDvBvarjaJ7l+xajdwc+IuEwb1L7TdHll0+FEBPaZadx9 Q0pbgz/nl5OHYUahzGtz4gpnZVyitRcynCkLYQJLFqmAdS0sYPxcxswJJFk2wwOS9o2/ pgyKZkmKDMYxwC105NnAPQx5RYlVvq0LGYmzQcR5PArJytedRRmtE0ZvI9q1PBVXXIVU nJZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=z45Ff2s4LjQ/0w6LVeLeQfQt9FRqNzLjr/0CDjBSMAM=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=jqQYQKR9DaHJw6Cs6avec3srs35puM9fpQrMzvAc06G7+FKzurQ0i39K/el0f9fNAs K40Rg9IglnslAGS8BO9zQFm1uRLLP7MtH/HGyKQOPmGFJ9kbzcmcfR2rQ9woYEUKOL5F gRq945nStQfSpzcTawlSeNm09TB1CspmKM5XjhQ8OcJfm2Zb9lM6700PjkIF4gzUre4i 8aMaJ5zRgZdf/KubGiCi0jVRgN3EifkT0oqmk6ZgkEQ8QKVkNSgFbGWuQiUL4Sha8NVv Ng6DPX3UgrMAvDBV3euv5JBUp0ET4QxWIU7CKWzUMRUpIOCiopeVO6W5bMFWXtkTUCR1 EQNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JG4FryKs; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id af79cd13be357-7b2f3a813ccsi580647685a.298.2024.11.01.19.57.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 19:57:09 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JG4FryKs; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gdb-patches-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 75487385801B for ; Sat, 2 Nov 2024 02:57:09 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id CB6D33858C51 for ; Sat, 2 Nov 2024 02:56:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB6D33858C51 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org CB6D33858C51 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::432 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730516205; cv=none; b=Zn7zWvQdffz0e26dmUrO+2u1p4QA/v/MPBwUMMUuO64gKMgtTcC0kgVpMLQjj9biwLet5DO8DfZy2ZGeqhGKT5KY2QOtFqvJamx77aw/XFZDZLMZwzAzW9XcfRH8ie4LvDH/1b6FowOa2ZBxeL5YaQmk3jWRoarJEGClGx+aXD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1730516205; c=relaxed/simple; bh=QJuNnoeQNvkwQmf+cB0CwrcyTmw1Bb4cuYLMeWvhMR8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=WQdU9HztQAqPIhUPHwT87GWGdoeDVoPX0ABs3ciUDuIKlNbpZSkG8lKTsWOiOKdgXA4y9oL4SENW75x7Y/R9cotyeuVtTORkGJXcxY4ed6vwqQQWQOFt7+wY3/5YFJgkRUSMXkOf6ooF0jKxYaEiOSjp6cRXB5tutnGL6UYtxKA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-720be27db74so1617907b3a.1 for ; Fri, 01 Nov 2024 19:56:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1730516202; x=1731121002; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=z45Ff2s4LjQ/0w6LVeLeQfQt9FRqNzLjr/0CDjBSMAM=; b=JG4FryKsAnRl9dJCCQef0o25M/VrHFWMjUVo+QRCuv568gyBXqY2L4mlqrl9F6FDJm njTABqT9C5QpV6WFhHegZvvv9gSK2d+15XtrYkAs/lWfTscHw1C3Qlz+obTTfaeu6tRV +nmoo8rKHG+2ugw1ZsA6Tzkq4Gyx3+7TogY2FzzS+RiBt3gDim4TwX5BqaGlZCiDUbM0 amvGTqnYYSNrvrF6SLfavy1jnKhBl6SFlk8Oj1nmuWsoDdhtP+ieccjBwHpVBJ/4RwXQ 58yQOk5W7Puv2+g2uOSQfVczfXt0B+L2KaYH3W1gMxyQGFVTpqSgycTl44NwwUrejDEI 4TXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730516202; x=1731121002; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=z45Ff2s4LjQ/0w6LVeLeQfQt9FRqNzLjr/0CDjBSMAM=; b=S8i/uXgFvg0f8Qi7D6j327oVJrtUpPSgIeH9qvkfMzRaQKFhfZ/u7qChPk1cIxNkaN Em3ylD/owRg2G7209G8xYmCb338a5KtZDHXmqKtlk5DvYXfmOlNChnFfnCx+0MXrbNZT BDs27XEL5AJq6gQ961MMRAtYrKhTwiemCtstH/HfXWXwldmD3D72Y9CRWt8Oe0fuC3hC t95c5yIHk/ctUzXEawPCiCeX8xO1lBKxaczPI9SkXqVFM5u0T7nyLI50LiBsUf7hlLJ7 efgOJdu5bqS0hUuf5ydtCYtpS8OSvni26nerfC+pZJBT8uDqADTMU90ZEjRjqtcoKc2v T+6g== X-Gm-Message-State: AOJu0YxZWVG4lyMYTUoHdJDyKsVuvLhICs84j/imsbCJmhVbthntOBO/ +BSyN+HZyO4h/VfcMoumI3z9LZJhXI49AmXzRqykRdq7qOF3nxW2HFfI84gbmY2FtRArs/P9VUv t X-Received: by 2002:a05:6a00:790:b0:71e:52f0:1c28 with SMTP id d2e1a72fcca58-720c945c433mr8479869b3a.0.1730516201612; Fri, 01 Nov 2024 19:56:41 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:f214:b4dc:314a:c1ee]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-720bc1b8ce8sm3376866b3a.35.2024.11.01.19.56.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Nov 2024 19:56:41 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Subject: [RFC PATCH v4 01/15] GDB, gdbserver: Convert regcache_register_size function to method Date: Fri, 1 Nov 2024 23:56:21 -0300 Message-ID: <20241102025635.586759-2-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20241102025635.586759-1-thiago.bauermann@linaro.org> References: <20241102025635.586759-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~patch=linaro.org@sourceware.org The regcache_register_size function has one implementation in GDB, and one in gdbserver. Both of them have a gdb::checked_static_cast to their corresponding regcache class. This can be avoided by defining a pure virtual register_size method in the reg_buffer_common class, which is then implemented by the reg_buffer class in GDB, and by the regcache class in gdbserver. Calls to the register_size () function from methods of classes in the reg_buffer_common hierarchy need to be changed to calls to the newly defined method, otherwise the compiler complains that a matching method cannot be found. --- gdb/i387-tdep.c | 4 ++-- gdb/nat/aarch64-hw-point.c | 2 +- gdb/regcache-dump.c | 2 +- gdb/regcache.c | 18 ++++++++---------- gdb/regcache.h | 3 +++ gdbserver/regcache.cc | 5 ++--- gdbserver/regcache.h | 3 +++ gdbsupport/common-regcache.h | 16 +++++----------- 8 files changed, 25 insertions(+), 28 deletions(-) diff --git a/gdb/i387-tdep.c b/gdb/i387-tdep.c index 3bda88807943..92f898caf770 100644 --- a/gdb/i387-tdep.c +++ b/gdb/i387-tdep.c @@ -1565,7 +1565,7 @@ i387_collect_xsave (const struct regcache *regcache, int regnum, byte_order, I387_FCTRL_INIT_VAL); else memset (FXSAVE_ADDR (tdep, regs, i), 0, - regcache_register_size (regcache, i)); + regcache->register_size (i)); } } } @@ -1888,7 +1888,7 @@ i387_collect_xsave (const struct regcache *regcache, int regnum, int regsize; regcache->raw_collect (i, raw); - regsize = regcache_register_size (regcache, i); + regsize = regcache->register_size (i); p = FXSAVE_ADDR (tdep, regs, i); if (memcmp (raw, p, regsize)) { diff --git a/gdb/nat/aarch64-hw-point.c b/gdb/nat/aarch64-hw-point.c index 6acee0fb814c..8ab91fe85142 100644 --- a/gdb/nat/aarch64-hw-point.c +++ b/gdb/nat/aarch64-hw-point.c @@ -166,7 +166,7 @@ aarch64_point_is_aligned (ptid_t ptid, int is_watchpoint, CORE_ADDR addr, /* Set alignment to 2 only if the current process is 32-bit, since thumb instruction can be 2-byte aligned. Otherwise, set alignment to AARCH64_HBP_ALIGNMENT. */ - if (regcache_register_size (regcache, 0) == 8) + if (regcache->register_size (0) == 8) alignment = AARCH64_HBP_ALIGNMENT; else alignment = 2; diff --git a/gdb/regcache-dump.c b/gdb/regcache-dump.c index 3e6880535235..0a851e3ed771 100644 --- a/gdb/regcache-dump.c +++ b/gdb/regcache-dump.c @@ -110,7 +110,7 @@ class register_dump_reg_buffer : public register_dump, reg_buffer { if (regnum < gdbarch_num_regs (m_gdbarch) || m_has_pseudo) { - auto size = register_size (m_gdbarch, regnum); + auto size = register_size (regnum); if (size == 0) return; diff --git a/gdb/regcache.c b/gdb/regcache.c index f04354d822f9..6e0c730d0d59 100644 --- a/gdb/regcache.c +++ b/gdb/regcache.c @@ -179,10 +179,9 @@ register_size (struct gdbarch *gdbarch, int regnum) /* See gdbsupport/common-regcache.h. */ int -regcache_register_size (const reg_buffer_common *regcache, int n) +reg_buffer::register_size (int regnum) const { - return register_size - (gdb::checked_static_cast (regcache)->arch (), n); + return ::register_size (this->arch (), regnum); } reg_buffer::reg_buffer (gdbarch *gdbarch, bool has_pseudo) @@ -939,7 +938,7 @@ register_status readable_regcache::read_part (int regnum, int offset, gdb::array_view dst, bool is_raw) { - int reg_size = register_size (arch (), regnum); + int reg_size = register_size (regnum); gdb_assert (offset >= 0); gdb_assert (offset + dst.size () <= reg_size); @@ -983,7 +982,7 @@ void reg_buffer::raw_collect_part (int regnum, int offset, gdb::array_view dst) const { - int reg_size = register_size (arch (), regnum); + int reg_size = register_size (regnum); gdb_assert (offset >= 0); gdb_assert (offset + dst.size () <= reg_size); @@ -1013,7 +1012,7 @@ register_status regcache::write_part (int regnum, int offset, gdb::array_view src, bool is_raw) { - int reg_size = register_size (arch (), regnum); + int reg_size = register_size (regnum); gdb_assert (offset >= 0); gdb_assert (offset + src.size () <= reg_size); @@ -1065,7 +1064,7 @@ void reg_buffer::raw_supply_part (int regnum, int offset, gdb::array_view src) { - int reg_size = register_size (arch (), regnum); + int reg_size = register_size (regnum); gdb_assert (offset >= 0); gdb_assert (offset + src.size () <= reg_size); @@ -1226,8 +1225,7 @@ regcache::transfer_regset_register (struct regcache *out_regcache, int regnum, const gdb_byte *in_buf, gdb_byte *out_buf, int slot_size, int offs) const { - struct gdbarch *gdbarch = arch (); - int reg_size = std::min (register_size (gdbarch, regnum), slot_size); + int reg_size = std::min (register_size (regnum), slot_size); /* Use part versions and reg_size to prevent possible buffer overflows when accessing the regcache. */ @@ -1244,7 +1242,7 @@ regcache::transfer_regset_register (struct regcache *out_regcache, int regnum, else if (in_buf != nullptr) { /* Zero-extend the register value if the slot is smaller than the register. */ - if (slot_size < register_size (gdbarch, regnum)) + if (slot_size < register_size (regnum)) out_regcache->raw_supply_zeroed (regnum); out_regcache->raw_supply_part (regnum, 0, gdb::make_array_view (in_buf + offs, diff --git a/gdb/regcache.h b/gdb/regcache.h index 2f4b7d94c693..65e9f7bb79da 100644 --- a/gdb/regcache.h +++ b/gdb/regcache.h @@ -256,6 +256,9 @@ class reg_buffer : public reg_buffer_common /* See gdbsupport/common-regcache.h. */ bool raw_compare (int regnum, const void *buf, int offset) const override; + /* See gdbsupport/common-regcache.h. */ + int register_size (int regnum) const override; + protected: /* Assert on the range of REGNUM. */ void assert_regnum (int regnum) const; diff --git a/gdbserver/regcache.cc b/gdbserver/regcache.cc index 1bb71d103288..6a1526246867 100644 --- a/gdbserver/regcache.cc +++ b/gdbserver/regcache.cc @@ -308,10 +308,9 @@ register_size (const struct target_desc *tdesc, int n) /* See gdbsupport/common-regcache.h. */ int -regcache_register_size (const reg_buffer_common *regcache, int n) +regcache::register_size (int regnum) const { - return register_size - (gdb::checked_static_cast (regcache)->tdesc, n); + return ::register_size (tdesc, regnum); } static gdb::array_view diff --git a/gdbserver/regcache.h b/gdbserver/regcache.h index 1752c3979d39..df0feca102e0 100644 --- a/gdbserver/regcache.h +++ b/gdbserver/regcache.h @@ -49,6 +49,9 @@ struct regcache : public reg_buffer_common /* See gdbsupport/common-regcache.h. */ enum register_status get_register_status (int regnum) const override; + /* See gdbsupport/common-regcache.h. */ + int register_size (int regnum) const override; + /* See gdbsupport/common-regcache.h. */ void raw_supply (int regnum, gdb::array_view src) override; diff --git a/gdbsupport/common-regcache.h b/gdbsupport/common-regcache.h index f8704c16939a..4594999346fd 100644 --- a/gdbsupport/common-regcache.h +++ b/gdbsupport/common-regcache.h @@ -48,11 +48,6 @@ enum register_status : signed char extern reg_buffer_common *get_thread_regcache_for_ptid (ptid_t ptid); -/* Return the size of register numbered N in REGCACHE. This function - must be provided by the client. */ - -extern int regcache_register_size (const reg_buffer_common *regcache, int n); - /* Read the PC register. This function must be provided by the client. */ @@ -78,6 +73,9 @@ struct reg_buffer_common buffer. */ virtual register_status get_register_status (int regnum) const = 0; + /* Return the size of register numbered REGNUM in this buffer. */ + virtual int register_size (int regnum) const = 0; + /* Supply register REGNUM, whose contents are stored in SRC, to this register buffer. */ virtual void raw_supply (int regnum, gdb::array_view src) @@ -91,9 +89,7 @@ struct reg_buffer_common void raw_supply (int regnum, const gdb_byte *src) { - raw_supply (regnum, - gdb::make_array_view (src, - regcache_register_size (this, regnum))); + raw_supply (regnum, gdb::make_array_view (src, register_size (regnum))); } /* Collect register REGNUM from this register buffer and store its contents in @@ -109,9 +105,7 @@ struct reg_buffer_common void raw_collect (int regnum, gdb_byte *dst) { - raw_collect (regnum, - gdb::make_array_view (dst, - regcache_register_size (this, regnum))); + raw_collect (regnum, gdb::make_array_view (dst, register_size (regnum))); } /* Compare the contents of the register stored in the regcache (ignoring the