Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Stephan Rohr <stephan.rohr@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/1] gdb: disable pagination during inferior creation
Date: Wed,  1 Jul 2026 07:03:24 +0000	[thread overview]
Message-ID: <20260701070324.36461-2-stephan.rohr@intel.com> (raw)
In-Reply-To: <20260701070324.36461-1-stephan.rohr@intel.com>

From: "Rohr, Stephan" <stephan.rohr@intel.com>

The '[New inferior ..]' and 'Added inferior' messages may cause
pagination in certain use-cases.  If the user inputs 'quit' when
prompted for pagination, GDB throws a quit error.  This aborts the
inferior setup and may leave the inferior in an incomplete state,
e.g., the inferior's pspace and aspace may be uninitialized.  This
triggers an assertion when switching to the inferior.  Temporarily
disable pagination when adding new inferiors.
---
 gdb/inferior.c                                |  7 ++
 gdb/remote.c                                  |  6 ++
 .../gdb.base/add-inferior-paginate.exp        | 67 +++++++++++++++++++
 3 files changed, 80 insertions(+)
 create mode 100644 gdb/testsuite/gdb.base/add-inferior-paginate.exp

diff --git a/gdb/inferior.c b/gdb/inferior.c
index 1481f46cdd1..6e346aee271 100644
--- a/gdb/inferior.c
+++ b/gdb/inferior.c
@@ -991,6 +991,13 @@ add_inferior_command (const char *args, int from_tty)
 
   scoped_restore_current_pspace_and_thread restore_pspace_thread;
 
+  /* Temporarily disable pagination.  If the '[New inferior ..]' or
+     'Added inferior ..' message cause pagination and the user quits, this
+     leaves the inferior not properly initialized, e.g., the inferior's
+     pspace and aspace could be left uninitialized.  */
+  scoped_restore save_pagination
+    = make_scoped_restore (&pagination_enabled, false);
+
   for (unsigned int i = 0; i < opts.num_copies; ++i)
     {
       inferior *inf = add_inferior_with_spaces ();
diff --git a/gdb/remote.c b/gdb/remote.c
index f8c7383cb03..b169371c818 100644
--- a/gdb/remote.c
+++ b/gdb/remote.c
@@ -3090,6 +3090,12 @@ remote_target::remote_add_inferior (bool fake_pid_p, int pid, int attached,
   if (attached == -1)
     attached = remote_query_attached (pid);
 
+  /* Temporarily disable pagination.  If the '[New inferior ..] or other
+     messages from the notifiers cause pagination and the user quits,
+     this would leave the inferior not properly initialized.  */
+  scoped_restore save_pagination
+    = make_scoped_restore (&pagination_enabled, false);
+
   if (gdbarch_has_global_solist (current_inferior ()->arch ()))
     {
       /* If the target shares code across all inferiors, then every
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..6dcb52db495
--- /dev/null
+++ b/gdb/testsuite/gdb.base/add-inferior-paginate.exp
@@ -0,0 +1,67 @@
+# 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 <http://www.gnu.org/licenses/>.
+
+# Test that "add-inferior" does not paginate while setting up a new
+# inferior.  If the '[New inferior ..]' message causes pagination and the
+# user quits, this leaves the inferior in a half baked state, e.g., the
+# inferior's program space is not initialized.
+
+standard_testfile advance.c
+
+if {[build_executable "failed to prepare" $testfile $srcfile debug] == -1} {
+    return
+}
+
+clean_restart
+
+# Avoid some confusing output from readline.
+gdb_test_no_output "set editing off"
+
+# Tests that neither the '[New inferior ..]' nor the 'Added inferior'
+# message cause pagination.
+gdb_test_no_output "set height 1"
+gdb_test_no_output "set width 10"
+
+gdb_test_multiple "add-inferior -exec $binfile" "add inferior" {
+    -re "\\\[New inferior 2\\\]" {
+	exp_continue
+    }
+    -re "Added inferior 2( on connection \[^\r\n\]*)?" {
+	exp_continue
+    }
+    -re "Reading symbols from \[^\r\n\]*$binfile\[^\r\n\]*" {
+	exp_continue
+    }
+    -re "$pagination_prompt$" {
+	# We unexpectedly hit the pagination prompt. Send 'quit' to
+	# trigger the assertion in the 'info inferiors' command.
+	send_gdb "q\n"
+	exp_continue
+    }
+    -re "Quit\r\n$gdb_prompt $" {
+	fail $gdb_test_name
+    }
+    -re "\r\n$gdb_prompt $" {
+	pass $gdb_test_name
+    }
+}
+
+gdb_test_no_output "set height unlimited"
+gdb_test_no_output "set width unlimited"
+
+# Test that the inferior is properly setup.  Without temporarly disabling
+# pagination, GDB hits an assertion here.
+gdb_test "info inferiors" "\\s+2\[^\r\n\]*$binfile\[^\r\n\]*" \
+    "info inferiors"
-- 
2.43.0

Intel Deutschland GmbH

Registered Address: Dornacher Strasse 1, 85622 Feldkirchen, Germany
Tel: +49 89 991 430, www.intel.de
Managing Directors: Harry Demas, Jeffrey Schneiderman, Yin Chong Sorrell
Chairperson of the Supervisory Board: Nicole Lau
Registered Seat: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928


      reply	other threads:[~2026-07-01  7:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01  7:03 [PATCH 0/1] " Stephan Rohr
2026-07-01  7:03 ` Stephan Rohr [this message]

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=20260701070324.36461-2-stephan.rohr@intel.com \
    --to=stephan.rohr@intel.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