From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 0aOXIf1xtWn8NSkAWB0awg (envelope-from ) for ; Sat, 14 Mar 2026 10:34:37 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DxOsrJky; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 856511E0DD; Sat, 14 Mar 2026 10:34:37 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id D94291E08D for ; Sat, 14 Mar 2026 10:34:36 -0400 (EDT) Received: from vm01.sourceware.org (localhost [127.0.0.1]) by sourceware.org (Postfix) with ESMTP id 05FB34C318B1 for ; Sat, 14 Mar 2026 14:34:36 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 05FB34C318B1 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=DxOsrJky Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 9E5954C31890 for ; Sat, 14 Mar 2026 14:32:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9E5954C31890 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9E5954C31890 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773498752; cv=none; b=WmqFHCARYQbLeohjdSW1weQkKppLuJvAiKYaKhVJh7Gl+w2PLGUUTWHVe/50bfwaOs12QB/EHk/qWkVxGKBzSUcMqyATycUWva4V84GBAZd4rj7cIjHYj61dHra1hG0egT8iFX+7XeEMugYySqbTksnYi/NijcVLrws22LFxLD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1773498752; c=relaxed/simple; bh=xihM6n1OIP4KEc6nRLpsIsc4Igt+GBt8bDbnEN5XdTE=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=owWajlqhBYuqXsmZwN2TLU4PWt459CkRidoJ3yNISh51PUU/nWf70qS8XrGX+g4sY5eJkr8W4NzlXvTYJndHVYwlr50nC7Uyqn4hLRbDpuL7HHpjof7FF8VoyUdA4Ic/GMJt6hU7wKkmBlro6IkEFesyOqWq4zPL9Tf3D2RTPy4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E5954C31890 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1773498752; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tzKDIqL2TdgNnyMjYU70iMYEZMPZgruFGit6FG9JrDg=; b=DxOsrJkyYf5q5jq6iBUyWUrw+Wulc0SanofaW9EQ8HY9fgcr9fyxOMKWOU+WPsPd/Tasc3 o5QUfaDxSJWBN74d50TFH+gPV4NBZNkDEJrEHLDd5264oxmw2NYFnN38x7XDJZorFFw5O7 szDZTyF4OKFJ+Bs4x+2S83Fvm4VFF3k= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-433-5Wr-kAZkPC-mBxPZGuRn4A-1; Sat, 14 Mar 2026 10:32:31 -0400 X-MC-Unique: 5Wr-kAZkPC-mBxPZGuRn4A-1 X-Mimecast-MFC-AGG-ID: 5Wr-kAZkPC-mBxPZGuRn4A_1773498750 Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-439c4d71603so2828405f8f.0 for ; Sat, 14 Mar 2026 07:32:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773498749; x=1774103549; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=tzKDIqL2TdgNnyMjYU70iMYEZMPZgruFGit6FG9JrDg=; b=N2ZiDGJqVb6IIn5Ug5mvVNXAmfk4JYl3asqMy1NQ7u9eX66B+wirXMMScq+4vy47Hu sziutYTYpi2go9spJkEJ5hCOjqSgmhswGOnb5+WlcYalD8t9+NHoE96GlJgzuqmftnjG 9A15goR4A2ZrGLr+xpPciS8yEpg5Tglr3kMvwJ55weMF2aNRDRKhjfwJlGUsB9tnHXGN 62waeZV8O/DgMoysyeBm5Xo6DXD+ZjE+Nxau/yDBTy1ybmFp8bFN0Yql2DyaQZVahcKV Rck/IBJ3QSo+rIdtm5ZN47eJF9AunUpgj9ot3N634xLjfW5VmbG3/c/0orjEs8sYFQIv 7tMw== X-Gm-Message-State: AOJu0Yzy2IB/GKfgIagjgVkuxQ09DR8WEXN4ZeKMQNFMrDDRWem8fLGH hxlClGmqN1FYawg4UxbwTczT9kb3BYKmuiz5nZolraWGyCPgYo8jQYUYTleEGPsXohX6zAVWVw7 UBiXRxPguWCUJLDZG0bEHXgl/oeJYDEc6MxsGDkpNqFKpc3/kfHV0zWx00h2b/UzHChn1hNBjS8 4P3K80Rpe3fzjkro0UTQgc4t8KVM2jGdJhQHk1dkdEyVkNS2o= X-Gm-Gg: ATEYQzxPZlucfKREE7kylYX7IL7LHzLPuSznSvZQYOrds+dSrkbhAbRXBe/i3EAp+EK cfZ6ZMrGiCGO6HhTUucgdhIz5zG57K+EsdXeXBpOZnDgiNqNhvKCaHfgqRvSrD1xgKQEfoyJZ3A 26k8ZNHv+56jHzq/4cO6mOBmrTFaXRthtEYtvAxMY+5L+gjxQr860RufBStQlfoRmxX2U/OzVLK 8u327tmz7nSlE3phIqQJDvrM6Jpe7aU8bXnz0X2sM6xmkXl0vk7wB2qqFZ0Q7ayOlwHpe2xIZMI QIWU604ER+q/Sg9ESVeZww8Ztod0sGdS4V9wLqryg6BnXFmFCVXPqD8Nul4YbqrtdCsDkKhHpD1 BhAkHpWSKEe0uPR2i2saaV1OsWotu9IqXB5Nc6dpEeU7o1A== X-Received: by 2002:a05:600c:4fd5:b0:46e:59bd:f7e2 with SMTP id 5b1f17b1804b1-48555b2c8fbmr115420735e9.11.1773498749065; Sat, 14 Mar 2026 07:32:29 -0700 (PDT) X-Received: by 2002:a05:600c:4fd5:b0:46e:59bd:f7e2 with SMTP id 5b1f17b1804b1-48555b2c8fbmr115420095e9.11.1773498748392; Sat, 14 Mar 2026 07:32:28 -0700 (PDT) Received: from localhost (92.40.185.182.threembb.co.uk. [92.40.185.182]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-48556413456sm46654885e9.5.2026.03.14.07.32.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 14 Mar 2026 07:32:27 -0700 (PDT) From: Andrew Burgess To: gdb-patches@sourceware.org Cc: Andrew Burgess Subject: [PATCH 1/5] gdb/testsuite: improve corefile-no-threads.py script Date: Sat, 14 Mar 2026 14:32:18 +0000 Message-Id: <108bd96facee514909bcc38bf74161689090921e.1773498341.git.aburgess@redhat.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: References: MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: vtFexfVVee1kvnZoOjvmU_YWOkPQpBUa7kmxdvvNHR4_1773498750 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true 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~public-inbox=simark.ca@sourceware.org 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 [ ] # -# Find all notes in the core file that have the type value -# . Change the type of those notes to 0xffffffff, which -# should prevent GDB from processing the note. The is -# modified in place. +# Find all notes in the core file that have the 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 is modified in place. # # The optional argument 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