From: Stephan Rohr <stephan.rohr@intel.com>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 2/2] gdb: disable pagination while following a fork
Date: Wed, 25 Nov 2026 13:08:02 +0000 [thread overview]
Message-ID: <20261125130802.117043-3-stephan.rohr@intel.com> (raw)
In-Reply-To: <20261125130802.117043-1-stephan.rohr@intel.com>
With "set detach-on-fork off", continueing from a fork catchpoint
follows the fork. Pagination is enabled. If the new inferior
notification triggers pagination and the user answers "q", the new
inferior is not fully set up. It is missing the target and threads:
(gdb) set height 1
(gdb) set width 10
(gdb) continue
Continuing.
[New infer--Type <RET> for more, q to quit, c to continue without paging--q
Quit
(gdb) inferior 2
Inferior has no threads.
Temporarily disable pagination in "follow_fork ()".
---
gdb/infrun.c | 6 ++
.../gdb.base/fork-inferior-paginate.exp | 83 +++++++++++++++++++
2 files changed, 89 insertions(+)
create mode 100644 gdb/testsuite/gdb.base/fork-inferior-paginate.exp
diff --git a/gdb/infrun.c b/gdb/infrun.c
index dced78a3963..b8864aabd76 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -812,6 +812,12 @@ follow_fork ()
{
INFRUN_SCOPED_DEBUG_ENTER_EXIT;
+ /* Temporarily disable pagination. Otherwise, the user could answer
+ 'q' at the pager prompt and abort following the fork, i.e., the new
+ inferior has no target and threads. */
+ scoped_restore save_pagination
+ = make_scoped_restore (&pagination_enabled, false);
+
bool follow_child = (follow_fork_mode_string == follow_fork_mode_child);
bool should_resume = true;
diff --git a/gdb/testsuite/gdb.base/fork-inferior-paginate.exp b/gdb/testsuite/gdb.base/fork-inferior-paginate.exp
new file mode 100644
index 00000000000..c394e5f8977
--- /dev/null
+++ b/gdb/testsuite/gdb.base/fork-inferior-paginate.exp
@@ -0,0 +1,83 @@
+# 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 there is no pagination if a new inferior is setup when following
+# a fork. "Continue" may still paginate but should not leave GDB incompletely
+# setup.
+
+require allow_fork_tests
+
+standard_testfile fork-print-inferior-events.c
+
+if {[build_executable "failed to prepare" $testfile $srcfile debug] == -1} {
+ return
+}
+
+set bp_line [gdb_get_line_number "return 0;"]
+
+proc test_paginate { follow_fork_mode } {
+ global gdb_prompt pagination_prompt
+
+ with_test_prefix "follow-fork-mode=$follow_fork_mode" {
+ clean_restart $::testfile
+
+ if {![runto_main]} {
+ return
+ }
+
+ gdb_test_no_output "set detach-on-fork off"
+ gdb_test_no_output "set follow-fork-mode $follow_fork_mode"
+ gdb_test "catch fork" "Catchpoint $::decimal \\(fork\\)"
+ gdb_test "continue" \
+ "Catchpoint $::decimal \\(forked process $::decimal\\).*"
+ gdb_breakpoint $::srcfile:$::bp_line
+
+ # Avoid unexpected output from readline.
+ gdb_test_no_output "set editing off"
+
+ # Following the fork shall not produce any pagination. "Continue"
+ # still may paginate, though.
+ set saw_fork_pagination 0
+ with_set height 1 {
+ with_set width 10 {
+ gdb_test_multiple "continue" "no pagination in follow fork" {
+ -re "(New infer|Attachin)\[^\r\n\]*$pagination_prompt$" {
+ set saw_fork_pagination 1
+ send_gdb "q\n"
+ exp_continue
+ }
+ -re "$pagination_prompt$" {
+ send_gdb "\n"
+ exp_continue
+ }
+ -re "\r\n$gdb_prompt $" {
+ gdb_assert { !$saw_fork_pagination } $gdb_test_name
+ }
+ }
+ }
+ }
+
+ # Check inferior 2 is properly set up.
+ gdb_test "info inferiors" \
+ "\r\n\\*?\\s+2\\s+process $::decimal\\s+$::decimal \\(\[^\r\n\]*"
+ gdb_test "inferior 2" \
+ "\\\[Switching to thread 2\\.1 \[^\r\n\]*\\\].*" \
+ "switch to inferior 2"
+ }
+}
+
+foreach follow_fork_mode {parent child} {
+ test_paginate $follow_fork_mode
+}
--
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.
prev parent reply other threads:[~2026-11-25 13:09 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 13:08 [PATCH v2 0/2] disable pagination for new inferior notification Stephan Rohr
2026-11-25 13:08 ` [PATCH v2 1/2] gdb: delay the " Stephan Rohr
2026-11-25 13:08 ` 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=20261125130802.117043-3-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