From patchwork Tue May 7 02:22:47 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: 795198 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:34e:ceec:bfcd with SMTP id k28csp88655wrc; Mon, 6 May 2024 19:24:08 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV6byl/y9TXvqKkmk+MyjrXTBYXCGrPLPTQ6FPfg5/nQcZi0aJPLxGBvs+YZm6ThH46KbR++mc78l2V5cweiBv5 X-Google-Smtp-Source: AGHT+IFLb/KRBgpTeOnoRS1ArUYR/ca6KQEfmmErxSro5Klzyss91vFLjTIjtcpstqJChWerS73b X-Received: by 2002:a05:620a:43a0:b0:790:6619:aa50 with SMTP id a32-20020a05620a43a000b007906619aa50mr14343146qkp.64.1715048648690; Mon, 06 May 2024 19:24:08 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715048648; cv=pass; d=google.com; s=arc-20160816; b=osGqrBLfK1BuoXYwWxPmDDTcfSAgwUU0B2ZGghzlX3MD7gK5J9zBHlwn4X/TrCDdu6 q0tTFcsXzX0PJ/nFB3u70H9HOaamCU6WwmaZg4X8VvdcFlT3m9E0GbVuzdYEUffw/piS P6AdTKh7Vjh+DLE7NwDnWEMpmTft238pLKgIibFA1sLlDDvGGv7uGG3I8eLO5YwQr/O6 uLvhHXok/aDDr7FoUVHokzUELk2Feyj+WE175DDS/RY/2qdAeTH9OoTpokj7Uz2nfhu8 qikQURVmCd2fmCtrXY4qIH7Hd54fhotSETEVidgymtRECe5/rhGKHGORVdkxNWKGLzuP BDjQ== 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:cc:to :from:dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=jK0lpo3PfnJUQjmadW7fHId5lyb0jsXDiINF5/l4n7w=; fh=AA1/l1kx9p7hoPrYVWA5ku4B9TvBXTIEFDQu7s+joq4=; b=J3UGsJNO18zUkJ0wFzd3RZyG4z/YMLhE8R1Hsax9I1dXNljvhpZDyz8+aQgDyyNtwN U08pEAuDGsK8NEIQIuUEylkZYWleMEY3Hf4P9t6F5ML+3XLB/QkFfJWCUeQ+LkvK2z6x ta+yUjgsmMvJwAc093fV94YDM+SEN67ch8hvACXigc2XNhZhRenGL/EDFM8+a6TgAt9t 87a+c6fmUcyg4o8pa2j14TRW/pjmRX3AMtAqiIUfVOWeODgMyfL5xXMTwR3wrd9Uym3S UHwgNRTxbP1wtgr8kvU4lrcy114Zvd1E2I7k7/Yod6LahzaE6S69do2veCUFk8tEmxNp rwkQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ogaNvmYe; 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 i14-20020a05620a404e00b0078eb9923f25si11610648qko.525.2024.05.06.19.24.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 19:24:08 -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=ogaNvmYe; 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 3705A3858CDA for ; Tue, 7 May 2024 02:24:08 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id 190B3384DD00 for ; Tue, 7 May 2024 02:23:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 190B3384DD00 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 190B3384DD00 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715048585; cv=none; b=szFzkb0w3rA+S3ck3xn6FCxgIbmOTV5PV8wEXUFX5/0eFDNZC+7QHd3tB5f9CbZo6MGm8uFyT6hevxnTZuQcfoi7b6vYKehzot8LW44/O+yUFra1nxDX4KPfRNvb675lIjemLbFAqayfZlyuRuRzssZceFguEcIHoBBvyN3L70k= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715048585; c=relaxed/simple; bh=HmgXD1J0ATTamJyrtJaYGdyjIOgOV0OGqAToskCL4vo=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=vZ4GazJQO+Fhm5rWK24uRhhjxLanJMnbOjIj05MFkpYIHVc2iaQg4HlcIYr4Yb+3WfYGVxkPtwIZ2oiEAJ1VLcfcxTba16pckRqucbtEc29mrujouUnihfEEpMn1Zp/tww/Bh+cyxQjakPZDeTzGMSOHO5FzZkwkXaAq9OSpi9E= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-1ec4dc64c6cso17815205ad.0 for ; Mon, 06 May 2024 19:23:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715048582; x=1715653382; darn=sourceware.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jK0lpo3PfnJUQjmadW7fHId5lyb0jsXDiINF5/l4n7w=; b=ogaNvmYeGQnMRoI1dS2HGj7R1dFCkbmS7HOeIPxcRw9ZPgGt3r0PaPYu01MPHrNl+k 8qIFOw8jsPnirzVHrSZUONeNN2nmJhm5R5bgOCFdbRulDhbN7/ZeGZiusMg40LJC48o2 0Gh7xNZI0I0w2ngfVooAKs57ud4c1RUliy2TGu7Kv9q7PagwojQWyormrc5bJ7kWDH+/ GcqBPDC4ZTJEowofWxBgTQ1Lk+vhQl0XzHR+E4rsSwhCKZf/5UHFzWUyAFMlG0M+4GNI THaMX/jp6bv2jrEhRWhkcMC/vm8U/G6ChNrRi3h7KSelLQ5DKHu+g1XDglISZJYzNsU4 ORFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715048582; x=1715653382; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jK0lpo3PfnJUQjmadW7fHId5lyb0jsXDiINF5/l4n7w=; b=LcjMn8XxRDaBH5H7JXZGKFlbvIfqq/wZsZYBom3qiwqCOFW0Ttqjrf1kg7pfXZfNoB qb4S43GwuCogjjUOtAH1Lr65OW0QKrN4t1RAXNs160fDn2mx5qMOLjnxq7mFdI1xNPcQ H90S8m1b6xPUQS8NluRF6JX+GLtOc0Gvi/R9ZX5Gvy8JFhNoP5QUicl8vyfKbxNJ3BS/ fGp+4I1gnaBq2abqL8d3mq5NtsT5Boa0pWaAiFhIM7OjeCERp4lpD06ygq60s9vpMeT8 nwSaLiN91aTxBBSRP3uDYMwFBCQXAhvITQu4VdxB0enkxoiTWQo9Td8Bd4M+WAaK5mAz /vYw== X-Gm-Message-State: AOJu0YyEFy7ytfN/gMDbnnzm48md+z2Pt0f0yrD21fSEtPXxzOLVuhE2 DmMTQRamBJEc1oQSKCGlHJ5SkUZ6Nnr75sxrxqsQleaaZKlNBdnCPOxCd8CBC+zqH16PNsl+9HR Z X-Received: by 2002:a17:902:ea02:b0:1e8:4ad9:cbdf with SMTP id s2-20020a170902ea0200b001e84ad9cbdfmr15333528plg.13.1715048581864; Mon, 06 May 2024 19:23:01 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:38ad:4156:59df:8141]) by smtp.gmail.com with ESMTPSA id b9-20020a170902650900b001e2bfd40b86sm3363869plk.47.2024.05.06.19.23.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 19:23:01 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Christophe Lyon Subject: [PATCH v2 3/5] gdb/testsuite: Add gdb.arch/aarch64-mops-watchpoint.exp Date: Mon, 6 May 2024 23:22:47 -0300 Message-ID: <20240507022249.554831-4-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240507022249.554831-1-thiago.bauermann@linaro.org> References: <20240507022249.554831-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 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 No change in v2. 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" {