From patchwork Tue Jun 2 11:11:21 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Schimpe, Christina" X-Patchwork-Id: 136294 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A58024BA2E0D for ; Tue, 2 Jun 2026 11:12:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A58024BA2E0D Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=CecTGt2r X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by sourceware.org (Postfix) with ESMTPS id 117584BA2E1C for ; Tue, 2 Jun 2026 11:11:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 117584BA2E1C Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 117584BA2E1C Authentication-Results: sourceware.org; arc=none smtp.remote-ip=198.175.65.9 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780398703; cv=none; b=s1A/qwuNI0TAcTSeHqv3tCdFh650hMnav55y1naMC4s6FqTKFF1X9SUAvJKU3HD8m6TWw2nCbhD64HH9VVOFO1hZoPkTisvSkBz8/dlh+cuiFitEfGhRLkJu0ZzEcZCKBjyYDo296C+7G4eT6icgtGX6K4MN4PzB3vtI0rzbbsw= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1780398703; c=relaxed/simple; bh=stnGir/zD4yV1jueFWMYzvy9lEfPyaPozR6ezzzDJhM=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=FJabiKI8YIU5TaaX3c4pkJJx9QBY+DAfEFqqbGjVb8aFPidmXun0cX+k4k0/GNMJnV0+og6Pe0uYOdSdDQhn9+gbUbzNk9/WRaR0VmQRW1dJjdW8+9eX5XJopzJWgHWJd6fZkRwBwd7XCPjMu8R4OqC4ZrLXlXeC4m399qd9x3g= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=CecTGt2r DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 117584BA2E1C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1780398703; x=1811934703; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=stnGir/zD4yV1jueFWMYzvy9lEfPyaPozR6ezzzDJhM=; b=CecTGt2rQJ2puZ/981naUtqS5YvbN6nBT017URhR4iTtP7/neINthybp zeYqLCmAmubqzWtkWbQLiA30cWwv8CIMnHfgT6xj10QOWq4GoWeKQOFPO /QbM7zdasByb6ZzcCb9HumQGW80J7qNt3D2TQ6YT/37CbhVNizG2jdkO0 +gpFBnmEwuUCR0T8Fpz2u7vp8a5xPJERSTLeG7pOwZqHgwP7Zb/yNtMjT x0cHLstQroON7nG9SVH49FPYtX5lC1aimfwgHmFf6qn9MkL5W0CYsXjbO dClMvDNMLCrMEILZGWjFUSgPdgopnesCxjbzRJfTLA9RZA9Il/TrFtPy5 w==; X-CSE-ConnectionGUID: 96G2g/vGTLu+68wyOfV4tg== X-CSE-MsgGUID: KrLYBqkqRn24wrtO3rbXUA== X-IronPort-AV: E=McAfee;i="6800,10657,11804"; a="103840257" X-IronPort-AV: E=Sophos;i="6.24,183,1774335600"; d="scan'208";a="103840257" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2026 04:11:42 -0700 X-CSE-ConnectionGUID: A2yt/k7sQZy0wW/T2g+hNA== X-CSE-MsgGUID: C4IUJBYwQCuywSCN0iDFmA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.24,183,1774335600"; d="scan'208";a="243989905" Received: from gkldtt-dev-004.igk.intel.com (HELO localhost) ([10.123.221.202]) by orviesa007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Jun 2026 04:11:42 -0700 From: Christina Schimpe To: gdb-patches@sourceware.org Cc: hjl.tools@gmail.com, keiths@redhat.com Subject: [PATCH 1/2] gdb: add maintenance set/show gcore xml-target-description command Date: Tue, 2 Jun 2026 11:11:21 +0000 Message-Id: <20260602111122.3187712-2-christina.schimpe@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20260602111122.3187712-1-christina.schimpe@intel.com> References: <20260602111122.3187712-1-christina.schimpe@intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE, SPF_NONE, TXREP, URIBL_BLOCKED shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org 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~patchwork=sourceware.org@sourceware.org From: Felix Willgerodt This command will allow to enable/disable creating the NT_GDB_TDESC note in corefiles. While GDB writes and reads this node, there aren't really many other pieces of software that create this node (e.g. the Linux kernel doesn't). To be able to test the code path in GDB that is used when NT_GDB_TDESC is not there, add a maintenance command which tests can use to test both cases. Co-authored-by: Christina Schimpe Reviewed-By: Eli Zaretskii Reviewed-By: Keith Seitz --- gdb/NEWS | 6 ++++++ gdb/doc/gdb.texinfo | 7 +++++++ gdb/elf-none-tdep.c | 16 +++++++++------- gdb/fbsd-tdep.c | 15 +++++++++------ gdb/gcore.c | 40 ++++++++++++++++++++++++++++++++++++++++ gdb/gcore.h | 3 +++ gdb/linux-tdep.c | 15 +++++++++------ 7 files changed, 83 insertions(+), 19 deletions(-) diff --git a/gdb/NEWS b/gdb/NEWS index 7c8cf9af4c2..eef1924c9f0 100644 --- a/gdb/NEWS +++ b/gdb/NEWS @@ -97,6 +97,12 @@ AArch64 MinGW aarch64-*-mingw* * New commands +maintenance set/show gcore xml-target-description + With this command you can control whether or not the generate-core-file + command emits the NT_GDB_TDESC note. This is mainly useful for testing + how GDB handles corefiles without this note, as not all software that + creates corefiles generates it. + set local-environment show local-environment unset local-environment diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo index a698b2b8451..636fd0d6b1f 100644 --- a/gdb/doc/gdb.texinfo +++ b/gdb/doc/gdb.texinfo @@ -42077,6 +42077,13 @@ buffer. Control whether @value{GDBN} will skip PAD packets when computing the packet history. +@kindex maint set gcore xml-target-description +@item maint set gcore xml-target-description +@kindex maint show gcore xml-target-description +@item maint show gcore xml-target-description +Control whether @value{GDBN} will create the NT_GDB_TDESC note when using +the @samp{generate-core-file} command. + @kindex maint info jit @item maint info jit Print information about JIT code objects loaded in the current inferior. diff --git a/gdb/elf-none-tdep.c b/gdb/elf-none-tdep.c index 0d063038f5e..f874ba9d4b9 100644 --- a/gdb/elf-none-tdep.c +++ b/gdb/elf-none-tdep.c @@ -109,13 +109,15 @@ elf_none_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, ¬e_data, note_size); } - - /* Include the target description when possible. Some architectures - allow for per-thread gdbarch so we should really be emitting a tdesc - per-thread, however, we don't currently support reading in a - per-thread tdesc, so just emit the tdesc for the signalled thread. */ - gdbarch = target_thread_architecture (signalled_thr->ptid); - gcore_elf_make_tdesc_note (gdbarch, obfd, ¬e_data, note_size); + if (maint_gcore_emit_xml_tdesc) + { + /* Include the target description when possible. Some architectures + allow for per-thread gdbarch so we should really be emitting a tdesc + per-thread, however, we don't currently support reading in a + per-thread tdesc, so just emit the tdesc for the signalled thread. */ + gdbarch = target_thread_architecture (signalled_thr->ptid); + gcore_elf_make_tdesc_note (gdbarch, obfd, ¬e_data, note_size); + } return note_data; } diff --git a/gdb/fbsd-tdep.c b/gdb/fbsd-tdep.c index 419f935ea72..d77395dbb45 100644 --- a/gdb/fbsd-tdep.c +++ b/gdb/fbsd-tdep.c @@ -762,12 +762,15 @@ fbsd_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) return NULL; } - /* Include the target description when possible. Some architectures - allow for per-thread gdbarch so we should really be emitting a tdesc - per-thread, however, we don't currently support reading in a - per-thread tdesc, so just emit the tdesc for the signalled thread. */ - gdbarch = target_thread_architecture (signalled_thr->ptid); - gcore_elf_make_tdesc_note (gdbarch, obfd, ¬e_data, note_size); + if (maint_gcore_emit_xml_tdesc) + { + /* Include the target description when possible. Some architectures + allow for per-thread gdbarch so we should really be emitting a tdesc + per-thread, however, we don't currently support reading in a + per-thread tdesc, so just emit the tdesc for the signalled thread. */ + gdbarch = target_thread_architecture (signalled_thr->ptid); + gcore_elf_make_tdesc_note (gdbarch, obfd, ¬e_data, note_size); + } return note_data; } diff --git a/gdb/gcore.c b/gdb/gcore.c index e50115370c7..03876969ae9 100644 --- a/gdb/gcore.c +++ b/gdb/gcore.c @@ -28,6 +28,7 @@ #include "completer.h" #include "gcore.h" #include "cli/cli-decode.h" +#include "cli/cli-cmds.h" #include #include "regcache.h" #include "regset.h" @@ -919,6 +920,24 @@ gcore_find_signalled_thread () return nullptr; } +/* When true, emit NT_GDB_TDESC. */ +bool maint_gcore_emit_xml_tdesc = true; + +/* Command lists for gcore maintenance commands. */ +struct cmd_list_element *maint_gcore_cmdlist; +struct cmd_list_element *maint_gcore_set_cmdlist; +struct cmd_list_element *maint_gcore_show_cmdlist; + +/* "Show" callback for "maint set gcore xml-target-description". */ +static void +show_gcore_xml_target_description (struct ui_file *file, int from_tty, + struct cmd_list_element *c, + const char *value) +{ + gdb_printf (file, _("Write NT_GDB_TDESC note into corefiles: %s.\n"), + value); +} + INIT_GDB_FILE (gcore) { cmd_list_element *generate_core_file_cmd @@ -928,4 +947,25 @@ Usage: generate-core-file [FILENAME]\n\ Argument is optional filename. Default filename is 'core.PROCESS_ID'.")); add_com_alias ("gcore", generate_core_file_cmd, class_files, 1); + + add_basic_prefix_cmd ("gcore", class_maintenance, + _("gcore maintenance commands."), + &maint_gcore_cmdlist, 0, &maintenancelist); + + add_setshow_prefix_cmd ("gcore", class_maintenance, + _("Set gcore specific variables."), + _("Show gcore specific variables."), + &maint_gcore_set_cmdlist, &maint_gcore_show_cmdlist, + &maintenance_set_cmdlist, &maintenance_show_cmdlist); + + add_setshow_boolean_cmd ("xml-target-description", class_obscure, + &maint_gcore_emit_xml_tdesc, _("\ +Set whether gcore emits a xml-target-description."), _("\ +Show whether gore emits a xml-target-description."), _("\ +By default, gcore emits the note NT_GDB_TDESC.\n\ +Disabling this setting will cause gcore to no longer emit this note."), + nullptr, + show_gcore_xml_target_description, + &maint_gcore_set_cmdlist, + &maint_gcore_show_cmdlist); } diff --git a/gdb/gcore.h b/gdb/gcore.h index 2431e123b60..2481bf0decc 100644 --- a/gdb/gcore.h +++ b/gdb/gcore.h @@ -37,4 +37,7 @@ extern bool objfile_find_memory_regions (struct target_ops *self, extern thread_info *gcore_find_signalled_thread (); +/* When true, emit NT_GDB_TDESC. */ +extern bool maint_gcore_emit_xml_tdesc; + #endif /* GDB_GCORE_H */ diff --git a/gdb/linux-tdep.c b/gdb/linux-tdep.c index a7381677498..6bc4e55aa56 100644 --- a/gdb/linux-tdep.c +++ b/gdb/linux-tdep.c @@ -2495,12 +2495,15 @@ linux_make_corefile_notes (struct gdbarch *gdbarch, bfd *obfd, int *note_size) /* File mappings. */ linux_make_mappings_corefile_notes (gdbarch, obfd, note_data, note_size); - /* Include the target description when possible. Some architectures - allow for per-thread gdbarch so we should really be emitting a tdesc - per-thread, however, we don't currently support reading in a - per-thread tdesc, so just emit the tdesc for the signalled thread. */ - gdbarch = target_thread_architecture (signalled_thr->ptid); - gcore_elf_make_tdesc_note (gdbarch, obfd, ¬e_data, note_size); + if (maint_gcore_emit_xml_tdesc) + { + /* Include the target description when possible. Some architectures + allow for per-thread gdbarch so we should really be emitting a tdesc + per-thread, however, we don't currently support reading in a + per-thread tdesc, so just emit the tdesc for the signalled thread. */ + gdbarch = target_thread_architecture (signalled_thr->ptid); + gcore_elf_make_tdesc_note (gdbarch, obfd, ¬e_data, note_size); + } return note_data; }