From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id 4aCvM+DdBmvwsDwAWB0awg (envelope-from ) for ; Wed, 25 Nov 2026 08:08:48 -0500 Authentication-Results: simark.ca; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=BbQRHUa2; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id CF0351E166; Wed, 25 Nov 2026 08:08:48 -0500 (EST) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.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 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 0C3211E09B for ; Wed, 25 Nov 2026 08:08:48 -0500 (EST) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6C05F40AE852 for ; Wed, 25 Nov 2026 13:08:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6C05F40AE852 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=BbQRHUa2 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) by sourceware.org (Postfix) with ESMTPS id 2F27D457CE6F for ; Wed, 25 Nov 2026 13:08:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2F27D457CE6F 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 2F27D457CE6F Authentication-Results: sourceware.org; arc=none smtp.remote-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795612098; cv=none; b=m1hfrQKHagXgSS9JyJC3wc10bqbhyMSkl9NvapM0tnGdcTTeZQXGI/PrbhusNGY+lviKnjB7XKtBJdL95fyGztLyHmBiuTDDN2HcX5jH7g8Zjc3jbP73BihdQTwXNv0a9xVmjrDFHFmr70bU6yFj/ZbrxluQ1XVZ1RXFNp2aynE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1795612098; c=relaxed/simple; bh=V2MdOdmFMjjhPLsPz6R8xzLky3ABp0iyHL1JCIL1I5A=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=tbPSkw9inztj6bluofNU0Q5zuLB7xfvx9quh5rjUAnmMDTFvNr/TlbVyv8hVTWqPAIEELzqtGVwCF98d2EN9dZpNh8H/Y2QWaN4NNkfNDlgZHminQeNaf9ARcMr1qZANDctX60vgyzhz8/uqzpSynRoXpCGw8ZPyRgvYQtxSwuA= 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=BbQRHUa2 DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F27D457CE6F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1795612099; x=1827148099; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=V2MdOdmFMjjhPLsPz6R8xzLky3ABp0iyHL1JCIL1I5A=; b=BbQRHUa2jZgWGa9Y/GrtJ8f3doU0B4Q7aoWe6o0p6sZ8d/q7WYmxeGhD AvjbTDi2bP1EwuSNKUHaV1kngsJNR/BrTg2/Mi1jmxu/eTdhoEz0LDFhy cixBJV9HNcnVu8O6eqMKtnfNEn/lKXdWRKrr1GQEXjkKZXQiVh9xJbtSq TYss4Y+1JCSKfHMhMyfmgDTzcS0VBXzHwcJ6dKP8QVJEJW6KZ5LTPGKBX 5A9Ca9jskUpqBSFcYtMAfbpapVq8Ei68ljpnSo+JXp5aFD3Rxr+gS3+l9 10rGzJnHW2+vWoW1ApQrShgcSUxPg4a9M6XXUa0CXusGM7OW9MVRBo5l6 w==; X-CSE-ConnectionGUID: 9ldLJYcvSUmPBK0lGsjRVw== X-CSE-MsgGUID: 0xz69OYjQnm/gLJkoRLfBg== X-IronPort-AV: E=McAfee;i="6800,10657,11977"; a="4550999" X-IronPort-AV: E=Sophos;i="6.27,232,1787036400"; d="scan'208";a="4550999" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2026 05:08:17 -0800 X-CSE-ConnectionGUID: fHvZqIBIQ7m0WKLc7A2iAQ== X-CSE-MsgGUID: w49185b6QROGTkJZ/IN/uQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,232,1787036400"; d="scan'208";a="11736183" Received: from dut1048pvc.igk.intel.com (HELO localhost) ([10.211.177.228]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2026 05:08:16 -0800 From: Stephan Rohr To: gdb-patches@sourceware.org Subject: [PATCH v2 1/2] gdb: delay the new inferior notification Date: Wed, 25 Nov 2026 13:08:01 +0000 Message-ID: <20261125130802.117043-2-stephan.rohr@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20261125130802.117043-1-stephan.rohr@intel.com> References: <20261125130802.117043-1-stephan.rohr@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit 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 Adding or cloning an inferior causes GDB to print the new inferior notification. If this causes pagination and the user answers "q", this leaves the inferior's program space uninitialized: (gdb) set width 10 (gdb) set height 1 (gdb) add-inferior [New infer--Type for more, q to quit, c to continue without paging--q Quit (gdb) set height unlimited (gdb) info inferiors Num Description Connection Executable * 1 2 .../gdb/progspace.c:329: internal-error: set_current_program_space: Assertion `pspace != NULL' failed. Remove "add_inferior ()" and replace with "add_inferior_silend ()" and "print_new_inferior ()" to delay the notification until the program space is set up. Still, answering "q" in certain scenarios may leave the inferior partly initialized, e.g., "clone-inferior" may not have copied the arguments and environment yet. --- gdb/inferior.c | 26 ++++---- gdb/inferior.h | 14 ++--- gdb/infrun.c | 12 +++- gdb/remote.c | 6 +- .../gdb.base/add-inferior-paginate.exp | 59 +++++++++++++++++++ 5 files changed, 96 insertions(+), 21 deletions(-) create mode 100644 gdb/testsuite/gdb.base/add-inferior-paginate.exp diff --git a/gdb/inferior.c b/gdb/inferior.c index 6f63c602050..d89553a2393 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -221,22 +221,20 @@ add_inferior_silent (int pid) return inf; } -struct inferior * -add_inferior (int pid) -{ - struct inferior *inf = add_inferior_silent (pid); +/* See inferior.h. */ +void +print_new_inferior (inferior *inf) +{ if (print_inferior_events) { - if (pid != 0) + if (inf->pid != 0) gdb_printf (_("[New inferior %d (%s)]\n"), inf->num, - target_pid_to_str (ptid_t (pid)).c_str ()); + target_pid_to_str (ptid_t (inf->pid)).c_str ()); else gdb_printf (_("[New inferior %d]\n"), inf->num); } - - return inf; } /* See inferior.h. */ @@ -906,7 +904,7 @@ add_inferior_with_spaces (void) doesn't really return a new address space; otherwise, it really does. */ pspace = new program_space (maybe_new_address_space ()); - inf = add_inferior (0); + inf = add_inferior_silent (0); inf->pspace = pspace; inf->aspace = pspace->aspace; @@ -918,6 +916,10 @@ add_inferior_with_spaces (void) always have a valid arch by now. */ gdb_assert (inf->arch () != nullptr); + /* Print the new inferior notification once the inferior is properly + set up. */ + print_new_inferior (inf); + return inf; } @@ -1168,11 +1170,15 @@ clone_inferior_command (const char *args, int from_tty) doesn't really return a new address space; otherwise, it really does. */ pspace = new program_space (maybe_new_address_space ()); - inf = add_inferior (0); + inf = add_inferior_silent (0); inf->pspace = pspace; inf->aspace = pspace->aspace; inf->set_arch (orginf->arch ()); + /* Print the new inferior notification once the program space and + address space are set up. */ + print_new_inferior (inf); + switch_to_inferior_and_push_target (inf, opts.no_connection, orginf); /* If the original inferior had a user specified target diff --git a/gdb/inferior.h b/gdb/inferior.h index 3d0befc0735..ca2c269a123 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -739,16 +739,14 @@ class inferior : public refcounted_object, gdbarch *m_gdbarch = nullptr; }; -/* Add an inferior to the inferior list, print a message that a new - inferior is found, and return the pointer to the new inferior. - Caller may use this pointer to initialize the private inferior - data. */ -extern struct inferior *add_inferior (int pid); - -/* Same as add_inferior, but don't print new inferior notifications to - the CLI. */ +/* Add an inferior to the inferior list and return the pointer to the + new inferior. Caller may use this pointer to initialize the private + inferior data. No new inferior notification is printed to the CLI. */ extern struct inferior *add_inferior_silent (int pid); +/* Print the new inferior notification for INF to the CLI, if enabled. */ +extern void print_new_inferior (inferior *inf); + extern void delete_inferior (struct inferior *todel); /* Delete an existing inferior list entry, due to inferior detaching. */ diff --git a/gdb/infrun.c b/gdb/infrun.c index 8f02c49cbcb..dced78a3963 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -560,7 +560,7 @@ holding the child stopped. Try \"set %ps\" or \"%ps\".\n"), else { /* Add process to GDB's tables. */ - child_inf = add_inferior (child_ptid.pid ()); + child_inf = add_inferior_silent (child_ptid.pid ()); child_inf->attach_flag = parent_inf->attach_flag; copy_terminal_info (child_inf, parent_inf); @@ -594,6 +594,10 @@ holding the child stopped. Try \"set %ps\" or \"%ps\".\n"), child_inf->removable = true; clone_program_space (child_inf->pspace, parent_inf->pspace); } + + /* Print the new inferior notification once the inferior is properly + setup. */ + print_new_inferior (child_inf); } if (has_vforked) @@ -636,7 +640,7 @@ holding the child stopped. Try \"set %ps\" or \"%ps\".\n"), /* Add the new inferior first, so that the target_detach below doesn't unpush the target. */ - child_inf = add_inferior (child_ptid.pid ()); + child_inf = add_inferior_silent (child_ptid.pid ()); child_inf->attach_flag = parent_inf->attach_flag; copy_terminal_info (child_inf, parent_inf); @@ -685,6 +689,10 @@ holding the child stopped. Try \"set %ps\" or \"%ps\".\n"), child_inf->symfile_flags = SYMFILE_NO_READ; clone_program_space (child_inf->pspace, parent_inf->pspace); } + + /* Print the new inferior notification once the inferior is properly + set up. */ + print_new_inferior (child_inf); } gdb_assert (current_inferior () == parent_inf); diff --git a/gdb/remote.c b/gdb/remote.c index abe6cf6d4be..d1b8c1486b2 100644 --- a/gdb/remote.c +++ b/gdb/remote.c @@ -3092,13 +3092,17 @@ remote_target::remote_add_inferior (bool fake_pid_p, int pid, int attached, { /* If the target shares code across all inferiors, then every attach adds a new inferior. */ - inf = add_inferior (pid); + inf = add_inferior_silent (pid); /* ... and every inferior is bound to the same program space. However, each inferior may still have its own address space. */ inf->aspace = maybe_new_address_space (); inf->pspace = current_program_space; + + /* Print the new inferior notification once the inferior is properly + set up. */ + print_new_inferior (inf); } else { diff --git a/gdb/testsuite/gdb.base/add-inferior-paginate.exp b/gdb/testsuite/gdb.base/add-inferior-paginate.exp new file mode 100644 index 00000000000..d00aaf8d3d2 --- /dev/null +++ b/gdb/testsuite/gdb.base/add-inferior-paginate.exp @@ -0,0 +1,59 @@ +# 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 . + +standard_testfile main.c + +if {[build_executable "failed to prepare" $testfile $srcfile debug] == -1} { + return +} + +# Run CMD and enforce pagination. Ensure the inferior is properly set up +# if the user answers "quit". + +proc test_paginate { name cmd } { + global testfile gdb_prompt pagination_prompt + + with_test_prefix $name { + clean_restart $testfile + + # Avoid unexpected output from readline. + gdb_test_no_output "set editing off" + + set saw_pagination 0 + with_set height 1 { + with_set width 10 { + gdb_test_multiple $cmd "quit at pagination prompt" { + -re "$pagination_prompt$" { + set saw_pagination 1 + send_gdb "q\n" + exp_continue + } + -re "Quit\r\n$gdb_prompt $" { + gdb_assert { $saw_pagination } $gdb_test_name + } + } + } + } + + # Check inferior 2 is properly set up. The quit happens before + # any executable is attached to inferior 2, so it has none. + gdb_test "info inferiors" "\r\n\\s+2\\s+\[^\r\n\]*" + gdb_test "inferior 2" "\\\[Switching to inferior 2 \[^\r\n\]*\\\]" \ + "switch to inferior 2" + } +} + +test_paginate "add-inferior" "add-inferior -exec $binfile" +test_paginate "clone-inferior" "clone-inferior" -- 2.43.0 ________________________________________ Intel Deutschland GmbH Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany Tel: +49 (89) 99143-0 www.intel.de Managing Directors: Candice Moore, Jeffrey Schneiderman, Ramachandran Sitaraman Chairperson of the Supervisory Board: Sonja Pierer Registered Seat: Munich Commercial Register B: Amtsgericht Munich HRB 186928 This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.