Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH 0/1] gdb: disable pagination during inferior creation
@ 2026-07-01  7:03 Stephan Rohr
  2026-07-01  7:03 ` [PATCH 1/1] " Stephan Rohr
  0 siblings, 1 reply; 2+ messages in thread
From: Stephan Rohr @ 2026-07-01  7:03 UTC (permalink / raw)
  To: gdb-patches

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

Hello all,

I came accross a bug that triggered an assertion if adding a new
inferior causes pagintion and I hit 'quit' instead of 'Return' or
'continue'.  A minimal reproducer is

  (gdb) set width 10
  (gdb) set height 1
  (gdb) add-inferior -exec <some file>

Send quit when prompted for pagination.  A subsequent command that
switches inferiors, e.g., 'info inferiors', hits an assertion as the
inferior's pspace is not initialized.

Fix this by temporarily disabling pagination when setting up a new
inferior.

I appreciate your feedback.

Thanks
Stephan


Rohr, Stephan (1):
  gdb: disable pagination during inferior creation

 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

-- 
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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [PATCH 1/1] gdb: disable pagination during inferior creation
  2026-07-01  7:03 [PATCH 0/1] gdb: disable pagination during inferior creation Stephan Rohr
@ 2026-07-01  7:03 ` Stephan Rohr
  0 siblings, 0 replies; 2+ messages in thread
From: Stephan Rohr @ 2026-07-01  7:03 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-07-01  7:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-01  7:03 [PATCH 0/1] gdb: disable pagination during inferior creation Stephan Rohr
2026-07-01  7:03 ` [PATCH 1/1] " Stephan Rohr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox