From patchwork Fri May 10 05:24:08 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: 796031 Delivered-To: patch@linaro.org Received: by 2002:a5d:452e:0:b0:34e:ceec:bfcd with SMTP id j14csp668972wra; Thu, 9 May 2024 22:25:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVqRtKr1u9RJ+UXSxtG+HuAd3T5YHaOoY302DQVBhEI+sLl543qea8tMdbQWye1jIDgxALklr2nPLwfomWYXAmA X-Google-Smtp-Source: AGHT+IGH0x7h2yOUWhGNufz6rqp9+Atxhkkqk8FnpV01ZAFnD+mFfCLXhvF2O2vfv5RdxnIrmWpo X-Received: by 2002:ae9:c103:0:b0:790:cb19:3205 with SMTP id af79cd13be357-792c75ffa6emr174877485a.74.1715318715416; Thu, 09 May 2024 22:25:15 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715318715; cv=pass; d=google.com; s=arc-20160816; b=uPqjpQ5c+yIEW99Ewuzhe7bkaersAXsPvK3srH1L7xtV43y0/GDgkGXw9eflfjcY2v 1YVmHZ1NV7rBnyaEDf7rf0v/uWl3IhJCwUvbFhh89wTcbHGpJvvx4r9cuq5IERNbJrIf yy3BeYkkdSiiO5q+Ux8faDGW64ekWaczhXEmOoQHyAb8ktMy6N30EVEcqsJ6ff2RrP/j PjZ5LbrbZOrc7EYKkaK2uunJzwYkoghHp8VnaMOkz2qcBTbzX8pur5TAK50P0miFxUF8 aLQ/Ml5Ws3HqkYAMOjIXQTASnIh5NyIbhW4Roq2qtYL0AjFGhIIMmh45u/wn+/NsCwyE +ReA== 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=eNgr8QBqk40xJ5H8ax7gu6F3/0FDwEJj//6MPJSjrWo=; fh=fCgs51ICTgFk+vSt57NFPMWoUahXD4XhqjP2ci5WYSU=; b=EGZUjgQPiXCGMTDXR20r5W3KUehRP7vGwM57WNeSuthDTbM43pdMQ+bJNMHV8cPFo5 z0CP0p8tblPRzcj0E/0cI4Gm5vdpViNtX2qXQ4qM2MQV7Wqlk245OyHmVEW67WRVVTAT ZEIB8ys6/6dskLRfvsfCZmLVV6U8p7z4kTVSgjjTh/uncnNgsfUmQdH4NxjSMploQWQW Gfih3vGIZ76ss14CinZU+bjNSZKgL/YBreTmFkF0kchvzvXV13l55XYRPxarzz4Ut1s6 vnwlLMBxofEzdDq5dcrGnkss4V9z5VEHRWSiyqbITXwLWqBBoQ1bZAfpIjbPbD1Wfdwb CXeg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VC20cvT4; 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-792bf30ab94si316816785a.336.2024.05.09.22.25.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 22:25:15 -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=VC20cvT4; 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 F28BF384404C for ; Fri, 10 May 2024 05:25:14 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id 82E1E386EC04 for ; Fri, 10 May 2024 05:24:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 82E1E386EC04 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 82E1E386EC04 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::434 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715318674; cv=none; b=PlBuTTExz4vwdhmOzw+LxNRcnsMw2q/Uo4P/wqhfqPsEId2uV+d3vcprMwq95IDQYtGCPtsUSNbSPjBqTUD9yKpeFZMG2RTqHhnwO85GKr3fsK0X2GwjYVW/i9sidxsy4GRH50cz/zn1ejXW9gR9bNwJFpnvNbUa5zkd4/Ufm74= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715318674; c=relaxed/simple; bh=syB7HsI5AE7yzvQ94uZhUQq4ApgQi2/o+C6xP+lTZoI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KgKL4kRIVDX7dBDc0JSon4c2UE6CztT/ltjuOOqSlwhMdbzpG799jsflZTp60l0tGFWiak8r0J2MTNYofT8AwMkXOe2TSY0cRgFcTjbR81ZZgmRoRMuxkDzMT96kU/v/r3xYmqTEm6aGF8glbT8MJ8q81nOCnaU88nJehM2pbWI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6ed3cafd766so1529574b3a.0 for ; Thu, 09 May 2024 22:24:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715318669; x=1715923469; 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=eNgr8QBqk40xJ5H8ax7gu6F3/0FDwEJj//6MPJSjrWo=; b=VC20cvT4xINzvL/OJ4jSiXq/qQVnlMd+erT6uxD75/iqg+pMJctOljm7ABR1AMhaq5 RXVybvhdOkWotJGNEjtiQZE5lHk+cgiu0z6BIptUpClq/dfe6+On+rTkQmWQbl6SAken vu4RuIrU2msutABZRTAjUvxJBgvcIDYuaKqEZfVcLpP6Kz1/6T7LYEcYvbvI04Weuidu kElBJ01NQMyUU0n10Dsgshzz2IUvZNMXJLy4G6AyhD51ZmyYu+/ftZ0AfdgK9gFfnh+H F1/KA2hqbjYDSSn+2xV8yj/N2Eh6SRNGQ2kA3SJXQ/T+DilKGezYXUgQhCPY5OHCY2s6 znxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715318669; x=1715923469; 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=eNgr8QBqk40xJ5H8ax7gu6F3/0FDwEJj//6MPJSjrWo=; b=jdFC+xZtucrTs8Xw7Vf+qVmo75C45/eioC1HmvPcaVSZDaFQ4vCOL1FiCPcHjNyi3c PnlsBiAD52ZrZ1EznI5penGd6DxSzcWKQ14ME5mYV2ka6Bc+6m/EPf0kn689RxRS0Fhb bFLRG3xxLF5ZVe1XROKEpW5mE2lv351RW8y+Rjt7bnCAO8mMmIetWxZPbYfH0g3y0t1l uYpN34ot8lTMHzMicAxQIuKpWJ34BQJFa0/S0oLO0wSy4Di2Au4mpf26Ji9fcMWmkpIK fwlyYA41ENAPa9YQKxkWE7NMU7qMAeTioRWbGBRdK6R4A4dWr6oFqarFXP9vt3Ot/ZPZ WhSg== X-Gm-Message-State: AOJu0YzTH2U5ocXGPo0I4YS+0mMZkspTLBkotjwXV3l2zh6kdS+NR+Ft gzz0YZD4KD1rPprI2jsdwejzvkJJQkMe+W+6/6fgaMXQ8ViGPfgZ6uWA3wzbENZqH6ger5oDPW5 m X-Received: by 2002:a05:6a00:1892:b0:6f0:b53c:dfb1 with SMTP id d2e1a72fcca58-6f4e029bae3mr1637387b3a.1.1715318669083; Thu, 09 May 2024 22:24:29 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:9d31:c7dc:c8bd:73d9]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-6f4d2b373e5sm2168661b3a.219.2024.05.09.22.24.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 May 2024 22:24:28 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Christophe Lyon , Luis Machado Subject: [PATCH v3 5/5] gdb/testsuite: Add gdb.reverse/aarch64-mops.exp Date: Fri, 10 May 2024 02:24:08 -0300 Message-ID: <20240510052408.2173579-6-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20240510052408.2173579-1-thiago.bauermann@linaro.org> References: <20240510052408.2173579-1-thiago.bauermann@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 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 The testcase verifies that MOPS instructions are recorded and correctly reversed. Not all variants of the copy and set instructions are tested, since there are many and the record and replay target processes them in the same way. --- gdb/testsuite/gdb.reverse/aarch64-mops.c | 71 +++++++++ gdb/testsuite/gdb.reverse/aarch64-mops.exp | 171 +++++++++++++++++++++ 2 files changed, 242 insertions(+) create mode 100644 gdb/testsuite/gdb.reverse/aarch64-mops.c create mode 100644 gdb/testsuite/gdb.reverse/aarch64-mops.exp No change since v1. diff --git a/gdb/testsuite/gdb.reverse/aarch64-mops.c b/gdb/testsuite/gdb.reverse/aarch64-mops.c new file mode 100644 index 000000000000..513f324b9dd6 --- /dev/null +++ b/gdb/testsuite/gdb.reverse/aarch64-mops.c @@ -0,0 +1,71 @@ +/* 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 . */ + +#define TEST_STRING "Just a test string." +#define BUF_SIZE sizeof(TEST_STRING) + +int +main (void) +{ + char dest[BUF_SIZE]; + char source[BUF_SIZE] = TEST_STRING; + register char *p asm ("x19"); + register char *q asm ("x20"); + register long size asm ("x21"); + register long zero asm ("x22"); + + p = dest; + size = BUF_SIZE; + zero = 0; + /* Before setp. */ + /* 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"); + + /* After sete. */ + p = dest; + q = source; + size = BUF_SIZE; + /* Before cpyp. */ + /* 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"); + /* After cpye. */ + p = dest; + q = source; + size = BUF_SIZE; + /* Before cpyfp. */ + /* 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"); + /* After cpyfe. */ + p = dest; + + return 0; +} diff --git a/gdb/testsuite/gdb.reverse/aarch64-mops.exp b/gdb/testsuite/gdb.reverse/aarch64-mops.exp new file mode 100644 index 000000000000..f9c1257e0b11 --- /dev/null +++ b/gdb/testsuite/gdb.reverse/aarch64-mops.exp @@ -0,0 +1,171 @@ +# 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 instruction record for AArch64 FEAT_MOPS instructions. +# Based on gdb.reverse/ppc_record_test_isa_3_1.exp +# +# The basic flow of the record tests are: +# 1) Stop before executing the instructions of interest. Record +# the initial value of the registers that the instruction will +# change, i.e. the destination register. +# 2) Execute the instructions. Record the new value of the +# registers that changed. +# 3) Reverse the direction of the execution and execute back to +# just before the instructions of interest. Record the final +# value of the registers of interest. +# 4) Check that the initial and new values of the registers are +# different, i.e. the instruction changed the registers as expected. +# 5) Check that the initial and final values of the registers are +# the same, i.e. GDB record restored the registers to their +# original values. + +require 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 +} + +if ![runto_main] { + return -1 +} + +gdb_test_no_output "record full" + +proc do_test { insn_prefix } { + global decimal hex + + set before_seq [gdb_get_line_number "Before ${insn_prefix}p"] + set after_seq [gdb_get_line_number "After ${insn_prefix}e"] + + with_test_prefix $insn_prefix { + gdb_test "break $before_seq" \ + "Breakpoint $decimal at $hex: file .*/aarch64-mops.c, line $decimal\\." \ + "break before instruction sequence" + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + "" \ + "Breakpoint $decimal, main \\(\\) at .*/aarch64-mops.c:$decimal" \ + "$decimal\[ \t\]+__asm__ volatile \\(\"${insn_prefix}p \[^\r\n\]+\""] \ + "about to execute instruction sequence" + + # Record the initial register values. + set x19_initial [capture_command_output "info register x19" ""] + set x21_initial [capture_command_output "info register x21" ""] + + # The set instructions use the ZERO variable, but not Q, and the other + # instructions are the opposite. + if {[string compare $insn_prefix "set"] == 0} { + set x22_initial [capture_command_output "info register x22" ""] + } else { + set x20_initial [capture_command_output "info register x20" ""] + } + + gdb_test "break $after_seq" \ + "Breakpoint $decimal at $hex: file .*/aarch64-mops.c, line $decimal\\." \ + "break after instruction sequence" + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + "" \ + "Breakpoint $decimal, main \\(\\) at .*/aarch64-mops.c:$decimal" \ + "$decimal\[ \t\]+p = dest;"] \ + "executed instruction sequence" + + # Record the new register values. + set x19_new [capture_command_output "info register x19" ""] + set x21_new [capture_command_output "info register x21" ""] + + if {[string compare $insn_prefix "set"] == 0} { + set x22_new [capture_command_output "info register x22" ""] + } else { + set x20_new [capture_command_output "info register x20" ""] + } + + # Execute in reverse to before the instruction sequence. + gdb_test_no_output "set exec-direction reverse" + + gdb_test "continue" \ + [multi_line \ + "Continuing\\." \ + "" \ + "Breakpoint $decimal, main \\(\\) at .*/aarch64-mops.c:$decimal" \ + "$decimal\[ \t\]+__asm__ volatile \\(\"${insn_prefix}p \[^\r\n\]+\""] \ + "reversed execution of instruction sequence" + + # Record the final register values. + set x19_final [capture_command_output "info register x19" ""] + set x21_final [capture_command_output "info register x21" ""] + + if {[string compare $insn_prefix "set"] == 0} { + set x22_final [capture_command_output "info register x22" ""] + } else { + set x20_final [capture_command_output "info register x20" ""] + } + + # Check initial and new values of x19 are different. + gdb_assert [string compare $x19_initial $x19_new] \ + "check x19 initial value versus x19 new value" + + # Check initial and new values of x21 are different. + gdb_assert [string compare $x21_initial $x21_new] \ + "check x21 initial value versus x21 new value" + + if {[string compare $insn_prefix "set"] == 0} { + # Check initial and new values of x22 are the same. + # The register with the value to set shouldn't change. + gdb_assert ![string compare $x22_initial $x22_new] \ + "check x22 initial value versus x22 new value" + } else { + # Check initial and new values of x20 are different. + gdb_assert [string compare $x20_initial $x20_new] \ + "check x20 initial value versus x20 new value" + } + + # Check initial and final values of x19 are the same. + gdb_assert ![string compare $x19_initial $x19_final] \ + "check x19 initial value versus x19 final value" + + # Check initial and final values of x21 are the same. + gdb_assert ![string compare $x21_initial $x21_final] \ + "check x21 initial value versus x21 final value" + + if {[string compare $insn_prefix "set"] == 0} { + # Check initial and final values of x22 are the same. + # The register with the value to set shouldn't change. + gdb_assert ![string compare $x22_initial $x22_final] \ + "check x22 initial value versus x22 final value" + } else { + # Check initial and final values of x20 are the same. + gdb_assert ![string compare $x20_initial $x20_final] \ + "check x20 initial value versus x20 final value" + } + + # Restore forward execution and go to end of recording. + gdb_test_no_output "set exec-direction forward" + gdb_test "record goto end" \ + [multi_line \ + "Go forward to insn number $decimal" \ + "#0 main \\(\\) at .*/aarch64-mops.c:$decimal" \ + "$decimal\[ \t\]+p = dest;"] + } +} + +do_test "set" +do_test "cpy" +do_test "cpyf"