51 #include "filenames.h"
54 #include "readline/readline.h"
55 #include "readline/history.h"
60 #include <sys/types.h>
72 #define PROMPT(X) the_prompts.prompt_stack[the_prompts.top + X].prompt
73 #define PREFIX(X) the_prompts.prompt_stack[the_prompts.top + X].prefix
74 #define SUFFIX(X) the_prompts.prompt_stack[the_prompts.top + X].suffix
78 #ifndef DEFAULT_PROMPT
79 #define DEFAULT_PROMPT "(gdb) "
100 "dangerous operations is %s.\n"),
210 char *(*deprecated_readline_hook) (
const char *);
240 char *cmd,
int from_tty);
300 do_chdir_cleanup (
void *old_dir)
332 static int warned = 0;
411 while (*p ==
' ' || *p ==
'\t')
444 p = arg + strlen (arg) - 1;
445 while (p >= arg && (*p ==
' ' || *p ==
'\t'))
464 error (
_(
"That is not a command, just a help topic."));
511 warning (
_(
"Current output protocol does not support redirection"));
538 int stdin_is_tty =
ISATTY (stdin);
546 if (instream == stdin && stdin_is_tty)
553 instream == stdin,
"prompt");
563 if (command[0] !=
'#')
620 int result_size = 80;
631 result = (
char *)
xmalloc (result_size);
652 if (input_index > 0 && result[input_index - 1] ==
'\r')
657 result[input_index++] = c;
658 while (input_index >= result_size)
661 result = (
char *)
xrealloc (result, result_size);
665 result[input_index++] =
'\0';
710 _(
"The number of history entries to look back at for "
711 "duplicates is %s.\n"),
721 "the command history is \"%s\".\n"),
827 cleanup =
xmalloc (
sizeof (*cleanup));
842 rl_already_prompted = 1;
845 (*after_char_processing_hook) ();
870 rl_get_previous_history (delta, 0);
877 rl_pre_input_hook = NULL;
894 where = where_history();
896 if ((history_is_stifled () && (history_length >= history_max_entries))
897 || (where >= history_length - 1))
902 return rl_newline (1, key);
919 int lookbehind_threshold;
932 for (lookbehind = 0; lookbehind < lookbehind_threshold; lookbehind++)
934 HIST_ENTRY *temp = previous_history ();
939 if (strcmp (temp->line, command) == 0)
941 HIST_ENTRY *prev = remove_history (where_history ());
943 free_history_entry (prev);
950 add_history (command);
959 int ret, saved_errno;
960 char *local_history_filename;
963 local_history_filename
969 if (ret < 0 && saved_errno != ENOENT)
971 warning (
_(
"Could not rename %s to %s: %s"),
988 write_history (local_history_filename);
993 if (history_is_stifled ())
994 history_truncate_file (local_history_filename, history_max_entries);
999 if (ret < 0 && saved_errno != EEXIST)
1000 warning (
_(
"Could not rename %s to %s: %s"),
1026 static char *linebuffer = 0;
1027 static unsigned linelength = 0;
1028 const char *prompt = prompt_arg;
1036 if (annotation_suffix == NULL)
1037 annotation_suffix =
"";
1043 local_prompt = alloca ((prompt == NULL ? 0 : strlen (prompt))
1044 + strlen (annotation_suffix) + 40);
1046 local_prompt[0] =
'\0';
1048 strcpy (local_prompt, prompt);
1049 strcat (local_prompt,
"\n\032\032");
1050 strcat (local_prompt, annotation_suffix);
1051 strcat (local_prompt,
"\n");
1053 prompt = local_prompt;
1056 if (linebuffer == 0)
1059 linebuffer = (
char *)
xmalloc (linelength);
1070 signal (STOP_SIGNAL, handle_stop_sig);
1095 rl = (*deprecated_readline_hook) (prompt);
1113 if (!rl || rl == (
char *) EOF)
1118 if (strlen (rl) + 1 + (p - linebuffer) > linelength)
1120 linelength = strlen (rl) + 1 + (p - linebuffer);
1121 nline = (
char *)
xrealloc (linebuffer, linelength);
1122 p += nline - linebuffer;
1133 if (p == linebuffer || *(p - 1) !=
'\\')
1142 signal (STOP_SIGNAL, SIG_DFL);
1149 #define SERVER_COMMAND_LENGTH 7
1166 char *history_value;
1170 expanded = history_expand (linebuffer, &history_value);
1179 xfree (history_value);
1183 if (strlen (history_value) > linelength)
1185 linelength = strlen (history_value) + 1;
1186 linebuffer = (
char *)
xrealloc (linebuffer, linelength);
1188 strcpy (linebuffer, history_value);
1189 p = linebuffer + strlen (linebuffer);
1191 xfree (history_value);
1196 if (repeat && p == linebuffer)
1198 for (p1 = linebuffer; *p1 ==
' ' || *p1 ==
'\t'; p1++);
1236 "Copyright (C) 2015 Free Software Foundation, Inc.\n");
1244 License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\
1245 \nThis is free software: you are free to change and redistribute it.\n\
1246 There is NO WARRANTY, to the extent permitted by law. Type \"show copying\"\n\
1247 and \"show warranty\" for details.\n");
1262 Type \"show configuration\" for configuration details.");
1267 _(
"\nFor bug reporting instructions, please see:\n"));
1271 _(
"Find the GDB manual and other documentation \
1272 resources online at:\n<http://www.gnu.org/software/gdb/documentation/>.\n"));
1275 commands related to \"word\"."));
1283 This GDB was configured as follows:\n\
1284 configure --host=%s --target=%s\n\
1287 --with-auto-load-dir=%s\n\
1288 --with-auto-load-safe-path=%s\n\
1301 --with-gdb-datadir=%s%s\n\
1305 --with-iconv-bin=%s%s\n\
1306 "), ICONV_BIN, ICONV_BIN_RELOCATABLE ?
" (relocatable)" :
"");
1310 --with-jit-reader-dir=%s%s\n\
1312 #if HAVE_LIBUNWIND_IA64_H
1314 --with-libunwind-ia64\n\
1318 --without-libunwind-ia64\n\
1330 #ifdef WITH_PYTHON_PATH
1332 --with-python=%s%s\n\
1346 --with-relocated-sources=%s\n\
1351 --with-separate-debug-dir=%s%s\n\
1355 --with-sysroot=%s%s\n\
1359 --with-system-gdbinit=%s%s\n\
1361 #if HAVE_LIBBABELTRACE
1363 --with-babeltrace\n\
1367 --without-babeltrace\n\
1373 (\"Relocatable\" means the directory can be moved with the GDB installation\n\
1374 tree, and GDB will still find it.)\n\
1396 char *p = xstrdup (s);
1453 _(
"\tInferior %d [%s] will be detached.\n"), inf->
num,
1457 _(
"\tInferior %d [%s] will be killed.\n"), inf->
num,
1489 qr =
query (
"%s", str);
1601 #define Hist_print 10
1616 if (args[0] ==
'+' && args[1] ==
'\0')
1642 offset < num +
Hist_print && offset < history_length;
1646 (history_get (history_base + offset))->
line);
1656 if (from_tty && args)
1672 if (history_size == -1)
1673 unstifle_history ();
1675 stifle_history (history_size);
1689 "by the name of a history subcommand.\n"));
1705 const char *cmdname =
"verbose";
1713 c->
doc =
"Set verbose printing of informational messages.";
1714 showcmd->
doc =
"Show verbose printing of informational messages.";
1718 c->
doc =
"Set verbosity.";
1719 showcmd->
doc =
"Show verbosity.";
1733 tmpenv = getenv (
"GDBHISTSIZE");
1742 var = strtol (tmpenv, &endptr, 10);
1743 saved_errno = errno;
1751 if (*endptr !=
'\0')
1753 else if (*tmpenv ==
'\0'
1760 || (var ==
INT_MAX && saved_errno == ERANGE))
1773 tmpenv = getenv (
"GDBHISTFILE");
1805 "they are typed is %s.\n"),
1821 "asynchronous execution commands is %s.\n"),
1880 rl_readline_name =
"gdb";
1881 rl_terminal_name = getenv (
"TERM");
1889 _(
"Set gdb's prompt"),
1890 _(
"Show gdb's prompt"),
1896 Don't repeat this command.\nPrimarily \
1897 used inside of user-defined commands that should not be repeated when\n\
1902 Set editing of command lines as they are typed."),
_(
"\
1903 Show editing of command lines as they are typed."),
_(
"\
1904 Use \"on\" to enable the editing, and \"off\" to disable it.\n\
1905 Without an argument, command line editing is enabled. To edit, use\n\
1906 EMACS-like or VI-like commands like control-P or ESC."),
1912 Set saving of the history record on exit."),
_(
"\
1913 Show saving of the history record on exit."),
_(
"\
1914 Use \"on\" to enable the saving, and \"off\" to disable it.\n\
1915 Without an argument, saving is enabled."),
1922 Set the size of the command history,"),
_(
"\
1923 Show the size of the command history,"),
_(
"\
1924 ie. the number of previous commands to keep a record of.\n\
1925 If set to \"unlimited\", the number of commands kept in the history\n\
1926 list is unlimited. This defaults to the value of the environment\n\
1927 variable \"GDBHISTSIZE\", or to 256 if this variable is not set."),
1934 Set how far back in history to look for and remove duplicate entries."),
_(
"\
1935 Show how far back in history to look for and remove duplicate entries."),
_(
"\
1936 If set to a nonzero value N, GDB will look back at the last N history entries\n\
1937 and remove the first history entry that is a duplicate of the most recent\n\
1938 entry, each time a new history entry is added.\n\
1939 If set to \"unlimited\", this lookbehind is unbounded.\n\
1940 Only history entries added during this session are considered for removal.\n\
1941 If set to 0, removal of duplicate history entries is disabled.\n\
1942 By default this option is set to 0."),
1948 Set the filename in which to record the command history"),
_(
"\
1949 Show the filename in which to record the command history"),
_(
"\
1950 (the list of previous commands of which a record is kept)."),
1956 Set whether to confirm potentially dangerous operations."),
_(
"\
1957 Show whether to confirm potentially dangerous operations."), NULL,
1963 Set annotation_level."),
_(
"\
1964 Show annotation_level."),
_(
"\
1965 0 == normal; 1 == fullname (for use when running under emacs)\n\
1966 2 == output annotated suitably for use by programs that control GDB."),
1973 Set notification of completion for asynchronous execution commands."),
_(
"\
1974 Show notification of completion for asynchronous execution commands."),
_(
"\
1975 Use \"on\" to enable the notification, and \"off\" to disable it."),
1982 _(
"Show GDB's data directory."),
1984 When set, GDB uses the specified path to search for data files."),
int have_live_inferiors(void)
void gdb_add_history(const char *command)
unsigned int deprecated_warn_user
struct value * value_mark(void)
void(* deprecated_register_changed_hook)(int regno)
void(* after_char_processing_hook)(void)
void(* deprecated_readline_begin_hook)(char *,...)
static void show_history_filename(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
char * get_gdb_completer_quote_characters(void)
void async_init_signals(void)
void language_info(int quietly)
int saved_command_line_size
void execute_cmd_pre_hook(struct cmd_list_element *c)
void add_setshow_zinteger_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void initialize_inferiors(void)
void fputs_unfiltered(const char *buf, struct ui_file *file)
void finish_ext_lang_initialization(void)
void(* input_handler)(char *)
__extension__ enum cmd_types type
void execute_user_command(struct cmd_list_element *c, char *args)
#define JIT_READER_DIR_RELOCATABLE
LONGEST value_as_long(struct value *val)
void clear_quit_flag(void)
char * gdb_readline(const char *prompt_arg)
void warning(const char *fmt,...)
void cli_display_match_list(char **matches, int len, int max)
void do_final_cleanups(struct cleanup *old_chain)
int query(const char *ctlstr,...)
char * async_annotation_suffix
void(* deprecated_attach_hook)(void)
char * ui_file_xstrdup(struct ui_file *file, long *length)
enum language set_language(enum language lang)
void target_detach(const char *args, int from_tty)
int(* deprecated_ui_loop_hook)(int)
struct ui_file * gdb_stdout
struct cleanup * make_cleanup_ui_out_redirect_pop(struct ui_out *uiout)
static char * history_filename
void show_history(char *args, int from_tty)
void switch_to_thread(ptid_t ptid)
void initialize_targets(void)
#define target_log_command(p)
#define AUTO_LOAD_SAFE_PATH
void quit_force(char *args, int from_tty)
struct cmd_list_element * lookup_cmd_1(const char **text, struct cmd_list_element *clist, struct cmd_list_element **result_list, int ignore_help_classes)
static int history_remove_duplicates
enum language la_language
static void set_readline_history_size(int history_size)
struct cmd_list_element * cmdlist
struct inferior * iterate_over_inferiors(int(*callback)(struct inferior *, void *), void *data)
void print_gdb_configuration(struct ui_file *stream)
static void dont_repeat_command(char *ignored, int from_tty)
char * target_pid_to_str(ptid_t ptid)
#define SERVER_COMMAND_LENGTH
char * skip_spaces(char *chp)
void(* deprecated_readline_end_hook)(void)
void deprecated_cmd_warning(const char *text)
void set_verbose(char *args, int from_tty, struct cmd_list_element *c)
static void show_annotation_level(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
struct cmd_list_element * lookup_cmd(const char **line, struct cmd_list_element *list, char *cmdtype, int allow_unknown, int ignore_help_classes)
static void show_history_remove_duplicates(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static int gdb_readline_wrapper_done
void initialize_all_files(void)
void set_initial_gdb_ttystate(void)
static int command_editing_p
int gdb_has_a_terminal(void)
static void set_history_filename(char *args, int from_tty, struct cmd_list_element *c)
struct cleanup * make_cleanup_restore_ui_file(struct ui_file **variable)
void printf_filtered(const char *format,...)
static void init_main(void)
void(* deprecated_call_command_hook)(struct cmd_list_element *c, char *cmd, int from_tty)
struct command_line * user_commands
struct cleanup * all_cleanups(void)
#define TARGET_SYSTEM_ROOT_RELOCATABLE
void null_cleanup(void *arg)
void cmd_func(struct cmd_list_element *cmd, char *args, int from_tty)
static int write_history_p
struct cmd_list_element * setlist
static void gdb_readline_wrapper_line(char *line)
char * default_word_break_characters(void)
void set_gdb_data_directory(const char *new_datadir)
void target_dcache_invalidate(void)
#define CATCH(EXCEPTION, MASK)
static void show_confirm(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
struct cleanup * make_cleanup_restore_integer(int *variable)
static int suppress_dont_repeat
static void show_async_command_editing_p(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
const char * source_file_name
void set_history(char *args, int from_tty)
struct cleanup * set_batch_flag_and_make_cleanup_restore_page_info(void)
void fprintf_filtered(struct ui_file *stream, const char *format,...)
static void show_gdb_datadir(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static void set_history_size_command(char *args, int from_tty, struct cmd_list_element *c)
void(* deprecated_warning_hook)(const char *, va_list)
mach_port_t mach_port_t name mach_port_t mach_port_t name error_t int status
struct cmd_list_element * showlist
void exception_print(struct ui_file *file, struct gdb_exception e)
struct cleanup * make_cleanup_value_free_to_mark(struct value *mark)
ptid_t pid_to_ptid(int pid)
struct cleanup * prevent_dont_repeat(void)
int async_command_editing_p
struct cleanup * make_cleanup(make_cleanup_ftype *function, void *arg)
struct frame_info * deprecated_safe_get_selected_frame(void)
void print_gdb_version(struct ui_file *stream)
#define GDB_DATADIR_RELOCATABLE
int(* deprecated_query_hook)(const char *, va_list)
int already_prompted_orig
void add_setshow_string_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void pop_all_targets(void)
void reinitialize_more_filter(void)
enum language get_frame_language(void)
char * execute_command_to_string(char *p, int from_tty)
static void gdb_rl_operate_and_get_next_completion(void)
#define target_is_async_p()
static int gdb_rl_operate_and_get_next(int count, int key)
void execute_command(char *p, int from_tty)
void init_cmd_lists(void)
#define CMD_LIST_AMBIGUOUS
static int kill_or_detach(struct inferior *inf, void *args)
#define target_has_execution
void(* pre_init_ui_hook)(void)
int is_complete_command(struct cmd_list_element *c)
char * xstrprintf(const char *format,...)
static int history_size_setshow_var
void wrap_here(char *indent)
void printf_unfiltered(const char *format,...)
static void set_gdb_datadir(char *args, int from_tty, struct cmd_list_element *c)
void maybe_wait_sync_command_done(int was_sync)
struct cmd_list_element * sethistlist
struct ui_file * gdb_stdlog
struct ui_file * mem_fileopen(void)
#define DEBUGDIR_RELOCATABLE
void(* deprecated_context_hook)(int id)
static char * staged_gdb_datadir
void cmd_show_list(struct cmd_list_element *list, int from_tty, const char *prefix)
char * gdb_readline_wrapper(const char *prompt)
void initialize_progspace(void)
void initialize_stdin_serial(void)
#define SYSTEM_GDBINIT_RELOCATABLE
PTR xrealloc(PTR ptr, size_t size)
#define PYTHON_PATH_RELOCATABLE
static int print_inferior_quit_action(struct inferior *inf, void *arg)
const char const char int
char * gdb_completion_word_break_characters(void)
void initialize_utils(void)
void help_list(struct cmd_list_element *list, const char *cmdtype, enum command_class theclass, struct ui_file *stream)
void discard_cleanups(struct cleanup *old_chain)
const struct language_defn * current_language
void puts_unfiltered(const char *string)
void add_setshow_zuinteger_unlimited_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void execute_cmd_post_hook(struct cmd_list_element *c)
struct cleanup * make_command_stats_cleanup(int msg_type)
struct cleanup * prepare_execute_command(void)
void check_frame_language_change(void)
struct cleanup * make_bpstat_clear_actions_cleanup(void)
static void(* saved_after_char_processing_hook)(void)
struct cleanup * make_cleanup_ui_file_delete(struct ui_file *arg)
int gdb_do_one_event(void)
void set_async_editing_command(char *args, int from_tty, struct cmd_list_element *c)
char * command_line_input(const char *prompt_arg, int repeat, char *annotation_suffix)
static void show_history_size(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
static void show_prompt(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
void do_restore_instream_cleanup(void *stream)
void gdb_rl_callback_handler_remove(void)
struct ui_file * gdb_stderr
char * readline_line_completion_function(const char *text, int matches)
char * safe_strerror(int)
static int operate_saved_history
void(* window_hook)(FILE *, char *)
const struct language_defn * expected_language
void set_prompt(const char *s)
static void show_write_history_p(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
enum command_class theclass
#define TARGET_SYSTEM_ROOT
void quit_command(char *args, int from_tty)
void add_setshow_filename_cmd(const char *name, enum command_class theclass, char **var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
struct ui_file * gdb_stdtarg
struct cleanup * make_final_cleanup(make_cleanup_ftype *function, void *arg)
int ui_out_redirect(struct ui_out *uiout, struct ui_file *outstream)
struct value * parse_and_eval(const char *exp)
void display_gdb_prompt(const char *new_prompt)
void disconnect_tracing(void)
void do_set_command(const char *arg, int from_tty, struct cmd_list_element *c)
char lang_frame_mismatch_warn[]
void(* handler_orig)(char *)
void bpstat_do_actions(void)
struct cmd_list_element * showhistlist
static void gdb_readline_wrapper_cleanup(void *arg)
void gdb_init(char *argv0)
void do_show_command(const char *arg, int from_tty, struct cmd_list_element *c)
int input_from_terminal_p(void)
void init_page_info(void)
struct ui_file * gdb_stdtargerr
void initialize_current_architecture(void)
static void gdb_safe_append_history(void)
void print_command_trace(const char *cmd)
void gdb_flush(struct ui_file *file)
struct ui_out * current_uiout
void observer_notify_gdb_datadir_changed(void)
static void show_exec_done_display_p(struct ui_file *file, int from_tty, struct cmd_list_element *c, const char *value)
char * saved_command_line
#define target_async(ENABLE)
char *(* deprecated_readline_hook)(const char *)
void(* deprecated_interactive_hook)(void)
int has_stack_frames(void)
void(* deprecated_print_frame_info_listing_hook)(struct symtab *s, int line, int stopline, int noerror)
struct thread_info * any_thread_of_process(int pid)
void error(const char *fmt,...)
int return_child_result_value
static char * gdb_readline_wrapper_result
struct cmd_list_element * add_com(const char *name, enum command_class theclass, cmd_cfunc_ftype *fun, const char *doc)
int cmd_func_p(struct cmd_list_element *cmd)
void do_cleanups(struct cleanup *old_chain)
void add_setshow_boolean_cmd(const char *name, enum command_class theclass, int *var, const char *set_doc, const char *show_doc, const char *help_doc, cmd_sfunc_ftype *set_func, show_value_ftype *show_func, struct cmd_list_element **set_list, struct cmd_list_element **show_list)
void(* deprecated_detach_hook)(void)
void read_command_file(FILE *stream)
ptid_t(* deprecated_target_wait_hook)(ptid_t ptid, struct target_waitstatus *status, int options)
void show_commands(char *args, int from_tty)
LONGEST parse_and_eval_long(const char *exp)