+complete_linespec_component (linespec_parser *parser,
+ completion_tracker &tracker,
+ const char *text,
+ linespec_complete_what component,
+ const char *source_filename)
+{
+ if (component == linespec_complete_what::KEYWORD)
+ {
+ complete_on_enum (tracker, linespec_keywords, text, text);
+ }
+ else if (component == linespec_complete_what::EXPRESSION)
+ {
+ const char *word
+ = advance_to_expression_complete_word_point (tracker, text);
+ complete_expression (tracker, text, word);
+ }
+ else if (component == linespec_complete_what::FUNCTION)
+ {
+ completion_list fn_list;
+
+ symbol_name_match_type match_type
+ = PARSER_EXPLICIT (parser)->func_name_match_type;
+ linespec_complete_function (tracker, text, match_type, source_filename);
+ if (source_filename == NULL)
+ {
+ /* Haven't seen a source component, like in "b
+ file.c:function[TAB]". Maybe this wasn't a function, but
+ a filename instead, like "b file.[TAB]". */
+ fn_list = complete_source_filenames (text);
+ }
+
+ /* If we only have a single filename completion, append a ':' for
+ the user, since that's the only thing that can usefully follow
+ the filename. */
+ if (fn_list.size () == 1 && !tracker.have_completions ())
+ {
+ char *fn = fn_list[0].release ();
+
+ /* If we also need to append a quote char, it needs to be
+ appended before the ':'. Append it now, and make ':' the
+ new "quote" char. */
+ if (tracker.quote_char ())
+ {
+ char quote_char_str[2] = { (char) tracker.quote_char () };
+
+ fn = reconcat (fn, fn, quote_char_str, (char *) NULL);
+ tracker.set_quote_char (':');
+ }
+ else
+ fn = reconcat (fn, fn, ":", (char *) NULL);
+ fn_list[0].reset (fn);
+
+ /* Tell readline to skip appending a space. */
+ tracker.set_suppress_append_ws (true);
+ }
+ tracker.add_completions (std::move (fn_list));
+ }
+}
+
+/* Helper for linespec_complete_label. Find labels that match
+ LABEL_NAME in the function symbols listed in the PARSER, and add
+ them to the tracker. */
+
+static void
+complete_label (completion_tracker &tracker,
+ linespec_parser *parser,
+ const char *label_name)
+{
+ std::vector<block_symbol> label_function_symbols;
+ std::vector<block_symbol> *labels
+ = find_label_symbols (PARSER_STATE (parser),
+ PARSER_RESULT (parser)->function_symbols,
+ &label_function_symbols,
+ label_name, true);
+
+ if (labels != nullptr)
+ {
+ for (const auto &label : *labels)
+ {
+ char *match = xstrdup (label.symbol->search_name ());
+ tracker.add_completion (gdb::unique_xmalloc_ptr<char> (match));
+ }
+ delete labels;
+ }
+}
+
+/* See linespec.h. */
+
+void
+linespec_complete_label (completion_tracker &tracker,
+ const struct language_defn *language,
+ const char *source_filename,
+ const char *function_name,
+ symbol_name_match_type func_name_match_type,
+ const char *label_name)
+{
+ linespec_parser parser (0, language, NULL, NULL, 0, NULL);
+
+ line_offset unknown_offset = { 0, LINE_OFFSET_UNKNOWN };
+
+ try
+ {
+ convert_explicit_location_to_linespec (PARSER_STATE (&parser),
+ PARSER_RESULT (&parser),
+ source_filename,
+ function_name,
+ func_name_match_type,
+ NULL, unknown_offset);
+ }
+ catch (const gdb_exception_error &ex)
+ {
+ return;
+ }
+
+ complete_label (tracker, &parser, label_name);
+}
+
+/* See description in linespec.h. */
+
+void
+linespec_complete (completion_tracker &tracker, const char *text,
+ symbol_name_match_type match_type)