From patchwork Sat Aug 31 00:56:07 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: 824404 Delivered-To: patch@linaro.org Received: by 2002:a5d:48c1:0:b0:367:895a:4699 with SMTP id p1csp1034976wrs; Fri, 30 Aug 2024 17:56:43 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXiQDOsWbDSOf1MaXeuE53ffZGVIHR67yvJ2+WNJS8nXADlPH7saiY9662mH5DZY3tku6yYAA==@linaro.org X-Google-Smtp-Source: AGHT+IF8R6r0DTGdg4I6XipvVSCFhSgbxhjnON/XjFtG7X0DaE27Zg6kbAInjMYvCvTnh9UJcKqK X-Received: by 2002:a05:6214:4805:b0:6c3:556b:1652 with SMTP id 6a1803df08f44-6c3556b17b8mr14460466d6.35.1725065803217; Fri, 30 Aug 2024 17:56:43 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1725065803; cv=pass; d=google.com; s=arc-20160816; b=ZrDzWvmo28qK7IeMgRd2m+bZXjSZsP4tat91Iv8WbU4ZNlgW+Et0qIPr5LavXWStGe w9Io2IEAuvE5i7sp6XCf7Ma/w3rriUfCJok+9MrypHh+LBneIvrmMv7tjsl0JTiIsNPX OWs7Pp3bnssov+wnEEsHb/KbArxMje3LNo+p23UUALm/O1wAtw5yT4TaMgRnuzUlfyBm 8VGEcffeQ1RBY8VrI24NSyQGfgsLC5mjlpILBL6BaihYHEvNcdOFhLyg6PvyNeXcnNZU y5UlL5Fx2CKrgZ+Br3+S0grqkUEO+bbXZOl0B+P2MDhvfuj4YzyBDxER+pW5sDvqbGHa CGZA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; 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=IhvmeYblkK0fU4NowNTdjdTcp07oO/AZvdoc9ZMtZH8=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=PpFd3uiN/SwmnIp0uGjSMkzhicaNhYUD+AOI1hmyP2I/yf3T6prpw0D1GmpXuyabEW 8YriiU4bdCx4v1jpbHSydl4Awcy2ewD3G6D3PQg0Jbi54N2FmOklgCKfoio6+mVary3/ mTusmdlpCFidadlPW2voFJaK7tk6aFP6Jhw1cVL90Bqk8bGba7MWwN4Ai/TUD4gNXolF +iyanZ1OUZHgi/dYvRAQ7WJgKoTgXg0s/d5nfii/BlYp7RHMl92s7RLo5RjLgP6YOFJT Hets7apwdrbkxOwiefUacswFkiwOuruCdecGR3MC8oLpUaCdyIfuiQ4F/Iz5vk1jkQTJ JZeg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B41rSxw2; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id 6a1803df08f44-6c340bf8ee7si51220636d6.75.2024.08.30.17.56.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 17:56:43 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=B41rSxw2; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 732193864832 for ; Sat, 31 Aug 2024 00:56:42 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by sourceware.org (Postfix) with ESMTPS id 2CF44384F032 for ; Sat, 31 Aug 2024 00:56:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2CF44384F032 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 2CF44384F032 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725065780; cv=none; b=JvfB4nIOEc9k9Jn+YcwJSgjO+lX15eCawBf1b/SPxh4fPWjYhLMiPm2Ex7idvefw8MAlcnFCv83SG38BqKyXu+VEM3LpU1E596DJnoOFUlYuAvLt4DXd4bkVa6GMntKGooscmGPt5nNsyzSdtE11Cj1GkI5BEcuSO1Kp8pOZShc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725065780; c=relaxed/simple; bh=bVy2j1w85IudzBTRJfTZQiiqvJ3iYnYY0Qx1F4PYafA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=NuQqEhH6+CE8FlHV0h0HeVkQzM7fKpEilq7J9EaOs2kvmKv+za+aAT9NwsrjHUkq0ZPVpP8wuoI8aNBlzxaVje6wiXpqRg+mOY5GhNJmj23wV8YKRqAHexGpfuooG2kX3HihGF9Mf784mOx9c6l1HeDp+DmH1OmbUNqzoGdn2Ms= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-715e3e03831so2364341b3a.2 for ; Fri, 30 Aug 2024 17:56:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725065774; x=1725670574; 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=IhvmeYblkK0fU4NowNTdjdTcp07oO/AZvdoc9ZMtZH8=; b=B41rSxw2xeggKFHuesZofJkdrRryd5OA4fRD4RCqjpamJJe2gOd30pZqUWJOaw4MHl 1RnuSvZioc9kaLQHBWH9O7tAuFa7LIs7TP8P9SPDTDO4baaD+DvO0bfP1E8w/G1tUS4H a1wT5KpB2kv/zRJdVx47bvNHdezf1jDRnpv627j4mSIjh5BtSwD1/9DmXqAZuFMj1MLT CU4qMp+vpSVXJD52mgYYWBon4WVJIUd6xtyyz4+DQVw5JmwexZ11CMZJ3DO4fpsbVD4E 1Luxe4+fBUQYj6CsgnULqOociL/rj7UsElz3Ivr8eCgsqwnd8fU/MnVLxNy1Xd615Xbg lKPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725065774; x=1725670574; 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=IhvmeYblkK0fU4NowNTdjdTcp07oO/AZvdoc9ZMtZH8=; b=U2L0o0kTAOGiaGPt9iXu53F0zqiV2uSYKFNXVo6/+Y65H/EUJHguC0fBYLQdzaeoHW neoqOZWN5WtAaa4uZEcac1cEbn++bM88QmXIgo84xoUmtuQtBM2NON1WM6q6IhH7NnTG NlIfCWoXJvXRkfhYmVx5pbsdb6orQhaohyCBzALDhovnnfn/HEusW7pSHf5WLWskvNFD Tpz3jPD0UehFt+tWiLeNJ7002xd28aTVv+ezW9OaF6+BGZOmifKYoVc2+BQdV56J3Dxu SG9rkdUJmwrW+Zhos5aO5bU7CPqRtnbjliSDf/PvD+lFMnXIEdQVP9y3v3Cjow4KUkVG aHig== X-Gm-Message-State: AOJu0YzHtmKJmxyYItT0q+FaJ9E+oDWASqMoip41nt9FJYnDNP4i/r56 ZDIaL884WywbCcfquyuEN2TLF6vCP56nG1ABTdIGxVqVgJGI+8bPYZDy8JrzMXuGwE6Nl87c/ZE v X-Received: by 2002:a05:6a20:9f89:b0:1c6:fb2a:4696 with SMTP id adf61e73a8af0-1cce100b917mr8583708637.19.1725065773914; Fri, 30 Aug 2024 17:56:13 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:1244:2c60:42b9:1830]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-205152cd8cbsm32266655ad.86.2024.08.30.17.56.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 17:56:13 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Subject: [PATCH 2/2] gdb: testsuite: Test whether PC register is expedited in gdb.server/server-run.exp Date: Fri, 30 Aug 2024 21:56:07 -0300 Message-ID: <20240831005607.2478217-2-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240831005607.2478217-1-thiago.bauermann@linaro.org> References: <20240831005607.2478217-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 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, T_SCC_BODY_TEXT_LINE 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.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 One thing GDB always does when the inferior stops is finding out where it's stopped at, by way of querying the value of the program counter register. To save a packet round trip, the remote target can send the PC value (often alongside other frequently consulted registers such as the stack pointer) in the stop reply packet as an "expedited register". Test that this is actually done for the targets where gdbserver is supposed to. Extend the "maintenance print remote-registers" command output with an "Expedited" column which says "yes" if the register was seen by GDB in the last stop reply packet it received, and is left blank otherwise. Tested for regressions on aarch64-linux-gnu native-extended-remote. The testcase was tested on aarch64-linux-gnu, i686-linux-gnu and x86_64-linux-gnu native-remote and native-extended-remote targets. --- gdb/regcache-dump.c | 9 +++++-- gdb/remote.c | 27 ++++++++++++++++++++- gdb/remote.h | 5 ++++ gdb/testsuite/gdb.server/server-run.exp | 31 +++++++++++++++++++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) diff --git a/gdb/regcache-dump.c b/gdb/regcache-dump.c index bc665dc08a67..1dfc881969eb 100644 --- a/gdb/regcache-dump.c +++ b/gdb/regcache-dump.c @@ -162,7 +162,7 @@ class register_dump_remote : public register_dump { if (regnum < 0) { - gdb_printf (file, "Rmt Nr g/G Offset"); + gdb_printf (file, "Rmt Nr g/G Offset Expedited"); } else if (regnum < gdbarch_num_regs (m_gdbarch)) { @@ -170,7 +170,12 @@ class register_dump_remote : public register_dump if (remote_register_number_and_offset (m_gdbarch, regnum, &pnum, &poffset)) - gdb_printf (file, "%7d %11d", pnum, poffset); + { + if (remote_register_is_expedited (regnum)) + gdb_printf (file, "%7d %11d yes", pnum, poffset); + else + gdb_printf (file, "%7d %11d", pnum, poffset); + } } } }; diff --git a/gdb/remote.c b/gdb/remote.c index 2c3988cb5075..c17572d51c8d 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -693,6 +693,10 @@ class remote_state qSupported. */ gdb_thread_options supported_thread_options = 0; + /* Contains the regnums of the expedited registers in the last stop + reply packet. */ + std::set last_seen_expedited_registers; + private: /* Asynchronous signal handle registered as event loop source for when we have pending events ready to be passed to the core. */ @@ -1490,6 +1494,20 @@ is_remote_target (process_stratum_target *target) return as_remote_target (target) != nullptr; } +/* See remote.h. */ + +bool +remote_register_is_expedited (int regnum) +{ + remote_target *rt = as_remote_target (current_inferior ()->process_target ()); + + if (rt == nullptr) + return false; + + remote_state *rs = rt->get_remote_state (); + return rs->last_seen_expedited_registers.count (regnum) > 0; +} + /* Per-program-space data key. */ static const registry::key> remote_pspace_data; @@ -8518,6 +8536,10 @@ remote_target::process_stop_reply (stop_reply_up stop_reply, { *status = stop_reply->ws; ptid_t ptid = stop_reply->ptid; + struct remote_state *rs = get_remote_state (); + + /* Forget about last reply's expedited registers. */ + rs->last_seen_expedited_registers.clear (); /* If no thread/process was reported by the stub then select a suitable thread/process. */ @@ -8544,7 +8566,10 @@ remote_target::process_stop_reply (stop_reply_up stop_reply, stop_reply->arch); for (cached_reg_t ® : stop_reply->regcache) - regcache->raw_supply (reg.num, reg.data.get ()); + { + regcache->raw_supply (reg.num, reg.data.get ()); + rs->last_seen_expedited_registers.insert (reg.num); + } } remote_thread_info *remote_thr = get_remote_thread_info (this, ptid); diff --git a/gdb/remote.h b/gdb/remote.h index cb0a66da66e5..bfe3c65b4637 100644 --- a/gdb/remote.h +++ b/gdb/remote.h @@ -121,4 +121,9 @@ extern void send_remote_packet (gdb::array_view &buf, extern bool is_remote_target (process_stratum_target *target); +/* Return true if REGNUM was returned as an expedited register in the last + stop reply we received. */ + +extern bool remote_register_is_expedited (int regnum); + #endif diff --git a/gdb/testsuite/gdb.server/server-run.exp b/gdb/testsuite/gdb.server/server-run.exp index 92eb38bd9db0..e22cee1e3c74 100644 --- a/gdb/testsuite/gdb.server/server-run.exp +++ b/gdb/testsuite/gdb.server/server-run.exp @@ -52,3 +52,34 @@ if { [istarget *-*-linux*] } { gdb_breakpoint main gdb_test "continue" "Breakpoint.* main .*" "continue to main" + +if { [istarget "aarch64*-*-*"] + || [istarget "arm*-*-*"] + || [istarget "csky*-*-*"] + || [istarget "loongarch*-*-*"] + || [istarget "riscv*-*-*"]} { + set pc_regname "pc" +} elseif { [is_amd64_regs_target] } { + set pc_regname "rip" +} elseif { [is_x86_like_target] } { + set pc_regname "eip" +} elseif { [istarget "tic6x-*-*"] } { + set pc_regname "PC" +} + +# Sending the PC register in advance is good practice. Test that this is +# actually done for the targets where gdbserver is supposed to. +set expedited_pc_test_name "send PC as expedited register in stop reply" +if { [info exists pc_regname] } { + gdb_test_multiple "maintenance print remote-registers" \ + $expedited_pc_test_name -lbl { + -re " ${pc_regname}\[\[:space:\]\]+${decimal}.*${decimal} yes" { + pass $gdb_test_name + } + -re " ${pc_regname}\[\[:space:\]\]+${decimal}.*${decimal}" { + fail $gdb_test_name + } + } +} else { + untested $expedited_pc_test_name +}