From patchwork Thu May 23 03:51:24 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: 90712 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9ABDE3865490 for ; Thu, 23 May 2024 03:52:22 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) by sourceware.org (Postfix) with ESMTPS id CB8BD38654AD for ; Thu, 23 May 2024 03:51:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CB8BD38654AD 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 CB8BD38654AD Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716436302; cv=none; b=GUdfztsXi23F8J1u5l/kmgrO8YFYaQRjaP862suK8uPHcAJze7xCJK2EG5dVVNYRhNwnb1UPJUPK5DuQ5iy5UCfEJ+NusQmGmpyaKAHlyq5/oNpNNkbB8koKfr9qQt78dz4F2IyilL4QWEJeegmoPa7h0HIYLKFJ00kP4Iu3nWs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716436302; c=relaxed/simple; bh=MCukXILfTqNFR9VFFKkVJeeWOlnNv03R4Xipj2Jdu4s=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FyZgYwtx9PLnLYtuUn2nsC5h3RTd+D/jOD8i3SJs0BoEXDSPWxNCNlEwrKvAKtBf7uNPvezacsHdwjjZuPGhrQUalsiOb/KXevacXDqFug8yKi2rPGLQRk0/RqT4rr/YfQn6akipTVsd4J0/B4pjhFPcNnrDq5ZCoFmqVkRs82Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42f.google.com with SMTP id d2e1a72fcca58-6f693fb0ad4so2419689b3a.1 for ; Wed, 22 May 2024 20:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1716436299; x=1717041099; 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=+Hlgtl9IW3h71ehJygtrZ7Azc2qhSTdSpst7m2YEwI0=; b=yvDP7i9sw9SeRhq8Eucq8edcFSrLHF1r3VHtay9KWUgQ/+K+bEOO1eq2lSUc3eILuS iK26akmRzwKfRJ7TiLAvZb57FanVymlLBEC9rvNAmEl43BCGXCd5wDhYHK7gT8Mcs+mN Tnv5YnvohvudHi0edX111JAMfGOzUBZOKlQ6LL1b5bSXx7ne7zu6YuY2E8W3fPlK7cLc NA25QvZKu7ordbCUbzJp+pDLcIspGGKsczd4caG4ZxT4nqfVbuGreSZRRR2Xp0hkVngy wVl2RMiwuQj2KysQ9sjCxrxN18M6avm2gljnmOdh9+ZEIS0OIskaeJ0Rb/yrqPN8RI/d Vrsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716436299; x=1717041099; 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=+Hlgtl9IW3h71ehJygtrZ7Azc2qhSTdSpst7m2YEwI0=; b=LDbik+t26KJkB/lCVAdIpwlaZz3IHWGXdZtFDGb9uoI3TYgA0ySuxXnA1LEJ+psKGo 1LM1VvVXTt5mgNyAMXJuSNFCU4LKvaR8gZCOt/VFTG93PN0QSdHqNDi5hzbR9cLmWfVT 1Q8uQprwmkvL12f2G/i2YzYSO3FlNm01J+94YBar3y4UBzSfRTsJaVXrIMva1TpFAset 3F/xM5BrTTqP0+7t4JMzjp0TP/jta71ergQAHkRYad7KwFYDYphdFQLU8w5BinsrvAzR SsE0skszZU7h1rcPF/ScgEWnTAP5staLHNws6zGeShaLms8Ie3Itx7jhKTeK9emRJSEm RmzA== X-Gm-Message-State: AOJu0YxgwxgNyrxvO65LEULDimk0lrrH790q0wKdRfav8aRCSiKidtZ2 NOdNmbPmWoDSo7Xh48qri5i4Qv9SOrtrgDfOOWBQY+nYoB+lchgZMLGXNlitV8Z0TprlYnFksWx I X-Google-Smtp-Source: AGHT+IG+dOvYNZs69ENtsmI3OVYaCaOdQ+H8LW87khu9ahqGWVO/4AsmdZ8k8OfHQZOfjqnQvItmuw== X-Received: by 2002:a05:6a00:3a25:b0:6ed:4f2e:ef22 with SMTP id d2e1a72fcca58-6f6d61e9ffemr4432177b3a.31.1716436298763; Wed, 22 May 2024 20:51:38 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:f149:d562:aa25:4733]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f679902e57sm12778803b3a.110.2024.05.22.20.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 May 2024 20:51:38 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Christophe Lyon , Luis Machado , Guinevere Larsen , Pedro Alves Subject: [PATCH v4 3/3] gdb/testsuite: Add gdb.arch/aarch64-mops-watchpoint.exp Date: Thu, 23 May 2024 00:51:24 -0300 Message-ID: <20240523035124.2639220-4-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240523035124.2639220-1-thiago.bauermann@linaro.org> References: <20240523035124.2639220-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 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+patchwork=sourceware.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. --- Changes in v4: - Moved procedure allow_aarch64_mops_tests to patch 1. - Fix typo in comment (Spotted by Luis). No change in v1, v2 or v3. .../gdb.arch/aarch64-mops-watchpoint.c | 66 ++++++++++++++++ .../gdb.arch/aarch64-mops-watchpoint.exp | 79 +++++++++++++++++++ 2 files changed, 145 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"