Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Andrew Burgess <aburgess@redhat.com>
To: gdb-patches@sourceware.org
Cc: Andrew Burgess <aburgess@redhat.com>
Subject: [PATCH 1/5] gdb/testsuite: improve corefile-no-threads.py script
Date: Sat, 14 Mar 2026 14:32:18 +0000	[thread overview]
Message-ID: <108bd96facee514909bcc38bf74161689090921e.1773498341.git.aburgess@redhat.com> (raw)
In-Reply-To: <cover.1773498341.git.aburgess@redhat.com>

Extend the Python script gdb.base/corefile-no-threads.py so that core
file note types can be specified by name, e.g. NT_PRSTATUS, rather
than having to use their hex value.

I've only added a few names for now.  The existing test only needs
NT_PRSTATUS, but I plan to reuse this script for a new test, in which
case I'll also need NT_FILE.  Additional names can be added in the
future as needed.

I then updated the gdb.base/corefile-no-threads.exp script to make use
of this functionality, and I improved the test pattern so that it
actually checks that a note was updated.

There should be no change in what is tested after this commit.
---
 .../gdb.base/corefile-no-threads.exp          | 10 ++--
 gdb/testsuite/gdb.base/corefile-no-threads.py | 47 ++++++++++++++-----
 2 files changed, 41 insertions(+), 16 deletions(-)

diff --git a/gdb/testsuite/gdb.base/corefile-no-threads.exp b/gdb/testsuite/gdb.base/corefile-no-threads.exp
index dfb2f806e9e..d21d7cf4030 100644
--- a/gdb/testsuite/gdb.base/corefile-no-threads.exp
+++ b/gdb/testsuite/gdb.base/corefile-no-threads.exp
@@ -15,8 +15,8 @@
 
 # Check how GDB handles a core file which appears to have no threads
 # within it.  We do this by asking the kernel to create a "normal"
-# core file, then use a Python script modify the core file, hiding the
-# NT_PRSTATUS notes.  The NT_PRSTATUS notes contain the general
+# core file, then use a Python script to modify the core file, hiding
+# the NT_PRSTATUS notes.  The NT_PRSTATUS notes contain the general
 # purpose registers for each thread, so with these gone GDB will
 # believe the core file has no threads.
 #
@@ -52,7 +52,11 @@ clean_restart
 # Load the Python script, and run the command which modifies the core
 # file.
 gdb_test_no_output "source $::pyfile" "import python scripts"
-gdb_test "modify-core-file \"$corefile\" 0x1" ".*" \
+gdb_test "modify-core-file \"$corefile\" NT_PRSTATUS" \
+    [multi_line \
+	 "Located PT_NOTE segment: \[^\r\n\]+" \
+	 "\\s+Found note with type $hex at file offset $hex\\..*" \
+	 "Successfully updated $decimal note\\(s\\) in \[^\r\n\]+"] \
     "update core file"
 
 set saw_no_regs_warning false
diff --git a/gdb/testsuite/gdb.base/corefile-no-threads.py b/gdb/testsuite/gdb.base/corefile-no-threads.py
index 5ba82ae9486..fb2a91e57d0 100644
--- a/gdb/testsuite/gdb.base/corefile-no-threads.py
+++ b/gdb/testsuite/gdb.base/corefile-no-threads.py
@@ -18,10 +18,10 @@
 #
 # modify-core-file <corefile> <note type> [ <name regex> ]
 #
-# Find all notes in the core file <corefile> that have the type value
-# <note type>.  Change the type of those notes to 0xffffffff, which
-# should prevent GDB from processing the note.  The <corefile> is
-# modified in place.
+# Find all notes in the core file <corefile> that have the type
+# <note type>, either a name (e.g. NT_PRSTATUS) or an integer.
+# Change the type of those notes to 0xffffffff, which should prevent
+# GDB from processing the note.  The <corefile> is modified in place.
 #
 # The optional argument <name regex> is a regular expression to match
 # against the name of the note in addition to the type value check.
@@ -130,7 +130,7 @@ def invalidate_corefile_notes(core_filepath, type_val, name_re):
     ei_data = read_field(core_data, 5, "=b")
     ei_version = read_field(core_data, 6, "=b")
 
-    # Based on the endinanness of the core file, select a character to
+    # Based on the endianness of the core file, select a character to
     # use with the 'struct' module for unpacking multi-byte fields.
     if ei_data == ELF_DATA_2_LSB:
         endian_char = "<"
@@ -194,7 +194,7 @@ def invalidate_corefile_notes(core_filepath, type_val, name_re):
     # Read the e_type field and check this is a core file.
     e_type = read_field(core_data, ELF_HDR_TYPE_OFFSET, ELF_HALF_FMT)
     if e_type != ELF_TYPE_CORE:
-        raise gdb.GdbError("Unsuported ELF e_type %d" % (e_type))
+        raise gdb.GdbError("Unsupported ELF e_type %d" % (e_type))
 
     # Read the offset to the program header table, and the number of
     # entries in the program header table.
@@ -308,6 +308,31 @@ def invalidate_corefile_notes(core_filepath, type_val, name_re):
             )
 
 
+# A limited set of note names.  Extend this as needed.
+NOTE_TYPES = {
+    "NT_PRSTATUS": 1,
+    "NT_FPREGSET": 2,
+    "NT_PRPSINFO": 3,
+    "NT_TASKSTRUCT": 4,
+    "NT_AUXV": 6,
+    "NT_SIGINFO": 0x53494749,
+    "NT_FILE": 0x46494C45,
+    "NT_PRXFPREG": 0x46E62B7F,
+}
+
+
+def parse_type(type_str):
+    """Resolves string name to integer or parses raw hex/int."""
+    if type_str in NOTE_TYPES:
+        return NOTE_TYPES[type_str]
+    try:
+        return int(type_str, 0)
+    except ValueError as e:
+        raise gdb.GdbError(
+            "Error: Unable to parse '%s' as number: %s" % (type_str, str(e))
+        )
+
+
 class modify_core_file(gdb.Command):
     """Update notes within a core file.
 
@@ -315,7 +340,8 @@ class modify_core_file(gdb.Command):
     modify-core-file COREFILE NOTE_TYPE [ NAME_REGEX ]
 
     Within COREFILE, find any notes matching NOTE_TYPE, which should
-    be an integer.  Change the type of these notes to 0xffffffff.
+    be either a note type name (e.g. NT_PRSTATUS) or an integer.
+    Change the type of these notes to 0xffffffff.
 
     If NAME_REGEX is supplied, and is not the empty string, then only
     notes whose type matches NOTE_TYPE, and whose name matches
@@ -352,12 +378,7 @@ class modify_core_file(gdb.Command):
                 "Error: Cannot write to '%s'. Check file permissions." % (filename)
             )
 
-        try:
-            type_val = int(type_str, 0)
-        except ValueError as e:
-            raise gdb.GdbError(
-                "Error: Unable to parse '%s' as number: %s" % (type_str, str(e))
-            )
+        type_val = parse_type(type_str)
 
         if name_re_str != "":
             name_re = re.compile(name_re_str)
-- 
2.25.4


  reply	other threads:[~2026-03-14 14:34 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-14 14:32 [PATCH 0/5] Improved support for core files with missing NT_FILE note Andrew Burgess
2026-03-14 14:32 ` Andrew Burgess [this message]
2026-03-14 14:32 ` [PATCH 2/5] gdb/testsuite: restructure gdb.base/corefile-buildid.exp Andrew Burgess
2026-03-14 14:32 ` [PATCH 3/5] gdb: remove 'num' argument from gdbarch_read_core_file_mappings callback Andrew Burgess
2026-03-14 14:32 ` [PATCH 4/5] gdb: remove pre-loop callback from gdbarch_read_core_file_mappings Andrew Burgess
2026-03-14 14:32 ` [PATCH 5/5] gdb/linux: handle missing NT_FILE note when opening core files Andrew Burgess
2026-04-23 22:08   ` Keith Seitz
2026-05-01 19:09     ` Andrew Burgess
2026-04-23 22:06 ` [PATCH 0/5] Improved support for core files with missing NT_FILE note Keith Seitz

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=108bd96facee514909bcc38bf74161689090921e.1773498341.git.aburgess@redhat.com \
    --to=aburgess@redhat.com \
    --cc=gdb-patches@sourceware.org \
    /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