+ /* Error if the input did not terminate properly. */
+ if (end == NULL)
+ error (_("unmatched quote"));
+
+ /* Skip over the ending quote and mark the length of the string. */
+ PARSER_STREAM (parser) = (char *) ++end;
+ LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - 2 - start;
+ }
+ else
+ {
+ const char *p;
+
+ /* Otherwise, only identifier characters are permitted.
+ Spaces are the exception. In general, we keep spaces,
+ but only if the next characters in the input do not resolve
+ to one of the keywords.
+
+ This allows users to forgo quoting CV-qualifiers, template arguments,
+ and similar common language constructs. */
+
+ while (1)
+ {
+ if (isspace (*PARSER_STREAM (parser)))
+ {
+ p = skip_spaces_const (PARSER_STREAM (parser));
+ /* When we get here we know we've found something followed by
+ a space (we skip over parens and templates below).
+ So if we find a keyword now, we know it is a keyword and not,
+ say, a function name. */
+ if (linespec_lexer_lex_keyword (p) != NULL)
+ {
+ LS_TOKEN_STOKEN (token).ptr = start;
+ LS_TOKEN_STOKEN (token).length
+ = PARSER_STREAM (parser) - start;
+ return token;
+ }
+
+ /* Advance past the whitespace. */
+ PARSER_STREAM (parser) = p;
+ }
+
+ /* If the next character is EOI or (single) ':', the
+ string is complete; return the token. */
+ if (*PARSER_STREAM (parser) == 0)
+ {
+ LS_TOKEN_STOKEN (token).ptr = start;
+ LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - start;
+ return token;
+ }
+ else if (PARSER_STREAM (parser)[0] == ':')
+ {
+ /* Do not tokenize the C++ scope operator. */
+ if (PARSER_STREAM (parser)[1] == ':')
+ ++(PARSER_STREAM (parser));
+
+ /* Do not tokenify if the input length so far is one
+ (i.e, a single-letter drive name) and the next character
+ is a directory separator. This allows Windows-style
+ paths to be recognized as filenames without quoting it. */
+ else if ((PARSER_STREAM (parser) - start) != 1
+ || !IS_DIR_SEPARATOR (PARSER_STREAM (parser)[1]))
+ {
+ LS_TOKEN_STOKEN (token).ptr = start;
+ LS_TOKEN_STOKEN (token).length
+ = PARSER_STREAM (parser) - start;
+ return token;
+ }
+ }
+ /* Special case: permit quote-enclosed linespecs. */
+ else if (parser->is_quote_enclosed
+ && strchr (linespec_quote_characters,
+ *PARSER_STREAM (parser))
+ && is_closing_quote_enclosed (PARSER_STREAM (parser)))
+ {
+ LS_TOKEN_STOKEN (token).ptr = start;
+ LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - start;
+ return token;
+ }
+ /* Because commas may terminate a linespec and appear in
+ the middle of valid string input, special cases for
+ '<' and '(' are necessary. */
+ else if (*PARSER_STREAM (parser) == '<'
+ || *PARSER_STREAM (parser) == '(')
+ {
+ const char *p;
+
+ p = find_parameter_list_end (PARSER_STREAM (parser));
+ if (p != NULL)
+ {
+ PARSER_STREAM (parser) = p;
+ continue;
+ }
+ }
+ /* Commas are terminators, but not if they are part of an
+ operator name. */
+ else if (*PARSER_STREAM (parser) == ',')
+ {
+ if ((PARSER_STATE (parser)->language->la_language
+ == language_cplus)
+ && (PARSER_STREAM (parser) - start) > 8
+ /* strlen ("operator") */)
+ {
+ char *p = strstr (start, "operator");
+
+ if (p != NULL && is_operator_name (p))
+ {
+ /* This is an operator name. Keep going. */
+ ++(PARSER_STREAM (parser));
+ continue;
+ }
+ }
+
+ /* Comma terminates the string. */
+ LS_TOKEN_STOKEN (token).ptr = start;
+ LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - start;
+ return token;
+ }
+
+ /* Advance the stream. */
+ ++(PARSER_STREAM (parser));
+ }
+ }
+
+ return token;
+}
+
+/* Lex a single linespec token from PARSER. */
+
+static linespec_token
+linespec_lexer_lex_one (linespec_parser *parser)
+{
+ const char *keyword;
+
+ if (parser->lexer.current.type == LSTOKEN_CONSUMED)
+ {
+ /* Skip any whitespace. */
+ PARSER_STREAM (parser) = skip_spaces_const (PARSER_STREAM (parser));
+
+ /* Check for a keyword, they end the linespec. */
+ keyword = NULL;
+ if (parser->keyword_ok)
+ keyword = linespec_lexer_lex_keyword (PARSER_STREAM (parser));
+ if (keyword != NULL)
+ {
+ parser->lexer.current.type = LSTOKEN_KEYWORD;
+ LS_TOKEN_KEYWORD (parser->lexer.current) = keyword;
+ return parser->lexer.current;
+ }
+
+ /* Handle other tokens. */
+ switch (*PARSER_STREAM (parser))
+ {
+ case 0:
+ parser->lexer.current.type = LSTOKEN_EOI;
+ break;
+
+ case '+': case '-':
+ case '0': case '1': case '2': case '3': case '4':
+ case '5': case '6': case '7': case '8': case '9':
+ if (!linespec_lexer_lex_number (parser, &(parser->lexer.current)))
+ parser->lexer.current = linespec_lexer_lex_string (parser);
+ break;
+
+ case ':':
+ /* If we have a scope operator, lex the input as a string.
+ Otherwise, return LSTOKEN_COLON. */
+ if (PARSER_STREAM (parser)[1] == ':')
+ parser->lexer.current = linespec_lexer_lex_string (parser);
+ else
+ {
+ parser->lexer.current.type = LSTOKEN_COLON;
+ ++(PARSER_STREAM (parser));
+ }
+ break;
+
+ case '\'': case '\"':
+ /* Special case: permit quote-enclosed linespecs. */
+ if (parser->is_quote_enclosed
+ && is_closing_quote_enclosed (PARSER_STREAM (parser)))
+ {
+ ++(PARSER_STREAM (parser));
+ parser->lexer.current.type = LSTOKEN_EOI;
+ }
+ else
+ parser->lexer.current = linespec_lexer_lex_string (parser);
+ break;
+
+ case ',':
+ parser->lexer.current.type = LSTOKEN_COMMA;
+ LS_TOKEN_STOKEN (parser->lexer.current).ptr
+ = PARSER_STREAM (parser);
+ LS_TOKEN_STOKEN (parser->lexer.current).length = 1;
+ ++(PARSER_STREAM (parser));
+ break;
+
+ default:
+ /* If the input is not a number, it must be a string.
+ [Keywords were already considered above.] */
+ parser->lexer.current = linespec_lexer_lex_string (parser);
+ break;
+ }
+ }
+
+ return parser->lexer.current;
+}
+
+/* Consume the current token and return the next token in PARSER's
+ input stream. */
+
+static linespec_token
+linespec_lexer_consume_token (linespec_parser *parser)
+{
+ parser->lexer.current.type = LSTOKEN_CONSUMED;
+ return linespec_lexer_lex_one (parser);
+}
+
+/* Return the next token without consuming the current token. */
+
+static linespec_token
+linespec_lexer_peek_token (linespec_parser *parser)
+{
+ linespec_token next;
+ const char *saved_stream = PARSER_STREAM (parser);
+ linespec_token saved_token = parser->lexer.current;
+
+ next = linespec_lexer_consume_token (parser);
+ PARSER_STREAM (parser) = saved_stream;
+ parser->lexer.current = saved_token;
+ return next;
+}
+
+/* Helper functions. */
+
+/* Add SAL to SALS. */
+
+static void
+add_sal_to_sals_basic (struct symtabs_and_lines *sals,
+ struct symtab_and_line *sal)
+{
+ ++sals->nelts;
+ sals->sals = xrealloc (sals->sals, sals->nelts * sizeof (sals->sals[0]));
+ sals->sals[sals->nelts - 1] = *sal;
+}
+
+/* Add SAL to SALS, and also update SELF->CANONICAL_NAMES to reflect
+ the new sal, if needed. If not NULL, SYMNAME is the name of the
+ symbol to use when constructing the new canonical name.
+
+ If LITERAL_CANONICAL is non-zero, SYMNAME will be used as the
+ canonical name for the SAL. */
+
+static void
+add_sal_to_sals (struct linespec_state *self,
+ struct symtabs_and_lines *sals,
+ struct symtab_and_line *sal,
+ const char *symname, int literal_canonical)
+{
+ add_sal_to_sals_basic (sals, sal);
+
+ if (self->canonical)
+ {
+ struct linespec_canonical_name *canonical;
+
+ self->canonical_names = xrealloc (self->canonical_names,
+ (sals->nelts
+ * sizeof (*self->canonical_names)));
+ canonical = &self->canonical_names[sals->nelts - 1];
+ if (!literal_canonical && sal->symtab)
+ {
+ const char *fullname = symtab_to_fullname (sal->symtab);
+
+ /* Note that the filter doesn't have to be a valid linespec
+ input. We only apply the ":LINE" treatment to Ada for
+ the time being. */
+ if (symname != NULL && sal->line != 0
+ && self->language->la_language == language_ada)
+ canonical->suffix = xstrprintf ("%s:%d", symname, sal->line);
+ else if (symname != NULL)
+ canonical->suffix = xstrdup (symname);
+ else
+ canonical->suffix = xstrprintf ("%d", sal->line);
+ canonical->symtab = sal->symtab;
+ }
+ else
+ {
+ if (symname != NULL)
+ canonical->suffix = xstrdup (symname);
+ else
+ canonical->suffix = xstrdup ("<unknown>");
+ canonical->symtab = NULL;
+ }
+ }
+}
+
+/* A hash function for address_entry. */
+
+static hashval_t
+hash_address_entry (const void *p)
+{
+ const struct address_entry *aep = p;
+ hashval_t hash;
+
+ hash = iterative_hash_object (aep->pspace, 0);
+ return iterative_hash_object (aep->addr, hash);
+}
+
+/* An equality function for address_entry. */
+
+static int
+eq_address_entry (const void *a, const void *b)
+{
+ const struct address_entry *aea = a;
+ const struct address_entry *aeb = b;
+
+ return aea->pspace == aeb->pspace && aea->addr == aeb->addr;
+}
+
+/* Check whether the address, represented by PSPACE and ADDR, is
+ already in the set. If so, return 0. Otherwise, add it and return
+ 1. */
+
+static int
+maybe_add_address (htab_t set, struct program_space *pspace, CORE_ADDR addr)
+{
+ struct address_entry e, *p;
+ void **slot;
+
+ e.pspace = pspace;
+ e.addr = addr;
+ slot = htab_find_slot (set, &e, INSERT);
+ if (*slot)
+ return 0;
+
+ p = XNEW (struct address_entry);
+ memcpy (p, &e, sizeof (struct address_entry));
+ *slot = p;
+
+ return 1;
+}
+
+/* A callback function and the additional data to call it with. */
+
+struct symbol_and_data_callback
+{
+ /* The callback to use. */
+ symbol_found_callback_ftype *callback;
+
+ /* Data to be passed to the callback. */
+ void *data;
+};
+
+/* A helper for iterate_over_all_matching_symtabs that is used to
+ restrict calls to another callback to symbols representing inline
+ symbols only. */
+
+static int
+iterate_inline_only (struct symbol *sym, void *d)
+{
+ if (SYMBOL_INLINED (sym))
+ {
+ struct symbol_and_data_callback *cad = d;
+
+ return cad->callback (sym, cad->data);
+ }
+ return 1; /* Continue iterating. */
+}
+
+/* Some data for the expand_symtabs_matching callback. */
+
+struct symbol_matcher_data
+{
+ /* The lookup name against which symbol name should be compared. */
+ const char *lookup_name;
+
+ /* The routine to be used for comparison. */
+ symbol_name_cmp_ftype symbol_name_cmp;
+};
+
+/* A helper for iterate_over_all_matching_symtabs that is passed as a
+ callback to the expand_symtabs_matching method. */
+
+static int
+iterate_name_matcher (const char *name, void *d)
+{
+ const struct symbol_matcher_data *data = d;
+
+ if (data->symbol_name_cmp (name, data->lookup_name) == 0)
+ return 1; /* Expand this symbol's symbol table. */
+ return 0; /* Skip this symbol. */
+}
+
+/* A helper that walks over all matching symtabs in all objfiles and
+ calls CALLBACK for each symbol matching NAME. If SEARCH_PSPACE is
+ not NULL, then the search is restricted to just that program
+ space. If INCLUDE_INLINE is nonzero then symbols representing
+ inlined instances of functions will be included in the result. */
+
+static void
+iterate_over_all_matching_symtabs (struct linespec_state *state,
+ const char *name,
+ const domain_enum domain,
+ symbol_found_callback_ftype *callback,
+ void *data,
+ struct program_space *search_pspace,
+ int include_inline)
+{
+ struct objfile *objfile;
+ struct program_space *pspace;
+ struct symbol_matcher_data matcher_data;
+
+ matcher_data.lookup_name = name;
+ matcher_data.symbol_name_cmp =
+ state->language->la_get_symbol_name_cmp != NULL
+ ? state->language->la_get_symbol_name_cmp (name)
+ : strcmp_iw;
+
+ ALL_PSPACES (pspace)
+ {
+ if (search_pspace != NULL && search_pspace != pspace)
+ continue;
+ if (pspace->executing_startup)
+ continue;
+
+ set_current_program_space (pspace);
+
+ ALL_OBJFILES (objfile)
+ {
+ struct symtab *symtab;
+
+ if (objfile->sf)
+ objfile->sf->qf->expand_symtabs_matching (objfile, NULL,
+ iterate_name_matcher,
+ ALL_DOMAIN,
+ &matcher_data);
+
+ ALL_OBJFILE_PRIMARY_SYMTABS (objfile, symtab)
+ {
+ iterate_over_file_blocks (symtab, name, domain, callback, data);
+
+ if (include_inline)
+ {
+ struct symbol_and_data_callback cad = { callback, data };
+ struct block *block;
+ int i;
+
+ for (i = FIRST_LOCAL_BLOCK;
+ i < BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (symtab)); i++)
+ {
+ block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), i);
+ state->language->la_iterate_over_symbols
+ (block, name, domain, iterate_inline_only, &cad);
+ }
+ }
+ }
+ }
+ }
+}
+
+/* Returns the block to be used for symbol searches from
+ the current location. */
+
+static const struct block *
+get_current_search_block (void)
+{
+ const struct block *block;
+ enum language save_language;
+
+ /* get_selected_block can change the current language when there is
+ no selected frame yet. */
+ save_language = current_language->la_language;
+ block = get_selected_block (0);
+ set_language (save_language);
+
+ return block;
+}
+
+/* Iterate over static and global blocks. */
+
+static void
+iterate_over_file_blocks (struct symtab *symtab,
+ const char *name, domain_enum domain,
+ symbol_found_callback_ftype *callback, void *data)
+{
+ struct block *block;
+
+ for (block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
+ block != NULL;
+ block = BLOCK_SUPERBLOCK (block))
+ LA_ITERATE_OVER_SYMBOLS (block, name, domain, callback, data);
+}
+
+/* A helper for find_method. This finds all methods in type T which
+ match NAME. It adds matching symbol names to RESULT_NAMES, and
+ adds T's direct superclasses to SUPERCLASSES. */
+
+static void
+find_methods (struct type *t, const char *name,
+ VEC (const_char_ptr) **result_names,
+ VEC (typep) **superclasses)
+{
+ int ibase;
+ const char *class_name = type_name_no_tag (t);
+
+ /* Ignore this class if it doesn't have a name. This is ugly, but
+ unless we figure out how to get the physname without the name of
+ the class, then the loop can't do any good. */
+ if (class_name)
+ {
+ int method_counter;
+
+ CHECK_TYPEDEF (t);
+
+ /* Loop over each method name. At this level, all overloads of a name
+ are counted as a single name. There is an inner loop which loops over
+ each overload. */