#include "top.h"
#include "version.h"
#include "serial.h"
-#include "doublest.h"
#include "main.h"
#include "event-loop.h"
#include "gdbthread.h"
char *current_directory;
-/* The directory name is actually stored here (usually). */
-char gdb_dirbuf[1024];
-
/* The last command line executed on the console. Used for command
repetitions. */
char *saved_command_line;
/* See top.h. */
-struct ui *
-new_ui (FILE *instream, FILE *outstream, FILE *errstream)
+ui::ui (FILE *instream_, FILE *outstream_, FILE *errstream_)
+ : next (nullptr),
+ num (++highest_ui_num),
+ call_readline (nullptr),
+ input_handler (nullptr),
+ command_editing (0),
+ interp_info (nullptr),
+ async (0),
+ secondary_prompt_depth (0),
+ stdin_stream (instream_),
+ instream (instream_),
+ outstream (outstream_),
+ errstream (errstream_),
+ input_fd (fileno (instream)),
+ input_interactive_p (ISATTY (instream)),
+ prompt_state (PROMPT_NEEDED),
+ m_gdb_stdout (new stdio_file (outstream)),
+ m_gdb_stdin (new stdio_file (instream)),
+ m_gdb_stderr (new stderr_file (errstream)),
+ m_gdb_stdlog (m_gdb_stderr),
+ m_current_uiout (nullptr)
{
- struct ui *ui;
-
- ui = XCNEW (struct ui);
-
- ui->num = ++highest_ui_num;
- ui->stdin_stream = instream;
- ui->instream = instream;
- ui->outstream = outstream;
- ui->errstream = errstream;
-
- ui->input_fd = fileno (ui->instream);
-
- ui->input_interactive_p = ISATTY (ui->instream);
-
- ui->m_gdb_stdin = new stdio_file (ui->instream);
- ui->m_gdb_stdout = new stdio_file (ui->outstream);
- ui->m_gdb_stderr = new stderr_file (ui->errstream);
- ui->m_gdb_stdlog = ui->m_gdb_stderr;
-
- ui->prompt_state = PROMPT_NEEDED;
+ buffer_init (&line_buffer);
if (ui_list == NULL)
- ui_list = ui;
+ ui_list = this;
else
{
struct ui *last;
for (last = ui_list; last->next != NULL; last = last->next)
;
- last->next = ui;
+ last->next = this;
}
-
- return ui;
}
-static void
-free_ui (struct ui *ui)
-{
- delete ui->m_gdb_stdin;
- delete ui->m_gdb_stdout;
- delete ui->m_gdb_stderr;
-
- xfree (ui);
-}
-
-void
-delete_ui (struct ui *todel)
+ui::~ui ()
{
struct ui *ui, *uiprev;
uiprev = NULL;
for (ui = ui_list; ui != NULL; uiprev = ui, ui = ui->next)
- if (ui == todel)
+ if (ui == this)
break;
gdb_assert (ui != NULL);
if (uiprev != NULL)
- uiprev->next = ui->next;
+ uiprev->next = next;
else
- ui_list = ui->next;
+ ui_list = next;
- free_ui (ui);
-}
-
-/* Cleanup that deletes a UI. */
-
-static void
-delete_ui_cleanup (void *void_ui)
-{
- struct ui *ui = (struct ui *) void_ui;
-
- delete_ui (ui);
-}
-
-/* See top.h. */
-
-struct cleanup *
-make_delete_ui_cleanup (struct ui *ui)
-{
- return make_cleanup (delete_ui_cleanup, ui);
+ 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
/* Implementation of the "new-ui" command. */
static void
-new_ui_command (char *args, int from_tty)
+new_ui_command (const char *args, int from_tty)
{
- struct ui *ui;
struct interp *interp;
gdb_file_up stream[3];
int i;
int argc;
const char *interpreter_name;
const char *tty_name;
- struct cleanup *failure_chain;
dont_repeat ();
for (i = 0; i < 3; i++)
stream[i] = open_terminal_stream (tty_name);
- ui = new_ui (stream[0].get (), stream[1].get (), stream[2].get ());
- failure_chain = make_cleanup (delete_ui_cleanup, ui);
+ std::unique_ptr<ui> ui
+ (new struct ui (stream[0].get (), stream[1].get (), stream[2].get ()));
ui->async = 1;
- current_ui = ui;
+ current_ui = ui.get ();
set_top_level_interpreter (interpreter_name);
stream[1].release ();
stream[2].release ();
- discard_cleanups (failure_chain);
+ ui.release ();
}
printf_unfiltered ("New UI allocated\n");
}
#endif
-struct cleanup *
-prepare_execute_command (void)
+scoped_value_mark
+prepare_execute_command ()
{
- struct value *mark;
- struct cleanup *cleanup;
-
- mark = value_mark ();
- cleanup = make_cleanup_value_free_to_mark (mark);
-
/* With multiple threads running while the one we're examining is
stopped, the dcache can get stale without us being able to detect
it. For the duration of the command, though, use the dcache to
if (non_stop)
target_dcache_invalidate ();
- return cleanup;
+ return scoped_value_mark ();
}
/* Tell the user if the language has changed (except first time) after
void
execute_command (char *p, int from_tty)
{
- struct cleanup *cleanup_if_error, *cleanup;
+ struct cleanup *cleanup_if_error;
struct cmd_list_element *c;
char *line;
cleanup_if_error = make_bpstat_clear_actions_cleanup ();
- cleanup = prepare_execute_command ();
+ scoped_value_mark cleanup = prepare_execute_command ();
/* Force cleanup of any alloca areas if using C alloca instead of
a builtin alloca. */
/* This can happen when command_line_input hits end of file. */
if (p == NULL)
{
- do_cleanups (cleanup);
discard_cleanups (cleanup_if_error);
return;
}
check_frame_language_change ();
- do_cleanups (cleanup);
discard_cleanups (cleanup_if_error);
}
std::string
execute_command_to_string (char *p, int from_tty)
{
- struct cleanup *cleanup;
-
/* GDB_STDOUT should be better already restored during these
restoration callbacks. */
- cleanup = set_batch_flag_and_make_cleanup_restore_page_info ();
+ set_batch_flag_and_restore_page_info save_page_info;
scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0);
string_file str_file;
- current_uiout->redirect (&str_file);
- make_cleanup_ui_out_redirect_pop (current_uiout);
-
- scoped_restore save_stdout
- = make_scoped_restore (&gdb_stdout, &str_file);
- scoped_restore save_stderr
- = make_scoped_restore (&gdb_stderr, &str_file);
- scoped_restore save_stdlog
- = make_scoped_restore (&gdb_stdlog, &str_file);
- scoped_restore save_stdtarg
- = make_scoped_restore (&gdb_stdtarg, &str_file);
- scoped_restore save_stdtargerr
- = make_scoped_restore (&gdb_stdtargerr, &str_file);
-
- execute_command (p, from_tty);
-
- do_cleanups (cleanup);
+ {
+ current_uiout->redirect (&str_file);
+ ui_out_redirect_pop redirect_popper (current_uiout);
+
+ scoped_restore save_stdout
+ = make_scoped_restore (&gdb_stdout, &str_file);
+ scoped_restore save_stderr
+ = make_scoped_restore (&gdb_stderr, &str_file);
+ scoped_restore save_stdlog
+ = make_scoped_restore (&gdb_stdlog, &str_file);
+ scoped_restore save_stdtarg
+ = make_scoped_restore (&gdb_stdtarg, &str_file);
+ scoped_restore save_stdtargerr
+ = make_scoped_restore (&gdb_stdtargerr, &str_file);
+
+ execute_command (p, from_tty);
+ }
return std::move (str_file.string ());
}
gdb_safe_append_history (void)
{
int ret, saved_errno;
- char *local_history_filename;
- struct cleanup *old_chain;
- local_history_filename
- = xstrprintf ("%s-gdb%ld~", history_filename, (long) getpid ());
- old_chain = make_cleanup (xfree, local_history_filename);
+ std::string local_history_filename
+ = string_printf ("%s-gdb%ld~", history_filename, (long) getpid ());
- ret = rename (history_filename, local_history_filename);
+ ret = rename (history_filename, local_history_filename.c_str ());
saved_errno = errno;
if (ret < 0 && saved_errno != ENOENT)
{
warning (_("Could not rename %s to %s: %s"),
- history_filename, local_history_filename,
+ history_filename, local_history_filename.c_str (),
safe_strerror (saved_errno));
}
else
to move it back anyway. Otherwise a global history file would
never get created! */
gdb_assert (saved_errno == ENOENT);
- write_history (local_history_filename);
+ write_history (local_history_filename.c_str ());
}
else
{
- append_history (command_count, local_history_filename);
+ append_history (command_count, local_history_filename.c_str ());
if (history_is_stifled ())
- history_truncate_file (local_history_filename, history_max_entries);
+ history_truncate_file (local_history_filename.c_str (),
+ history_max_entries);
}
- ret = rename (local_history_filename, history_filename);
+ ret = rename (local_history_filename.c_str (), history_filename);
saved_errno = errno;
if (ret < 0 && saved_errno != EEXIST)
warning (_("Could not rename %s to %s: %s"),
- local_history_filename, history_filename,
+ local_history_filename.c_str (), history_filename,
safe_strerror (saved_errno));
}
-
- do_cleanups (old_chain);
}
/* Read one line from the command input stream `instream' into a local
{
struct ui *saved_top_level = current_ui;
- target_terminal_ours ();
+ target_terminal::ours ();
current_ui = main_ui;
}
void
-set_history (char *args, int from_tty)
+set_history (const char *args, int from_tty)
{
printf_unfiltered (_("\"set history\" must be followed "
"by the name of a history subcommand.\n"));
}
void
-show_history (char *args, int from_tty)
+show_history (const char *args, int from_tty)
{
cmd_show_list (showhistlist, from_tty, "");
}