-/* Insert the user defined arguments stored in user_arg into the $arg
- arguments found in line, with the updated copy being placed into nline. */
-
-static char *
-insert_args (char *line)
-{
- char *p, *save_line, *new_line;
- unsigned len, i;
-
- /* First we need to know how much memory to allocate for the new line. */
- save_line = line;
- len = 0;
- while ((p = locate_arg (line)))
- {
- len += p - line;
- i = p[4] - '0';
-
- if (i >= user_args->count)
- {
- error ("Missing argument %d in user function.\n", i);
- return NULL;
- }
- len += user_args->a[i].len;
- line = p + 5;
- }
-
- /* Don't forget the tail. */
- len += strlen (line);
-
- /* Allocate space for the new line and fill it in. */
- new_line = (char *) xmalloc (len + 1);
- if (new_line == NULL)
- return NULL;
-
- /* Restore pointer to beginning of old line. */
- line = save_line;
-
- /* Save pointer to beginning of new line. */
- save_line = new_line;
-
- while ((p = locate_arg (line)))
- {
- int i, len;
-
- memcpy (new_line, line, p - line);
- new_line += p - line;
- i = p[4] - '0';
-
- len = user_args->a[i].len;
- if (len)
- {
- memcpy (new_line, user_args->a[i].arg, len);
- new_line += len;
- }
- line = p + 5;
- }
- /* Don't forget the tail. */
- strcpy (new_line, line);
-
- /* Return a pointer to the beginning of the new line. */
- return save_line;
-}
-
-void
-execute_user_command (struct cmd_list_element *c, char *args)
-{
- register struct command_line *cmdlines;
- struct cleanup *old_chain;
- enum command_control_type ret;
-
- old_chain = setup_user_args (args);
-
- 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 (do_restore_instream_cleanup, instream);
- instream = (FILE *) 0;
- while (cmdlines)
- {
- ret = execute_control_command (cmdlines);
- if (ret != simple_control && ret != break_control)
- {
- warning ("Error in control structure.\n");
- break;
- }
- cmdlines = cmdlines->next;
- }
- do_cleanups (old_chain);
-}
-
-/* Execute the line P as a command.
- Pass FROM_TTY as second argument to the defining function. */
-
-void
-execute_command (char *p, int from_tty)
-{
- register struct cmd_list_element *c;
- register enum language flang;
- static int warned = 0;
- char *line;
- /* FIXME: These should really be in an appropriate header file */
-extern void serial_log_command (const char *);
-
- free_all_values ();
-
- /* Force cleanup of any alloca areas if using C alloca instead of
- a builtin alloca. */
- alloca (0);
-
- /* This can happen when command_line_input hits end of file. */
- if (p == NULL)
- return;
-
- serial_log_command (p);
-
- while (*p == ' ' || *p == '\t')
- p++;
- if (*p)
- {
- char *arg;
- line = p;
-
- c = lookup_cmd (&p, cmdlist, "", 0, 1);
-
- /* If the target is running, we allow only a limited set of
- commands. */
- if (event_loop_p && target_can_async_p () && target_executing)
- if (!strcmp (c->name, "help")
- && !strcmp (c->name, "pwd")
- && !strcmp (c->name, "show")
- && !strcmp (c->name, "stop"))
- error ("Cannot execute this command while the target is running.");
-
- /* Pass null arg rather than an empty one. */
- arg = *p ? p : 0;
-
- /* Clear off trailing whitespace, except for set and complete command. */
- if (arg && c->type != set_cmd && c->function.cfunc != complete_command)
- {
- p = arg + strlen (arg) - 1;
- while (p >= arg && (*p == ' ' || *p == '\t'))
- p--;
- *(p + 1) = '\0';
- }
-
- /* If this command has been pre-hooked, run the hook first. */
- if ((c->hook_pre) && (!c->hook_in))
- {
- c->hook_in = 1; /* Prevent recursive hooking */
- execute_user_command (c->hook_pre, (char *) 0);
- c->hook_in = 0; /* Allow hook to work again once it is complete */
- }
-
- if (c->flags & DEPRECATED_WARN_USER)
- deprecated_cmd_warning (&line);
-
- if (c->class == class_user)
- execute_user_command (c, arg);
- 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 if (call_command_hook)
- call_command_hook (c, arg, from_tty & caution);
- else
- (*c->function.cfunc) (arg, from_tty & caution);
-
- /* If this command has been post-hooked, run the hook last. */
- if ((c->hook_post) && (!c->hook_in))
- {
- c->hook_in = 1; /* Prevent recursive hooking */
- execute_user_command (c->hook_post, (char *) 0);
- c->hook_in = 0; /* allow hook to work again once it is complete */
- }
-
- }
-
- /* Tell the user if the language has changed (except first time). */
- if (current_language != expected_language)
- {
- if (language_mode == language_mode_auto)
- {
- language_info (1); /* Print what changed. */
- }
- 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;
- }
- }
-}
-
-/* Read commands from `instream' and execute them
- until end of file or error reading instream. */
-
-void
-command_loop (void)
-{
- struct cleanup *old_chain;
- char *command;
- int stdin_is_tty = ISATTY (stdin);
- long time_at_cmd_start;
-#ifdef HAVE_SBRK
- long space_at_cmd_start = 0;
-#endif
- extern int display_time;
- extern int display_space;
-
- while (instream && !feof (instream))
- {
-#if defined(TUI)
- extern int insert_mode;
-#endif
- if (window_hook && instream == stdin)
- (*window_hook) (instream, get_prompt ());
-
- quit_flag = 0;
- if (instream == stdin && stdin_is_tty)
- reinitialize_more_filter ();
- old_chain = make_cleanup (null_cleanup, 0);
-
-#if defined(TUI)
- /* A bit of paranoia: I want to make sure the "insert_mode" global
- * is clear except when it is being used for command-line editing
- * (see tuiIO.c, utils.c); otherwise normal output will
- * get messed up in the TUI. So clear it before/after
- * the command-line-input call. - RT
- */
- insert_mode = 0;
-#endif
- /* Get a command-line. This calls the readline package. */
- command = command_line_input (instream == stdin ?
- get_prompt () : (char *) NULL,
- instream == stdin, "prompt");
-#if defined(TUI)
- insert_mode = 0;
-#endif
- if (command == 0)
- return;
-
- time_at_cmd_start = get_run_time ();
-
- if (display_space)
- {
-#ifdef HAVE_SBRK
- extern char **environ;
- char *lim = (char *) sbrk (0);
-
- space_at_cmd_start = (long) (lim - (char *) &environ);
-#endif
- }
-
- execute_command (command, instream == stdin);
- /* Do any commands attached to breakpoint we stopped at. */
- bpstat_do_actions (&stop_bpstat);
- do_cleanups (old_chain);
-
- if (display_time)
- {
- long cmd_time = get_run_time () - time_at_cmd_start;
-
- printf_unfiltered ("Command execution time: %ld.%06ld\n",
- cmd_time / 1000000, cmd_time % 1000000);
- }
-
- if (display_space)
- {
-#ifdef HAVE_SBRK
- extern char **environ;
- char *lim = (char *) sbrk (0);
- long space_now = lim - (char *) &environ;
- long space_diff = space_now - space_at_cmd_start;
-
- printf_unfiltered ("Space used: %ld (%c%ld for this command)\n",
- space_now,
- (space_diff >= 0 ? '+' : '-'),
- space_diff);
-#endif
- }
- }
-}
-
-/* Read commands from `instream' and execute them until end of file or
- error reading instream. This command loop doesnt care about any
- such things as displaying time and space usage. If the user asks
- for those, they won't work. */
-void
-simplified_command_loop (char *(*read_input_func) (char *),
- void (*execute_command_func) (char *, int))
-{
- struct cleanup *old_chain;
- char *command;
- int stdin_is_tty = ISATTY (stdin);
-
- while (instream && !feof (instream))
- {
- quit_flag = 0;
- if (instream == stdin && stdin_is_tty)
- reinitialize_more_filter ();
- old_chain = make_cleanup (null_cleanup, 0);
-
- /* Get a command-line. */
- command = (*read_input_func) (instream == stdin ?
- get_prompt () : (char *) NULL);
-
- if (command == 0)
- return;
-
- (*execute_command_func) (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 (void)
-{
- if (server_command)
- return;
-
- /* 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 PROMPT_ARG 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 (char *prompt_arg)
-{
- int c;
- char *result;
- int input_index = 0;
- int result_size = 80;
-
- if (prompt_arg)
- {
- /* Don't use a _filtered function here. It causes the assumed
- character position to be off, since the newline we read from
- the user is not accounted for. */
- fputs_unfiltered (prompt_arg, gdb_stdout);
-#ifdef MPW
- /* Move to a new line so the entered line doesn't have a prompt
- on the front of it. */
- fputs_unfiltered ("\n", gdb_stdout);
-#endif /* MPW */
- gdb_flush (gdb_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)
- {
- if (input_index > 0)
- /* The last line does not end with a newline. Return it, and
- if we are called again fgetc will still return EOF and
- we'll return NULL then. */
- break;
- free (result);
- return NULL;
- }
-
- if (c == '\n')
-#ifndef CRLF_SOURCE_FILES
- break;
-#else
- {
- if (input_index > 0 && result[input_index - 1] == '\r')
- input_index--;
- break;
- }
-#endif
-
- 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;
-/* NOTE 1999-04-29: This variable will be static again, once we modify
- gdb to use the event loop as the default command loop and we merge
- event-top.c into this file, top.c */
-/* static */ int history_expansion_p;
-static int write_history_p;
-static int history_size;
-static char *history_filename;
-
-/* readline uses the word breaks for two things:
- (1) In figuring out where to point the TEXT parameter to the
- rl_completion_entry_function. Since we don't use TEXT for much,
- it doesn't matter a lot what the word breaks are for this purpose, but
- it does affect how much stuff M-? lists.
- (2) If one of the matches contains a word break character, readline
- will quote it. That's why we switch between
- gdb_completer_word_break_characters and
- gdb_completer_command_word_break_characters. I'm not sure when
- we need this behavior (perhaps for funky characters in C++ symbols?). */
-
-/* Variables which are necessary for fancy command line editing. */
-char *gdb_completer_word_break_characters =
-" \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,-";
-
-/* When completing on command names, we remove '-' from the list of
- word break characters, since we use it in command names. If the
- readline library sees one in any of the current completion strings,
- it thinks that the string needs to be quoted and automatically supplies
- a leading quote. */
-char *gdb_completer_command_word_break_characters =
-" \t\n!@#$%^&*()+=|~`}{[]\"';:?/>.<,";
-
-/* When completing on file names, we remove from the list of word
- break characters any characters that are commonly used in file
- names, such as '-', '+', '~', etc. Otherwise, readline displays
- incorrect completion candidates. */
-char *gdb_completer_file_name_break_characters = " \t\n*|\"';:?/><";
-
-/* Characters that can be used to quote completion strings. Note that we
- can't include '"' because the gdb C parser treats such quoted sequences
- as strings. */
-char *gdb_completer_quote_characters =
-"'";
-
-/* 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 (char *text, char *prefix)
-{
- return NULL;
-}
-
-/* Complete on filenames. */
-char **
-filename_completer (char *text, char *word)
-{
- /* From readline. */
-extern char *filename_completion_function (char *, int);
- int subsequent_name;
- char **return_val;
- int return_val_used;
- int return_val_alloced;
-
- return_val_used = 0;
- /* Small for testing. */
- return_val_alloced = 1;
- return_val = (char **) xmalloc (return_val_alloced * sizeof (char *));
-
- subsequent_name = 0;
- while (1)
- {
- char *p;
- p = filename_completion_function (text, subsequent_name);
- if (return_val_used >= return_val_alloced)
- {
- return_val_alloced *= 2;
- return_val =
- (char **) xrealloc (return_val,
- return_val_alloced * sizeof (char *));
- }
- if (p == NULL)
- {
- return_val[return_val_used++] = p;
- break;
- }
- /* We need to set subsequent_name to a non-zero value before the
- continue line below, because otherwise, if the first file seen
- by GDB is a backup file whose name ends in a `~', we will loop
- indefinitely. */
- subsequent_name = 1;
- /* Like emacs, don't complete on old versions. Especially useful
- in the "source" command. */
- if (p[strlen (p) - 1] == '~')
- continue;
-
- {
- char *q;
- if (word == text)
- /* Return exactly p. */
- return_val[return_val_used++] = p;
- else if (word > text)
- {
- /* Return some portion of p. */
- q = xmalloc (strlen (p) + 5);
- strcpy (q, p + (word - text));
- return_val[return_val_used++] = q;
- free (p);
- }
- else
- {
- /* Return some of TEXT plus p. */
- q = xmalloc (strlen (p) + (text - word) + 5);
- strncpy (q, word, text - word);
- q[text - word] = '\0';
- strcat (q, p);
- return_val[return_val_used++] = q;
- free (p);
- }
- }
- }
-#if 0
- /* There is no way to do this just long enough to affect quote inserting
- without also affecting the next completion. This should be fixed in
- readline. FIXME. */
- /* Insure that readline does the right thing
- with respect to inserting quotes. */
- rl_completer_word_break_characters = "";
-#endif
- return return_val;
-}
-
-/* Here are some useful test cases for completion. FIXME: These should
- be put in the test suite. They should be tested with both M-? and TAB.
-
- "show output-" "radix"
- "show output" "-radix"
- "p" ambiguous (commands starting with p--path, print, printf, etc.)
- "p " ambiguous (all symbols)
- "info t foo" no completions
- "info t " no completions
- "info t" ambiguous ("info target", "info terminal", etc.)
- "info ajksdlfk" no completions
- "info ajksdlfk " no completions
- "info" " "
- "info " ambiguous (all info commands)
- "p \"a" no completions (string constant)
- "p 'a" ambiguous (all symbols starting with a)
- "p b-a" ambiguous (all symbols starting with a)
- "p b-" ambiguous (all symbols)
- "file Make" "file" (word break hard to screw up here)
- "file ../gdb.stabs/we" "ird" (needs to not break word at slash)
- */
-
-/* Generate completions one by one for the completer. Each time we are
- called return another potential completion to the caller.
- line_completion just completes on commands or passes the buck to the
- command's completer function, the stuff specific to symbol completion
- is in make_symbol_completion_list.
-
- TEXT is the caller's idea of the "word" we are looking at.
-
- MATCHES is the number of matches that have currently been collected from
- calling this completion function. When zero, then we need to initialize,
- otherwise the initialization has already taken place and we can just
- return the next potential completion string.
-
- LINE_BUFFER is available to be looked at; it contains the entire text
- of the line. POINT is the offset in that line of the cursor. You
- should pretend that the line ends at POINT.
-
- Returns NULL if there are no more completions, else a pointer to a string
- which is a possible completion, it is the caller's responsibility to
- free the string. */
-
-static char *
-line_completion_function (char *text, int matches, char *line_buffer, int point)
-{
- static char **list = (char **) NULL; /* Cache of completions */
- static int index; /* Next cached completion */
- char *output = NULL;
- char *tmp_command, *p;
- /* Pointer within tmp_command which corresponds to text. */
- char *word;
- struct cmd_list_element *c, *result_list;
-
- if (matches == 0)
- {
- /* The caller is beginning to accumulate a new set of completions, so
- we need to find all of them now, and cache them for returning one at
- a time on future calls. */
-
- if (list)
- {
- /* Free the storage used by LIST, but not by the strings inside.
- This is because rl_complete_internal () frees the strings. */
- free ((PTR) list);
- }
- list = 0;
- index = 0;
-
- /* Choose the default set of word break characters to break completions.
- If we later find out that we are doing completions on command strings
- (as opposed to strings supplied by the individual command completer
- functions, which can be any string) then we will switch to the
- special word break set for command strings, which leaves out the
- '-' character used in some commands. */
-
- rl_completer_word_break_characters =
- gdb_completer_word_break_characters;
-
- /* Decide whether to complete on a list of gdb commands or on symbols. */
- tmp_command = (char *) alloca (point + 1);
- p = tmp_command;
-
- strncpy (tmp_command, line_buffer, point);
- tmp_command[point] = '\0';
- /* Since text always contains some number of characters leading up
- to point, we can find the equivalent position in tmp_command
- by subtracting that many characters from the end of tmp_command. */
- word = tmp_command + point - strlen (text);
-
- if (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)
- {
- /* It is an unrecognized command. So there are no
- possible completions. */
- list = NULL;
- }
- else if (c == (struct cmd_list_element *) -1)
- {
- char *q;
-
- /* lookup_cmd_1 advances p up to the first ambiguous thing, but
- doesn't advance over that thing itself. Do so now. */
- q = p;
- while (*q && (isalnum (*q) || *q == '-' || *q == '_'))
- ++q;
- if (q != tmp_command + point)
- {
- /* There is something beyond the ambiguous
- command, so there are no possible completions. For
- example, "info t " or "info t foo" does not complete
- to anything, because "info t" can be "info target" or
- "info terminal". */
- list = NULL;
- }
- else
- {
- /* We're trying to complete on the command which was ambiguous.
- This we can deal with. */
- if (result_list)
- {
- list = complete_on_cmdlist (*result_list->prefixlist, p,
- word);
- }
- else
- {
- list = complete_on_cmdlist (cmdlist, p, word);
- }
- /* Insure that readline does the right thing with respect to
- inserting quotes. */
- rl_completer_word_break_characters =
- gdb_completer_command_word_break_characters;
- }
- }
- else
- {
- /* We've recognized a full command. */
-
- if (p == tmp_command + point)
- {
- /* There is no non-whitespace in the line beyond the command. */
-
- if (p[-1] == ' ' || p[-1] == '\t')
- {
- /* The command is followed by whitespace; we need to complete
- on whatever comes after command. */
- if (c->prefixlist)
- {
- /* It is a prefix command; what comes after it is
- a subcommand (e.g. "info "). */
- list = complete_on_cmdlist (*c->prefixlist, p, word);
-
- /* Insure that readline does the right thing
- with respect to inserting quotes. */
- rl_completer_word_break_characters =
- gdb_completer_command_word_break_characters;
- }
- else if (c->enums)
- {
- list = complete_on_enum (c->enums, p, word);
- rl_completer_word_break_characters =
- gdb_completer_command_word_break_characters;
- }
- else
- {
- /* It is a normal command; what comes after it is
- completed by the command's completer function. */
- list = (*c->completer) (p, word);
- if (c->completer == filename_completer)
- rl_completer_word_break_characters =
- gdb_completer_file_name_break_characters;
- }
- }
- else
- {
- /* The command is not followed by whitespace; we need to
- complete on the command itself. e.g. "p" which is a
- command itself but also can complete to "print", "ptype"
- etc. */
- char *q;
-
- /* Find the command we are completing on. */
- q = p;
- while (q > tmp_command)
- {
- if (isalnum (q[-1]) || q[-1] == '-' || q[-1] == '_')
- --q;
- else
- break;
- }
-
- list = complete_on_cmdlist (result_list, q, word);
-
- /* Insure that readline does the right thing
- with respect to inserting quotes. */
- rl_completer_word_break_characters =
- gdb_completer_command_word_break_characters;
- }
- }
- else
- {
- /* There is non-whitespace beyond the command. */
-
- if (c->prefixlist && !c->allow_unknown)
- {
- /* It is an unrecognized subcommand of a prefix command,
- e.g. "info adsfkdj". */
- list = NULL;
- }
- else if (c->enums)
- {
- list = complete_on_enum (c->enums, p, word);
- }
- else
- {
- /* It is a normal command. */
- list = (*c->completer) (p, word);
- if (c->completer == filename_completer)
- rl_completer_word_break_characters =
- gdb_completer_file_name_break_characters;
- }
- }
- }
- }
-
- /* If we found a list of potential completions during initialization then
- dole them out one at a time. The vector of completions is NULL
- terminated, so after returning the last one, return NULL (and continue
- to do so) each time we are called after that, until a new list is
- available. */
-
- if (list)
- {
- output = list[index];
- if (output)
- {
- index++;
- }
- }
-
-#if 0
- /* Can't do this because readline hasn't yet checked the word breaks
- for figuring out whether to insert a quote. */
- if (output == NULL)
- /* Make sure the word break characters are set back to normal for the
- next time that readline tries to complete something. */
- rl_completer_word_break_characters =
- gdb_completer_word_break_characters;
-#endif
-
- return (output);
-}
-
-/* Line completion interface function for readline. */
-
-static char *
-readline_line_completion_function (char *text, int matches)
-{
- return line_completion_function (text, matches, rl_line_buffer, rl_point);
-}
-
-/* Skip over a possibly quoted word (as defined by the quote characters
- and word break characters the completer uses). Returns pointer to the
- location after the "word". */
-
-char *
-skip_quoted (char *str)
-{
- char quote_char = '\0';
- char *scan;
-
- for (scan = str; *scan != '\0'; scan++)
- {
- if (quote_char != '\0')
- {
- /* Ignore everything until the matching close quote char */
- if (*scan == quote_char)
- {
- /* Found matching close quote. */
- scan++;
- break;
- }
- }
- else if (strchr (gdb_completer_quote_characters, *scan))
- {
- /* Found start of a quoted string. */
- quote_char = *scan;
- }
- else if (strchr (gdb_completer_word_break_characters, *scan))
- {
- break;
- }
- }
- return (scan);
-}
-\f
-
-#ifdef STOP_SIGNAL
-static void
-stop_sig (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);
-#endif
- printf_unfiltered ("%s", get_prompt ());
- gdb_flush (gdb_stdout);
-
- /* Forget about any previous command -- null line now will do nothing. */
- dont_repeat ();
-}
-#endif /* STOP_SIGNAL */
-
-/* Initialize signal handlers. */
-static void
-do_nothing (int signo)
-{
- /* Under System V the default disposition of a signal is reinstated after
- the signal is caught and delivered to an application process. On such
- systems one must restore the replacement signal handler if one wishes
- to continue handling the signal in one's program. On BSD systems this
- is not needed but it is harmless, and it simplifies the code to just do
- it unconditionally. */
- signal (signo, do_nothing);
-}
-
-static void
-init_signals (void)
-{
- signal (SIGINT, request_quit);
-
- /* If SIGTRAP was set to SIG_IGN, then the SIG_IGN will get passed
- to the inferior and breakpoints will be ignored. */
-#ifdef SIGTRAP
- signal (SIGTRAP, SIG_DFL);
-#endif
-
- /* If we initialize SIGQUIT to SIG_IGN, then the SIG_IGN will get
- passed to the inferior, which we don't want. It would be
- possible to do a "signal (SIGQUIT, SIG_DFL)" after we fork, but
- on BSD4.3 systems using vfork, that can affect the
- GDB process as well as the inferior (the signal handling tables
- might be in memory, shared between the two). Since we establish
- a handler for SIGQUIT, when we call exec it will set the signal
- to SIG_DFL for us. */
- signal (SIGQUIT, do_nothing);
-#ifdef SIGHUP
- if (signal (SIGHUP, do_nothing) != SIG_IGN)
- signal (SIGHUP, disconnect);
-#endif
- signal (SIGFPE, float_handler);
-
-#if defined(SIGWINCH) && defined(SIGWINCH_HANDLER)
- signal (SIGWINCH, SIGWINCH_HANDLER);
-#endif
-}
-\f
-/* Read one line from the command input stream `instream'
- into the local static buffer `linebuffer' (whose current length
- is `linelength').
- The buffer is made bigger as necessary.
- Returns the address of the start of the line.
-
- NULL is returned for end of file.
-
- *If* the instream == stdin & stdin is a terminal, the line read
- is copied into the file line saver (global var char *line,
- length linesize) so that it can be duplicated.
-
- This routine either uses fancy command line editing or
- simple input as the user has requested. */
-
-char *
-command_line_input (char *prompt_arg, int repeat, char *annotation_suffix)
-{
- static char *linebuffer = 0;
- static unsigned linelength = 0;
- register char *p;
- char *p1;
- char *rl;
- char *local_prompt = prompt_arg;
- char *nline;
- char got_eof = 0;
-
- /* The annotation suffix must be non-NULL. */
- if (annotation_suffix == NULL)
- annotation_suffix = "";
-
- if (annotation_level > 1 && instream == stdin)
- {
- local_prompt = alloca ((prompt_arg == NULL ? 0 : strlen (prompt_arg))
- + strlen (annotation_suffix) + 40);
- if (prompt_arg == NULL)
- local_prompt[0] = '\0';
- else
- strcpy (local_prompt, prompt_arg);
- strcat (local_prompt, "\n\032\032");
- strcat (local_prompt, annotation_suffix);
- strcat (local_prompt, "\n");
- }
-
- if (linebuffer == 0)
- {
- linelength = 80;
- linebuffer = (char *) xmalloc (linelength);
- }
-
- p = linebuffer;
-
- /* Control-C quits instantly if typed while in this loop
- since it should not wait until the user types a newline. */
- immediate_quit++;
-#ifdef STOP_SIGNAL
- if (job_control)
- {
- if (event_loop_p)
- signal (STOP_SIGNAL, handle_stop_sig);
- else
- signal (STOP_SIGNAL, stop_sig);
- }
-#endif
-
- while (1)
- {
- /* Make sure that all output has been output. Some machines may let
- you get away with leaving out some of the gdb_flush, but not all. */
- wrap_here ("");
- gdb_flush (gdb_stdout);
- gdb_flush (gdb_stderr);
-
- if (source_file_name != NULL)
- {
- ++source_line_number;
- sprintf (source_error,
- "%s%s:%d: Error in sourced command file:\n",
- source_pre_error,
- source_file_name,
- source_line_number);
- error_pre_print = source_error;
- }
-
- if (annotation_level > 1 && instream == stdin)
- {
- printf_unfiltered ("\n\032\032pre-");
- printf_unfiltered (annotation_suffix);
- printf_unfiltered ("\n");
- }
-
- /* Don't use fancy stuff if not talking to stdin. */
- if (readline_hook && instream == NULL)
- {
- rl = (*readline_hook) (local_prompt);
- }
- else if (command_editing_p && instream == stdin && ISATTY (instream))
- {
- rl = readline (local_prompt);
- }
- else
- {
- rl = gdb_readline (local_prompt);
- }
-
- if (annotation_level > 1 && instream == stdin)
- {
- printf_unfiltered ("\n\032\032post-");
- printf_unfiltered (annotation_suffix);
- printf_unfiltered ("\n");
- }
-
- if (!rl || rl == (char *) EOF)
- {
- got_eof = 1;
- break;
- }
- if (strlen (rl) + 1 + (p - linebuffer) > linelength)
- {
- linelength = strlen (rl) + 1 + (p - linebuffer);
- nline = (char *) xrealloc (linebuffer, linelength);
- p += nline - linebuffer;
- linebuffer = nline;
- }
- p1 = rl;
- /* Copy line. Don't copy null at end. (Leaves line alone
- if this was just a newline) */
- while (*p1)
- *p++ = *p1++;
-
- free (rl); /* Allocated in readline. */
-
- if (p == linebuffer || *(p - 1) != '\\')
- break;
-
- p--; /* Put on top of '\'. */
- local_prompt = (char *) 0;
- }