From patchwork Sat Apr 12 05:03:38 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: 880578 Delivered-To: patch@linaro.org Received: by 2002:a5d:4882:0:b0:38f:210b:807b with SMTP id g2csp1076724wrq; Fri, 11 Apr 2025 22:04:26 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWE3l1xZzKIODEKSOM6Gixc0phHjdhXEQQxjjCTo7SjkR7CrDQBhwlDRiYmAzfP41u+6PM7hA==@linaro.org X-Google-Smtp-Source: AGHT+IH8Vx+nR7SajELslXecvXy/SKUxaQa1aeb/B7DWmeMVVnHnbCBHUXtEtcq1XDAaTCogejdl X-Received: by 2002:ac8:7e81:0:b0:479:1a41:b50d with SMTP id d75a77b69052e-47977530327mr64923421cf.17.1744434266423; Fri, 11 Apr 2025 22:04:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1744434266; cv=pass; d=google.com; s=arc-20240605; b=aD3tYO9scygwL2KuHl2NOsIpQuW9orX8Ujt+XylRLuOu33hSAQR5Tt+rf055bgcWkZ uKiO8RptImlr4gVL91N2QGyypU/vAEZ/ncQQba6HPyy6ichOGSFcaBZlEJ0+DqSaFdTX +flatRqXmw+ZEGvj8xahfG0j9R3LmoxYuerEJPLp/N4Po4ytCVmW+M9koUeJ/ecSJ7vm QG7fFiJwe+u/mSageTResqFyfB7MnWsYkZDF0jQGWGoL6QxPeGPZbXQ5jajh4g3Kdnjg lr3MyBTrGHhvobJ19618Yp76biy4t7yw2RJnYF+lXioLpvr9WsZCKtZ8HPefF9YvSzDb o33A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :dkim-filter:arc-filter:dmarc-filter:delivered-to:dkim-filter; bh=TgeU3vXtQ6iSM5Caz7IZftK+iuqtA1ijasIcGIyebyw=; fh=vIMyHvWMi3lWkQwmVe6rT877H5fflUQuIxiU8RM1TMo=; b=Bo8BIoVqSZ23x8Z0HXvCvMqHa8d6PocqjICay44zo9F2TMSEMtMTdlCYfSnXaye7oB 2qd1xRoadIuH2WrZ21OgEzE0t0hKNXq2HZn3IkGfuOQBQCi8sM3ZvEdUOFAGUFI7hWgS ZVyeOAwF8DOR6aYpSeSZnaYPGz7GOr1Tk3sm+V7PGnKVFYQEwGzee9vIa/SHLw8ObCm+ QrDfBdvKFkhjOM57E4V4ks9Oix3SonlMzvP19RLqxVIi0DtRkCpCWwX4q3VsE0zuQlNE YfqDtfYeaPOgzcEfCuCup7LF3ixUNsCST8BCU6USDpxKVi0WbVWqxHfIuYqgbKhaWNtq /wpQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AKQHgNNh; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 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. [8.43.85.97]) by mx.google.com with ESMTPS id d75a77b69052e-4796edd6a7bsi43940071cf.437.2025.04.11.22.04.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Apr 2025 22:04:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AKQHgNNh; arc=pass (i=1); spf=pass (google.com: domain of gdb-patches-bounces~patch=linaro.org@sourceware.org designates 8.43.85.97 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 DF43E3860C30 for ; Sat, 12 Apr 2025 05:04:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DF43E3860C30 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=AKQHgNNh X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id 1279F38515E3 for ; Sat, 12 Apr 2025 05:03:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1279F38515E3 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 1279F38515E3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1744434223; cv=none; b=ONX65dScYzPACUN+Z9eaxGPUdbm0/Tepfm36YvPVVf5v3kB9sx/XXSPnJvvsZ3M1i58ChySyMlLS1d0Efa39KgsmRNzscHf9JR/p3aXhqGFK7gJdlJXJGIoT4JbGiJ+EdrfwYDTxQDulQUbXpl89tKdVLkLXCtJvOPZQ9Tl7CEs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1744434223; c=relaxed/simple; bh=SG5QKpiv0G51r5wsaTE/Z0OtCfmjGZcjs3uDCDtJOu8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=WEow8EsnjFB4HhVyhUflTpR0S0uOhAeTlh6cmNis4PGAldGySXDGoZR/+amhKAns6roH5FNnDpMyXeJtk3veAX7XiIkDS0Qao95XeQ57xaGoQofXjUzXa2Z2HZE1tQHKRo+etjQAdJ5UzdoAv+ytg8YxwPm9lr7c7o0k4N2a8rQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1279F38515E3 Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-b06e9bcc986so13105a12.0 for ; Fri, 11 Apr 2025 22:03:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744434222; x=1745039022; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=TgeU3vXtQ6iSM5Caz7IZftK+iuqtA1ijasIcGIyebyw=; b=AKQHgNNhjrrGXVo7HPM9R0xv+BetM1FLP9h5McQgymfIieZAjjjfYEUvHBAXcZBp3Q F8eE9uc30d1QePoMXl6qwJEp8onJDRSJFkkcyc/K0WScOKklj2gBXd6GiXoSe8Io/jS+ mY1zWJ2i+KHtvDJJ/KmWS8bIrUX9JIvv53umtZmo5trQxmbgmYnm3/sOlIX2KIaGoTPJ kJyhPTnjt2eODL6Lpcmpmj6HaFagnlghki8lV2PVKT7IN+SZpguUT14xjLHGXEy96Qf2 PVi3iqY/o/14WjWLtgb0lTldNW2IZIiEFKfstPfMJvDYYcnJjJ6o7JmVxFsf9XwkLOn/ V+tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744434222; x=1745039022; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TgeU3vXtQ6iSM5Caz7IZftK+iuqtA1ijasIcGIyebyw=; b=EwJVrDVLVsZrY6SRs5Dl7DwLxh+Pk5vcdM7pJFxdbFrm3oaF3aOLrPp7Q3N/MXvv4x DeDkOhykVIxU9uY8CB5OcOEgOKM+N0hh9d/+y726lVjOgrQtXXvI7OVgjuDg2+pkeKLm YjZjQW3G9I6no5bHKQvHj6MJKAAdmtlcHx481aoM2np6GDG159LIBiI5owLASATiV4cE TW9dBxnxFHiN4tyWmUKa3wXtYRntlrTLcdKSXWovpioZuOM+cJ1qefrSsCHbnIN/2EmP KitzLoE/LNaKAyWsO06Wab/O3tqOCAqZa7kO9HXLRuy+uv2zWLmd1DD+UKcqL9pynJki Xh/A== X-Gm-Message-State: AOJu0Yx8JGRCV1GxIg0jVP1QP2ZcUGOF4946vHnWx/PrxT5fkB1q6y9i BQANkSSGi7OCKB/HeBb+ubJIxNJ9v9fblwt0I5TqKFd3RhmorVULlKFkkq/2Di1btnGyLJncD6e 3 X-Gm-Gg: ASbGnctkP1JRsy6sBkbAN+7nFhSuqA3SDuqwe+QKHwYNrWdCD0csEskJmn8pUdRYdDN 8ZJa9yioX9QII3JejksfKvWt7nZyTiM4YIzEokTmvOPuMvBsEVorHEZyYLxQcWc5hfQH3vSE0RY YyQ6tutrq6zg5RjgtbUHoIIMiPLvbv37Am6HzS3uMUdx9qE+185e5zMLmCGviSCS/5+2bseoyeN C0lxsuQv1oZfjdIvxQrtFnHMVzQWsaenndgq8r5wIwlYAZ5mq5k7NCg5ESsFXofK4U+eNQUvAsE mfiprHFuMOPo+El1E/yWnpyl/vZajhmlI8t2WizbuvoTbnu1wv8= X-Received: by 2002:a17:903:1b6f:b0:224:c47:cb7 with SMTP id d9443c01a7336-22bea3f02aemr77876375ad.0.1744434221749; Fri, 11 Apr 2025 22:03:41 -0700 (PDT) Received: from localhost ([2804:14d:7e39:8209:4825:414d:f0f6:b2c9]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-22ac7c95cafsm59759465ad.134.2025.04.11.22.03.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Apr 2025 22:03:41 -0700 (PDT) From: Thiago Jung Bauermann To: gdb-patches@sourceware.org Cc: Luis Machado Subject: [PATCH v2] gdb/testsuite: Add gdb.arch/aarch64-sve-sigunwind.exp Date: Sat, 12 Apr 2025 02:03:38 -0300 Message-ID: <20250412050338.2260505-1-thiago.bauermann@linaro.org> X-Mailer: git-send-email 2.49.0 MIME-Version: 1.0 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 There's currently no test for unwinding the SVE registers from a signal frame, so add one. Tested on aarch64-linux-gnu native. Tested-By: Luis Machado --- .../gdb.arch/aarch64-sve-sigunwind.c | 205 ++++++++++++++++++ .../gdb.arch/aarch64-sve-sigunwind.exp | 106 +++++++++ 2 files changed, 311 insertions(+) create mode 100644 gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.c create mode 100644 gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.exp Hello, This version addresses Luis' comments from v1. By using the testsuite's vector list, it's easy to return early in the .exp file if the system supports only one vector length, and I don't hit the corner case that Luis described anymore. I decided to make the test more complete by also checking the contents of all registers in the SVE context of the signal frame. Unfortunately I get the following failures: Running /path/to/gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.exp ... FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $z0.b.u contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $z1.b.u contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $z2.b.u contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $z3.b.u contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $z4.b.u contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $z5.b.u contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p0 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p1 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p2 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p3 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p4 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p5 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p6 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p7 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p8 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p9 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p10 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p11 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p12 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p13 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p14 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: $p15 contents were correctly unwound FAIL: gdb.arch/aarch64-sve-sigunwind.exp: ffr contents were correctly unwound === gdb Summary === # of expected passes 144 # of unexpected failures 23 After some investigation, I suspect this is a bug in the kernel though. To take GDB out of the picture, I wrote the following test program: https://people.linaro.org/~thiago.bauermann/sve/sve-sigunwind.c Running it in a QEMU VM with VL of 128 bits, I get: SVE context: vl = 16 SVE context: flags = 0 SVE context: Z0 = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SVE context: Z1 = 0 0 0 0 0 0 3 232 0 0 0 0 0 0 3 232 SVE context: Z2 = 0 0 0 0 0 0 0 0 0 0 235 17 78 62 96 0 SVE context: Z3 = 0 0 0 0 0 0 0 0 0 0 202 159 237 8 8 128 SVE context: Z4 = 0 0 0 0 0 0 0 56 0 0 202 159 237 8 0 64 SVE context: Z5 = 0 0 0 0 0 0 16 0 0 0 0 0 0 0 0 9 SVE context: Z6 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z7 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z8 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z9 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z10 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z11 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z12 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z13 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z14 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z15 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z16 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z17 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z18 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z19 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z20 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z21 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z22 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z23 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z24 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z25 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z26 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z27 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z28 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z29 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z30 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: Z31 = 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 255 SVE context: P0 = 0 0 SVE context: P1 = 0 0 SVE context: P2 = 0 0 SVE context: P3 = 0 0 SVE context: P4 = 0 0 SVE context: P5 = 0 0 SVE context: P6 = 0 0 SVE context: P7 = 0 0 SVE context: P8 = 0 0 SVE context: P9 = 0 0 SVE context: P10 = 0 0 SVE context: P11 = 0 0 SVE context: P12 = 0 0 SVE context: P13 = 0 0 SVE context: P14 = 0 0 SVE context: P15 = 0 0 SVE context: FFR = 0 0 Maybe there's a bug in my test program as well? I couldn't find it, but it's interesting that the registers with wrong contents are the same ones that GDB gets. I'll investigate some more and report the problem on the kernel mailing list if I don't find anything. In any case, I think it's worth to add the test even with these failures. Changes in v2: - Use vector length list detected by the testsuite's helper to find two valid vector lengths that the test can use (suggested by Luis). - Test unwinding Z, P and FFR register contents, not just VG. - Rename test files to aarch64-sve-sigunwind.{c,exp}. base-commit: 4fa9476ad23d5868c2bc4c02dc1a73acaefbcbc2 diff --git a/gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.c b/gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.c new file mode 100644 index 000000000000..c86beaf5dda0 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.c @@ -0,0 +1,205 @@ +/* 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 SVE registers from a signal frame. */ + +#include +#include +#include +#include +#include + +static int second_vl = 0; + +static void +initialize_sve_state_main () +{ + __asm __volatile ("dup z0.b, -1"); + __asm __volatile ("dup z1.b, -1"); + __asm __volatile ("dup z2.b, -1"); + __asm __volatile ("dup z3.b, -1"); + __asm __volatile ("dup z4.b, -1"); + __asm __volatile ("dup z5.b, -1"); + __asm __volatile ("dup z6.b, -1"); + __asm __volatile ("dup z7.b, -1"); + __asm __volatile ("dup z8.b, -1"); + __asm __volatile ("dup z9.b, -1"); + __asm __volatile ("dup z10.b, -1"); + __asm __volatile ("dup z11.b, -1"); + __asm __volatile ("dup z12.b, -1"); + __asm __volatile ("dup z13.b, -1"); + __asm __volatile ("dup z14.b, -1"); + __asm __volatile ("dup z15.b, -1"); + __asm __volatile ("dup z16.b, -1"); + __asm __volatile ("dup z17.b, -1"); + __asm __volatile ("dup z18.b, -1"); + __asm __volatile ("dup z19.b, -1"); + __asm __volatile ("dup z20.b, -1"); + __asm __volatile ("dup z21.b, -1"); + __asm __volatile ("dup z22.b, -1"); + __asm __volatile ("dup z23.b, -1"); + __asm __volatile ("dup z24.b, -1"); + __asm __volatile ("dup z25.b, -1"); + __asm __volatile ("dup z26.b, -1"); + __asm __volatile ("dup z27.b, -1"); + __asm __volatile ("dup z28.b, -1"); + __asm __volatile ("dup z29.b, -1"); + __asm __volatile ("dup z30.b, -1"); + __asm __volatile ("dup z31.b, -1"); + __asm __volatile ("ptrue p0.d"); + __asm __volatile ("ptrue p1.d"); + __asm __volatile ("ptrue p2.d"); + __asm __volatile ("ptrue p3.d"); + __asm __volatile ("ptrue p4.d"); + __asm __volatile ("ptrue p5.d"); + __asm __volatile ("ptrue p6.d"); + __asm __volatile ("ptrue p7.d"); + __asm __volatile ("ptrue p8.d"); + __asm __volatile ("ptrue p9.d"); + __asm __volatile ("ptrue p10.d"); + __asm __volatile ("ptrue p11.d"); + __asm __volatile ("ptrue p12.d"); + __asm __volatile ("ptrue p13.d"); + __asm __volatile ("ptrue p14.d"); + __asm __volatile ("ptrue p15.d"); + __asm __volatile ("setffr"); +} + +static void +initialize_sve_state_sighandler () +{ + __asm __volatile ("dup z0.b, -2"); + __asm __volatile ("dup z1.b, -2"); + __asm __volatile ("dup z2.b, -2"); + __asm __volatile ("dup z3.b, -2"); + __asm __volatile ("dup z4.b, -2"); + __asm __volatile ("dup z5.b, -2"); + __asm __volatile ("dup z6.b, -2"); + __asm __volatile ("dup z7.b, -2"); + __asm __volatile ("dup z8.b, -2"); + __asm __volatile ("dup z9.b, -2"); + __asm __volatile ("dup z10.b, -2"); + __asm __volatile ("dup z11.b, -2"); + __asm __volatile ("dup z12.b, -2"); + __asm __volatile ("dup z13.b, -2"); + __asm __volatile ("dup z14.b, -2"); + __asm __volatile ("dup z15.b, -2"); + __asm __volatile ("dup z16.b, -2"); + __asm __volatile ("dup z17.b, -2"); + __asm __volatile ("dup z18.b, -2"); + __asm __volatile ("dup z19.b, -2"); + __asm __volatile ("dup z20.b, -2"); + __asm __volatile ("dup z21.b, -2"); + __asm __volatile ("dup z22.b, -2"); + __asm __volatile ("dup z23.b, -2"); + __asm __volatile ("dup z24.b, -2"); + __asm __volatile ("dup z25.b, -2"); + __asm __volatile ("dup z26.b, -2"); + __asm __volatile ("dup z27.b, -2"); + __asm __volatile ("dup z28.b, -2"); + __asm __volatile ("dup z29.b, -2"); + __asm __volatile ("dup z30.b, -2"); + __asm __volatile ("dup z31.b, -2"); + __asm __volatile ("pfalse p0.b"); + __asm __volatile ("pfalse p1.b"); + __asm __volatile ("pfalse p2.b"); + __asm __volatile ("pfalse p3.b"); + __asm __volatile ("pfalse p4.b"); + __asm __volatile ("pfalse p5.b"); + __asm __volatile ("pfalse p6.b"); + __asm __volatile ("pfalse p7.b"); + __asm __volatile ("pfalse p8.b"); + __asm __volatile ("pfalse p9.b"); + __asm __volatile ("pfalse p10.b"); + __asm __volatile ("pfalse p11.b"); + __asm __volatile ("pfalse p12.b"); + __asm __volatile ("pfalse p13.b"); + __asm __volatile ("pfalse p14.b"); + __asm __volatile ("pfalse p15.b"); + __asm __volatile ("setffr"); +} + +/* 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 sig, siginfo_t *info, void *ucontext) +{ + /* Set vector length to the second value. */ + second_vl = set_vl (second_vl); + initialize_sve_state_sighandler (); + printf ("sighandler: second_vl = %d\n", second_vl); /* Break here. */ +} + +int +main (int argc, char *argv[]) +{ + if (argc != 3) + { + fprintf (stderr, "Usage: %s \n", argv[0]); + return 1; + } + + int first_vl = atoi (argv[1]); + second_vl = atoi (argv[2]); + + if (first_vl == 0 || second_vl == 0) + { + fprintf (stderr, "Invalid vector length.\n"); + return 1; + } + + /* Set vector length to the first value. */ + first_vl = set_vl (first_vl); + + printf ("main: first_vl = %d\n", first_vl); + + 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"); + + initialize_sve_state_main (); + + struct sigaction sigact; + sigact.sa_sigaction = sighandler; + sigact.sa_flags = SA_SIGINFO; + sigaction (SIGUSR1, &sigact, NULL); + + kill (getpid (), SIGUSR1); + + return 0; +} diff --git a/gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.exp b/gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.exp new file mode 100644 index 000000000000..32340bb53a33 --- /dev/null +++ b/gdb/testsuite/gdb.arch/aarch64-sve-sigunwind.exp @@ -0,0 +1,106 @@ +# 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 SVE registers from a signal frame. + +require allow_aarch64_sve_tests +# Remote targets can't communicate vector length changes to GDB via the RSP. +require !gdb_protocol_is_remote + +set first_vl 0 +set second_vl 0 + +# Find two valid VL values to use in the test. +# The minimum supported VL is 16 bytes, maximum is 256 bytes, and VL can change +# in increments of at least 16 bytes. +for {set i 16} {$i <= 256} {incr i 16} { + if {![aarch64_supports_sve_vl $i]} { + continue + } + + if {$first_vl == 0} { + set first_vl $i + } elseif {$second_vl == 0} { + set second_vl $i + break + } +} + +if {$first_vl == 0 || $second_vl == 0} { + untested "test needs to support at least two vector lengths" + return +} + +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."] +gdb_test_no_output "set args $first_vl $second_vl" + +if ![runto ${linespec}] { + return +} + +set first_vg [expr $first_vl/8] +set second_vg [expr $second_vl/8] + +gdb_test "print \$vg" ". = $second_vg" "vg was changed" + +for {set row 0} {$row < 32} {incr row} { + set register_name "\$z${row}\.b\.u" + gdb_test "print sizeof $register_name" " = $second_vl" \ + "size of $register_name in the signal handler" + gdb_test "print $register_name" ". = \\{254 \\}" \ + "$register_name contents in signal handler" +} + +for {set row 0} {$row < 16} {incr row} { + set register_name "\$p${row}" + gdb_test "print $register_name" ". = \\{(0, ){[expr $second_vl/8 - 1]}0\\}" \ + "$register_name contents in signal handler" +} +gdb_test "print \$ffr" ". = \\{(255, ){[expr $second_vl/8 - 1]}255\\}" \ + "ffr contents in signal handler" + +gdb_test "frame function main" \ + [multi_line "#$decimal $hex in main \[^\r\n\]+" \ + "$decimal\[ \t\]+kill \\(getpid \\(\\), SIGUSR1\\);"] + +gdb_test "print \$vg" ". = $first_vg" "vg was correctly unwound" + +for {set row 0} {$row < 32} {incr row} { + set register_name "\$z${row}\.b\.u" + gdb_test "print sizeof $register_name" " = $first_vl" \ + "size of $register_name was correctly unwound" + gdb_test "print $register_name" ". = \\{255 \\}" \ + "$register_name contents were correctly unwound" +} + +for {set row 0} {$row < 16} {incr row} { + set register_name "\$p${row}" + gdb_test "print $register_name" ". = \\{(1, ){[expr $first_vl/8 - 1]}1\\}" \ + "$register_name contents were correctly unwound" +} +gdb_test "print \$ffr" ". = \\{(255, ){[expr $first_vl/8 - 1]}255\\}" \ + "ffr contents were correctly unwound"