X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=gdb%2Ftop.c;h=c62eb57695c21365d360b1afc6049aadea8d67fd;hb=refs%2Fheads%2Fconcurrent-displaced-stepping-2020-04-01;hp=a266bfa59256406b64624b1ee6547c1668b15293;hpb=5b6d1e4fa4fc6827c7b3f0e99ff120dfa14d65d2;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/top.c b/gdb/top.c index a266bfa592..c62eb57695 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -42,7 +42,7 @@ #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" @@ -51,7 +51,7 @@ #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" @@ -84,6 +84,8 @@ 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 @@ -172,7 +174,7 @@ static const char *previous_repeat_arguments; 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. */ @@ -884,13 +886,22 @@ static bool command_editing_p; /* 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" @@ -919,14 +930,30 @@ show_history_remove_duplicates (struct ui_file *file, int from_tty, 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 \"%ps\".\n"), - styled_string (file_name_style.style (), 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. @@ -1528,6 +1555,16 @@ This GDB was configured as follows:\n\ ")); #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\ @@ -1607,21 +1644,14 @@ set_prompt (const char *s) } -struct qt_args -{ - int from_tty; -}; - -/* Callback for iterate_over_inferiors. Kills or detaches the given - inferior, depending on how we originally gained control of it. */ +/* 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) @@ -1632,37 +1662,30 @@ kill_or_detach (struct inferior *inf, void *args) 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 @@ -1679,7 +1702,10 @@ quit_confirm (void) 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 ()); @@ -1712,7 +1738,6 @@ void quit_force (int *exit_arg, int from_tty) { int exit_code = 0; - struct qt_args qt; undo_terminal_modifications_before_exit (); @@ -1723,15 +1748,14 @@ quit_force (int *exit_arg, int from_tty) 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) { @@ -1758,12 +1782,11 @@ quit_force (int *exit_arg, int from_tty) { 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)) { @@ -1925,20 +1948,6 @@ set_history_size_command (const char *args, 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. */ @@ -2020,9 +2029,9 @@ init_history (void) 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 @@ -2037,7 +2046,9 @@ init_history (void) gdb::unique_xmalloc_ptr temp (gdb_abspath (fname)); history_filename = temp.release (); } - read_history (history_filename); + + if (!history_filename_empty ()) + read_history (history_filename); } static void @@ -2106,6 +2117,8 @@ show_gdb_datadir (struct ui_file *file, int from_tty, gdb_datadir.c_str ())); } +/* Implement 'set history filename'. */ + static void set_history_filename (const char *args, int from_tty, struct cmd_list_element *c) @@ -2113,7 +2126,7 @@ set_history_filename (const char *args, /* 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 temp (gdb_abspath (history_filename)); @@ -2220,7 +2233,7 @@ By default this option is set to 0."), 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)."),