From patchwork Sat Apr 5 00:50:03 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thiago Jung Bauermann X-Patchwork-Id: 109904 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 F1C82384A85A for ; Sat, 5 Apr 2025 00:51:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F1C82384A85A Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=tEs/f5d0 X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id 56F85385AC3D for ; Sat, 5 Apr 2025 00:50:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 56F85385AC3D 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 56F85385AC3D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::635 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1743814207; cv=none; b=aYHU/FQxd2sUlvvrawj/Wm6P6wJb55yvJhlbB8h3oloyUIG7qOff2yCLvaBW93Fn9LUFBbSqp3TSXtyeX+gbQg17x2WdK+t5biA4oBxWbKLNjSl7sb63Zanr2IA6X1ODoiWJPIhb9xbhxgPwdcRgmM3kFjFkIFtt5PMsRfbISCI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1743814207; c=relaxed/simple; bh=vvZtxGi9OCPF+Ws3DmUFarnUYAfJwgamW64/JBj8EL8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=I5/SZydLhsQ3yfVtOIB0lf2dloX2sU49w9cwBXtHRmAWSlgqsU4VQGptp4K0PGjWiW4D9483yolQXxIGOaWFsSTi1VwlgSanNxZuoV8qkSpdJGhNeHJINGOD5OSpuoIHJKUbu4kkLuOXhpn/n7wsRI1ctyWz60FHsTm5iynj1sk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56F85385AC3D Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-2260c91576aso22152025ad.3 for ; Fri, 04 Apr 2025 17:50:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1743814206; x=1744419006; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=o8BjSqs3AzG8epyFTS2BTBG6p6T7De2xEiVtdhXF8Fs=; b=tEs/f5d0hDUgNVmJKtKIKQblhc+9fv2JYYRMA1AsJ2qAw4LCxiV7N+DUJ4FsTHR5lo lcE16XKz3O8/aDevMiuStWnko5K1/NN+NmYq166g0gOMNskW5vmow/RrSJy+98/Qd1WP 1Fcr8CPr1Gxk8+z5s/eX/Yxdf1YDCBlDoOPRKmZYgQRLWcQfbcZTlbzW21UmJg9cF55X RHnTfEnaxoy+NlRaSJCusGckmJUBS8RdO5PlJdNdPvrxoSc4WTlhTqzsNp3kK7LgXxS3 19AYTTuIGjqODjKqQBko8QQHeZNbsVuit6mPJNrd/mg6kmyQtoUHupKqQ5zA9g/rqUaw b7Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1743814206; x=1744419006; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=o8BjSqs3AzG8epyFTS2BTBG6p6T7De2xEiVtdhXF8Fs=; b=GnS2hdmvwjaMh+Rx8Lg0YZZfnvV8XmyI19C8wJWaWIX5kAZL9snTJHVFvxDrmqMx9L RdYvqkLoOZEQdY83wNx/4cC2dPQuUH/vLr2TlUI7ZPq+wh0qwPO8uC0pPMadNGw804V8 ywvxtJaAf2EwykXrCN72AhA4tAN4JCkSBPwjdFo3Jm0tha7B3xv1hUl8m0hpGsT8a3X+ zCu/tfv7ncPPylYNkMdfKmT5MVTX8yB/DUPqzD5TVcuFKBRz04p8ZCYE5VljnW1IaJxW Uta2quw5K+o+4hG5TT9f3ULau7lmZBcN6eh7D84IyQ/C++X7zGy80cWencas/6u4tEfy x+3A== X-Gm-Message-State: AOJu0Yz9l1vQwcOX8yqWZwVTVEYR/UMSLffBhUeNanEOd/vlbKC88lwR O1SqL9RfDFviX40tswqdlo5kca1pQCUVjc+0iaYa310nems/KFVofdojFNNCA2zh/15xvmgtT8/ m X-Gm-Gg: ASbGncslUSHAnKGB7CZcTCv4/D8Ff8a87fWry4lk5Cd2akHNxbTlGNr4u60wIwFolTR pKFE7wZr+QhCzFWbJh2+Ypd042ZuyxoDafAy0rFYQZwjw28ma3HuJ5CVXKNqBtCNs1hmmCND8fy NhuQH2P61RFLbmV+y9bp3IJOF+doVlI45nwIaKCMyIK+b6MV/CKVY4T4Ls4VpaZnLIAlHz8pkIe ENDyYxWi1g4uUmpPgVXTjxESuQtgeYoJ5H+2ozOORvMwrJm83/Ub8/+MoN07NX0gnwHUe5iFMnw 7oEzTpzjbAEAsEOObqz+6iFsOoS85x6/UWbP4JxFjN0x+T97gH4fRdU= X-Google-Smtp-Source: AGHT+IFE3SoebDvuH1Iyiu6YES3dzKwuYM8wf7Kh2xsM+kEx23UlaUSA1OBtw1q9i4VjKjQ2aX1hog== X-Received: by 2002:a17:903:2ac4:b0:224:2200:5940 with SMTP id d9443c01a7336-22a8a1b8c85mr77797615ad.38.1743814206199; Fri, 04 Apr 2025 17:50:06 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8209:7091:f5fc:7d55:fdf9]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-229785bffd4sm39032785ad.57.2025.04.04.17.50.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Apr 2025 17:50:05 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Subject: [PATCH] gdb/testsuite: Add gdb.arch/aarch64-sve-vg-sigunwind.exp Date: Fri, 4 Apr 2025 21:50:03 -0300 Message-ID: <20250405005003.752820-1-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 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 There's currently not test for unwinding the VG register from a signal frame, so add one. All tests in the testcase pass. Tested on aarch64-linux-gnu native, native-gdbserver and native-extended-gdbserver. --- .../gdb.arch/aarch64-sve-vg-sigunwind.c | 87 +++++++++++++++++++ .../gdb.arch/aarch64-sve-vg-sigunwind.exp | 55 ++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 gdb/testsuite/gdb.arch/aarch64-sve-vg-sigunwind.c create mode 100644 gdb/testsuite/gdb.arch/aarch64-sve-vg-sigunwind.exp base-commit: 4fa9476ad23d5868c2bc4c02dc1a73acaefbcbc2 diff --git a/gdb/testsuite/gdb.arch/aarch64-sve-vg-sigunwind.c b/gdb/testsuite/gdb.arch/aarch64-sve-vg-sigunwind.c new file mode 100644 index 000000000000..f2403ae448d1 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sve-vg-sigunwind.c @@ -0,0 +1,87 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2025 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 . */ + +/* Exercise unwinding AArch64's Scalable Vector Extension VG register. */ + +#include +#include +#include /* For SVE_VL_MAX. */ +#include +#include +#include + +static int max_vl = 0; + +/* Set new value for the SVE vector length. + Return the value that was set. */ + +static int +set_vl (int vl) +{ + int rc; + + rc = prctl (PR_SVE_SET_VL, vl, 0, 0, 0); + if (rc < 0) + { + perror ("FAILED to PR_SVE_SET_VL"); + exit (EXIT_FAILURE); + } + + return rc & PR_SVE_VL_LEN_MASK; +} + +static void +sighandler (int) +{ + int current_vl; + + /* Decrease vector length by 16 bytes. */ + printf ("sighandler: setting to %d\n", max_vl - 16); + current_vl = set_vl (max_vl - 16); + printf ("sighandler: current_vl = %d\n", current_vl); /* Break here. */ +} + +int +main (int argc, char *argv[]) +{ + /* Set vector length to the maximum size allowed. */ + max_vl = set_vl (SVE_VL_MAX); + + printf ("main: max_vl = %d\n", max_vl); + + /* If maximum VL is less than 32 bytes we can't decrease it in the signal + handler. */ + if (max_vl < 32) + return 1; + + unsigned char buf[256]; + + /* Use an SVE register to make the kernel start saving the SVE bank. */ + asm volatile ("mov z0.b, #255\n\t" + "str z0, %0" + : + : "m" (buf) + : "z0", "memory"); + + struct sigaction sigact; + sigact.sa_handler = sighandler; + sigaction (SIGUSR1, &sigact, NULL); + + kill (getpid (), SIGUSR1); + + return 0; +} diff --git a/gdb/testsuite/gdb.arch/aarch64-sve-vg-sigunwind.exp b/gdb/testsuite/gdb.arch/aarch64-sve-vg-sigunwind.exp new file mode 100644 index 000000000000..7fea93ffbd58 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sve-vg-sigunwind.exp @@ -0,0 +1,55 @@ +# Copyright 2025 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 . + +# Exercise unwinding AArch64's Scalable Vector Extension VG register. + +require allow_aarch64_sve_tests + +standard_testfile +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile} \ + [list debug additional_flags=-march=armv9-a]] } { + return +} + +# We want SIGUSR1 to be delivered normally. +gdb_test "handle SIGUSR1 nostop" \ + [multi_line {Signal Stop Print Pass to program Description} \ + {SIGUSR1 No Yes Yes User defined signal 1}] \ + "don't stop for SIGUSR1" + +set linespec ${srcfile}:[gdb_get_line_number "Break here."] + +if ![runto ${linespec}] { + return +} + +set max_vl [get_valueof "" "max_vl" 0] +set max_vg [expr $max_vl/8] + +# If maximum VL is less than 256 bits we can't decrease it in the signal +# handler and the test can't work. +if { $max_vl < 32 } { + untested "Maximum vector length is too small." + return +} + +set reduced_vg [expr "$max_vg - 2"] +gdb_test "print \$vg" ". = ${reduced_vg}" "vg was reduced" + +gdb_test "frame function main" \ + [multi_line "#$decimal $hex in main \[^\r\n\]+" \ + "$decimal\[ \t\]+kill \\(getpid \\(\\), SIGUSR1\\);"] + +gdb_test "print \$vg" ". = $max_vg" "vg was correctly unwound"