From patchwork Sat Aug 31 00:56:06 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: 824403 Delivered-To: patch@linaro.org Received: by 2002:a5d:48c1:0:b0:367:895a:4699 with SMTP id p1csp1034946wrs; Fri, 30 Aug 2024 17:56:37 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXR1wGcOEs1DgekXgIEP1vVod/sScqRWPEkQj0EmqJiTuaMqBhOSrevxY6mVR1Ka6oNqy1CPA==@linaro.org X-Google-Smtp-Source: AGHT+IGMaCGDprmW0YX8XyhCl/hDTreEWCVXeAOKXoAFQd0HB5aCj6WVXkKXFdOPhF+2Dlv00wDH X-Received: by 2002:a05:620a:31a0:b0:79d:5503:a925 with SMTP id af79cd13be357-7a8f6bd6d69mr116584285a.35.1725065797102; Fri, 30 Aug 2024 17:56:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1725065797; cv=pass; d=google.com; s=arc-20160816; b=fH1VvnONVLs3YS6+qtL1X3QjqJGbJbx0S6zeIUzVqfvdjOx82WztS1vqFGkSI1VKby msF0o+2VVLcLtrnHwTGwef7Nc8NS99YKg9KX2FZxMHzHpos4a9oR68+QNaFxNfBfczXF 9SDwqArK2fnlPKb9Uadvx178yz0cFPq88mI9Uw/l0S/pS3MW4b/sLNFrM2czGjeXRMzp 166d4e2kjVLhtk0I7CGqLCVYGic2cr1SIGKKCGTNSmkWgXPNFr3r4dRleos/ZFdJZroV BI4XECNEEfz3jmU01u5ooGrFYXFxCFoGnoKTdSEt1BofJ92oylSemFPGPKe4vXeb0Wft hvKA== 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:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=NdgjSt2sIx9RR2r1VuidfGpWR8S9QBhJ4oIFmI6toiI=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=VE73o26hmkxyDZ/rP7WB0OFZzoxP3EkcVTr1PBvZQ/uBwJrwElgC6rd3XT/Sw1ICWY cz04xd/TioJpCBmW2Q2UCX64wWbkbLQhMuKMYg2rgb0wBY8NRQK3VGxcrJw3/qKx68J6 MI+LhHEgf+mOuo/TnnOmS9WGNx6Wys902s7BEdjU3Y7I3HOWvPzUVoP0Csr+Iw3i92vr nLe9Cx4c422OjH7DgVNrLVve/jdNyCgfZ7eG3EfAC+1ocBA4Lv0xT8rjbCe4jk+2Akyo /avod7Mij0eEuV7ruv0GvPLUQp/VNpBhz2qpGGOrhZaxCL0mIPxgyBmAk17TuUsj5erP XA/g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ROKzDufX; 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-7a806d51436si522507485a.370.2024.08.30.17.56.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 17:56:37 -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=ROKzDufX; 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 B217A3864C15 for ; Sat, 31 Aug 2024 00:56:36 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-oo1-xc2a.google.com (mail-oo1-xc2a.google.com [IPv6:2607:f8b0:4864:20::c2a]) by sourceware.org (Postfix) with ESMTPS id 4DE9F384F4BF for ; Sat, 31 Aug 2024 00:56:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4DE9F384F4BF 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 4DE9F384F4BF Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c2a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725065774; cv=none; b=eiNZTnOvZQlJDRrmIgIlu/yIQ6kGtXJhgFA+yCOeJK3fxMJdecjGKnYusYAkpJhCC7KKr+bP+igGu3IaQ0OfttxefE5Q2kMOFyFTn2qliCzsbaddSnXinBPaf6dQVRhCrPm5i73x5pzEP2RFRhgiy4DEamf5/aN9Ghs7FjL8Osg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1725065774; c=relaxed/simple; bh=KO7StLgCLhX+mmwFRQAdrDf3UY5BoN1y3Mg7iQcLPhA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=K2pSWRd24UGQ/ZvdnterVauhzn3Bs88JYo0mBTYBW3wBSmfudyUAePZhp2RDxEfz8zQp/dmRGZsGoxO63QVDbvMsj/WZb9YZnWnPQm4uV/44Ys21JA+jkxOJnEmPO3DBZ1/mXPPFLHpCd5jJo/BUX16fe8I1tK0L6yJyE39vwvY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc2a.google.com with SMTP id 006d021491bc7-5d5c7f24372so1471194eaf.0 for ; Fri, 30 Aug 2024 17:56:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1725065770; x=1725670570; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=NdgjSt2sIx9RR2r1VuidfGpWR8S9QBhJ4oIFmI6toiI=; b=ROKzDufX+l2EJn9D7E/mNegOov6irn7otmKOMuCMRgBeYA76aMk62cXxBi+c+xznNB Sb7D/aNNbVSSo7YjJ3cB6z2bskhSKX4kk75gkXhBA4+ownmYjjhDWsY5YMfxuP6ehiXZ 3DYliWUQNSV2hzzwWb56ZZvRAQeqM2QgQ75uLK6anwgcwrPas0aCQ3zVH0fmdQL98kUC 2bec7Y0VCOoor9/gLvapuXx5ge0Hc1u41ojcrMPVBcwxtCNdUVhplrg6cX0iHPu7JKbK UWNQiV/VRkMJ8N0BmkPxQNnBXCBpiR0/QwJWIXP6k/uQGa21ZrfSKLM/Sa3vgNisfS6k zIEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725065770; x=1725670570; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NdgjSt2sIx9RR2r1VuidfGpWR8S9QBhJ4oIFmI6toiI=; b=JKfVhla0QsBwV0jQs82dDxLOt+xTDJKalvHKqVOR5USR41OreDm4U75x9XNF9IFTy9 86NZSBJ1uplaXhSku0YnW8WDGlW2vQmL8MOKnHZRT5UDu1mW7HPZPyZ1sLgcmbv+/NdP Hm2xX5xhair6csk3rN9OodvCQEhu+zJaaWlsTufxw0jx2SSbJOs38zaWPCT/Qo2G8EId kttNTKWb+1FjiLQT0Vz/rJhjYf6xbrWgxH0W8YYn7h4TcUt2NiFch+vhynddDzvuQRDO 5m5ZStXLGKhBVGnWg47wLuTInZIofOcdLSAfNGtZusJhXfxYHcc3rpYkyV2GtQDrWYPs R2gQ== X-Gm-Message-State: AOJu0YxzI7oFT+41dO05Ee3fkxSk2CDrt9OaMCP2Z+410Lzm2A2q4XWP 1fLVnvtHO+tKWDpleqncvlhlFeZU5njHa7ssSA16c6dRG7/BzpMpdAG0uIIOcWrGcLV4P011qdT W X-Received: by 2002:a05:6871:2b10:b0:261:360:746c with SMTP id 586e51a60fabf-277901159fcmr8533335fac.19.1725065770517; Fri, 30 Aug 2024 17:56:10 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:1244:2c60:42b9:1830]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-715e569ecc8sm3433390b3a.140.2024.08.30.17.56.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 30 Aug 2024 17:56:09 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Subject: [PATCH 1/2] gdbserver: aarch64: Fix expedited registers list Date: Fri, 30 Aug 2024 21:56:06 -0300 Message-ID: <20240831005607.2478217-1-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.45.2 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 Since this commit: commit a8651ef51822f91ec86d0d5caffbf2e50b174c23 CommitDate: Fri Jun 14 14:47:38 2024 +0100 gdb/aarch64: prevent crash from in process agent gdbserver isn't sending expedited registers with its stop reply packets anymore. The problem is with how the constructor of the expedited_registers std::vector is called: The intent of the expedited_registers initialization in aarch64_linux_read_description is to create a vector with capacity for 6 elements, but that's not how the std::vector constructor works. Instead it creates a vector pre-populated with 6 elements initialized with the default value for the type of the elements, and thus the first 6 elements are null pointers. The actual expedited registers are added starting at the 7th element. This causes init_target_desc to consider that the expedite_regs list is empty, since it stops checking at the first nullptr element. The end result is that gdbserver doesn't send any expedited registers to GDB in its stop replies. Fix by not specifying an element count when declaring the vector. Tested for regressions on aarch64-linux-gnu native-extended-remote. --- gdbserver/linux-aarch64-tdesc.cc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) base-commit: a253bea8995323201b016fe477280c1782688ab4 diff --git a/gdbserver/linux-aarch64-tdesc.cc b/gdbserver/linux-aarch64-tdesc.cc index 5d3b6ddffffa..31ec7854cc0b 100644 --- a/gdbserver/linux-aarch64-tdesc.cc +++ b/gdbserver/linux-aarch64-tdesc.cc @@ -52,14 +52,10 @@ aarch64_linux_read_description (const aarch64_features &features) { tdesc = aarch64_create_target_description (features); - /* Configure the expedited registers. By default we include x29, sp - and pc, but we allow for up to 6 pointers as this is (currently) - the most that we push. - - Calling init_target_desc takes a copy of all the strings pointed - to by expedited_registers so this vector only needs to live for - the scope of this function. */ - std::vector expedited_registers (6); + /* Configure the expedited registers. Calling init_target_desc takes + a copy of all the strings pointed to by expedited_registers so this + vector only needs to live for the scope of this function. */ + std::vector expedited_registers; expedited_registers.push_back ("x29"); expedited_registers.push_back ("sp"); expedited_registers.push_back ("pc"); 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 +}