From patchwork Thu Sep 5 04:42:02 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: 825612 Delivered-To: patch@linaro.org Received: by 2002:adf:a345:0:b0:367:895a:4699 with SMTP id d5csp125683wrb; Wed, 4 Sep 2024 21:42:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVa0FR5nhiVWGOEybCxfOUoaGozMaqCqI1QRO2QxMk82s1M1/rtevgM13kavJaMLJkN52TAEA==@linaro.org X-Google-Smtp-Source: AGHT+IEyxFjKMQXROE/4A8hgTKdnJf+MOjuuorvk6BxTS1tdP0yRKq4i51GtMfXAiawiTWJ5TKo1 X-Received: by 2002:a05:620a:244f:b0:7a2:c6f:fa40 with SMTP id af79cd13be357-7a902f6a801mr1963765485a.64.1725511349581; Wed, 04 Sep 2024 21:42:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1725511349; cv=pass; d=google.com; s=arc-20240605; b=dgMPAapswdI3lci1XwFc9RDh/8LkwcTLTrtcmLTKHxN/nY5bi1l53kKfZGeVPYJwKJ pbUcdr6SWmDqbNK30VzQ7PACG56nbswk2cgOH2/UVSmp5VSxDzIU7p8cQi8g78hFEYBu bpXdAgVsqDGsncyb0rd2ITVjgeFAefxWfKrlHLJunKb8R/9vXku4wtz45uy/6YlFivk7 871bwA2TU0O7oHOJXMDpG44j/e6qMYRQ50mtxVr9uIhj7gFcMINFBX3NgGBC3BpqoSVZ hb1CoQiw0bnNMrew4TTLdTevfaAZeOGCdCaospqzF9rDVpSQ2EWZTJ1oWA4yZ3ajcqG8 iExg== 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:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=dXk7xf3JLnSWXMgneYmugq+nS/dk+FVXcPqhr5QvCG4=; fh=1IQIRXIzM9fyr7VeQSLsmrO+UmogvFI06vj+8+Pr0AQ=; b=IRhxfzFrFzW9+FGl88RuKw7IJYmxpSzy416zPTqLAPL4/MIG3YaSzcrQmKUsOyS6Fo N/gebSuZ5mWXs/sRJc0pu8O8l3MpJjigjZMRDNCP6IPkdagmFtfMFv0jPRAsV/RwOa43 RlnuhUFoD3mrM3t/MPSv5JqA20FvBqvXNq1O7Pr+zhRN6CF6SMfmt2gMO03sXxHuR6J3 JpQa0RBLRNaOKlXX7GBi/jRfvzUBIgPloQgka/2G/HmgBNcb7eSY57ivJCuyCdvm2xkt aBOFf5Vh/ts6o6LRjy3XibuuLf4TI/D2UdXw8lcZbYCTAnw4+XQg2BVCf/v6DXFjXP65 /K8Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sPVYALj2; 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 af79cd13be357-7a98f007eeasi111870685a.400.2024.09.04.21.42.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:42:29 -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=sPVYALj2; 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 37346385020D for ; Thu, 5 Sep 2024 04:42:29 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by sourceware.org (Postfix) with ESMTPS id CBC973860C34 for ; Thu, 5 Sep 2024 04:42:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CBC973860C34 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 CBC973860C34 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1036 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725511329; cv=none; b=Mq1BNV2+RfS0pwQRRshQ5QQST/OImiF1UCXhpiRzPSPIvtvpy2DMdJjsZss/R6Y5rWj/AzjSgi2lbNZkdsUs/122gI7fW/1yp6arrJezfCzMZnEl9elTOYjbcCe7iSPbvlYLHQ3y7q2fk2QjXlKATwEs22r4xbME5BkSlRZ+TvY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725511329; c=relaxed/simple; bh=kAutyvD4fhPPBvct1sSjMcvDuNVNBAf8ZpFTZZjf0qk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=dhjIKiCpTxMxiHvRpnnwva6cnObpwtyK7V+/ljeXCJaKdI0WW7iSJlWi+qQOYgDMtmwueAjwLvZ7NnzViZW9OR36CD/j+XbrEwjYsdiNb1+bhZaakzoqZ1wo77OAft9JADPj7A9VBeQivmOdev+E8Bc0jTMfQkM1qpgJcRudoOM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1036.google.com with SMTP id 98e67ed59e1d1-2d86f713557so206408a91.2 for ; Wed, 04 Sep 2024 21:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725511326; x=1726116126; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dXk7xf3JLnSWXMgneYmugq+nS/dk+FVXcPqhr5QvCG4=; b=sPVYALj2PHShz2WAYHC+6t8RRcj10UGwl1QfjpvSUCy68WbQ3tyZhVSphOMGGy3dzK nVxA/KNs7XjB2aaeOWjcWaf3yTvgbkADYXM2ZvCXM50ckr1668kiRUECEFmndPiYY56c YnAfNwWmcuObKGaQe2w7ktHAHx7TjGi9RaDzkCGLhvD4BayYxLCywNPsYpulmdGU4yc2 kpbLWL9ozmX6qN52BoTcQJnAOPU7zv3kFdsN5R+pX0BoDcjwjyq65t+BJ1rGBuFmcdDe coNYWJWdNdsGkQIdLhs0d27fTbVEyWCkRSxmgmE8IDtXqSJBFMdGPa7MIise0HaSpYjz +qFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725511326; x=1726116126; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dXk7xf3JLnSWXMgneYmugq+nS/dk+FVXcPqhr5QvCG4=; b=dFHXad96tnG+B6WNJOuIUfdmyrxKBEEsLoidkdbFlXLvcskJJJP3UqX97RGcAKw61F VvgjMJeVmCa/5Jf6HrYAjFKpIXe+sGJWuJUMjMzrN2SstyN1Izbwiwof+8C84x/Fwb1j o4auBMd0zypcSgXjjpEh5KyIlDxM5SVwkoi1BWXB8h3QqtTeil15VDEm8AKsjJBCt0SO Hp1Uv26dib6XOne0yjanGJ5vPoUkKTG+OeLxOHgWl/cf7RhINsr8ldd1UunzRIhumlmB Eq6sJgQN42RMRHCClrakRnxjAOQ02PQeCX7jLCpfGuvaGwMjbMGa3PzuJ8C0Q5ZEzRrC 5aTA== X-Gm-Message-State: AOJu0YyNIRo+AEYYfTNnt317xTI6BNlMCQKJjdayPUCi8IVFmTkJ537h PSUc/gSnAQH6x+lbUKIwR5QKX/GDlfxZYE8Nr/VxlJBqyIeK1O85CPlnGtSP+8stq1X0NC6vwAn X X-Received: by 2002:a17:90a:de93:b0:2d8:8a04:1b16 with SMTP id 98e67ed59e1d1-2d8905ed640mr15770829a91.33.1725511325384; Wed, 04 Sep 2024 21:42:05 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:854e:f6dc:30d1:ca48]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d8f5ec4bc6sm6506988a91.57.2024.09.04.21.42.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Sep 2024 21:42:04 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH v2] gdb: testsuite: Test whether PC register is expedited in gdb.server/server-run.exp Date: Thu, 5 Sep 2024 01:42:02 -0300 Message-ID: <20240905044202.259066-1-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Spam-Status: No, score=-11.1 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. Reviewed-By: Eli Zaretskii --- gdb/NEWS | 7 ++++++ gdb/doc/gdb.texinfo | 6 ++++- gdb/regcache-dump.c | 19 +++++++++----- gdb/remote.c | 27 +++++++++++++++++++- gdb/remote.h | 5 ++++ gdb/testsuite/gdb.server/server-run.exp | 33 +++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 8 deletions(-) Changes in v2: - Added NEWS entry and updated documentation for maint print remote-registers command (suggested by Andrew). - Updated help string for maint print remote-registers command. - Adopted Andrew's gdb_test_multiple invocation to avoid leaving unmatched ouptut in Expect's buffer. v1 is here: https://inbox.sourceware.org/gdb-patches/20240831005607.2478217-2-thiago.bauermann@linaro.org/ base-commit: 43af2e08dc0af7796b557d14f13317c0c24f948a diff --git a/gdb/NEWS b/gdb/NEWS index 2f5d5ebbcef1..8820fadb6436 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -40,6 +40,13 @@ history has been reached. It also specifies that the forward execution can continue, and the recording will also continue. +* Changed commands + +maintenance print remote-registers + Add an "Expedited" column to the output of the command. It indicates + which registers were included in the last stop reply packet received by + GDB. + * New commands maintenance info inline-frames [ADDRESS] diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index 8cde2f22637b..26c7b609f86f 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -42048,7 +42048,11 @@ including registers which aren't available on the target nor visible to user; the command @code{maint print register-groups} includes the groups that each register is a member of; and the command @code{maint print remote-registers} includes the remote target's register numbers -and offsets in the `G' packets. +and offsets in the `G' packets, as well as an indication of which +registers were included in the last stop reply packet received by +@value{GDBN} (@pxref{Stop Reply Packets}). Please note that the list +of registers included in a stop reply can change from one stop to the +next. These commands take an optional parameter, a file name to which to write the information. diff --git a/gdb/regcache-dump.c b/gdb/regcache-dump.c index bc665dc08a67..6b711bf6c2a0 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); + } } } }; @@ -324,9 +329,11 @@ _initialize_regcache_dump () "Takes an optional file parameter."), &maintenanceprintlist); add_cmd ("remote-registers", class_maintenance, - maintenance_print_remote_registers, _("\ -Print the internal register configuration including remote register number " -"and g/G packets offset.\n\ -Takes an optional file parameter."), + maintenance_print_remote_registers, + _("Print the internal register configuration including remote " + "register number and g/G packets offset.\n" + "Also prints which registers were sent in the last stop reply " + "packet (i.e. expedited).\n" + "Takes an optional file parameter."), &maintenanceprintlist); } 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..af5a5f53ca03 100644 --- a/gdb/testsuite/gdb.server/server-run.exp +++ b/gdb/testsuite/gdb.server/server-run.exp @@ -52,3 +52,36 @@ 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] } { + set seen_line false + gdb_test_multiple "maintenance print remote-registers" \ + $expedited_pc_test_name -lbl { + -re " ${pc_regname}\[\[:space:\]\]+${decimal}.*${decimal} yes" { + set seen_line true + exp_continue + } + -re "\r\n$gdb_prompt $" { + gdb_assert { $seen_line } $gdb_test_name + } + } +} else { + untested $expedited_pc_test_name +}