aboutsummaryrefslogtreecommitdiff
path: root/gdb/top.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@efficios.com>2023-04-28 14:27:11 -0400
committerSimon Marchi <simon.marchi@efficios.com>2023-05-01 15:40:54 -0400
commit13d03262f25bfbf15e4a5f1d867cca243c7ee3ca (patch)
tree882bd6ca945e1ab7f1bc31f64b2b425b382a9271 /gdb/top.c
parent7d3b43a15bd4267b5782ca40c0bb1dec1fa3f476 (diff)
downloadgdb-13d03262f25bfbf15e4a5f1d867cca243c7ee3ca.zip
gdb-13d03262f25bfbf15e4a5f1d867cca243c7ee3ca.tar.gz
gdb-13d03262f25bfbf15e4a5f1d867cca243c7ee3ca.tar.bz2
gdb: move struct ui and related things to ui.{c,h}
I'd like to move some things so they become methods on struct ui. But first, I think that struct ui and the related things are big enough to deserve their own file, instead of being scattered through top.{c,h} and event-top.c. Change-Id: I15594269ace61fd76ef80a7b58f51ff3ab6979bc
Diffstat (limited to 'gdb/top.c')
-rw-r--r--gdb/top.c149
1 files changed, 6 insertions, 143 deletions
diff --git a/gdb/top.c b/gdb/top.c
index 81f74f7..0b81909 100644
--- a/gdb/top.c
+++ b/gdb/top.c
@@ -39,6 +39,7 @@
#include "annotate.h"
#include "completer.h"
#include "top.h"
+#include "ui.h"
#include "gdbsupport/version.h"
#include "serial.h"
#include "main.h"
@@ -253,13 +254,9 @@ void (*deprecated_call_command_hook) (struct cmd_list_element * c,
void (*deprecated_context_hook) (int id);
-/* The highest UI number ever assigned. */
-static int highest_ui_num;
-
-/* Unbuffer STREAM. This is a wrapper around setbuf(STREAM, nullptr)
- which applies some special rules for MS-Windows hosts. */
+/* See top.h. */
-static void
+void
unbuffer_stream (FILE *stream)
{
/* Unbuffer the input stream so that in gdb_readline_no_editing_callback,
@@ -291,118 +288,6 @@ unbuffer_stream (FILE *stream)
#endif
}
-/* See top.h. */
-
-ui::ui (FILE *instream_, FILE *outstream_, FILE *errstream_)
- : num (++highest_ui_num),
- stdin_stream (instream_),
- instream (instream_),
- outstream (outstream_),
- errstream (errstream_),
- input_fd (fileno (instream)),
- m_input_interactive_p (ISATTY (instream)),
- m_gdb_stdout (new pager_file (new stdio_file (outstream))),
- m_gdb_stdin (new stdio_file (instream)),
- m_gdb_stderr (new stderr_file (errstream)),
- m_gdb_stdlog (new timestamped_file (m_gdb_stderr))
-{
- unbuffer_stream (instream_);
-
- if (ui_list == NULL)
- ui_list = this;
- else
- {
- struct ui *last;
-
- for (last = ui_list; last->next != NULL; last = last->next)
- ;
- last->next = this;
- }
-}
-
-ui::~ui ()
-{
- struct ui *ui, *uiprev;
-
- uiprev = NULL;
-
- for (ui = ui_list; ui != NULL; uiprev = ui, ui = ui->next)
- if (ui == this)
- break;
-
- gdb_assert (ui != NULL);
-
- if (uiprev != NULL)
- uiprev->next = next;
- else
- ui_list = next;
-
- delete m_gdb_stdin;
- delete m_gdb_stdout;
- delete m_gdb_stderr;
-}
-
-/* Open file named NAME for read/write, making sure not to make it the
- controlling terminal. */
-
-static gdb_file_up
-open_terminal_stream (const char *name)
-{
- scoped_fd fd = gdb_open_cloexec (name, O_RDWR | O_NOCTTY, 0);
- if (fd.get () < 0)
- perror_with_name (_("opening terminal failed"));
-
- return fd.to_file ("w+");
-}
-
-/* Implementation of the "new-ui" command. */
-
-static void
-new_ui_command (const char *args, int from_tty)
-{
- int argc;
- const char *interpreter_name;
- const char *tty_name;
-
- dont_repeat ();
-
- gdb_argv argv (args);
- argc = argv.count ();
-
- if (argc < 2)
- error (_("Usage: new-ui INTERPRETER TTY"));
-
- interpreter_name = argv[0];
- tty_name = argv[1];
-
- {
- scoped_restore save_ui = make_scoped_restore (&current_ui);
-
- /* Open specified terminal. Note: we used to open it three times,
- once for each of stdin/stdout/stderr, but that does not work
- with Windows named pipes. */
- gdb_file_up stream = open_terminal_stream (tty_name);
-
- std::unique_ptr<ui> ui
- (new struct ui (stream.get (), stream.get (), stream.get ()));
-
- ui->async = 1;
-
- current_ui = ui.get ();
-
- set_top_level_interpreter (interpreter_name);
-
- interp_pre_command_loop (top_level_interpreter ());
-
- /* Make sure the file is not closed. */
- stream.release ();
-
- ui.release ();
- }
-
- gdb_printf ("New UI allocated\n");
-}
-
/* Handler for SIGHUP. */
#ifdef SIGHUP
@@ -1917,8 +1802,9 @@ quit_force (int *exit_arg, int from_tty)
exit (exit_code);
}
-/* The value of the "interactive-mode" setting. */
-static enum auto_boolean interactive_mode = AUTO_BOOLEAN_AUTO;
+/* See top.h. */
+
+auto_boolean interactive_mode = AUTO_BOOLEAN_AUTO;
/* Implement the "show interactive-mode" option. */
@@ -1935,20 +1821,6 @@ show_interactive_mode (struct ui_file *file, int from_tty,
gdb_printf (file, "Debugger's interactive mode is %s.\n", value);
}
-/* Returns whether GDB is running on an interactive terminal. */
-
-bool
-ui::input_interactive_p () const
-{
- if (batch_flag)
- return false;
-
- if (interactive_mode != AUTO_BOOLEAN_AUTO)
- return interactive_mode == AUTO_BOOLEAN_TRUE;
-
- return m_input_interactive_p;
-}
-
static void
dont_repeat_command (const char *ignored, int from_tty)
{
@@ -2241,8 +2113,6 @@ show_startup_quiet (struct ui_file *file, int from_tty,
static void
init_main (void)
{
- struct cmd_list_element *c;
-
/* Initialize the prompt to a simple "(gdb) " prompt or to whatever
the DEFAULT_PROMPT is. */
set_prompt (DEFAULT_PROMPT);
@@ -2395,13 +2265,6 @@ affect future GDB sessions."),
show_startup_quiet,
&setlist, &showlist);
- c = add_cmd ("new-ui", class_support, new_ui_command, _("\
-Create a new UI.\n\
-Usage: new-ui INTERPRETER TTY\n\
-The first argument is the name of the interpreter to run.\n\
-The second argument is the terminal the UI runs on."), &cmdlist);
- set_cmd_completer (c, interpreter_completer);
-
struct internalvar *major_version_var = create_internalvar ("_gdb_major");
struct internalvar *minor_version_var = create_internalvar ("_gdb_minor");
int vmajor = 0, vminor = 0, vrevision = 0;