From patchwork Tue May 7 02:22:48 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: 795199 Delivered-To: patch@linaro.org Received: by 2002:a5d:525c:0:b0:34e:ceec:bfcd with SMTP id k28csp88702wrc; Mon, 6 May 2024 19:24:23 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCXuU0MuFzqI1gKE/Nx7qNfUVa3FokaFy/aohfCO8vL+HpAcBPKagYQPIrlzGPFr298/YfR4TzqYMbDWnPnQSQCh X-Google-Smtp-Source: AGHT+IFQjSYx9CpxwBQ28+VCLHyTGq0a9gFNOkQTH21CLMhaqfq8vSbzXtjd3986NwqoVkVeZ9kD X-Received: by 2002:ad4:5caf:0:b0:6a0:d291:a349 with SMTP id q15-20020ad45caf000000b006a0d291a349mr14636605qvh.54.1715048662993; Mon, 06 May 2024 19:24:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715048662; cv=pass; d=google.com; s=arc-20160816; b=IUWZZSXmyWfpDfYTLe0zPfoNAIZZPjHfKkVe4OluS8vwMHGMO/x4Wu11o9U4aT84co zkYPkB9OTp18S8IYBviIbOReZEgh2N+L27W8IQhFPsSzEeZnHSdKmx1xDwlE/61YO+Ro DGnB6PpUX+wHBIKjEuw25oGi3LuX39Rxky8ztuLJ+OFpBKC28clzyeMi9G0weGU5TT89 VyotL5+pcDbymgjU8JXt7+yMMjLdnyZWW35XmGXjy7oGr1MP+B7S0PQNgNMmi9Lhsxzw 2YTQz9QX8ySwZZXiU8dLmTRVmprA9E7pE2fIUHlYxiVpASNzmx7bqBybr87p9eJLGKws 89Eg== 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=jhnOpx0S2vZLxex5HYSP8fiDUIbY5dBJwkG3GTu8nmg=; fh=AA1/l1kx9p7hoPrYVWA5ku4B9TvBXTIEFDQu7s+joq4=; b=WecdQ09rWFXQUA0b1iHhVsWc5FoAcwzNboPptF0r+kjSzFtS9ZOz9H/b/rnWbcSK4V fpgzmoC3TIyo5mvFsjVLn7m0S/b6dQbCgcna4XrF1WVkSi4s4VS2Be9Qr9WPEXzwxMdT IdDXKwqJn/G3X0VrRLs3CXeGfp/zgp+8K4fNwGn3I1KT6z/PE0XAby/GcOkva1rYeI44 Glec7Z8lKYYFSN1aZu8DWJ31M2um+RIuW9H+0LxyxVDguOGthsWrrawgJGIro69ToPFa 9lcZZRhZtDLUI2bK+iLpNs68dOYcP/WUJ4QTJ/J6FOEvqVhqqnZgWm26sdGxPhGPW3Yl IkEw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gao+x8j3; 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 s12-20020a0562140cac00b006a0c923adc4si10868683qvs.500.2024.05.06.19.24.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 19:24:22 -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=gao+x8j3; 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 9EE973858D39 for ; Tue, 7 May 2024 02:24:22 +0000 (GMT) X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id D2575384AB51 for ; Tue, 7 May 2024 02:23:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D2575384AB51 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 D2575384AB51 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::432 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715048590; cv=none; b=ee6JqYuO/psEdIhaZWHLXYAEAmqWQLBtCyA0C43iyOoqMVldF5m6VyMytylCndfTfNUjN7f4DpbRQT4HX7y9D+/45u6Y+a8lQKk4eyz/pHZnogsmEn/Oi2cRKriNY4e6lR1aTuW6r2IAgjHoi38mCePATBIPLRyD0DdaUqrNPsM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715048590; c=relaxed/simple; bh=C7YgwK6v/uiRtRUk9Rkna+rGftjH3PDeFbkeEwgVaAM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jtsFbP3NNu7zYPt5KQLrTtuuN38TUnyw+ikiYCZDcrh+YyomlU6rVZ9Voht5tsCxXfjps8wPFIn9Ib3HxpAgSxAH1Vh3DuOeWXpssxXTDHafqa9wh8B4LtiRq0kKWJw5qH5CU+WZ5GyfcsYRAusPMOv+CfeilLK2lMy5bDNxqAc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-6f45f1179c3so1776317b3a.3 for ; Mon, 06 May 2024 19:23:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1715048585; x=1715653385; 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=jhnOpx0S2vZLxex5HYSP8fiDUIbY5dBJwkG3GTu8nmg=; b=gao+x8j3J/cyC6Ct1mOyE+I+9xAU74xlxoSYooHgDKBOpK6xln2lz7gm/Zeaqhb1jN JwGpFu8/cp7fbk0vbcu34SaPPUux1JYyvtqH/+7JkDiB6toi1+5FxucNlZStfF2RRAlG /5MEO637IsRqssmqs3d1lkmS0HN9nArTW6Z0M3EYT90aNC0tt2D0n9ZFkCXm06mhxPqZ LM+RS5EPozMXerQVU4K0YUjHkXoQzPNykZTw3O5xyKhfLC2QkIqBJAXzsu3N3E9WYvL8 bDXMJ7LgwHaF1o+RaTuJJyF+px5M/AOiZEgQWtgDKFQ4ypawuBfCmYJCQDIoZMxF9eOQ Nv7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715048585; x=1715653385; 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=jhnOpx0S2vZLxex5HYSP8fiDUIbY5dBJwkG3GTu8nmg=; b=i9/KffsIAsZmhBYfNgu8vG50OKds3CnwgHTRJapnUyl1G5tGpXQop0gWm7EyzjoCPk WdAtLUZT6gDlATdE0whyx6jplXJRvpayJEq6Z04h8Exqm56PqrLqIop+qTHOSapGcGyF jISfZhtW0um1pmb3LJtxJ/SCw5MxVDSxQAO7drx99dnt0D3ZEMxhKSmfdARKqw9yRFQh FPdMz+/w7MqiyrSbXtPafsomOSAcuK6eatJoDW85KuTIJzLmZpS6iUQ07un8JhT6TH9Z HIENSPnxXYRAFQYJeOfyTOD29oIgJPUU18Tke0D0vvVdNyRbrhW4Q5gAcN296LPYEbwj pE2Q== X-Gm-Message-State: AOJu0Yxe6quGu+8IVW6o+w3oxT4sX8lIYcitG9KaKiaTMku7eiNu+eqC hCqOEaHeP+5/K98MBZrecUmRcbtjbp2n9znZ+Eix4DNs4KEOBYxnZEceP52bHJk7LsXLI0yrdKe l X-Received: by 2002:a05:6a21:6d99:b0:1a7:a72c:6f4 with SMTP id wl25-20020a056a216d9900b001a7a72c06f4mr13084147pzb.41.1715048584752; Mon, 06 May 2024 19:23:04 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8470:38ad:4156:59df:8141]) by smtp.gmail.com with ESMTPSA id h3-20020a170902680300b001e2c1740264sm9140715plk.252.2024.05.06.19.23.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 May 2024 19:23:04 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Christophe Lyon Subject: [PATCH v2 4/5] gdb/testsuite: Add gdb.arch/aarch64-mops-atomic-inst.exp Date: Mon, 6 May 2024 23:22:48 -0300 Message-ID: <20240507022249.554831-5-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.0 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 sequences are stepped over when stepping the inferior instruction by instruction. --- .../gdb.arch/aarch64-mops-atomic-inst.c | 69 ++++++++++++++ .../gdb.arch/aarch64-mops-atomic-inst.exp | 94 +++++++++++++++++++ 2 files changed, 163 insertions(+) create mode 100644 gdb/testsuite/gdb.arch/aarch64-mops-atomic-inst.c create mode 100644 gdb/testsuite/gdb.arch/aarch64-mops-atomic-inst.exp Changes in v2: - Add prfm instruction after each MOPS sequence and look for it in the testcase to verify that the sequence was stepped through (Suggested by Christophe). diff --git a/gdb/testsuite/gdb.arch/aarch64-mops-atomic-inst.c b/gdb/testsuite/gdb.arch/aarch64-mops-atomic-inst.c new file mode 100644 index 000000000000..e33ba6a5900b --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-mops-atomic-inst.c @@ -0,0 +1,69 @@ +/* This file 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) +{ + const char source[BUF_SIZE] = TEST_STRING; + char dest[BUF_SIZE]; + char *p = dest; + const char *q; + const long zero = 0; + long size = BUF_SIZE; + + /* Note: The prfm instruction in the asm statements below is there just + to allow the testcase to recognize when the PC is at the instruction + right after the MOPS sequence. */ + + /* Break memset. */ + /* 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" + "prfm pldl3keep, [%0, #0]\n\t" + : "+&r"(p), "+&r"(size) + : "r"(zero) + : "memory"); + + p = dest; + q = source; + /* Break memcpy. */ + /* 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" + "prfm pldl3keep, [%0, #0]\n\t" + : "+&r" (p), "+&r" (q), "+&r" (size) + : + : "memory"); + + p = dest; + q = source; + /* Break memmove. */ + /* 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" + "prfm pldl3keep, [%0, #0]\n\t" + : "+&r" (p), "+&r" (q), "+&r" (size) + : + : "memory"); + + return 0; +} diff --git a/gdb/testsuite/gdb.arch/aarch64-mops-atomic-inst.exp b/gdb/testsuite/gdb.arch/aarch64-mops-atomic-inst.exp new file mode 100644 index 000000000000..f28da6c3321b --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-mops-atomic-inst.exp @@ -0,0 +1,94 @@ +# 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 . +# +# This file is part of the GDB testsuite. + +# Test single stepping through MOPS (memory operations) atomic sequences. + +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 +} + +proc is_at_instruction { instruction } { + global gdb_prompt hex + + set test "pc points to $instruction" + gdb_test_multiple {x/i $pc} $test { + -re -wrap "=> $hex \[^\r\n\]+:\t$instruction\t\[^\r\n\]+" { + return 1 + } + -re "\r\n$gdb_prompt $" { + return 0 + } + } + + return 0 +} + +proc arrive_at_instruction { instruction } { + set count 0 + + while { [is_at_instruction $instruction] != 1 } { + gdb_test -nopass "nexti" ".*__asm__ volatile.*" \ + "nexti #$count to reach $instruction" + incr count + + if { $count > 50 } { + fail "didn't reach $instruction" + return 0 + } + } + + return 1 +} + +if ![runto_main] { + return -1 +} + +gdb_breakpoint ${srcfile}:[gdb_get_line_number "Break memset"] +gdb_breakpoint ${srcfile}:[gdb_get_line_number "Break memcpy"] +gdb_breakpoint ${srcfile}:[gdb_get_line_number "Break memmove"] + +gdb_continue_to_breakpoint "memset breakpoint" + +if { [arrive_at_instruction setp] } { + # The nexti output isn't useful to detect whether we skipped the sequence. + gdb_test "nexti" "\[^\r\n\]+" "step through the memset sequence" + gdb_assert { [is_at_instruction prfm] == 1 } \ + "stepped through the memset sequence" +} + +gdb_continue_to_breakpoint "memcpy breakpoint" + +if { [arrive_at_instruction cpyfp] } { + # The nexti output isn't useful to detect whether we skipped the sequence. + gdb_test "nexti" "\[^\r\n\]+" "step through the memcpy sequence" + gdb_assert { [is_at_instruction prfm] == 1 } \ + "stepped through the memcpy sequence" +} + +gdb_continue_to_breakpoint "memmove breakpoint" + +if { [arrive_at_instruction cpyp] } { + # The nexti output isn't useful to detect whether we skipped the sequence. + gdb_test "nexti" "\[^\r\n\]+" "step through the memmove sequence" + gdb_assert { [is_at_instruction prfm] == 1 } \ + "stepped through the memmove sequence" +}