-}
-
-/* Execute the line P as a command.
- Pass FROM_TTY as second argument to the defining function. */
-
-void
-execute_command (p, from_tty)
- char *p;
- int from_tty;
-{
- register struct cmd_list_element *c;
- register struct command_line *cmdlines;
- register enum language flang;
- static const struct language_defn *saved_language = 0;
- static int warned = 0;
-
- free_all_values ();
-
- /* This can happen when command_line_input hits end of file. */
- if (p == NULL)
- return;
-
- while (*p == ' ' || *p == '\t') p++;
- if (*p)
- {
- char *arg;
-
- c = lookup_cmd (&p, cmdlist, "", 0, 1);
- /* Pass null arg rather than an empty one. */
- arg = *p ? p : 0;
- if (c->class == class_user)
- {
- struct cleanup *old_chain;
-
- if (*p)
- error ("User-defined commands cannot take arguments.");
- cmdlines = c->user_commands;
- if (cmdlines == 0)
- /* Null command */
- return;
-
- /* Set the instream to 0, indicating execution of a
- user-defined function. */
- old_chain = make_cleanup (source_cleanup, instream);
- instream = (FILE *) 0;
- while (cmdlines)
- {
- execute_command (cmdlines->line, 0);
- cmdlines = cmdlines->next;
- }
- do_cleanups (old_chain);
- }
- else if (c->type == set_cmd || c->type == show_cmd)
- do_setshow_command (arg, from_tty & caution, c);
- else if (c->function.cfunc == NO_FUNCTION)
- error ("That is not a command, just a help topic.");
- else
- (*c->function.cfunc) (arg, from_tty & caution);
- }
-
- /* Tell the user if the language has changed (except first time). */
- if (current_language != saved_language)
- {
- if (language_mode == language_mode_auto) {
- if (saved_language)
- language_info (1); /* Print what changed. */
- }
- saved_language = current_language;
- warned = 0;
- }
-
- /* Warn the user if the working language does not match the
- language of the current frame. Only warn the user if we are
- actually running the program, i.e. there is a stack. */
- /* FIXME: This should be cacheing the frame and only running when
- the frame changes. */
- if (target_has_stack)
- {
- flang = get_frame_language ();
- if (!warned
- && flang != language_unknown
- && flang != current_language->la_language)
- {
- printf_filtered ("%s\n", lang_frame_mismatch_warn);
- warned = 1;
- }
- }
-}
-
-/* ARGSUSED */
-static void
-command_loop_marker (foo)
- int foo;
-{
-}
-
-/* Read commands from `instream' and execute them
- until end of file or error reading instream. */
-static void
-command_loop ()
-{
- struct cleanup *old_chain;
- char *command;
- int stdin_is_tty = ISATTY (stdin);
-
- while (!feof (instream))
- {
- if (window_hook && instream == stdin)
- (*window_hook) (instream, prompt);
-
- quit_flag = 0;
- if (instream == stdin && stdin_is_tty)
- reinitialize_more_filter ();
- old_chain = make_cleanup (command_loop_marker, 0);
- command = command_line_input (instream == stdin ? prompt : (char *) NULL,
- instream == stdin);
- if (command == 0)
- return;
- execute_command (command, instream == stdin);
- /* Do any commands attached to breakpoint we stopped at. */
- bpstat_do_actions (&stop_bpstat);
- do_cleanups (old_chain);
- }
-}
-\f
-/* Commands call this if they do not want to be repeated by null lines. */
-
-void
-dont_repeat ()
-{
- /* If we aren't reading from standard input, we are saving the last
- thing read from stdin in line and don't want to delete it. Null lines
- won't repeat here in any case. */
- if (instream == stdin)
- *line = 0;
-}
-\f
-/* Read a line from the stream "instream" without command line editing.
-
- It prints PRROMPT once at the start.
- Action is compatible with "readline", e.g. space for the result is
- malloc'd and should be freed by the caller.
-
- A NULL return means end of file. */
-char *
-gdb_readline (prrompt)
- char *prrompt;
-{
- int c;
- char *result;
- int input_index = 0;
- int result_size = 80;
-
- if (prrompt)
- {
- printf (prrompt);
- fflush (stdout);
- }
-
- result = (char *) xmalloc (result_size);
-
- while (1)
- {
- /* Read from stdin if we are executing a user defined command.
- This is the right thing for prompt_for_continue, at least. */
- c = fgetc (instream ? instream : stdin);
-
- if (c == EOF)
- {
- free (result);
- return NULL;
- }
-
- if (c == '\n')
- break;
-
- result[input_index++] = c;
- while (input_index >= result_size)
- {
- result_size *= 2;
- result = (char *) xrealloc (result, result_size);
- }
- }
-
- result[input_index++] = '\0';
- return result;
-}
-
-/* Variables which control command line editing and history
- substitution. These variables are given default values at the end
- of this file. */
-static int command_editing_p;
-static int history_expansion_p;
-static int write_history_p;
-static int history_size;
-static char *history_filename;
-
-/* Variables which are necessary for fancy command line editing. */
-char *gdb_completer_word_break_characters =
- " \t\n!@#$%^&*()-+=|~`}{[]\"';:?/>.<,";
-
-/* Functions that are used as part of the fancy command line editing. */
-
-/* This can be used for functions which don't want to complete on symbols
- but don't want to complete on anything else either. */
-/* ARGSUSED */
-char **
-noop_completer (text)
- char *text;
-{
- return NULL;
-}
-
-/* Generate symbol names one by one for the completer. If STATE is
- zero, then we need to initialize, otherwise the initialization has
- already taken place. TEXT is what we expect the symbol to start
- with. RL_LINE_BUFFER is available to be looked at; it contains the
- entire text of the line. RL_POINT is the offset in that line of
- the cursor. You should pretend that the line ends at RL_POINT.
- The result is NULL if there are no more completions, else a char
- string which is a possible completion. */
-
-static char *
-symbol_completion_function (text, state)
- char *text;
- int state;
-{
- static char **list = (char **)NULL;
- static int index;
- char *output;
- extern char *rl_line_buffer;
- extern int rl_point;
- char *tmp_command, *p;
- struct cmd_list_element *c, *result_list;
-
- if (!state)
- {
- /* Free the storage used by LIST, but not by the strings inside. This is
- because rl_complete_internal () frees the strings. */
- if (list)
- free (list);
- list = 0;
- index = 0;
-
- /* Decide whether to complete on a list of gdb commands or on
- symbols. */
- tmp_command = (char *) alloca (rl_point + 1);
- p = tmp_command;
-
- strncpy (tmp_command, rl_line_buffer, rl_point);
- tmp_command[rl_point] = '\0';
-
- if (rl_point == 0)
- {
- /* An empty line we want to consider ambiguous; that is,
- it could be any command. */
- c = (struct cmd_list_element *) -1;
- result_list = 0;
- }
- else
- c = lookup_cmd_1 (&p, cmdlist, &result_list, 1);
-
- /* Move p up to the next interesting thing. */
- while (*p == ' ' || *p == '\t')
- p++;
-
- if (!c)
- /* He's typed something unrecognizable. Sigh. */
- list = (char **) 0;
- else if (c == (struct cmd_list_element *) -1)
- {
- /* If we didn't recognize everything up to the thing that
- needs completing, and we don't know what command it is
- yet, we are in trouble. Part of the trouble might be
- that the list of delimiters used by readline includes
- '-', which we use in commands. Check for this. */
- if (p + strlen(text) != tmp_command + rl_point) {
- if (tmp_command[rl_point - strlen(text) - 1] == '-')
- text = p;
- else {
- /* This really should not produce an error. Better would
- be to pretend to hit RETURN here; this would produce a
- response like "Ambiguous command: foo, foobar, etc",
- and leave the line available for re-entry with ^P. Instead,
- this error blows away the user's typed input without
- any way to get it back. */
- error (" Unrecognized command.");
- }
- }
-
- /* He's typed something ambiguous. This is easier. */
- if (result_list)
- list = complete_on_cmdlist (*result_list->prefixlist, text);
- else
- list = complete_on_cmdlist (cmdlist, text);
- }
- else
- {
- /* If we've gotten this far, gdb has recognized a full
- command. There are several possibilities:
-
- 1) We need to complete on the command.
- 2) We need to complete on the possibilities coming after
- the command.
- 2) We need to complete the text of what comes after the
- command. */
-
- if (!*p && *text)
- /* Always (might be longer versions of thie command). */
- list = complete_on_cmdlist (result_list, text);
- else if (!*p && !*text)
- {
- if (c->prefixlist)
- list = complete_on_cmdlist (*c->prefixlist, "");
- else
- list = (*c->completer) ("");
- }
- else
- {
- if (c->prefixlist && !c->allow_unknown)
- {
-#if 0
- /* Something like "info adsfkdj". But error() is not
- the proper response; just return no completions
- instead. */
- *p = '\0';
- error ("\"%s\" command requires a subcommand.",
- tmp_command);
-#else
- list = NULL;
-#endif
- }
- else
- list = (*c->completer) (text);
- }
- }
- }
-
- /* If the debugged program wasn't compiled with symbols, or if we're
- clearly completing on a command and no command matches, return
- NULL. */
- if (!list)
- return ((char *)NULL);
-
- output = list[index];
- if (output)
- index++;
-
- return (output);
-}
-\f
-#ifdef STOP_SIGNAL
-static void
-stop_sig (signo)
-int signo;
-{
-#if STOP_SIGNAL == SIGTSTP
- signal (SIGTSTP, SIG_DFL);
- sigsetmask (0);
- kill (getpid (), SIGTSTP);
- signal (SIGTSTP, stop_sig);
-#else
- signal (STOP_SIGNAL, stop_sig);