Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Thiago Jung Bauermann <thiago.bauermann@linaro.org>
To: <srinath.parvathaneni@arm.com>
Cc: <gdb-patches@sourceware.org>,  <luis.machado.foss@gmail.com>,
	<guinevere@redhat.com>,  <Ezra.Sitorus@arm.com>,
	<Matthieu.Longo@arm.com>
Subject: Re: [PATCH v2 7/7] gdb/testsuite: Add FEAT_S1POE testcases
Date: Wed, 01 Jul 2026 05:12:21 +0000	[thread overview]
Message-ID: <87cxx7guoa.fsf@linaro.org> (raw)
In-Reply-To: <20260626180821.376406-8-srinath.parvathaneni@arm.com> (srinath parvathaneni's message of "Fri, 26 Jun 2026 18:08:21 +0000")

Hello Srinath,

Today I ran the testcases on FVP and was able to complete the review of
this patch. Sorry for the delay.

<srinath.parvathaneni@arm.com> writes:

> From: Srinath Parvathaneni <srinath.parvathaneni@arm.com>
>
> Add testcases for POR_EL0 register access, SIGSEGV diagnostics, fix-and-continue
> support (updating $por_el0 after SIGSEGV and continuing with signal 0), and core
> file support.

A good selection of test scenarios, thanks!

> ---
>  gdb/testsuite/gdb.arch/aarch64-poe-core.exp   | 102 ++++++++++++++++++
>  gdb/testsuite/gdb.arch/aarch64-poe-sigsegv.c  |  52 +++++++++
>  .../gdb.arch/aarch64-poe-sigsegv.exp          |  60 +++++++++++
>  gdb/testsuite/gdb.arch/aarch64-poe.c          |  29 +++++
>  gdb/testsuite/gdb.arch/aarch64-poe.exp        |  44 ++++++++
>  gdb/testsuite/lib/gdb.exp                     |  55 ++++++++++
>  6 files changed, 342 insertions(+)
>  create mode 100644 gdb/testsuite/gdb.arch/aarch64-poe-core.exp
>  create mode 100644 gdb/testsuite/gdb.arch/aarch64-poe-sigsegv.c
>  create mode 100644 gdb/testsuite/gdb.arch/aarch64-poe-sigsegv.exp
>  create mode 100644 gdb/testsuite/gdb.arch/aarch64-poe.c
>  create mode 100644 gdb/testsuite/gdb.arch/aarch64-poe.exp
>
> diff --git a/gdb/testsuite/gdb.arch/aarch64-poe-core.exp b/gdb/testsuite/gdb.arch/aarch64-poe-core.exp
> new file mode 100644
> index 00000000000..ab998781f10
> --- /dev/null
> +++ b/gdb/testsuite/gdb.arch/aarch64-poe-core.exp
> @@ -0,0 +1,102 @@
> +# Copyright (C) 2026 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 <http://www.gnu.org/licenses/>.
> +
> +# This file is part of the gdb testsuite.
> +
> +# Test generating and reading a core file with POR_EL0.
> +
> +proc check_poe_core_file {core_filename} {
> +    # Load the core file.
> +    if {
> +        [gdb_test "core $core_filename" \

This file is indented only with spaces, when the GDB style is to use
tabs and spaces. Please adjust.

I recently mentioned the .editorconfig file which we use to help
configure editors to automatically use the right settings, perhaps it
can be useful:

https://inbox.sourceware.org/gdb-patches/87zf0jwr23.fsf@linaro.org/

> +            [multi_line \
> +                "Core was generated by .*" \
> +                "Program terminated with signal SIGSEGV, Segmentation fault\\." \

This regexp isn't matching in my test run because GDB doesn't print the
last dot:

Core was generated by `/home/bauermann/.cache/builds/gdb-native/gdb/testsuite/outputs/gdb.arch/aarch64-poe-core/aarch64-poe-core'.^M
Program terminated with signal SIGSEGV, Segmentation fault^M
Protection Key Violation while accessing address 0x0000fffff7ff3000 with Protection Key = 1.^M
#0  0x0000aaaaaaaa09a4 in main () at /home/bauermann/src/binutils-gdb/gdb/testsuite/gdb.arch/aarch64-poe-sigsegv.c:49^M
49	  buf[0] = 42;  /* Expect SIGSEGV POE violation.  */^M
(gdb) FAIL: gdb.arch/aarch64-poe-core.exp: gcore corefile: load core file
UNTESTED: gdb.arch/aarch64-poe-core.exp: gcore corefile: failed to load core file

> +                "Protection Key Violation while accessing address ${::hex} with Protection Key = ${::decimal}\\." \
> +                "#0  ${::hex} in main \\(.*\\) at .*" \
> +                ".*buf\\\[0\\\] = 42;.*"] \
> +            "load core file"]
> +    } {
> +        untested "failed to load core file"
> +        return -1
> +    }
> +
> +    # Check the value of POR_EL0 in the core file.
> +    gdb_test "print/x \$por_el0" " = 0x55" \
> +        "por_el0 contents from core file"

When I remove the dot from the pattern above, this test fails:

print/x $por_el0^M
$1 = 0x37^M
(gdb) FAIL: gdb.arch/aarch64-poe-core.exp: gcore corefile: por_el0 contents from core file

I get the output above both for the gcore and the native corefile.

> +}
> +
> +require is_aarch64_target

This require is redundant, since allow_aarch64_poe_tests already calls
is_aarch64_target.

> +require allow_aarch64_poe_tests
> +
> +standard_testfile aarch64-poe-sigsegv.c
> +
> +if {[prepare_for_testing "failed to prepare" ${testfile} ${srcfile}]} {
> +    return
> +}
> +
> +set binfile [standard_output_file ${testfile}]
> +
> +if {![runto_main]} {
> +    return
> +}
> +
> +set poe_crash_re [multi_line \
> +    "Program received signal SIGSEGV, Segmentation fault\\." \

I also had to remove the dot here to make the RE match.

> +    "Protection Key Violation while accessing address ${::hex} with Protection Key = ${::decimal}\\." \
> +    ".*buf\\\[0\\\] = 42;.*"]
> +
> +gdb_test_multiple "continue" "run to POE crash" {
> +    -re "$poe_crash_re.*$gdb_prompt $" {

$poe_crash_re already has .* at the end, so either remove .* there or
here.

> +        pass $gdb_test_name
> +    }
> +
> +    -re ".*exited with code 01.*$gdb_prompt $" {
> +        unsupported "POE userspace support unavailable"
> +        return
> +    }
> +}
> +
> +# Generate the gcore core file.
> +set gcore_filename [standard_output_file "${testfile}.gcore"]
> +set gcore_generated [gdb_gcore_cmd "$gcore_filename" "generate gcore file"]
> +
> +# Generate a native core file.
> +set core_filename [core_find ${binfile}]
> +set core_generated [expr {$core_filename != ""}]
> +
> +# At this point we have a couple core files, the gcore one generated by GDB
> +# and the native one generated by the Linux Kernel.  Make sure GDB can read
> +# both correctly.
> +
> +if {$gcore_generated} {
> +    clean_restart
> +    gdb_load ${binfile}
> +    with_test_prefix "gcore corefile" {
> +        check_poe_core_file $gcore_filename
> +    }
> +} else {
> +    fail "gcore corefile not generated"
> +}
> +
> +if {$core_generated} {
> +    clean_restart
> +    gdb_load ${binfile}
> +    with_test_prefix "native corefile" {
> +        check_poe_core_file $core_filename
> +    }
> +} else {
> +    untested "native corefile not generated"
> +}
> diff --git a/gdb/testsuite/gdb.arch/aarch64-poe-sigsegv.c b/gdb/testsuite/gdb.arch/aarch64-poe-sigsegv.c
> new file mode 100644
> index 00000000000..6b0c07e782f
> --- /dev/null
> +++ b/gdb/testsuite/gdb.arch/aarch64-poe-sigsegv.c
> @@ -0,0 +1,52 @@
> +/* This test program is part of GDB, the GNU debugger.
> +
> +   Copyright 2026 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 <http://www.gnu.org/licenses/>.  */
> +
> +/* Exercise AArch64's POE Extension.  */
> +
> +/* This test is based on the Linux kernel documentation for Memory
> +   Protection Keys, including the arm64 Permission Overlay Extension
> +   (FEAT_S1POE) support described in
> +   Documentation/core-api/protection-keys.rst.  */
> +
> +#define _GNU_SOURCE
> +#include <sys/mman.h>
> +#include <unistd.h>
> +
> +int
> +main (void)
> +{
> +  long pagesize = sysconf (_SC_PAGESIZE);
> +
> +  int *buf = mmap (NULL, pagesize, PROT_READ | PROT_WRITE,
> +		   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +  if (buf == MAP_FAILED)
> +    return 1;
> +
> +  int pkey = pkey_alloc (0, 0);
> +  if (pkey == -1)
> +    return 1;
> +
> +  if (pkey_mprotect (buf, pagesize, PROT_READ | PROT_WRITE, pkey) == -1)
> +    return 1;
> +
> +  if (pkey_set (pkey, PKEY_DISABLE_WRITE) == -1)
> +    return 1;
> +
> +  buf[0] = 42;  /* Expect SIGSEGV POE violation.  */
> +
> +  return 1;

This needs to be "return 0" for aarch64-poe-sigsegv.exp to pass.

> +}
> diff --git a/gdb/testsuite/gdb.arch/aarch64-poe-sigsegv.exp b/gdb/testsuite/gdb.arch/aarch64-poe-sigsegv.exp
> new file mode 100644
> index 00000000000..b22814f9ab9
> --- /dev/null
> +++ b/gdb/testsuite/gdb.arch/aarch64-poe-sigsegv.exp
> @@ -0,0 +1,60 @@
> +# Copyright (C) 2026 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 <http://www.gnu.org/licenses/>.
> +
> +# Test a binary that supports FEAT_S1POE and exposes POR_EL0 register.
> +
> +global hex
> +global decimal
> +
> +require is_aarch64_target
> +
> +if {![allow_aarch64_poe_tests]} {
> +    unsupported "AArch64 POE not supported"
> +    return
> +}

Like in the previous testcase, is_aarch64_target is redundant, and the
if block above should just be "require allow_aarch64_poe_tests".

> +
> +standard_testfile
> +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
> +    return
> +}
> +
> +if {![runto_main]} {
> +    return
> +}
> +
> +# Display POE violation SIGSEGV error message.
> +set poe_sigsegv_re [multi_line \
> +    "Program received signal SIGSEGV, Segmentation fault\\." \
> +    "Protection Key Violation while accessing address ${hex} with Protection Key = ${decimal}"]
> +
> +gdb_test_multiple "continue" "display POE violation information" {
> +    -re "$poe_sigsegv_re.*$gdb_prompt $" {
> +	pass $gdb_test_name
> +    }
> +    -re ".*exited with code 01.*$gdb_prompt $" {
> +	unsupported "POE userspace support unavailable"
> +	return
> +    }
> +}
> +
> +# Fix the POE permissions (set $por_el0) and continue without delivering SIGSEGV.
> +gdb_test "set \$por_el0 = 0x47" "" \
> +    "allow write access by updating POR_EL0"

It's clearer to use gdb_test_no_output here.

> +
> +gdb_test_multiple "signal 0" "continue after fixing POE fault" {
> +    -re ".*exited normally.*$gdb_prompt $" {

Here is where the change of the last return statement in
aarch64-poe-sigsegv.c is needed, otherwise I get:

signal 0^M
Continuing with no signal.^M
[Inferior 1 (process 1513) exited with code 01]^M
(gdb) FAIL: gdb.arch/aarch64-poe-sigsegv.exp: continue after fixing POE fault (the program exited)

> +	pass $gdb_test_name
> +    }
> +}
> diff --git a/gdb/testsuite/gdb.arch/aarch64-poe.exp b/gdb/testsuite/gdb.arch/aarch64-poe.exp
> new file mode 100644
> index 00000000000..ae2663a7dbc
> --- /dev/null
> +++ b/gdb/testsuite/gdb.arch/aarch64-poe.exp
> @@ -0,0 +1,44 @@
> +# Copyright (C) 2026 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 <http://www.gnu.org/licenses/>.
> +
> +# Test a binary that uses POE and exposed POR_EL0 register.
> +
> +global hex
> +global decimal
> +
> +require is_aarch64_target
> +
> +if {![allow_aarch64_poe_tests]} {
> +    unsupported "AArch64 POE not supported"
> +    return
> +}

Same here: is_aarch64_target is redundant, and the if block above should
just be "require allow_aarch64_poe_tests".

> +
> +standard_testfile
> +if { [prepare_for_testing "failed to prepare" ${testfile} ${srcfile}] } {
> +    return
> +}
> +
> +if {![runto_main]} {
> +    return
> +}
> +
> +# Validate the presence of the POE register.
> +    gdb_test "info registers por_el0" \
> +	     "por_el0\[ \t\]+$hex.*" \
> +	     "register por_el0 available"
> +
> +    gdb_test "p/x \$por_el0" \
> +	     "\\$\[0-9\]+ = ${hex}" \
> +	     "print por_el0"

The gdb_test statements above should start at the first column.

> diff --git a/gdb/testsuite/lib/gdb.exp b/gdb/testsuite/lib/gdb.exp
> index d8619ded236..40a8124955a 100644
> --- a/gdb/testsuite/lib/gdb.exp
> +++ b/gdb/testsuite/lib/gdb.exp
> @@ -5654,6 +5654,61 @@ gdb_caching_proc allow_aarch64_gcs_tests {} {
>      return $allow_gcs_tests
>  }
>  
> +# Run a test on the target to see if it supports AArch64 POE extensions.
> +# Return 1 if so, 0 if it does not.  Note this causes a restart of GDB.
> +
> +gdb_caching_proc allow_aarch64_poe_tests {} {
> +    global srcdir subdir gdb_prompt inferior_exited_re
> +
> +    set me "allow_aarch64_poe_tests"
> +
> +    if { ![is_aarch64_target]} {

Extraneous space after the { above.

> +	return 0
> +    }
> +
> +    # Compile a program that tests the POE feature.
> +    set src {
> +	#include <stdbool.h>
> +	#include <sys/auxv.h>
> +
> +	/* Feature check for POE feature.  */
> +	#ifndef HWCAP2_POE
> +	#define HWCAP2_POE (1ULL << 63)
> +	#endif
> +
> +	int main (void) {
> +	    bool poe_supported = getauxval (AT_HWCAP2) & HWCAP2_POE;
> +
> +	    /* Return success if POE is supported.  */
> +	    return !poe_supported;
> +	}
> +    }
> +
> +    if {![gdb_simple_compile $me $src executable]} {
> +	return 0
> +    }
> +
> +    # Compilation succeeded so now run it via gdb.
> +    set allow_poe_tests 0
> +    clean_restart
> +    gdb_load $obj
> +    gdb_run_cmd
> +    gdb_expect {
> +	-re ".*$inferior_exited_re normally.*${gdb_prompt} $" {
> +	    verbose -log "\n$me: poe support detected"
> +	    set allow_poe_tests 1
> +	}
> +	-re ".*$inferior_exited_re with code 01.*${gdb_prompt} $" {
> +	    verbose -log "\n$me: poe support not detected"
> +	}
> +    }
> +    gdb_exit
> +    remote_file build delete $obj
> +
> +    verbose "$me:  returning $allow_poe_tests" 2

Extraneous space after the : above.

> +    return $allow_poe_tests
> +}
> +
>  # A helper that compiles a test case to see if __int128 is supported.
>  proc gdb_int128_helper {lang} {
>      return [gdb_can_simple_compile "i128-for-$lang" {

-- 
Thiago
(he/him)

  reply	other threads:[~2026-07-01  5:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-26 18:08 [PATCH v2 0/7] gdb/aarch64: Add support for FEAT_S1POE feature srinath.parvathaneni
2026-06-26 18:08 ` [PATCH v2 1/7] gdb/aarch64: Add POR_EL0 register support for FEAT_S1POE srinath.parvathaneni
2026-06-27  6:06   ` Thiago Jung Bauermann
2026-06-29 10:44     ` Srinath Parvathaneni
2026-07-01  5:16       ` Thiago Jung Bauermann
2026-07-01 14:45         ` Marc Zyngier
2026-06-26 18:08 ` [PATCH v2 2/7] gdb/aarch64: Add custom printing for POR_EL0 srinath.parvathaneni
2026-06-27  7:03   ` Thiago Jung Bauermann
2026-06-29  7:02     ` Srinath Parvathaneni
2026-06-29 15:58       ` Ezra Sitorus
2026-06-26 18:08 ` [PATCH v2 3/7] gdb: Improve SIGSEGV diagnostics for POE faults srinath.parvathaneni
2026-06-29  2:42   ` Thiago Jung Bauermann
2026-06-26 18:08 ` [PATCH v2 4/7] gdbserver/aarch64: Add POR_EL0 register support srinath.parvathaneni
2026-06-29  2:43   ` Thiago Jung Bauermann
2026-06-26 18:08 ` [PATCH v2 5/7] bfd/readelf: Add core file support for FEAT_S1POE srinath.parvathaneni
2026-06-29  2:43   ` Thiago Jung Bauermann
2026-06-26 18:08 ` [PATCH v2 6/7] gdb/aarch64: " srinath.parvathaneni
2026-06-29  2:44   ` Thiago Jung Bauermann
2026-06-26 18:08 ` [PATCH v2 7/7] gdb/testsuite: Add FEAT_S1POE testcases srinath.parvathaneni
2026-07-01  5:12   ` Thiago Jung Bauermann [this message]
2026-06-29 12:18 ` [PATCH v2 0/7] gdb/aarch64: Add support for FEAT_S1POE feature Guinevere Larsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87cxx7guoa.fsf@linaro.org \
    --to=thiago.bauermann@linaro.org \
    --cc=Ezra.Sitorus@arm.com \
    --cc=Matthieu.Longo@arm.com \
    --cc=gdb-patches@sourceware.org \
    --cc=guinevere@redhat.com \
    --cc=luis.machado.foss@gmail.com \
    --cc=srinath.parvathaneni@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox