+ 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. */
+ const 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;
+ }
+
+ if (reason != handle_brkchars)
+ list = complete_on_cmdlist (result_list, q, word,
+ ignore_help_classes);
+
+ /* Ensure that readline does the right thing
+ with respect to inserting quotes. */
+ rl_completer_word_break_characters =
+ gdb_completer_command_word_break_characters;
+ }
+ }
+ else if (reason == handle_help)
+ list = NULL;
+ 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)
+ {
+ if (reason != handle_brkchars)
+ list = complete_on_enum (c->enums, p, word);
+ }
+ else
+ {
+ /* It is a normal command. */
+ if (c->completer == filename_completer)
+ {
+ /* See the commentary above about the specifics
+ of file-name completion. */
+ for (p = word;
+ p > tmp_command
+ && strchr (gdb_completer_file_name_break_characters,
+ p[-1]) == NULL;
+ p--)
+ ;
+ rl_completer_word_break_characters =
+ gdb_completer_file_name_break_characters;
+ }
+ else if (c->completer == location_completer)
+ {
+ for (p = word;
+ p > tmp_command
+ && p[-1] != ' ' && p[-1] != '\t';
+ p--)
+ ;
+ }
+ if (reason == handle_brkchars
+ && c->completer_handle_brkchars != NULL)
+ (*c->completer_handle_brkchars) (c, p, word);
+ if (reason != handle_brkchars && c->completer != NULL)
+ list = (*c->completer) (c, p, word);
+ }
+ }
+ }
+
+ return list;
+}
+/* Generate completions all at once. Returns a vector of strings.
+ Each element is allocated with xmalloc. It can also return NULL if
+ there are no completions.
+
+ TEXT is the caller's idea of the "word" we are looking at.
+
+ 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. */
+
+VEC (char_ptr) *
+complete_line (const char *text, const char *line_buffer, int point)
+{
+ return complete_line_internal (text, line_buffer,
+ point, handle_completions);
+}
+
+/* Complete on command names. Used by "help". */
+VEC (char_ptr) *
+command_completer (struct cmd_list_element *ignore,
+ const char *text, const char *word)
+{
+ return complete_line_internal (word, text,
+ strlen (text), handle_help);
+}
+
+/* Complete on signals. */
+
+VEC (char_ptr) *
+signal_completer (struct cmd_list_element *ignore,
+ const char *text, const char *word)
+{
+ VEC (char_ptr) *return_val = NULL;
+ size_t len = strlen (word);
+ enum gdb_signal signum;
+ const char *signame;
+
+ for (signum = GDB_SIGNAL_FIRST; signum != GDB_SIGNAL_LAST; ++signum)
+ {
+ /* Can't handle this, so skip it. */
+ if (signum == GDB_SIGNAL_0)
+ continue;
+
+ signame = gdb_signal_to_name (signum);
+
+ /* Ignore the unknown signal case. */
+ if (!signame || strcmp (signame, "?") == 0)
+ continue;
+
+ if (strncasecmp (signame, word, len) == 0)
+ VEC_safe_push (char_ptr, return_val, xstrdup (signame));
+ }
+
+ return return_val;
+}
+
+/* Get the list of chars that are considered as word breaks
+ for the current command. */
+
+char *
+gdb_completion_word_break_characters (void)
+{
+ VEC (char_ptr) *list;
+
+ list = complete_line_internal (rl_line_buffer, rl_line_buffer, rl_point,
+ handle_brkchars);
+ gdb_assert (list == NULL);
+ return rl_completer_word_break_characters;
+}
+
+/* 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 (const char *text, int matches,
+ char *line_buffer, int point)
+{
+ static VEC (char_ptr) *list = NULL; /* Cache of completions. */
+ static int index; /* Next cached completion. */
+ char *output = NULL;
+
+ 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. As complete_line may abort by calling
+ `error' clear LIST now. */
+ VEC_free (char_ptr, list);