Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH v5 3/4] [gdb] Add defaulted_query_auto_answers_p
Date: Sat, 14 Mar 2026 18:37:36 +0100	[thread overview]
Message-ID: <20260314173737.1436116-4-tdevries@suse.de> (raw)
In-Reply-To: <20260314173737.1436116-1-tdevries@suse.de>

Factor out "static bool defaulted_query_auto_answers_p (bool)" out of
defaulted_query, and use it to implement
"extern tribool defaulted_query_auto_answers_p (void)".
---
 gdb/utils.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 gdb/utils.h |  4 ++++
 2 files changed, 54 insertions(+), 5 deletions(-)

diff --git a/gdb/utils.c b/gdb/utils.c
index ef8ef87bc5b..0de356eac80 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -742,6 +742,54 @@ class scoped_input_handler
 };
 
 \f
+/* Return true if defaulted queries should be answered:
+   - if VERBOSELY, automatically and verbosely
+   - otherwise, automatically and quietly.  */
+
+static bool
+defaulted_query_auto_answers_p (bool verbosely)
+{
+  if (verbosely)
+    {
+      /* Automatically answer verbosely if input isn't coming from the user
+	 directly.  */
+      return (current_ui->instream != current_ui->stdin_stream
+	      || !current_ui->input_interactive_p ()
+	      /* Restrict queries to the main UI.  */
+	      || current_ui != main_ui);
+    }
+  else
+    {
+      /* Automatically answer quietly if:
+	 - the user did not want prompts, or
+	 - the command was issued with the server prefix.  */
+      return !confirm || server_command;
+    }
+}
+
+/* See utils.h.  */
+
+tribool
+defaulted_query_auto_answers_p ()
+{
+  if (defaulted_query_auto_answers_p (false)
+      || defaulted_query_auto_answers_p (true))
+    return TRIBOOL_TRUE;
+
+  if (deprecated_query_hook)
+    {
+      /* The only user of deprecated_query_hook in core gdb seems to be
+	 mi_interp_query_hook, for which we could return TRIBOOL_TRUE here.
+	 If that turns out to be required, we could accomplish this by
+	 changing the hook interface to say:
+	   int (*deprecated_query_hook) (const char *, va_list,
+					 bool auto_answers_p = false)
+	 and calling it here with auto_answers_p == true.  */
+      return TRIBOOL_UNKNOWN;
+    }
+
+  return TRIBOOL_FALSE;
+}
 
 /* This function supports the query, nquery, and yquery functions.
    Ask user a y-or-n question and return 0 if answer is no, 1 if
@@ -789,17 +837,14 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args)
 
   /* Automatically answer the default value if the user did not want
      prompts or the command was issued with the server prefix.  */
-  if (!confirm || server_command)
+  if (defaulted_query_auto_answers_p (false))
     return def_value;
 
   /* If input isn't coming from the user directly, just say what
      question we're asking, and then answer the default automatically.  This
      way, important error messages don't get lost when talking to GDB
      over a pipe.  */
-  if (current_ui->instream != current_ui->stdin_stream
-      || !current_ui->input_interactive_p ()
-      /* Restrict queries to the main UI.  */
-      || current_ui != main_ui)
+  if (defaulted_query_auto_answers_p (true))
     {
       target_terminal::scoped_restore_terminal_state term_state;
       target_terminal::ours_for_output ();
diff --git a/gdb/utils.h b/gdb/utils.h
index 7cab021e7a9..6ef2049b2a4 100644
--- a/gdb/utils.h
+++ b/gdb/utils.h
@@ -515,4 +515,8 @@ struct deferred_warnings final : public warning_hook_handler_type
   std::vector<string_file> m_warnings;
 };
 
+/* Whether defaulted queries are answered automatically.  */
+
+extern tribool defaulted_query_auto_answers_p ();
+
 #endif /* GDB_UTILS_H */
-- 
2.51.0


  parent reply	other threads:[~2026-03-14 17:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-14 17:37 [PATCH v5 0/4] [gdb/tui] Fix crash with debuginfod query Tom de Vries
2026-03-14 17:37 ` [PATCH v5 1/4] [gdb] Simplify debuginfod_is_enabled Tom de Vries
2026-04-14 12:40   ` Tom de Vries
2026-03-14 17:37 ` [PATCH v5 2/4] [gdb] Add debuginfod_enabled_ask_p Tom de Vries
2026-03-14 17:37 ` Tom de Vries [this message]
2026-03-14 17:37 ` [PATCH v5 4/4] [gdb/tui] Don't enter TUI if debuginfod enabled == ask Tom de Vries

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=20260314173737.1436116-4-tdevries@suse.de \
    --to=tdevries@suse.de \
    --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