From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by sourceware.org (Postfix) with ESMTPS id B08C73858292 for ; Tue, 5 Jul 2022 17:15:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B08C73858292 Received: by mail-io1-xd2b.google.com with SMTP id h85so11753270iof.4 for ; Tue, 05 Jul 2022 10:15:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZjHYOaDn4I3ifq5CAehi2bN4RlzP9bxuaRpUzeH1vGg=; b=U4WxcayN8D0Pm5RmIGyainXBQ+aDwcib5GHj80oqYgaMBvu3gp2B/uwwuRUwfE52gY L0T7inIwe3jVE9ZGUMPZ5VHO3L9yNz7gWCN23ZpN4nvjziJhGpCL5GLRdhHNVwBUfE/s DcQ22a/RWB1Rb+urM4dDNQI09D8CQQR8M7lw3J5wDdsKZyPvenJg6JfVAst6i/Ud9rHd 3+c2Al0WNvub46dk7y31n0ZpKRi6lxaCeDSRSRH/TBb+uaXYyBapaM+V11rebOnEwn5Y pocwW0hPLp4xSDwF11SzHUuaHjginTmOF8DnNa6/QREV0Vsbbb/UDpFDCFOT7uWyvqKm bqBw== X-Gm-Message-State: AJIora+qeZrPB5Yu66pkbU3quhtyvE5MQMeRGSzR29rF9uDZg7DkR4Af GmulMBg+um6FZgG1fu45cwLSAeMqS6Qh4g== X-Google-Smtp-Source: AGRyM1s4ir98meC9GH7LI4gVKNn3pc9tfLfPVv2ePqynPlnCFFAlWeaBbVxSHEIm4DfYdJQAUd7ueg== X-Received: by 2002:a05:6602:1409:b0:5e7:487:133c with SMTP id t9-20020a056602140900b005e70487133cmr19620396iov.196.1657041333968; Tue, 05 Jul 2022 10:15:33 -0700 (PDT) Received: from murgatroyd.Home (71-211-187-180.hlrn.qwest.net. [71.211.187.180]) by smtp.gmail.com with ESMTPSA id k1-20020a926f01000000b002dbee570531sm4631034ilc.18.2022.07.05.10.15.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Jul 2022 10:15:33 -0700 (PDT) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH 2/4] Replace input_interactive_p with a method Date: Tue, 5 Jul 2022 11:15:30 -0600 Message-Id: <20220705171532.1072851-3-tromey@adacore.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220705171532.1072851-1-tromey@adacore.com> References: <20220705171532.1072851-1-tromey@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jul 2022 17:15:36 -0000 This replaces the global input_interactive_p function with a new method ui::input_interactive_p. --- gdb/cli/cli-script.c | 4 ++-- gdb/defs.h | 2 -- gdb/event-top.c | 4 ++-- gdb/top.c | 18 +++++++++--------- gdb/top.h | 5 ++++- gdb/utils.c | 2 +- 6 files changed, 18 insertions(+), 17 deletions(-) diff --git a/gdb/cli/cli-script.c b/gdb/cli/cli-script.c index aa73d5307b3..5f81db418bc 100644 --- a/gdb/cli/cli-script.c +++ b/gdb/cli/cli-script.c @@ -1176,7 +1176,7 @@ counted_command_line read_command_lines (const char *prompt_arg, int from_tty, int parse_commands, gdb::function_view validator) { - if (from_tty && input_interactive_p (current_ui)) + if (from_tty && current_ui->input_interactive_p ()) { if (deprecated_readline_begin_hook) { @@ -1203,7 +1203,7 @@ read_command_lines (const char *prompt_arg, int from_tty, int parse_commands, validator); } - if (from_tty && input_interactive_p (current_ui) + if (from_tty && current_ui->input_interactive_p () && deprecated_readline_end_hook) { (*deprecated_readline_end_hook) (); diff --git a/gdb/defs.h b/gdb/defs.h index 99bfdd526ff..6ee804765af 100644 --- a/gdb/defs.h +++ b/gdb/defs.h @@ -319,8 +319,6 @@ extern void print_prompt (void); struct ui; -extern int input_interactive_p (struct ui *); - extern bool info_verbose; /* From printcmd.c */ diff --git a/gdb/event-top.c b/gdb/event-top.c index 2863a8aff69..02b3786320f 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -687,7 +687,7 @@ handle_line_of_input (struct buffer *cmd_line_buffer, } /* Do history expansion if that is wished. */ - if (history_expansion_p && from_tty && input_interactive_p (current_ui)) + if (history_expansion_p && from_tty && current_ui->input_interactive_p ()) { char *cmd_expansion; int expanded; @@ -729,7 +729,7 @@ handle_line_of_input (struct buffer *cmd_line_buffer, and then later fetch it from the value history and remove the '#'. The kill ring is probably better, but some people are in the habit of commenting things out. */ - if (*cmd != '\0' && from_tty && input_interactive_p (current_ui)) + if (*cmd != '\0' && from_tty && current_ui->input_interactive_p ()) gdb_add_history (cmd); /* Save into global buffer if appropriate. */ diff --git a/gdb/top.c b/gdb/top.c index 86c9971fa6d..60835acd5e5 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -308,7 +308,7 @@ ui::ui (FILE *instream_, FILE *outstream_, FILE *errstream_) outstream (outstream_), errstream (errstream_), input_fd (fileno (instream)), - input_interactive_p (ISATTY (instream)), + m_input_interactive_p (ISATTY (instream)), prompt_state (PROMPT_NEEDED), m_gdb_stdout (new pager_file (new stdio_file (outstream))), m_gdb_stdin (new stdio_file (instream)), @@ -1405,13 +1405,13 @@ command_line_input (const char *prompt_arg, const char *annotation_suffix) /* Don't use fancy stuff if not talking to stdin. */ if (deprecated_readline_hook && from_tty - && input_interactive_p (current_ui)) + && current_ui->input_interactive_p ()) { rl.reset ((*deprecated_readline_hook) (prompt)); } else if (command_editing_p && from_tty - && input_interactive_p (current_ui)) + && current_ui->input_interactive_p ()) { rl.reset (gdb_readline_wrapper (prompt)); } @@ -1875,7 +1875,7 @@ quit_force (int *exit_arg, int from_tty) any UI with a terminal, save history. */ for (ui *ui : all_uis ()) { - if (input_interactive_p (ui)) + if (ui->input_interactive_p ()) { save = 1; break; @@ -1923,23 +1923,23 @@ show_interactive_mode (struct ui_file *file, int from_tty, if (interactive_mode == AUTO_BOOLEAN_AUTO) gdb_printf (file, "Debugger's interactive mode " "is %s (currently %s).\n", - value, input_interactive_p (current_ui) ? "on" : "off"); + value, current_ui->input_interactive_p () ? "on" : "off"); else gdb_printf (file, "Debugger's interactive mode is %s.\n", value); } /* Returns whether GDB is running on an interactive terminal. */ -int -input_interactive_p (struct ui *ui) +bool +ui::input_interactive_p () const { if (batch_flag) - return 0; + return false; if (interactive_mode != AUTO_BOOLEAN_AUTO) return interactive_mode == AUTO_BOOLEAN_TRUE; - return ui->input_interactive_p; + return m_input_interactive_p; } static void diff --git a/gdb/top.h b/gdb/top.h index 18c49cc5513..5c1db84b2ce 100644 --- a/gdb/top.h +++ b/gdb/top.h @@ -124,7 +124,7 @@ struct ui /* Whether ISATTY returns true on input_fd. Cached here because quit_force needs to know this _after_ input_fd might be closed. */ - int input_interactive_p; + bool m_input_interactive_p; /* See enum prompt_state's description. */ enum prompt_state prompt_state; @@ -154,6 +154,9 @@ struct ui /* Unregister the UI's input file descriptor from the event loop. */ void unregister_file_handler (); + + /* Return true if this UI's input fd is a tty. */ + bool input_interactive_p () const; }; /* The main UI. This is the UI that is bound to stdin/stdout/stderr. diff --git a/gdb/utils.c b/gdb/utils.c index 5503acfd6bc..b0841e1fe5e 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -880,7 +880,7 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args) way, important error messages don't get lost when talking to GDB over a pipe. */ if (current_ui->instream != current_ui->stdin_stream - || !input_interactive_p (current_ui) + || !current_ui->input_interactive_p () /* Restrict queries to the main UI. */ || current_ui != main_ui) { -- 2.34.1