/* Top level stuff for GDB, the GNU debugger.
- Copyright (C) 1986-2019 Free Software Foundation, Inc.
+ Copyright (C) 1986-2020 Free Software Foundation, Inc.
This file is part of GDB.
#include "gdbsupport/version.h"
#include "serial.h"
#include "main.h"
-#include "event-loop.h"
+#include "gdbsupport/event-loop.h"
#include "gdbthread.h"
#include "extension.h"
#include "interps.h"
#include "filenames.h"
#include "frame.h"
#include "gdbsupport/buffer.h"
-#include "gdb_select.h"
+#include "gdbsupport/gdb_select.h"
#include "gdbsupport/scope-exit.h"
#include "gdbarch.h"
#include "gdbsupport/pathstuff.h"
+#include "cli/cli-style.h"
/* readline include files. */
#include "readline/readline.h"
extern void initialize_all_files (void);
+static bool history_filename_empty (void);
+
#define PROMPT(X) the_prompts.prompt_stack[the_prompts.top + X].prompt
#define PREFIX(X) the_prompts.prompt_stack[the_prompts.top + X].prefix
#define SUFFIX(X) the_prompts.prompt_stack[the_prompts.top + X].suffix
whatever) can issue its own commands and also send along commands
from the user, and have the user not notice that the user interface
is issuing commands too. */
-int server_command;
+bool server_command;
/* Timeout limit for response from target. */
/* static */ bool history_expansion_p;
+/* Should we write out the command history on exit? In order to write out
+ the history both this flag must be true, and the history_filename
+ variable must be set to something sensible. */
static bool write_history_p;
+
+/* Implement 'show history save'. */
static void
show_write_history_p (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
- fprintf_filtered (file, _("Saving of the history record on exit is %s.\n"),
- value);
+ if (!write_history_p || !history_filename_empty ())
+ fprintf_filtered (file, _("Saving of the history record on exit is %s.\n"),
+ value);
+ else
+ fprintf_filtered (file, _("Saving of the history is disabled due to "
+ "the value of 'history filename'.\n"));
}
/* The variable associated with the "set/show history size"
value);
}
+/* The name of the file in which GDB history will be written. If this is
+ set to NULL, of the empty string then history will not be written. */
static char *history_filename;
+
+/* Return true if the history_filename is either NULL or the empty string,
+ indicating that we should not try to read, nor write out the history. */
+static bool
+history_filename_empty (void)
+{
+ return (history_filename == nullptr || *history_filename == '\0');
+}
+
+/* Implement 'show history filename'. */
static void
show_history_filename (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
- fprintf_filtered (file, _("The filename in which to record "
- "the command history is \"%s\".\n"),
- value);
+ if (!history_filename_empty ())
+ fprintf_filtered (file, _("The filename in which to record "
+ "the command history is \"%ps\".\n"),
+ styled_string (file_name_style.style (), value));
+ else
+ fprintf_filtered (file, _("There is no filename currently set for "
+ "recording the command history in.\n"));
}
/* This is like readline(), but it has some gdb-specific behavior.
saved_errno = errno;
if (ret < 0 && saved_errno != ENOENT)
{
- warning (_("Could not rename %s to %s: %s"),
- history_filename, local_history_filename.c_str (),
+ warning (_("Could not rename %ps to %ps: %s"),
+ styled_string (file_name_style.style (), history_filename),
+ styled_string (file_name_style.style (),
+ local_history_filename.c_str ()),
safe_strerror (saved_errno));
}
else
"));
#endif
+#if HAVE_LIBDEBUGINFOD
+ fprintf_filtered (stream, _("\
+ --with-debuginfod\n\
+"));
+#else
+ fprintf_filtered (stream, _("\
+ --without-debuginfod\n\
+"));
+#endif
+
#if HAVE_GUILE
fprintf_filtered (stream, _("\
--with-guile\n\
}
\f
-struct qt_args
-{
- int from_tty;
-};
+/* Kills or detaches the given inferior, depending on how we originally
+ gained control of it. */
-/* Callback for iterate_over_inferiors. Kills or detaches the given
- inferior, depending on how we originally gained control of it. */
-
-static int
-kill_or_detach (struct inferior *inf, void *args)
+static void
+kill_or_detach (inferior *inf, int from_tty)
{
- struct qt_args *qt = (struct qt_args *) args;
-
if (inf->pid == 0)
- return 0;
+ return;
thread_info *thread = any_thread_of_inferior (inf);
if (thread != NULL)
if (target_has_execution)
{
if (inf->attach_flag)
- target_detach (inf, qt->from_tty);
+ target_detach (inf, from_tty);
else
target_kill ();
}
}
-
- return 0;
}
-/* Callback for iterate_over_inferiors. Prints info about what GDB
- will do to each inferior on a "quit". ARG points to a struct
- ui_out where output is to be collected. */
+/* Prints info about what GDB will do to inferior INF on a "quit". OUT is
+ where to collect the output. */
-static int
-print_inferior_quit_action (struct inferior *inf, void *arg)
+static void
+print_inferior_quit_action (inferior *inf, ui_file *out)
{
- struct ui_file *stb = (struct ui_file *) arg;
-
if (inf->pid == 0)
- return 0;
+ return;
if (inf->attach_flag)
- fprintf_filtered (stb,
+ fprintf_filtered (out,
_("\tInferior %d [%s] will be detached.\n"), inf->num,
target_pid_to_str (ptid_t (inf->pid)).c_str ());
else
- fprintf_filtered (stb,
+ fprintf_filtered (out,
_("\tInferior %d [%s] will be killed.\n"), inf->num,
target_pid_to_str (ptid_t (inf->pid)).c_str ());
-
- return 0;
}
/* If necessary, make the user confirm that we should quit. Return
string_file stb;
stb.puts (_("A debugging session is active.\n\n"));
- iterate_over_inferiors (print_inferior_quit_action, &stb);
+
+ for (inferior *inf : all_inferiors ())
+ print_inferior_quit_action (inf, &stb);
+
stb.puts (_("\nQuit anyway? "));
return query ("%s", stb.c_str ());
quit_force (int *exit_arg, int from_tty)
{
int exit_code = 0;
- struct qt_args qt;
undo_terminal_modifications_before_exit ();
else if (return_child_result)
exit_code = return_child_result_value;
- qt.from_tty = from_tty;
-
/* We want to handle any quit errors and exit regardless. */
/* Get out of tfind mode, and kill or detach all inferiors. */
try
{
disconnect_tracing ();
- iterate_over_inferiors (kill_or_detach, &qt);
+ for (inferior *inf : all_inferiors ())
+ kill_or_detach (inf, from_tty);
}
catch (const gdb_exception &ex)
{
/* Give all pushed targets a chance to do minimal cleanup, and pop
them all out. */
- try
- {
- pop_all_targets ();
- }
- catch (const gdb_exception &ex)
+ for (inferior *inf : all_inferiors ())
{
- exception_print (gdb_stderr, ex);
+ switch_to_inferior_no_thread (inf);
+ try
+ {
+ pop_all_targets ();
+ }
+ catch (const gdb_exception &ex)
+ {
+ exception_print (gdb_stderr, ex);
+ }
}
/* Save the history information if it is appropriate to do so. */
{
if (write_history_p && history_filename)
{
- struct ui *ui;
int save = 0;
/* History is currently shared between all UIs. If there's
any UI with a terminal, save history. */
- ALL_UIS (ui)
+ for (ui *ui : all_uis ())
{
if (input_interactive_p (ui))
{
set_readline_history_size (history_size_setshow_var);
}
-void
-set_history (const char *args, int from_tty)
-{
- printf_unfiltered (_("\"set history\" must be followed "
- "by the name of a history subcommand.\n"));
- help_list (sethistlist, "set history ", all_commands, gdb_stdout);
-}
-
-void
-show_history (const char *args, int from_tty)
-{
- cmd_show_list (showhistlist, from_tty, "");
-}
-
bool info_verbose = false; /* Default verbose msgs off. */
/* Called by do_set_command. An elaborate joke. */
set_readline_history_size (history_size_setshow_var);
tmpenv = getenv ("GDBHISTFILE");
- if (tmpenv)
+ if (tmpenv != nullptr)
history_filename = xstrdup (tmpenv);
- else if (!history_filename)
+ else if (history_filename == nullptr)
{
/* We include the current directory so that if the user changes
directories the file written will be the same as the one
gdb::unique_xmalloc_ptr<char> temp (gdb_abspath (fname));
history_filename = temp.release ();
}
- read_history (history_filename);
+
+ if (!history_filename_empty ())
+ read_history (history_filename);
}
static void
show_gdb_datadir (struct ui_file *file, int from_tty,
struct cmd_list_element *c, const char *value)
{
- fprintf_filtered (file, _("GDB's data directory is \"%s\".\n"),
- gdb_datadir.c_str ());
+ fprintf_filtered (file, _("GDB's data directory is \"%ps\".\n"),
+ styled_string (file_name_style.style (),
+ gdb_datadir.c_str ()));
}
+/* Implement 'set history filename'. */
+
static void
set_history_filename (const char *args,
int from_tty, struct cmd_list_element *c)
/* We include the current directory so that if the user changes
directories the file written will be the same as the one
that was read. */
- if (!IS_ABSOLUTE_PATH (history_filename))
+ if (!history_filename_empty () && !IS_ABSOLUTE_PATH (history_filename))
{
gdb::unique_xmalloc_ptr<char> temp (gdb_abspath (history_filename));
show_history_remove_duplicates,
&sethistlist, &showhistlist);
- add_setshow_filename_cmd ("filename", no_class, &history_filename, _("\
+ add_setshow_optional_filename_cmd ("filename", no_class, &history_filename, _("\
Set the filename in which to record the command history."), _("\
Show the filename in which to record the command history."), _("\
(the list of previous commands of which a record is kept)."),
#endif
init_cmd_lists (); /* This needs to be done first. */
- initialize_targets (); /* Setup target_terminal macros for utils.c. */
init_page_info ();