From patchwork Tue May 7 02:22:49 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: 795197 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:34e:ceec:bfcd with SMTP id k28csp88637wrc; Mon, 6 May 2024 19:24:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXWhMy/mXxlJjAtAeyRcVEw4+8+KNYSwL3VTEHRXgujXxkET0Spa9hj7x5kyP4+XaESe6AKLBtQW0Ao5DI3f1wi X-Google-Smtp-Source: AGHT+IHT4aWZFYwxQz+y6nwSBPTigLxuTuMrbjVlF1k853EwzOmy1pnAXPSjXTLc4WpHCvSVvIVS X-Received: by 2002:a05:622a:592:b0:43a:ed9c:36f3 with SMTP id c18-20020a05622a059200b0043aed9c36f3mr13557440qtb.42.1715048645607; Mon, 06 May 2024 19:24:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715048645; cv=pass; d=google.com; s=arc-20160816; b=v64Q7h9Pz+FZVtiSIZNfAaRAjTfmAAh8o97y3rn05/7XPUQtwzamnzP+eZ6+PjxFa6 sv6K7JIPTDcim7if/cuyJi2K7LB++frh7ipjvnjk05nXeamNXfJJj19v5eUKspdjThEw Zl/2rx3DqFe6DoU5yL8WihBwYW9YLNc0LyOuXqFfref74I4gDFKSVuZFrL6+IvzlLGB5 HXKshxRwmkUuqk/CptRrsgpuWehbpR5dzbtoalFmAWeGOjxLyZ3azz68mAJKe8q0BgPt R3CY1VPLK38eiUGh+/89HuJf+ioqRoTEJfwQH8bti7/ohv7t8Z8uAzHTggjpfzZguwG3 +Asw== 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=c5idTVXlOPa1WbMSzopnoS6g/NcKA3HOGBDAr56EjDA=; fh=AA1/l1kx9p7hoPrYVWA5ku4B9TvBXTIEFDQu7s+joq4=; b=ZLzxZhvZif4EfST9gzmy0/YC5suZdx/rBbpXWV71CdvUcY34d7VQDM7XHZJQ1VOHEq XfBpRxQL4BIFBk2QeHbncn4JkMfzPnYSNa/wxBybuTkkOrftqEyj+pVqpS5Zh/HP8kka D+r7WXrGk83XVTzTCvFT+chyAFxDi4ZmPfHBVW1ooczWiRYLoD1P+P8HHUlQ4KQjWqMm Gbqm4BGLH189w2tboaAdwlWiXnijDwlIPBLEOxzb6nLl8qye6lzIZ9B9RhBAE2O0Sxap ZxWvxClRo2lfRIftzwrQWFY8at5PJDybhj3I1fUQre5ewqDscppEO6jLj/0puM/8sVYC JNtw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jMXmjl7C; 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 dh5-20020a05622a4e0500b0043ad021c197si9656370qtb.719.2024.05.06.19.24.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 19:24:05 -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=jMXmjl7C; 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 2FB8F3858C35 for ; Tue, 7 May 2024 02:24:05 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-ot1-x329.google.com (mail-ot1-x329.google.com [IPv6:2607:f8b0:4864:20::329]) by sourceware.org (Postfix) with ESMTPS id 01C8A3858D1E for ; Tue, 7 May 2024 02:23:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 01C8A3858D1E 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 01C8A3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::329 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715048591; cv=none; b=aKUYTTthl+lALFkcAubTjww8wkPPEF+7xqeiSDPtN6ANLSpqJ+ha3MTQclVHSdDJxSeS/Hs2GvZzpZ2BOc6dcMEJYvpCsSo5b3vfE+StCgrN0mO73kmFbSU/mZ0CT3WMRhxfB3z5WbYvXMRYpOrL0wUh7kVVLo8iYB0Km9Qzw/o= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715048591; c=relaxed/simple; bh=XA0q/9m8Pe/Po/E2uf1rT4JiDuH5WfuAPB0zX3P7qpc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=nWBk+jR/5gqlNjrqZd6BGfbedESCMVK9eCLGjA+6HhMwaP8Gnp/A4bQYP4fbtSu0BODhgn911JTAtq3c3ZkDwUDKj8KshbRVKr5P7serpbOYyZR5mj97ao3S0TrYMn9evfV5+qffd7j2rDbvGcKblqCV3DOo6CIxMTyHVGB+FpE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ot1-x329.google.com with SMTP id 46e09a7af769-6f04f01f29aso1232161a34.0 for ; Mon, 06 May 2024 19:23:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715048588; x=1715653388; 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=c5idTVXlOPa1WbMSzopnoS6g/NcKA3HOGBDAr56EjDA=; b=jMXmjl7CaZpVQvasGK7wveeYOyTf2FRlxKRHh2g5pKP7dNwE0TDx1xqRYTEUzPQK9p i3QPG6qPjqcjB1fp4ohKW+quLgEAeTvSUMPENHxRnF9JhpfcZ9raTNe1GMPBKh4eUpoQ Vme9VbWbeJkpSXfhm3rybTHuXFQaYEPDBpMV3IwdMIcWm0AZ9Imyw2URenUn3VuUJxS2 4BRKhVuyFIGGrva0JJvsjTWWcDzLhR1S9CFcRaPhni79N8JxOcAcy9L35SBHlYXCVOU9 CUFonOgBliFEvs3zKv2CXjH5rikQXX2LxzvKfIPS6xfzmNdyv/HYIb1doXr7KI0GyBBa StfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715048588; x=1715653388; 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=c5idTVXlOPa1WbMSzopnoS6g/NcKA3HOGBDAr56EjDA=; b=UMpozIUlQTee069LsmaFSHe36a2xINwbI7xJtebSP2tjn25f03A1o4C1vCJA8n6BAB cj1z3+vZN1DjXuesvLVO4vRGcznQVrX9wuwtBHdTIpfTfGUeGZsgH5bNuQzIXYBbj3ix iMtXGwzhjphiuT4wGAWgdZwUJQzwsC8WAvuoA6aME8YKSYTekWOcYqskEkqkTkOSOVv2 eZvwxReoN+wpdE49/NvJZDUl+AobSB4MgJgAyBYP8MLtc/y4vcQvgnl4p3MK9mg5uGXM 5q3UuE4nePKTOjXoHE064bHw+S5pq1GeMZ5BaHyc2vueLIoaIu3sNz8c9L1CcSpJkuej PwHg== X-Gm-Message-State: AOJu0Yy5ZNWpI3u/fiwbBJE4W+Zgmo7bbzgGuC4ZiO4RAkG3h9N8sAVU gPyLDScWnrfZ/nz8s0JtKadTyeYjNzef96kSv6j4FY2pOb/X479ziRbsHYtaN6xQDPdoTi+C7Hg L X-Received: by 2002:a05:6358:7242:b0:18f:55aa:d946 with SMTP id i2-20020a056358724200b0018f55aad946mr15366817rwa.4.1715048588089; Mon, 06 May 2024 19:23:08 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:38ad:4156:59df:8141]) by smtp.gmail.com with ESMTPSA id c12-20020a631c4c000000b005c6617b52e6sm8759997pgm.5.2024.05.06.19.23.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 19:23:07 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Christophe Lyon Subject: [PATCH v2 5/5] gdb/testsuite: Add gdb.reverse/aarch64-mops.exp Date: Mon, 6 May 2024 23:22:49 -0300 Message-ID: <20240507022249.554831-6-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=-11.1 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 in v2. 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"