From patchwork Sat May 4 00:05:19 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: 794556 Delivered-To: patch@linaro.org Received: by 2002:adf:a153:0:b0:34d:5089:5a9e with SMTP id r19csp985832wrr; Fri, 3 May 2024 17:06:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUPDUKby7n/rTiurPGpaBOnZk9GAEpCk9WxFI7Ezhr68nwQfxQP8fRDJRUo9K/0GGIekfTUXGpZa8XM+M5a6XbA X-Google-Smtp-Source: AGHT+IEDCnXOweTSE8af2tE50mjmJaOx0/3LKJm44vx3cxM7giIqYGBXe2Z3HPZynmNQu9XVZM4f X-Received: by 2002:a05:620a:c84:b0:78d:6b37:ee7a with SMTP id q4-20020a05620a0c8400b0078d6b37ee7amr3705375qki.50.1714781179858; Fri, 03 May 2024 17:06:19 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714781179; cv=pass; d=google.com; s=arc-20160816; b=zK6p2ljOpVWPwjaabEx9XfT80mzTvHXX+F+XTAK6HeNnGGZBABe4iOUgBe6wH/5MvU DUuLXcxTChBtu7t1MVu1PXmPFtTILJ3lW/DutLVoE55hH31mqy4KkRzEcVvmL5sFQwst B3CuRTh15bkOIqIiBjOucAWXjXXQ8y4g6zOMr4y7eZtpCE8eZLZJqti8lak5gp930JbB gsudxveM6gndh6jo/ryqqzrPkKd8HctcqjZUS/gvdTQH+WHy+FFA9Q4jUoX1w/klVGOK wEPuDdd5yd1izLmVtUbA7R1pDuZn8P6uZpRT7TbuvQkWIuU7eROaxMcaxP2Y1tckAWBR BXHQ== 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=x6tAzyEiM50fLZnGF9T10lQdqQJkOFJz6OH73fa4REs=; fh=72kqq0iQhigvR9Vv/oqX5ebs3Yyyw7XhzWxOOEPdupI=; b=I5LBI7+3iGTAuq1SCOiWR0gHE6IHIicBPFGBIQ3dJOynWGetSZlVarE7A487qeopLb nmfrCGAAIVqRGcUs32PXTeOaHUxh+G0m8Qd6QTTxDF4xt6zWdqHmAnEYUd9Z0/zNR/HC BJujP38r3FqOeEvpzOXLAq1s8U0hfOc8Wd07/2jCQuoUk3fqh6DvfkP/VtF9IEAP1VhS LDN5JktwGkN99Mr+l1O2RhP1iyits8L0U5KE6S9atF5XMMfEjZnTMszslGnbA/zM7FJY Mhykr9veTCGANDtUvOUFkx04pFPAqd15NanVXsvcMZqDwn6pGk9lhtspCqmoeVLzZPM5 2t6Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xOHtuWpv; 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 yf13-20020a05620a3bcd00b0078eba18c1e5si4171217qkn.705.2024.05.03.17.06.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 17:06:19 -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=xOHtuWpv; 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 709FF386F426 for ; Sat, 4 May 2024 00:06:19 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id AEB05384476C for ; Sat, 4 May 2024 00:05:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AEB05384476C 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 AEB05384476C Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714781140; cv=none; b=PJYrkWHe9A1J5WapwTBy0aaylB0FRCmne/XwQ/f29RNT5cLVlNSxIT0BwvT4oDDYek4AWUF28elGRYQRrFPXzkgQXLCtMjs3YyRZJxQpoSszii5eOWbixjyeWVFTrMAmGqLi4F2GfYr70pGUZq+1E/eUfgUupEtykxUs3ln4yG4= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714781140; c=relaxed/simple; bh=Mk88gP6CXxklUiMRj8QxF6+pEDH7g5U4XoK7QAvC4sU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=O7c0/qoIkrvbvmgpoWKJwLA/DAW49heqGwkJO39yKUzzdb8/AHQHEHdY3DY3bFQC7MYGFJQETV7LULRCOEqL+8x89bU6v3jHvKt2XxhNL2K+0keDvwtsp0t349VL6jJsMMPxlkgDbeez5vR5QAUOjTZD2CzzOdhL/uPQxUbglDo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6f453d2c5a1so265655b3a.2 for ; Fri, 03 May 2024 17:05:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714781136; x=1715385936; 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=x6tAzyEiM50fLZnGF9T10lQdqQJkOFJz6OH73fa4REs=; b=xOHtuWpvEAJbXqXwXb11ZmbWEqIRrgQFg+cKPHDpuSQ/hSeVpEUN5t1NSkoc+mDxCV qZz3acDUppCEE/yNvwz/upK6EqyiAvm7OOrPPiL5/ZzOYEgcaaOP+TS4AkXkJkfs/4MI Ohz+qoOiBB2vVRyl6+7xYj5gHfdsu6sAdLUgiZfbuV4cZ2/iOShDbskb31g5kqo6u9xj bPBP14AvFwHNpTj93+NvnDO2a+GBGIh//tuEdDQ63MnoIzkknAU/EFVuKWXv+nIpMU7t S4Q+pzesivsmzW05SICiSbFmKVSp4DOCQQzwwyeMqzHLZdMNxQJsCdOfUeuzmaOXQycR ODPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714781136; x=1715385936; 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=x6tAzyEiM50fLZnGF9T10lQdqQJkOFJz6OH73fa4REs=; b=oJXrJBLS6yszrZyF6UE+/MVB93bYxgcKLjOkenphJJTqY8M+ZSnOJ/eHSXnV1V0BK7 qeWA1Yh30wOHcaoKdds/ipc4JwA32+gIHytIFm6tj0hAIw/lEcnNBjdnfxEOuwugUt8X MGIqLxGYw6Vt7ZTbuaFCRHU+c/bcBv0LyFPB2E/UOGcvTxVkKJu8ibbIx8jp5AlW3Bvn B6OYoWuj2SOkL0o4XJdPXdw+bZZbVt9/x37eQjWNFHmtBi56rt3oF47G6uc/EOrbz+yI 4HNJeYLlGml3g9YOMHpEXu6V6CVFKX9ZKGrJZTPTNcjSPHiiTPAJtml5IdzD89RERTNh Zd5g== X-Gm-Message-State: AOJu0YxZLWxStNwR1o5x2umhUvM0e9EkvI2C1NP0jXHKhiz4MDhr0eYt p48Wk45xkyCWZ6q1MX9vpWElFqZAWXCoINWosLHprVTS7WZ8PnSJYwyI3AkhF4KSvYRj4AOZMKe i X-Received: by 2002:a05:6a00:a1a:b0:6f3:368d:6f64 with SMTP id p26-20020a056a000a1a00b006f3368d6f64mr5474090pfh.2.1714781136521; Fri, 03 May 2024 17:05:36 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:50e3:94e0:79b0:c9f9]) by smtp.gmail.com with ESMTPSA id it21-20020a056a00459500b006f4401df6c9sm3271302pfb.113.2024.05.03.17.05.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 17:05:36 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Subject: [PATCH 3/5] gdb/testsuite: Add gdb.arch/aarch64-mops-watchpoint.exp Date: Fri, 3 May 2024 21:05:19 -0300 Message-ID: <20240504000521.314531-4-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240504000521.314531-1-thiago.bauermann@linaro.org> References: <20240504000521.314531-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 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 Test behaviour of watchpoints triggered by MOPS instructions. This test is similar to gdb.base/memops-watchpoint.exp, but specifically for MOPS instructions rather than whatever instructions are used in the libc's implementation of memset/memcpy/memmove. There's a separate watched variable for each set of instructions so that the testcase can test whether GDB correctly identified the watchpoint that triggered in each case. --- .../gdb.arch/aarch64-mops-watchpoint.c | 66 ++++++++++++++++ .../gdb.arch/aarch64-mops-watchpoint.exp | 79 +++++++++++++++++++ gdb/testsuite/lib/gdb.exp | 61 ++++++++++++++ 3 files changed, 206 insertions(+) create mode 100644 gdb/testsuite/gdb.arch/aarch64-mops-watchpoint.c create mode 100644 gdb/testsuite/gdb.arch/aarch64-mops-watchpoint.exp diff --git a/gdb/testsuite/gdb.arch/aarch64-mops-watchpoint.c b/gdb/testsuite/gdb.arch/aarch64-mops-watchpoint.c new file mode 100644 index 000000000000..b981f033d210 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-mops-watchpoint.c @@ -0,0 +1,66 @@ +/* This test program is part of GDB, the GNU debugger. + + Copyright 2024 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +int +main (void) +{ + char source[40] __attribute__ ((aligned (8))) + = "This is a relatively long string..."; + char a[40] __attribute__ ((aligned (8))) + = "String to be overwritten with zeroes"; + char b[40] __attribute__ ((aligned (8))) + = "Another string to be memcopied..."; + char c[40] __attribute__ ((aligned (8))) + = "Another string to be memmoved..."; + char *p, *q; + long size, zero; + + /* Break here. */ + p = a; + size = sizeof (a); + zero = 0; + /* memset implemented in MOPS instructions. */ + __asm__ volatile ("setp [%0]!, %1!, %2\n\t" + "setm [%0]!, %1!, %2\n\t" + "sete [%0]!, %1!, %2\n\t" + : "+&r"(p), "+&r"(size) + : "r"(zero) + : "memory"); + + p = b; + q = source; + size = sizeof (b); + /* memmove implemented in MOPS instructions. */ + __asm__ volatile ("cpyp [%0]!, [%1]!, %2!\n\t" + "cpym [%0]!, [%1]!, %2!\n\t" + "cpye [%0]!, [%1]!, %2!\n\t" + : "+&r" (p), "+&r" (q), "+&r" (size) + : + : "memory"); + p = c; + q = source; + size = sizeof (c); + /* memcpy implemented in MOPS instructions. */ + __asm__ volatile ("cpyfp [%0]!, [%1]!, %2!\n\t" + "cpyfm [%0]!, [%1]!, %2!\n\t" + "cpyfe [%0]!, [%1]!, %2!\n\t" + : "+&r" (p), "+&r" (q), "+&r" (size) + : + : "memory"); + + return 0; +} diff --git a/gdb/testsuite/gdb.arch/aarch64-mops-watchpoint.exp b/gdb/testsuite/gdb.arch/aarch64-mops-watchpoint.exp new file mode 100644 index 000000000000..9e210602d800 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-mops-watchpoint.exp @@ -0,0 +1,79 @@ +# Copyright 2024 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# Test a binary that uses MOPS (Memory Operations) instructions. +# This test is similar to gdb.base/memops-watchpoint.exp, but specifically +# tests MOPS instructions rather than whatever instructions are used in the +# system libc's implementation of memset/memcpy/memmove. + +require allow_hw_watchpoint_tests allow_aarch64_mops_tests + +standard_testfile + +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ + [list debug additional_flags=-march=armv9.3-a]] } { + return -1 +} + +set linespec ${srcfile}:[gdb_get_line_number "Break here"] +if ![runto ${linespec}] { + return -1 +} + +gdb_test "watch -location a\[28\]" \ + "(Hardware w|W)atchpoint ${decimal}: -location a\\\[28\\\]" \ + "set watch on a" +gdb_test "watch -location b\[28\]" \ + "(Hardware w|W)atchpoint ${decimal}: -location b\\\[28\\\]" \ + "set watchpoint on b" +gdb_test "watch -location c\[28\]" \ + "(Hardware w|W)atchpoint ${decimal}: -location c\\\[28\\\]" \ + "set watchpoint on c" + +gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + "" \ + "Hardware watchpoint ${decimal}: -location a\\\[28\\\]" \ + "" \ + "Old value = 104 'h'" \ + "New value = 0 '\\\\000'" \ + "$hex in main \\(\\) at .*aarch64-mops-watchpoint.c:$decimal" \ + "${decimal}\\s+__asm__ volatile \\(\"setp.*\\\\n\\\\t\""] \ + "continue until set watchpoint hits" + +gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + "" \ + "Hardware watchpoint ${decimal}: -location b\\\[28\\\]" \ + "" \ + "Old value = 101 'e'" \ + "New value = 114 'r'" \ + "$hex in main \\(\\) at .*aarch64-mops-watchpoint.c:$decimal" \ + "${decimal}\\s+__asm__ volatile \\(\"cpyp.*\\\\n\\\\t\""] \ + "continue until cpy watchpoint hits" + +gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + "" \ + "Hardware watchpoint ${decimal}: -location c\\\[28\\\]" \ + "" \ + "Old value = 100 'd'" \ + "New value = 114 'r'" \ + "$hex in main \\(\\) at .*aarch64-mops-watchpoint.c:$decimal" \ + "${decimal}\\s+__asm__ volatile \\(\"cpyfp.*\\\\n\\\\t\""] \ + "continue until cpyf watchpoint hits" diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp index fe3f05c18df9..78c926ac80b6 100644 --- a/gdb/testsuite/lib/gdb.exp +++ b/gdb/testsuite/lib/gdb.exp @@ -4497,6 +4497,67 @@ proc aarch64_supports_sme_svl { length } { return 1 } +# Run a test on the target to see if it supports Aarch64 MOPS (Memory +# Operations) extensions. Return 0 if so, 1 if it does not. Note this causes +# a restart of GDB. + +gdb_caching_proc allow_aarch64_mops_tests {} { + global srcdir subdir gdb_prompt inferior_exited_re + + set me "allow_aarch64_mops_tests" + + if { ![is_aarch64_target]} { + return 0 + } + + # ARMv9.3-A contains the MOPS extension. The test program doesn't use it, + # but take the opportunity to check whether the toolchain knows about MOPS. + set compile_flags "{additional_flags=-march=armv9.3-a}" + + # Compile a program that tests the MOPS feature. + set src { + #include + #include + + #ifndef HWCAP2_MOPS + #define HWCAP2_MOPS (1UL << 43) + #endif + + int main() { + bool mops_supported = getauxval (AT_HWCAP2) & HWCAP2_MOPS; + + return !mops_supported; + } + } + + if {![gdb_simple_compile $me $src executable $compile_flags]} { + return 0 + } + + # Compilation succeeded so now run it via gdb. + clean_restart $obj + gdb_run_cmd + gdb_expect { + -re ".*$inferior_exited_re with code 01.*${gdb_prompt} $" { + verbose -log "\n$me mops support not detected" + set allow_mops_tests 0 + } + -re ".*$inferior_exited_re normally.*${gdb_prompt} $" { + verbose -log "\n$me: mops support detected" + set allow_mops_tests 1 + } + default { + warning "\n$me: default case taken" + set allow_mops_tests 0 + } + } + gdb_exit + remote_file build delete $obj + + verbose "$me: returning $allow_mops_tests" 2 + return $allow_mops_tests +} + # A helper that compiles a test case to see if __int128 is supported. proc gdb_int128_helper {lang} { return [gdb_can_simple_compile "i128-for-$lang" {