From: Vignesh Balasubramanian <vigbalas@amd.com>
To: <gdb-patches@sourceware.org>, <jinisusan.george@amd.com>,
<christina.schimpe@intel.com>, <AlokKumar.Sharma@amd.com>,
<jhb@FreeBSD.org>, <simark@simark.ca>
Subject:
Date: Sun, 8 Feb 2026 09:48:14 +0530 [thread overview]
Message-ID: <20260208041850.750817-1-vigbalas@amd.com> (raw)
In-Reply-To: <SN7PR11MB76384822431D85238D8B5165F9ACA@SN7PR11MB7638.namprd11.prod.outlook.com>
The test validates two things: (1) the gcore component that generates a
kernel-like core note using the gcore command, and (2) the gdb component
that internalizes that note via "maint info sections".
The test does not depend on the OS version.
The test is currently unsupported under gdbserver because support for
target-specific core notes for remote targets is not yet implemented.
Updated the patch with distinct functions and to improve error handling.
Please share your comments, i will send v4 with this test case.
From 2d7bde97ed90f43bfb18e83beb9ebec2ce22b7d2 Mon Sep 17 00:00:00 2001
From: Vignesh Balasubramanian <vigbalas@amd.com>
Date: Sun, 8 Feb 2026 09:03:43 +0530
Subject: [PATCH] Test case to validate the new .note section
NT_X86_XSAVE_LAYOUT
This test case is divided into 3 parts.
First, it calls gdb on a small program and dumps a core file through
the 'gcore' command.
Second, load the generated core file into gdb and invoke
"maint info sect .reg-xsave-layout" to learn the offsets of xsave features
from the new .note section in the core file and size of the note.
Third, invoke another program, with core file and its information,
which validates the value of xsave feature records inside the .note section
using cpuid instruction.
So it validates both the core consumption(Patch-1) and generation through
gcore(Patch-2).
Co-Authored-By: Jini Susan George <jinisusan.george@amd.com>
---
gdb/testsuite/gdb.arch/x86-xsave-layout.c | 120 ++++++++++++++++++
gdb/testsuite/gdb.arch/x86-xsave-layout.exp | 131 ++++++++++++++++++++
2 files changed, 251 insertions(+)
create mode 100644 gdb/testsuite/gdb.arch/x86-xsave-layout.c
create mode 100644 gdb/testsuite/gdb.arch/x86-xsave-layout.exp
diff --git a/gdb/testsuite/gdb.arch/x86-xsave-layout.c b/gdb/testsuite/gdb.arch/x86-xsave-layout.c
new file mode 100644
index 00000000000..6d127af151b
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/x86-xsave-layout.c
@@ -0,0 +1,120 @@
+/* Test program for .note section that contains XSAVE layout description
+ in core files.
+
+ Copyright 2021-2025 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ 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/>. */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include "nat/x86-cpuid.h"
+
+#define XSAVE_LEAF 0xD
+
+struct x86_xfeat_component
+{
+ uint32_t type;
+ uint32_t size;
+ uint32_t offset;
+ uint32_t flags;
+};
+
+#define FAIL_IF(x) if (x) { \
+ printf("Record Mismatch."); \
+ exit (1); }
+
+/* This function read xsave feature records present in the .note of core
+ file and compare it with value of cpuid instruction. */
+
+void
+read_and_test_cpuid_records (const char *core_path, unsigned file_off,
+ unsigned note_size)
+{
+ FILE *fp = fopen (core_path, "rb");
+
+ fseek(fp, file_off, SEEK_SET);
+
+ struct x86_xfeat_component *xsave_layout_desc = (struct x86_xfeat_component *)
+ malloc (note_size);
+ if (fread(xsave_layout_desc, 1, note_size, fp) != note_size)
+ {
+ printf ("Couldn't read records from core file\n");
+ free (xsave_layout_desc);
+ fclose(fp);
+ exit(1);
+ }
+
+ int num_records = (note_size / sizeof(struct x86_xfeat_component));
+
+ unsigned int eax=0,ebx=0,ecx=0,edx=0;
+ for (int i=0; i<num_records; i++)
+ {
+
+ x86_cpuid_count (XSAVE_LEAF,
+ xsave_layout_desc[i].type,
+ &eax, &ebx, &ecx, &edx);
+
+ FAIL_IF (xsave_layout_desc[i].size != eax );
+ FAIL_IF (xsave_layout_desc[i].offset != ebx);
+ FAIL_IF (xsave_layout_desc[i].flags != ecx);
+ }
+
+ free(xsave_layout_desc);
+ fclose(fp);
+}
+
+
+/* This program is called with core file, offset of .note section
+ * where xsave feature records are saved and number of records */
+int main(int argc, char *argv[])
+{
+ unsigned file_off;
+ unsigned note_size;
+
+ /* argv[1] = core file name.
+ argv[2] = file offset at which cpuid record starts.
+ argv[3] = total size of cpuid records. */
+
+ if (argc < 4)
+ {
+ printf ("%d: bad command line arguments\n", argc);
+ exit (1);
+ }
+
+ if (sscanf (argv[2], "%x", &file_off) != 1)
+ {
+ printf ("%s: bad command line arguments\n", argv[2]);
+ exit (1);
+ }
+
+ if (sscanf (argv[3], "%x", ¬e_size) != 1)
+ {
+ printf ("%s: bad command line arguments\n", argv[3]);
+ exit(1);
+ }
+
+ /* sanity check. */
+ if ((note_size % sizeof (struct x86_xfeat_component)) != 0 || note_size == 0)
+ {
+ printf ("invalid size of cpuid records = %d\n", note_size);
+ exit(1);
+ }
+
+ /* read the records from core file and test. */
+ read_and_test_cpuid_records(argv[1], file_off, note_size);
+ printf ("Records matches with CPUID instruction .\n");
+}
diff --git a/gdb/testsuite/gdb.arch/x86-xsave-layout.exp b/gdb/testsuite/gdb.arch/x86-xsave-layout.exp
new file mode 100644
index 00000000000..6a5fdfdfb39
--- /dev/null
+++ b/gdb/testsuite/gdb.arch/x86-xsave-layout.exp
@@ -0,0 +1,131 @@
+# Copyright 2025-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/>.
+
+# Program x86-xsave-layout.c is compiled and invoked with args
+# gcore file "x86-xsave-layout.gcore", offset at which cpuid record starts
+# and size of cpuid records to validate the .note section.
+
+require {is_any_target "x86_64-*-linux*"}
+
+# target-specific core note functionality has not yet been implemented for remote
+# targets, so gdbserver doesn't dump this note.
+require !gdb_protocol_is_remote
+
+standard_testfile
+
+set options [list c++ debug \
+ additional_flags=-I$srcdir/../ \
+ additional_flags=-I$srcdir/../../ ]
+
+if { [build_executable "failed to prepare" $testfile $srcfile $options] } {
+ return
+}
+
+# Dump a core file throug gcore.
+proc test_dump_native_core { corefile } {
+
+ if {![gcore_cmd_available]} {
+ unsupported "gcore command not available"
+ return 0
+ }
+
+ clean_restart $::testfile
+ if {![runto_main]} {
+ return 0
+ }
+
+ if {![gdb_gcore_cmd $corefile "dump core"]} {
+ return 0
+ }
+
+ gdb_exit
+
+ return 1
+}
+
+# Use "maint info section" command to find the new note section and
+# offset at which stored in file as well as size of it.
+proc get_note_offset_size {corefile} {
+ clean_restart
+
+ if { $corefile eq "" } {
+ unsupported "unable to generate core file"
+ return
+ }
+ gdb_core_cmd $corefile "load corefile"
+
+ set xsave_record [capture_command_output "maint info sect .reg-xsave-layout" ""]
+
+ set info_line [lindex [split $xsave_record "\n"] 2]
+ set info_line_substr [regexp -all -inline {\S+} $info_line]
+ set offset [regsub ":" [lindex $info_line_substr 3] ""]
+ set size [lindex [split [lindex $info_line_substr 1] "->"] 2]
+
+ return [list $offset $size]
+}
+
+# Compare the the data in core file with the output of CPUID instruction.
+proc compare_gcore_cpuid {corefile offset size} {
+ clean_restart $::testfile
+
+ gdb_test "set args $corefile $offset $size "
+
+ if {![runto_main]} {
+ return
+ }
+
+ # Look for "Records matches with CPUID"
+ set test "Compare CPUID Records"
+ gdb_test_multiple "continue" $test {
+ -re "Records matches with CPUID" {
+ pass $test
+ }
+ }
+}
+
+# Dump core file through gcore command.
+# Find the offset and size of the note section and compare it
+# with the output of CPUID instruction.
+proc test_gcore_xsave_layout_note {} {
+
+ set corefile [standard_output_file ${::testfile}.gcore]
+
+ #Dump a gcore file
+ if {![test_dump_native_core $corefile]} {
+ unsupported "Core dump failed"
+ return
+ }
+
+ set offset 0
+ set size 0
+
+ if { $corefile eq "" } {
+ unsupported "unable to generate core file"
+ return
+ }
+
+ #Find offset and size of a xsave layout note in the corefile
+ lassign [get_note_offset_size $corefile] offset size
+
+ if { $offset eq "" || $size eq "" } {
+ fail "No xsave layout note section present in core file."
+ return
+ }
+
+ compare_gcore_cpuid $corefile $offset $size
+}
+
+#test
+test_gcore_xsave_layout_note
--
2.34.1
next prev parent reply other threads:[~2026-02-08 4:20 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-08 8:38 [PATCH 32 0/2] Handle the new .note section introduced in Linux Vignesh Balasubramanian
2025-12-08 8:38 ` [PATCH 32 1/2] core: Consume the new .note section that contains descriptions of xsave layout Vignesh Balasubramanian
2025-12-08 8:38 ` [PATCH 32 2/2] gcore: Create a new .note section for x86 Vignesh Balasubramanian
2025-12-14 13:39 ` [PATCH 32 0/2] Handle the new .note section introduced in Linux Schimpe, Christina
2026-01-06 6:48 ` Balasubrmanian, Vignesh
2026-03-06 7:08 ` Schimpe, Christina
2026-03-06 7:42 ` Balasubrmanian, Vignesh
2026-03-06 8:13 ` Schimpe, Christina
2026-03-11 9:50 ` Schimpe, Christina
2026-03-13 14:08 ` Schimpe, Christina
2026-03-17 10:02 ` Schimpe, Christina
2026-02-08 4:18 ` Vignesh Balasubramanian [this message]
2026-03-16 12:59 ` Schimpe, Christina
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=20260208041850.750817-1-vigbalas@amd.com \
--to=vigbalas@amd.com \
--cc=AlokKumar.Sharma@amd.com \
--cc=christina.schimpe@intel.com \
--cc=gdb-patches@sourceware.org \
--cc=jhb@FreeBSD.org \
--cc=jinisusan.george@amd.com \
--cc=simark@simark.ca \
/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