1 /* Parser for linespec for the GNU debugger, GDB.
3 Copyright (C) 1986-2005, 2007-2012 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
29 #include "completer.h"
31 #include "cp-support.h"
32 #include "parser-defs.h"
34 #include "objc-lang.h"
36 #include "exceptions.h"
39 #include "mi/mi-cmds.h"
41 #include "arch-utils.h"
43 #include "cli/cli-utils.h"
44 #include "filenames.h"
47 typedef struct symtab *symtab_p;
50 typedef struct symbol *symbolp;
53 typedef struct type *typep;
56 /* An address entry is used to ensure that any given location is only
57 added to the result a single time. It holds an address and the
58 program space from which the address came. */
62 struct program_space *pspace;
66 /* An instance of this is used to keep all state while linespec
67 operates. This instance is passed around as a 'this' pointer to
68 the various implementation methods. */
72 /* The program space as seen when the module was entered. */
73 struct program_space *program_space;
75 /* The default symtab to use, if no other symtab is specified. */
76 struct symtab *default_symtab;
78 /* The default line to use. */
81 /* If the linespec started with "FILE:", this holds all the matching
82 symtabs. Otherwise, it will hold a single NULL entry, meaning
83 that the default symtab should be used. */
84 VEC (symtab_p) *file_symtabs;
86 /* If the linespec started with "FILE:", this holds an xmalloc'd
90 /* If the linespec is "FUNCTION:LABEL", this holds an xmalloc'd copy
94 /* The 'funfirstline' value that was passed in to decode_line_1 or
98 /* Nonzero if we are running in 'list' mode; see decode_line_list. */
101 /* The 'canonical' value passed to decode_line_full, or NULL. */
102 struct linespec_result *canonical;
104 /* Canonical strings that mirror the symtabs_and_lines result. */
105 char **canonical_names;
107 /* This is a set of address_entry objects which is used to prevent
108 duplicate symbols from being entered into the result. */
112 /* This is a helper object that is used when collecting symbols into a
117 /* The linespec object in use. */
118 struct linespec_state *state;
120 /* The result being accumulated. */
121 struct symtabs_and_lines result;
124 /* Prototypes for local functions. */
126 static void initialize_defaults (struct symtab **default_symtab,
129 static struct symtabs_and_lines decode_indirect (struct linespec_state *self,
132 static char *locate_first_half (char **argptr, int *is_quote_enclosed);
134 static struct symtabs_and_lines decode_objc (struct linespec_state *self,
137 static struct symtabs_and_lines decode_compound (struct linespec_state *self,
142 static VEC (symbolp) *lookup_prefix_sym (char **argptr, char *p,
146 static struct symtabs_and_lines find_method (struct linespec_state *self,
149 const char *class_name,
150 VEC (symbolp) *sym_classes);
152 static void cplusplus_error (const char *name, const char *fmt, ...)
153 ATTRIBUTE_NORETURN ATTRIBUTE_PRINTF (2, 3);
155 static char *find_toplevel_char (char *s, char c);
157 static int is_objc_method_format (const char *s);
159 static VEC (symtab_p) *symtabs_from_filename (char **argptr,
160 char *p, int is_quote_enclosed,
161 char **user_filename);
163 static VEC (symbolp) *find_function_symbols (char **argptr, char *p,
164 int is_quote_enclosed,
165 char **user_function);
167 static struct symtabs_and_lines decode_all_digits (struct linespec_state *self,
171 static struct symtabs_and_lines decode_dollar (struct linespec_state *self,
174 static int decode_label (struct linespec_state *self,
175 VEC (symbolp) *function_symbols,
177 struct symtabs_and_lines *result);
179 static struct symtabs_and_lines decode_variable (struct linespec_state *self,
182 static int symbol_to_sal (struct symtab_and_line *result,
183 int funfirstline, struct symbol *sym);
185 static void add_matching_symbols_to_info (const char *name,
186 struct collect_info *info,
187 struct program_space *pspace);
189 static void add_all_symbol_names_from_pspace (struct collect_info *info,
190 struct program_space *pspace,
191 VEC (const_char_ptr) *names);
193 /* Helper functions. */
195 /* Add SAL to SALS. */
198 add_sal_to_sals_basic (struct symtabs_and_lines *sals,
199 struct symtab_and_line *sal)
202 sals->sals = xrealloc (sals->sals, sals->nelts * sizeof (sals->sals[0]));
203 sals->sals[sals->nelts - 1] = *sal;
206 /* Add SAL to SALS, and also update SELF->CANONICAL_NAMES to reflect
207 the new sal, if needed. If not NULL, SYMNAME is the name of the
208 symbol to use when constructing the new canonical name. */
211 add_sal_to_sals (struct linespec_state *self,
212 struct symtabs_and_lines *sals,
213 struct symtab_and_line *sal,
216 add_sal_to_sals_basic (sals, sal);
220 char *canonical_name = NULL;
222 self->canonical_names = xrealloc (self->canonical_names,
223 sals->nelts * sizeof (char *));
224 if (sal->symtab && sal->symtab->filename)
226 char *filename = sal->symtab->filename;
228 /* Note that the filter doesn't have to be a valid linespec
229 input. We only apply the ":LINE" treatment to Ada for
231 if (symname != NULL && sal->line != 0
232 && current_language->la_language == language_ada)
233 canonical_name = xstrprintf ("%s:%s:%d", filename, symname,
235 else if (symname != NULL)
236 canonical_name = xstrprintf ("%s:%s", filename, symname);
238 canonical_name = xstrprintf ("%s:%d", filename, sal->line);
241 self->canonical_names[sals->nelts - 1] = canonical_name;
245 /* A hash function for address_entry. */
248 hash_address_entry (const void *p)
250 const struct address_entry *aep = p;
253 hash = iterative_hash_object (aep->pspace, 0);
254 return iterative_hash_object (aep->addr, hash);
257 /* An equality function for address_entry. */
260 eq_address_entry (const void *a, const void *b)
262 const struct address_entry *aea = a;
263 const struct address_entry *aeb = b;
265 return aea->pspace == aeb->pspace && aea->addr == aeb->addr;
268 /* Check whether the address, represented by PSPACE and ADDR, is
269 already in the set. If so, return 0. Otherwise, add it and return
273 maybe_add_address (htab_t set, struct program_space *pspace, CORE_ADDR addr)
275 struct address_entry e, *p;
280 slot = htab_find_slot (set, &e, INSERT);
284 p = XNEW (struct address_entry);
285 memcpy (p, &e, sizeof (struct address_entry));
291 /* Issue a helpful hint on using the command completion feature on
292 single quoted demangled C++ symbols as part of the completion
296 cplusplus_error (const char *name, const char *fmt, ...)
298 struct ui_file *tmp_stream;
301 tmp_stream = mem_fileopen ();
302 make_cleanup_ui_file_delete (tmp_stream);
307 va_start (args, fmt);
308 vfprintf_unfiltered (tmp_stream, fmt, args);
312 while (*name == '\'')
314 fprintf_unfiltered (tmp_stream,
315 ("Hint: try '%s<TAB> or '%s<ESC-?>\n"
316 "(Note leading single quote.)"),
319 message = ui_file_xstrdup (tmp_stream, NULL);
320 make_cleanup (xfree, message);
321 throw_error (NOT_FOUND_ERROR, "%s", message);
324 /* A helper for iterate_over_all_matching_symtabs that is passed as a
325 callback to the expand_symtabs_matching method. */
328 iterate_name_matcher (const struct language_defn *language,
329 const char *name, void *d)
331 const char **dname = d;
333 if (language->la_symbol_name_compare (name, *dname) == 0)
338 /* A helper that walks over all matching symtabs in all objfiles and
339 calls CALLBACK for each symbol matching NAME. If SEARCH_PSPACE is
340 not NULL, then the search is restricted to just that program
344 iterate_over_all_matching_symtabs (const char *name,
345 const domain_enum domain,
346 int (*callback) (struct symbol *, void *),
348 struct program_space *search_pspace)
350 struct objfile *objfile;
351 struct program_space *pspace;
355 if (search_pspace != NULL && search_pspace != pspace)
357 if (pspace->executing_startup)
360 set_current_program_space (pspace);
362 ALL_OBJFILES (objfile)
364 struct symtab *symtab;
367 objfile->sf->qf->expand_symtabs_matching (objfile, NULL,
368 iterate_name_matcher,
372 ALL_OBJFILE_SYMTABS (objfile, symtab)
378 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
379 LA_ITERATE_OVER_SYMBOLS (block, name, domain, callback, data);
386 /* Returns the block to be used for symbol searches for the given SYMTAB,
387 which may be NULL. */
389 static struct block *
390 get_search_block (struct symtab *symtab)
395 block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
398 enum language save_language;
400 /* get_selected_block can change the current language when there is
401 no selected frame yet. */
402 save_language = current_language->la_language;
403 block = get_selected_block (0);
404 set_language (save_language);
410 /* A helper for find_method. This finds all methods in type T which
411 match NAME. It adds resulting symbol names to RESULT_NAMES, and
412 adds T's direct superclasses to SUPERCLASSES. */
415 find_methods (struct type *t, const char *name,
416 VEC (const_char_ptr) **result_names,
417 VEC (typep) **superclasses)
421 char *class_name = type_name_no_tag (t);
424 /* Ignore this class if it doesn't have a name. This is ugly, but
425 unless we figure out how to get the physname without the name of
426 the class, then the loop can't do any good. */
430 int name_len = strlen (name);
434 /* Loop over each method name. At this level, all overloads of a name
435 are counted as a single name. There is an inner loop which loops over
438 for (method_counter = TYPE_NFN_FIELDS (t) - 1;
442 char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
445 if (strncmp (method_name, "__", 2) == 0 ||
446 strncmp (method_name, "op", 2) == 0 ||
447 strncmp (method_name, "type", 4) == 0)
449 if (cplus_demangle_opname (method_name, dem_opname, DMGL_ANSI))
450 method_name = dem_opname;
451 else if (cplus_demangle_opname (method_name, dem_opname, 0))
452 method_name = dem_opname;
455 if (strcmp_iw (method_name, name) == 0)
459 for (field_counter = (TYPE_FN_FIELDLIST_LENGTH (t, method_counter)
465 const char *phys_name;
467 f = TYPE_FN_FIELDLIST1 (t, method_counter);
468 if (TYPE_FN_FIELD_STUB (f, field_counter))
470 phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
471 VEC_safe_push (const_char_ptr, *result_names, phys_name);
477 for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
478 VEC_safe_push (typep, *superclasses, TYPE_BASECLASS (t, ibase));
481 /* Find an instance of the character C in the string S that is outside
482 of all parenthesis pairs, single-quoted strings, and double-quoted
483 strings. Also, ignore the char within a template name, like a ','
484 within foo<int, int>. */
487 find_toplevel_char (char *s, char c)
489 int quoted = 0; /* zero if we're not in quotes;
490 '"' if we're in a double-quoted string;
491 '\'' if we're in a single-quoted string. */
492 int depth = 0; /* Number of unclosed parens we've seen. */
495 for (scan = s; *scan; scan++)
501 else if (*scan == '\\' && *(scan + 1))
504 else if (*scan == c && ! quoted && depth == 0)
506 else if (*scan == '"' || *scan == '\'')
508 else if (*scan == '(' || *scan == '<')
510 else if ((*scan == ')' || *scan == '>') && depth > 0)
517 /* Determines if the gives string corresponds to an Objective-C method
518 representation, such as -[Foo bar:] or +[Foo bar]. Objective-C symbols
519 are allowed to have spaces and parentheses in them. */
522 is_objc_method_format (const char *s)
524 if (s == NULL || *s == '\0')
526 /* Handle arguments with the format FILENAME:SYMBOL. */
527 if ((s[0] == ':') && (strchr ("+-", s[1]) != NULL)
528 && (s[2] == '[') && strchr(s, ']'))
530 /* Handle arguments that are just SYMBOL. */
531 else if ((strchr ("+-", s[0]) != NULL) && (s[1] == '[') && strchr(s, ']'))
536 /* Given FILTERS, a list of canonical names, filter the sals in RESULT
537 and store the result in SELF->CANONICAL. */
540 filter_results (struct linespec_state *self,
541 struct symtabs_and_lines *result,
542 VEC (const_char_ptr) *filters)
547 for (i = 0; VEC_iterate (const_char_ptr, filters, i, name); ++i)
549 struct linespec_sals lsal;
552 memset (&lsal, 0, sizeof (lsal));
554 for (j = 0; j < result->nelts; ++j)
556 if (strcmp (name, self->canonical_names[j]) == 0)
557 add_sal_to_sals_basic (&lsal.sals, &result->sals[j]);
560 if (lsal.sals.nelts > 0)
562 lsal.canonical = xstrdup (name);
563 VEC_safe_push (linespec_sals, self->canonical->sals, &lsal);
567 self->canonical->pre_expanded = 0;
570 /* Store RESULT into SELF->CANONICAL. */
573 convert_results_to_lsals (struct linespec_state *self,
574 struct symtabs_and_lines *result)
576 struct linespec_sals lsal;
578 lsal.canonical = NULL;
580 VEC_safe_push (linespec_sals, self->canonical->sals, &lsal);
583 /* Handle multiple results in RESULT depending on SELECT_MODE. This
584 will either return normally, throw an exception on multiple
585 results, or present a menu to the user. On return, the SALS vector
586 in SELF->CANONICAL is set up properly. */
589 decode_line_2 (struct linespec_state *self,
590 struct symtabs_and_lines *result,
591 const char *select_mode)
596 struct cleanup *old_chain;
597 VEC (const_char_ptr) *item_names = NULL, *filters = NULL;
598 struct get_number_or_range_state state;
600 gdb_assert (select_mode != multiple_symbols_all);
601 gdb_assert (self->canonical != NULL);
603 old_chain = make_cleanup (VEC_cleanup (const_char_ptr), &item_names);
604 make_cleanup (VEC_cleanup (const_char_ptr), &filters);
605 for (i = 0; i < result->nelts; ++i)
610 gdb_assert (self->canonical_names[i] != NULL);
611 for (j = 0; VEC_iterate (const_char_ptr, item_names, j, iter); ++j)
613 if (strcmp (iter, self->canonical_names[i]) == 0)
621 VEC_safe_push (const_char_ptr, item_names, self->canonical_names[i]);
624 if (select_mode == multiple_symbols_cancel
625 && VEC_length (const_char_ptr, item_names) > 1)
626 error (_("canceled because the command is ambiguous\n"
627 "See set/show multiple-symbol."));
629 if (select_mode == multiple_symbols_all
630 || VEC_length (const_char_ptr, item_names) == 1)
632 do_cleanups (old_chain);
633 convert_results_to_lsals (self, result);
637 printf_unfiltered (_("[0] cancel\n[1] all\n"));
638 for (i = 0; VEC_iterate (const_char_ptr, item_names, i, iter); ++i)
639 printf_unfiltered ("[%d] %s\n", i + 2, iter);
641 prompt = getenv ("PS2");
646 args = command_line_input (prompt, 0, "overload-choice");
648 if (args == 0 || *args == 0)
649 error_no_arg (_("one or more choice numbers"));
651 init_number_or_range (&state, args);
652 while (!state.finished)
656 num = get_number_or_range (&state);
659 error (_("canceled"));
662 /* We intentionally make this result in a single breakpoint,
663 contrary to what older versions of gdb did. The
664 rationale is that this lets a user get the
665 multiple_symbols_all behavior even with the 'ask'
666 setting; and he can get separate breakpoints by entering
667 "2-57" at the query. */
668 do_cleanups (old_chain);
669 convert_results_to_lsals (self, result);
674 if (num >= VEC_length (const_char_ptr, item_names))
675 printf_unfiltered (_("No choice number %d.\n"), num);
678 const char *elt = VEC_index (const_char_ptr, item_names, num);
682 VEC_safe_push (const_char_ptr, filters, elt);
683 VEC_replace (const_char_ptr, item_names, num, NULL);
687 printf_unfiltered (_("duplicate request for %d ignored.\n"),
693 filter_results (self, result, filters);
694 do_cleanups (old_chain);
697 /* Valid delimiters for linespec keywords "if", "thread" or "task". */
700 is_linespec_boundary (char c)
702 return c == ' ' || c == '\t' || c == '\0' || c == ',';
705 /* A helper function for decode_line_1 and friends which skips P
706 past any method overload information at the beginning of P, e.g.,
707 "(const struct foo *)".
709 This function assumes that P has already been validated to contain
710 overload information, and it will assert if *P != '('. */
712 find_method_overload_end (char *p)
716 gdb_assert (*p == '(');
736 /* Keep important information used when looking up a name. This includes
737 template parameters, overload information, and important keywords, including
738 the possible Java trailing type. */
741 keep_name_info (char *p, int on_boundary)
743 const char *quotes = get_gdb_completer_quote_characters ();
749 if (strchr (quotes, *p))
752 if (*p == ',' && !nest)
755 if (on_boundary && !nest)
757 const char *const words[] = { "if", "thread", "task" };
760 for (wordi = 0; wordi < ARRAY_SIZE (words); wordi++)
761 if (strncmp (p, words[wordi], strlen (words[wordi])) == 0
762 && is_linespec_boundary (p[strlen (words[wordi])]))
764 if (wordi < ARRAY_SIZE (words))
768 if (*p == '(' || *p == '<' || *p == '[')
770 else if ((*p == ')' || *p == '>' || *p == ']') && nest > 0)
775 /* The ',' check could fail on "operator ,". */
776 p += cp_validate_operator (p);
778 on_boundary = is_linespec_boundary (p[-1]);
781 while (p > saved_p && is_linespec_boundary (p[-1]))
788 /* The parser of linespec itself. */
790 /* Parse a string that specifies a line number.
791 Pass the address of a char * variable; that variable will be
792 advanced over the characters actually parsed.
796 LINENUM -- that line number in current file. PC returned is 0.
797 FILE:LINENUM -- that line in that file. PC returned is 0.
798 FUNCTION -- line number of openbrace of that function.
799 PC returned is the start of the function.
800 LABEL -- a label in the current scope
801 VARIABLE -- line number of definition of that variable.
803 FILE:FUNCTION -- likewise, but prefer functions in that file.
804 *EXPR -- line in which address EXPR appears.
806 This may all be followed by an "if EXPR", which we ignore.
808 FUNCTION may be an undebuggable function found in minimal symbol table.
810 If the argument FUNFIRSTLINE is nonzero, we want the first line
811 of real code inside a function when a function is specified, and it is
812 not OK to specify a variable or type to get its line number.
814 DEFAULT_SYMTAB specifies the file to use if none is specified.
815 It defaults to current_source_symtab.
816 DEFAULT_LINE specifies the line number to use for relative
817 line numbers (that start with signs). Defaults to current_source_line.
818 If CANONICAL is non-NULL, store an array of strings containing the canonical
819 line specs there if necessary. Currently overloaded member functions and
820 line numbers or static functions without a filename yield a canonical
821 line spec. The array and the line spec strings are allocated on the heap,
822 it is the callers responsibility to free them.
824 Note that it is possible to return zero for the symtab
825 if no file is validly specified. Callers must check that.
826 Also, the line number returned may be invalid. */
828 /* We allow single quotes in various places. This is a hideous
829 kludge, which exists because the completer can't yet deal with the
830 lack of single quotes. FIXME: write a linespec_completer which we
831 can use as appropriate instead of make_symbol_completion_list. */
833 struct symtabs_and_lines
834 decode_line_internal (struct linespec_state *self, char **argptr)
840 /* This says whether or not something in *ARGPTR is quoted with
841 completer_quotes (i.e. with single quotes). */
843 /* Is *ARGPTR enclosed in double quotes? */
844 int is_quote_enclosed;
845 int is_objc_method = 0;
846 char *saved_arg = *argptr;
847 /* If IS_QUOTED, the end of the quoted bit. */
848 char *end_quote = NULL;
849 /* Is *ARGPTR enclosed in single quotes? */
850 int is_squote_enclosed = 0;
851 /* The "first half" of the linespec. */
854 /* If we are parsing `function:label', this holds the symbols
855 matching the function name. */
856 VEC (symbolp) *function_symbols = NULL;
857 /* If FUNCTION_SYMBOLS is not NULL, then this is the exception that
858 was thrown when trying to parse a filename. */
859 volatile struct gdb_exception file_exception;
861 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
863 /* Defaults have defaults. */
865 initialize_defaults (&self->default_symtab, &self->default_line);
867 /* See if arg is *PC. */
871 do_cleanups (cleanup);
872 return decode_indirect (self, argptr);
875 is_quoted = (strchr (get_gdb_completer_quote_characters (),
880 end_quote = skip_quoted (*argptr);
881 if (*end_quote == '\0')
882 is_squote_enclosed = 1;
885 /* Check to see if it's a multipart linespec (with colons or
888 /* Locate the end of the first half of the linespec.
889 After the call, for instance, if the argptr string is "foo.c:123"
890 p will point at "123". If there is only one part, like "foo", p
891 will point to "". If this is a C++ name, like "A::B::foo", p will
892 point to "::B::foo". Argptr is not changed by this call. */
894 first_half = p = locate_first_half (argptr, &is_quote_enclosed);
896 /* First things first: if ARGPTR starts with a filename, get its
897 symtab and strip the filename from ARGPTR. */
898 TRY_CATCH (file_exception, RETURN_MASK_ERROR)
900 self->file_symtabs = symtabs_from_filename (argptr, p, is_quote_enclosed,
901 &self->user_filename);
904 if (VEC_empty (symtab_p, self->file_symtabs))
906 /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB. */
907 VEC_safe_push (symtab_p, self->file_symtabs, NULL);
910 if (file_exception.reason >= 0)
912 /* Check for single quotes on the non-filename part. */
913 is_quoted = (**argptr
914 && strchr (get_gdb_completer_quote_characters (),
917 end_quote = skip_quoted (*argptr);
919 /* Locate the next "half" of the linespec. */
920 first_half = p = locate_first_half (argptr, &is_quote_enclosed);
923 /* Check if this is an Objective-C method (anything that starts with
924 a '+' or '-' and a '['). */
925 if (is_objc_method_format (p))
928 /* Check if the symbol could be an Objective-C selector. */
931 struct symtabs_and_lines values;
933 values = decode_objc (self, argptr);
934 if (values.sals != NULL)
936 do_cleanups (cleanup);
941 /* Does it look like there actually were two parts? */
943 if (p[0] == ':' || p[0] == '.')
945 /* Is it a C++ or Java compound data structure?
946 The check on p[1] == ':' is capturing the case of "::",
947 since p[0]==':' was checked above.
948 Note that the call to decode_compound does everything
949 for us, including the lookup on the symbol table, so we
952 if (p[0] == '.' || p[1] == ':')
954 struct symtabs_and_lines values;
955 volatile struct gdb_exception ex;
956 char *saved_argptr = *argptr;
958 if (is_quote_enclosed)
961 /* Initialize it just to avoid a GCC false warning. */
962 memset (&values, 0, sizeof (values));
964 TRY_CATCH (ex, RETURN_MASK_ERROR)
966 values = decode_compound (self, argptr, saved_arg, p);
968 if ((is_quoted || is_squote_enclosed) && **argptr == '\'')
969 *argptr = *argptr + 1;
973 do_cleanups (cleanup);
977 if (ex.error != NOT_FOUND_ERROR)
978 throw_exception (ex);
980 *argptr = saved_argptr;
984 /* If there was an exception looking up a specified filename earlier,
985 then check whether we were really given `function:label'. */
986 if (file_exception.reason < 0)
988 function_symbols = find_function_symbols (argptr, p,
990 &self->user_function);
992 /* If we did not find a function, re-throw the original
994 if (!function_symbols)
995 throw_exception (file_exception);
997 make_cleanup (VEC_cleanup (symbolp), &function_symbols);
1000 /* Check for single quotes on the non-filename part. */
1003 is_quoted = (**argptr
1004 && strchr (get_gdb_completer_quote_characters (),
1007 end_quote = skip_quoted (*argptr);
1012 /* self->file_symtabs holds the specified file symtabs, or 0 if no file
1014 If we are parsing `function:symbol', then FUNCTION_SYMBOLS holds the
1015 functions before the `:'.
1016 arg no longer contains the file name. */
1018 /* If the filename was quoted, we must re-check the quotation. */
1020 if (end_quote == first_half && *end_quote!= '\0')
1022 is_quoted = (**argptr
1023 && strchr (get_gdb_completer_quote_characters (),
1026 end_quote = skip_quoted (*argptr);
1029 /* Check whether arg is all digits (and sign). */
1032 if (*q == '-' || *q == '+')
1034 while (*q >= '0' && *q <= '9')
1037 if (q != *argptr && (*q == 0 || *q == ' ' || *q == '\t' || *q == ',')
1038 && function_symbols == NULL)
1040 struct symtabs_and_lines values;
1042 /* We found a token consisting of all digits -- at least one digit. */
1043 values = decode_all_digits (self, argptr, q);
1044 do_cleanups (cleanup);
1048 /* Arg token is not digits => try it as a variable name
1049 Find the next token (everything up to end or next whitespace). */
1051 if (**argptr == '$') /* May be a convenience variable. */
1052 /* One or two $ chars possible. */
1053 p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1));
1054 else if (is_quoted || is_squote_enclosed)
1058 error (_("Unmatched single quote."));
1060 else if (is_objc_method)
1062 /* allow word separators in method names for Obj-C. */
1063 p = skip_quoted_chars (*argptr, NULL, "");
1067 p = skip_quoted (*argptr);
1070 /* Keep any important naming information. */
1071 p = keep_name_info (p, p == saved_arg || is_linespec_boundary (p[-1]));
1073 copy = (char *) alloca (p - *argptr + 1);
1074 memcpy (copy, *argptr, p - *argptr);
1075 copy[p - *argptr] = '\0';
1078 && copy[0] == copy[p - *argptr - 1]
1079 && strchr (get_gdb_completer_quote_characters (), copy[0]) != NULL)
1081 copy[p - *argptr - 1] = '\0';
1084 else if (is_quoted || is_squote_enclosed)
1085 copy[p - *argptr - 1] = '\0';
1087 *argptr = skip_spaces (p);
1089 /* If it starts with $: may be a legitimate variable or routine name
1090 (e.g. HP-UX millicode routines such as $$dyncall), or it may
1091 be history value, or it may be a convenience variable. */
1093 if (*copy == '$' && function_symbols == NULL)
1095 struct symtabs_and_lines values;
1097 values = decode_dollar (self, copy);
1098 do_cleanups (cleanup);
1102 /* Try the token as a label, but only if no file was specified,
1103 because we can only really find labels in the current scope. */
1105 if (VEC_length (symtab_p, self->file_symtabs) == 1
1106 && VEC_index (symtab_p, self->file_symtabs, 0) == NULL)
1108 struct symtabs_and_lines label_result;
1109 if (decode_label (self, function_symbols, copy, &label_result))
1111 do_cleanups (cleanup);
1112 return label_result;
1116 if (function_symbols)
1117 throw_exception (file_exception);
1119 /* Look up that token as a variable.
1120 If file specified, use that file's per-file block to start with. */
1123 struct symtabs_and_lines values;
1125 values = decode_variable (self, copy);
1126 do_cleanups (cleanup);
1131 /* A constructor for linespec_state. */
1134 linespec_state_constructor (struct linespec_state *self,
1136 struct symtab *default_symtab,
1138 struct linespec_result *canonical)
1140 memset (self, 0, sizeof (*self));
1141 self->funfirstline = (flags & DECODE_LINE_FUNFIRSTLINE) ? 1 : 0;
1142 self->list_mode = (flags & DECODE_LINE_LIST_MODE) ? 1 : 0;
1143 self->default_symtab = default_symtab;
1144 self->default_line = default_line;
1145 self->canonical = canonical;
1146 self->program_space = current_program_space;
1147 self->addr_set = htab_create_alloc (10, hash_address_entry, eq_address_entry,
1148 xfree, xcalloc, xfree);
1151 /* A destructor for linespec_state. */
1154 linespec_state_destructor (void *arg)
1156 struct linespec_state *self = arg;
1158 xfree (self->user_filename);
1159 xfree (self->user_function);
1160 VEC_free (symtab_p, self->file_symtabs);
1161 htab_delete (self->addr_set);
1164 /* See linespec.h. */
1167 decode_line_full (char **argptr, int flags,
1168 struct symtab *default_symtab,
1169 int default_line, struct linespec_result *canonical,
1170 const char *select_mode,
1173 struct symtabs_and_lines result;
1174 struct linespec_state state;
1175 struct cleanup *cleanups;
1176 char *arg_start = *argptr;
1177 VEC (const_char_ptr) *filters = NULL;
1179 gdb_assert (canonical != NULL);
1180 /* The filter only makes sense for 'all'. */
1181 gdb_assert (filter == NULL || select_mode == multiple_symbols_all);
1182 gdb_assert (select_mode == NULL
1183 || select_mode == multiple_symbols_all
1184 || select_mode == multiple_symbols_ask
1185 || select_mode == multiple_symbols_cancel);
1186 gdb_assert ((flags & DECODE_LINE_LIST_MODE) == 0);
1188 linespec_state_constructor (&state, flags,
1189 default_symtab, default_line, canonical);
1190 cleanups = make_cleanup (linespec_state_destructor, &state);
1191 save_current_program_space ();
1193 result = decode_line_internal (&state, argptr);
1195 gdb_assert (result.nelts == 1 || canonical->pre_expanded);
1196 gdb_assert (canonical->addr_string != NULL);
1197 canonical->pre_expanded = 1;
1199 /* Fill in the missing canonical names. */
1200 if (result.nelts > 0)
1204 if (state.canonical_names == NULL)
1205 state.canonical_names = xcalloc (result.nelts, sizeof (char *));
1206 make_cleanup (xfree, state.canonical_names);
1207 for (i = 0; i < result.nelts; ++i)
1209 if (state.canonical_names[i] == NULL)
1210 state.canonical_names[i] = savestring (arg_start,
1211 *argptr - arg_start);
1212 make_cleanup (xfree, state.canonical_names[i]);
1216 if (select_mode == NULL)
1218 if (ui_out_is_mi_like_p (interp_ui_out (top_level_interpreter ())))
1219 select_mode = multiple_symbols_all;
1221 select_mode = multiple_symbols_select_mode ();
1224 if (select_mode == multiple_symbols_all)
1228 make_cleanup (VEC_cleanup (const_char_ptr), &filters);
1229 VEC_safe_push (const_char_ptr, filters, filter);
1230 filter_results (&state, &result, filters);
1233 convert_results_to_lsals (&state, &result);
1236 decode_line_2 (&state, &result, select_mode);
1238 do_cleanups (cleanups);
1241 struct symtabs_and_lines
1242 decode_line_1 (char **argptr, int flags,
1243 struct symtab *default_symtab,
1246 struct symtabs_and_lines result;
1247 struct linespec_state state;
1248 struct cleanup *cleanups;
1250 linespec_state_constructor (&state, flags,
1251 default_symtab, default_line, NULL);
1252 cleanups = make_cleanup (linespec_state_destructor, &state);
1253 save_current_program_space ();
1255 result = decode_line_internal (&state, argptr);
1256 do_cleanups (cleanups);
1262 /* First, some functions to initialize stuff at the beggining of the
1266 initialize_defaults (struct symtab **default_symtab, int *default_line)
1268 if (*default_symtab == 0)
1270 /* Use whatever we have for the default source line. We don't use
1271 get_current_or_default_symtab_and_line as it can recurse and call
1273 struct symtab_and_line cursal =
1274 get_current_source_symtab_and_line ();
1276 *default_symtab = cursal.symtab;
1277 *default_line = cursal.line;
1283 /* Decode arg of the form *PC. */
1285 static struct symtabs_and_lines
1286 decode_indirect (struct linespec_state *self, char **argptr)
1288 struct symtabs_and_lines values;
1290 char *initial = *argptr;
1292 if (current_program_space->executing_startup)
1293 /* The error message doesn't really matter, because this case
1294 should only hit during breakpoint reset. */
1295 throw_error (NOT_FOUND_ERROR, _("cannot evaluate expressions while "
1296 "program space is in startup"));
1299 pc = value_as_address (parse_to_comma_and_eval (argptr));
1301 values.sals = (struct symtab_and_line *)
1302 xmalloc (sizeof (struct symtab_and_line));
1305 values.sals[0] = find_pc_line (pc, 0);
1306 values.sals[0].pc = pc;
1307 values.sals[0].section = find_pc_overlay (pc);
1308 values.sals[0].explicit_pc = 1;
1310 if (self->canonical)
1311 self->canonical->addr_string = savestring (initial, *argptr - initial);
1318 /* Locate the first half of the linespec, ending in a colon, period,
1319 or whitespace. (More or less.) Also, check to see if *ARGPTR is
1320 enclosed in double quotes; if so, set is_quote_enclosed, advance
1321 ARGPTR past that and zero out the trailing double quote.
1322 If ARGPTR is just a simple name like "main", p will point to ""
1326 locate_first_half (char **argptr, int *is_quote_enclosed)
1332 /* Maybe we were called with a line range FILENAME:LINENUM,FILENAME:LINENUM
1333 and we must isolate the first half. Outer layers will call again later
1334 for the second half.
1336 Don't count commas that appear in argument lists of overloaded
1337 functions, or in quoted strings. It's stupid to go to this much
1338 trouble when the rest of the function is such an obvious roach hotel. */
1339 ii = find_toplevel_char (*argptr, ',');
1340 has_comma = (ii != 0);
1342 /* Temporarily zap out second half to not confuse the code below.
1343 This is undone below. Do not change ii!! */
1349 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION. May also be
1350 CLASS::MEMBER, or NAMESPACE::NAME. Look for ':', but ignore
1356 *is_quote_enclosed = 1;
1362 *is_quote_enclosed = 0;
1363 if (strchr (get_gdb_completer_quote_characters (), *p))
1371 /* Check for a drive letter in the filename. This is done on all hosts
1372 to capture cross-compilation environments. On Unixen, directory
1373 separators are illegal in filenames, so if the user enters "e:/foo.c",
1374 he is referring to a directory named "e:" and a source file named
1375 "foo.c", and we still want to keep these two pieces together. */
1376 if (isalpha (p[0]) && p[1] == ':' && IS_DIR_SEPARATOR (p[2]))
1383 char *temp_end = find_template_name_end (p);
1386 error (_("malformed template specification in command"));
1391 p = find_method_overload_end (p);
1393 /* Check for a colon and a plus or minus and a [ (which
1394 indicates an Objective-C method). */
1395 if (is_objc_method_format (p))
1399 /* Check for the end of the first half of the linespec. End of
1400 line, a tab, a colon or a space. But if enclosed in double
1401 quotes we do not break on enclosed spaces. */
1405 || ((p[0] == ' ') && !*is_quote_enclosed))
1407 if (p[0] == '.' && strchr (p, ':') == NULL)
1409 /* Java qualified method. Find the *last* '.', since the
1410 others are package qualifiers. Stop at any open parenthesis
1411 which might provide overload information. */
1412 for (p1 = p; *p1 && *p1 != '('; p1++)
1420 p = skip_spaces (p);
1422 /* If the closing double quote was left at the end, remove it. */
1423 if (*is_quote_enclosed)
1425 char *closing_quote = strchr (p - 1, '"');
1427 if (closing_quote && closing_quote[1] == '\0')
1428 *closing_quote = '\0';
1431 /* Now that we've safely parsed the first half, put back ',' so
1432 outer layers can see it. */
1441 /* Here's where we recognise an Objective-C Selector. An Objective C
1442 selector may be implemented by more than one class, therefore it
1443 may represent more than one method/function. This gives us a
1444 situation somewhat analogous to C++ overloading. If there's more
1445 than one method that could represent the selector, then use some of
1446 the existing C++ code to let the user choose one. */
1448 static struct symtabs_and_lines
1449 decode_objc (struct linespec_state *self, char **argptr)
1451 struct collect_info info;
1452 VEC (const_char_ptr) *symbol_names = NULL;
1454 struct cleanup *cleanup = make_cleanup (VEC_cleanup (const_char_ptr),
1458 info.result.sals = NULL;
1459 info.result.nelts = 0;
1461 new_argptr = find_imps (*argptr, &symbol_names);
1462 if (VEC_empty (const_char_ptr, symbol_names))
1464 do_cleanups (cleanup);
1468 add_all_symbol_names_from_pspace (&info, NULL, symbol_names);
1470 if (info.result.nelts > 0)
1474 saved_arg = alloca (new_argptr - *argptr + 1);
1475 memcpy (saved_arg, *argptr, new_argptr - *argptr);
1476 saved_arg[new_argptr - *argptr] = '\0';
1478 if (self->canonical)
1480 self->canonical->pre_expanded = 1;
1481 if (self->user_filename)
1482 self->canonical->addr_string
1483 = xstrprintf ("%s:%s", self->user_filename, saved_arg);
1485 self->canonical->addr_string = xstrdup (saved_arg);
1489 *argptr = new_argptr;
1491 do_cleanups (cleanup);
1495 /* This handles C++ and Java compound data structures. P should point
1496 at the first component separator, i.e. double-colon or period. As
1497 an example, on entrance to this function we could have ARGPTR
1498 pointing to "AAA::inA::fun" and P pointing to "::inA::fun". */
1500 static struct symtabs_and_lines
1501 decode_compound (struct linespec_state *self,
1502 char **argptr, char *the_real_saved_arg, char *p)
1504 struct symtabs_and_lines values;
1506 char *saved_arg2 = *argptr;
1510 VEC (symbolp) *sym_classes;
1511 char *saved_arg, *class_name;
1512 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
1514 /* If the user specified any completer quote characters in the input,
1515 strip them. They are superfluous. */
1516 saved_arg = alloca (strlen (the_real_saved_arg) + 1);
1518 char *dst = saved_arg;
1519 char *src = the_real_saved_arg;
1520 char *quotes = get_gdb_completer_quote_characters ();
1521 while (*src != '\0')
1523 if (strchr (quotes, *src) == NULL)
1530 /* First check for "global" namespace specification, of the form
1531 "::foo". If found, skip over the colons and jump to normal
1532 symbol processing. I.e. the whole line specification starts with
1533 "::" (note the condition that *argptr == p). */
1535 && ((*argptr == p) || (p[-1] == ' ') || (p[-1] == '\t')))
1538 /* Given our example "AAA::inA::fun", we have two cases to consider:
1540 1) AAA::inA is the name of a class. In that case, presumably it
1541 has a method called "fun"; we then look up that method using
1544 2) AAA::inA isn't the name of a class. In that case, either the
1545 user made a typo, AAA::inA is the name of a namespace, or it is
1546 the name of a minimal symbol.
1547 In this case we just delegate to decode_variable.
1549 Thus, our first task is to find everything before the last set of
1550 double-colons and figure out if it's the name of a class. So we
1551 first loop through all of the double-colons. */
1553 p2 = p; /* Save for restart. */
1555 /* This is very messy. Following the example above we have now the
1558 argptr -> "AAA::inA::fun
1559 saved_arg -> "AAA::inA::fun
1560 saved_arg2 -> "AAA::inA::fun
1561 p2 -> "::inA::fun". */
1563 /* In the loop below, with these strings, we'll make 2 passes, each
1564 is marked in comments. */
1568 static char *break_characters = " \t(";
1570 /* Move pointer up to next possible class/namespace token. */
1572 p = p2 + 1; /* Restart with old value +1. */
1574 /* PASS1: at this point p2->"::inA::fun", so p->":inA::fun",
1575 i.e. if there is a double-colon, p will now point to the
1577 /* PASS2: p2->"::fun", p->":fun" */
1579 /* Move pointer ahead to next double-colon. */
1581 && strchr (break_characters, *p) == NULL
1582 && strchr (get_gdb_completer_quote_characters (), *p) == NULL)
1584 if (current_language->la_language == language_cplus)
1585 p += cp_validate_operator (p);
1589 temp_end = find_template_name_end (p);
1591 error (_("malformed template specification in command"));
1594 /* Note that, since, at the start of this loop, p would be
1595 pointing to the second colon in a double-colon, we only
1596 satisfy the condition below if there is another
1597 double-colon to the right (after). I.e. there is another
1598 component that can be a class or a namespace. I.e, if at
1599 the beginning of this loop (PASS1), we had
1600 p->":inA::fun", we'll trigger this when p has been
1601 advanced to point to "::fun". */
1602 /* PASS2: we will not trigger this. */
1603 else if ((p[0] == ':') && (p[1] == ':'))
1604 break; /* Found double-colon. */
1607 /* PASS2: We'll keep getting here, until P points to one of the
1608 break characters, at which point we exit this loop. */
1612 && strncmp (&p[1], CP_ANONYMOUS_NAMESPACE_STR,
1613 CP_ANONYMOUS_NAMESPACE_LEN) == 0)
1614 p += CP_ANONYMOUS_NAMESPACE_LEN;
1615 else if (strchr (break_characters, *p) == NULL)
1622 break; /* Out of the while (1). This would happen
1623 for instance if we have looked up
1624 unsuccessfully all the components of the
1625 string, and p->""(PASS2). */
1627 /* We get here if p points to one of the break characters or "" (i.e.,
1629 /* Save restart for next time around. */
1631 /* Restore argptr as it was on entry to this function. */
1632 *argptr = saved_arg2;
1633 /* PASS1: at this point p->"::fun" argptr->"AAA::inA::fun",
1636 /* All ready for next pass through the loop. */
1640 /* Start of lookup in the symbol tables. */
1642 /* Lookup in the symbol table the substring between argptr and
1643 p. Note, this call changes the value of argptr. */
1644 /* Before the call, argptr->"AAA::inA::fun",
1645 p->"", p2->"::fun". After the call: argptr->"fun", p, p2
1647 sym_classes = lookup_prefix_sym (argptr, p2, self->file_symtabs,
1649 make_cleanup (VEC_cleanup (symbolp), &sym_classes);
1650 make_cleanup (xfree, class_name);
1652 /* If a class has been found, then we're in case 1 above. So we
1653 look up "fun" as a method of those classes. */
1654 if (!VEC_empty (symbolp, sym_classes))
1656 /* Arg token is not digits => try it as a function name.
1657 Find the next token (everything up to end or next
1660 && strchr (get_gdb_completer_quote_characters (),
1663 p = skip_quoted (*argptr);
1664 *argptr = *argptr + 1;
1668 /* At this point argptr->"fun". */
1672 while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p != ':'
1675 /* At this point p->"". String ended. */
1676 /* Nope, C++ operators could have spaces in them
1677 ("foo::operator <" or "foo::operator delete []").
1678 I apologize, this is a bit hacky... */
1679 if (current_language->la_language == language_cplus
1680 && *p == ' ' && p - 8 - *argptr + 1 > 0)
1682 /* The above loop has already swallowed "operator". */
1683 p += cp_validate_operator (p - 8) - 8;
1686 /* Keep any important naming information. */
1687 p = keep_name_info (p, 1);
1690 /* Allocate our own copy of the substring between argptr and
1692 copy = (char *) alloca (p - *argptr + 1);
1693 memcpy (copy, *argptr, p - *argptr);
1694 copy[p - *argptr] = '\0';
1696 && copy[p - *argptr - 1]
1697 && strchr (get_gdb_completer_quote_characters (),
1698 copy[p - *argptr - 1]) != NULL)
1699 copy[p - *argptr - 1] = '\0';
1701 /* At this point copy->"fun", p->"". */
1703 /* No line number may be specified. */
1704 *argptr = skip_spaces (p);
1705 /* At this point arptr->"". */
1707 /* Look for copy as a method of sym_class. */
1708 /* At this point copy->"fun", sym_class is "AAA:inA",
1709 saved_arg->"AAA::inA::fun". This concludes the scanning of
1710 the string for possible components matches. If we find it
1711 here, we return. If not, and we are at the and of the string,
1712 we'll lookup the whole string in the symbol tables. */
1714 values = find_method (self, saved_arg, copy, class_name, sym_classes);
1716 do_cleanups (cleanup);
1718 } /* End if symbol found. */
1721 /* We couldn't find a class, so we're in case 2 above. We check the
1722 entire name as a symbol instead. The simplest way to do this is
1723 to just throw an exception and let our caller fall through to
1726 throw_error (NOT_FOUND_ERROR, _("see caller, this text doesn't matter"));
1729 /* An instance of this type is used when collecting prefix symbols for
1732 struct decode_compound_collector
1734 /* The result vector. */
1735 VEC (symbolp) *symbols;
1737 /* A hash table of all symbols we found. We use this to avoid
1738 adding any symbol more than once. */
1742 /* A callback for iterate_over_symbols that is used by
1743 lookup_prefix_sym to collect type symbols. */
1746 collect_one_symbol (struct symbol *sym, void *d)
1748 struct decode_compound_collector *collector = d;
1752 if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
1755 t = SYMBOL_TYPE (sym);
1757 if (TYPE_CODE (t) != TYPE_CODE_STRUCT
1758 && TYPE_CODE (t) != TYPE_CODE_UNION
1759 && TYPE_CODE (t) != TYPE_CODE_NAMESPACE)
1762 slot = htab_find_slot (collector->unique_syms, sym, INSERT);
1766 VEC_safe_push (symbolp, collector->symbols, sym);
1772 /* Return the symbol corresponding to the substring of *ARGPTR ending
1773 at P, allowing whitespace. Also, advance *ARGPTR past the symbol
1774 name in question, the compound object separator ("::" or "."), and
1775 whitespace. Note that *ARGPTR is changed whether or not the
1776 this call finds anything (i.e we return NULL). As an
1777 example, say ARGPTR is "AAA::inA::fun" and P is "::inA::fun". */
1779 static VEC (symbolp) *
1780 lookup_prefix_sym (char **argptr, char *p, VEC (symtab_p) *file_symtabs,
1787 struct decode_compound_collector collector;
1788 struct cleanup *outer;
1789 struct cleanup *cleanup;
1790 struct block *search_block;
1792 /* Extract the class name. */
1794 while (p != *argptr && p[-1] == ' ')
1796 copy = (char *) xmalloc (p - *argptr + 1);
1797 memcpy (copy, *argptr, p - *argptr);
1798 copy[p - *argptr] = 0;
1800 outer = make_cleanup (xfree, copy);
1802 /* Discard the class name from the argptr. */
1803 p = p1 + (p1[0] == ':' ? 2 : 1);
1804 p = skip_spaces (p);
1807 /* At this point p1->"::inA::fun", p->"inA::fun" copy->"AAA",
1808 argptr->"inA::fun". */
1810 collector.symbols = NULL;
1811 make_cleanup (VEC_cleanup (symbolp), &collector.symbols);
1813 collector.unique_syms = htab_create_alloc (1, htab_hash_pointer,
1814 htab_eq_pointer, NULL,
1816 cleanup = make_cleanup_htab_delete (collector.unique_syms);
1818 for (ix = 0; VEC_iterate (symtab_p, file_symtabs, ix, elt); ++ix)
1822 iterate_over_all_matching_symtabs (copy, STRUCT_DOMAIN,
1823 collect_one_symbol, &collector,
1825 iterate_over_all_matching_symtabs (copy, VAR_DOMAIN,
1826 collect_one_symbol, &collector,
1831 struct block *search_block;
1833 /* Program spaces that are executing startup should have
1834 been filtered out earlier. */
1835 gdb_assert (!SYMTAB_PSPACE (elt)->executing_startup);
1836 set_current_program_space (SYMTAB_PSPACE (elt));
1837 search_block = get_search_block (elt);
1838 LA_ITERATE_OVER_SYMBOLS (search_block, copy, STRUCT_DOMAIN,
1839 collect_one_symbol, &collector);
1840 LA_ITERATE_OVER_SYMBOLS (search_block, copy, VAR_DOMAIN,
1841 collect_one_symbol, &collector);
1845 do_cleanups (cleanup);
1846 discard_cleanups (outer);
1847 return collector.symbols;
1850 /* A qsort comparison function for symbols. The resulting order does
1851 not actually matter; we just need to be able to sort them so that
1852 symbols with the same program space end up next to each other. */
1855 compare_symbols (const void *a, const void *b)
1857 struct symbol * const *sa = a;
1858 struct symbol * const *sb = b;
1861 uia = (uintptr_t) SYMTAB_PSPACE (SYMBOL_SYMTAB (*sa));
1862 uib = (uintptr_t) SYMTAB_PSPACE (SYMBOL_SYMTAB (*sb));
1869 uia = (uintptr_t) *sa;
1870 uib = (uintptr_t) *sb;
1880 /* Look for all the matching instances of each symbol in NAMES. Only
1881 instances from PSPACE are considered; other program spaces are
1882 handled by our caller. If PSPACE is NULL, then all program spaces
1883 are considered. Results are stored into INFO. */
1886 add_all_symbol_names_from_pspace (struct collect_info *info,
1887 struct program_space *pspace,
1888 VEC (const_char_ptr) *names)
1893 for (ix = 0; VEC_iterate (const_char_ptr, names, ix, iter); ++ix)
1894 add_matching_symbols_to_info (iter, info, pspace);
1898 find_superclass_methods (VEC (typep) *superclasses,
1900 VEC (const_char_ptr) **result_names)
1902 int old_len = VEC_length (const_char_ptr, *result_names);
1903 VEC (typep) *iter_classes;
1904 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
1906 iter_classes = superclasses;
1909 VEC (typep) *new_supers = NULL;
1913 make_cleanup (VEC_cleanup (typep), &new_supers);
1914 for (ix = 0; VEC_iterate (typep, iter_classes, ix, t); ++ix)
1915 find_methods (t, name, result_names, &new_supers);
1917 if (VEC_length (const_char_ptr, *result_names) != old_len
1918 || VEC_empty (typep, new_supers))
1921 iter_classes = new_supers;
1924 do_cleanups (cleanup);
1927 /* This finds the method COPY in the class whose type is given by one
1928 of the symbols in SYM_CLASSES. */
1930 static struct symtabs_and_lines
1931 find_method (struct linespec_state *self, char *saved_arg,
1932 char *copy, const char *class_name, VEC (symbolp) *sym_classes)
1936 struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
1938 int last_result_len;
1939 VEC (typep) *superclass_vec;
1940 VEC (const_char_ptr) *result_names;
1941 struct collect_info info;
1944 /* NAME is typed by the user: it needs to be canonicalized before
1945 searching the symbol tables. */
1946 canon = cp_canonicalize_string_no_typedefs (copy);
1950 make_cleanup (xfree, copy);
1953 /* Sort symbols so that symbols with the same program space are next
1955 qsort (VEC_address (symbolp, sym_classes),
1956 VEC_length (symbolp, sym_classes),
1961 info.result.sals = NULL;
1962 info.result.nelts = 0;
1964 /* Iterate over all the types, looking for the names of existing
1965 methods matching COPY. If we cannot find a direct method in a
1966 given program space, then we consider inherited methods; this is
1967 not ideal (ideal would be to respect C++ hiding rules), but it
1968 seems good enough and is what GDB has historically done. We only
1969 need to collect the names because later we find all symbols with
1970 those names. This loop is written in a somewhat funny way
1971 because we collect data across the program space before deciding
1973 superclass_vec = NULL;
1974 make_cleanup (VEC_cleanup (typep), &superclass_vec);
1975 result_names = NULL;
1976 make_cleanup (VEC_cleanup (const_char_ptr), &result_names);
1977 last_result_len = 0;
1978 for (ix = 0; VEC_iterate (symbolp, sym_classes, ix, sym); ++ix)
1981 struct program_space *pspace;
1983 /* Program spaces that are executing startup should have
1984 been filtered out earlier. */
1985 gdb_assert (!SYMTAB_PSPACE (SYMBOL_SYMTAB (sym))->executing_startup);
1986 pspace = SYMTAB_PSPACE (SYMBOL_SYMTAB (sym));
1987 set_current_program_space (pspace);
1988 t = check_typedef (SYMBOL_TYPE (sym));
1989 find_methods (t, copy, &result_names, &superclass_vec);
1991 /* Handle all items from a single program space at once; and be
1992 sure not to miss the last batch. */
1993 if (ix == VEC_length (symbolp, sym_classes) - 1
1995 != SYMTAB_PSPACE (SYMBOL_SYMTAB (VEC_index (symbolp, sym_classes,
1998 /* If we did not find a direct implementation anywhere in
1999 this program space, consider superclasses. */
2000 if (VEC_length (const_char_ptr, result_names) == last_result_len)
2001 find_superclass_methods (superclass_vec, copy, &result_names);
2003 /* We have a list of candidate symbol names, so now we
2004 iterate over the symbol tables looking for all
2005 matches in this pspace. */
2006 add_all_symbol_names_from_pspace (&info, pspace, result_names);
2008 VEC_truncate (typep, superclass_vec, 0);
2009 last_result_len = VEC_length (const_char_ptr, result_names);
2013 if (info.result.nelts > 0)
2015 if (self->canonical)
2017 self->canonical->pre_expanded = 1;
2018 if (self->user_filename)
2019 self->canonical->addr_string
2020 = xstrprintf ("%s:%s", self->user_filename, saved_arg);
2022 self->canonical->addr_string = xstrdup (saved_arg);
2025 do_cleanups (cleanup);
2031 cplusplus_error (saved_arg,
2032 "the class `%s' does not have destructor defined\n",
2035 cplusplus_error (saved_arg,
2036 "the class %s does not have any method named %s\n",
2042 /* This object is used when collecting all matching symtabs. */
2044 struct symtab_collector
2046 /* The result vector of symtabs. */
2047 VEC (symtab_p) *symtabs;
2049 /* This is used to ensure the symtabs are unique. */
2050 htab_t symtab_table;
2053 /* Callback for iterate_over_symtabs. */
2056 add_symtabs_to_list (struct symtab *symtab, void *d)
2058 struct symtab_collector *data = d;
2061 slot = htab_find_slot (data->symtab_table, symtab, INSERT);
2065 VEC_safe_push (symtab_p, data->symtabs, symtab);
2071 /* Given a file name, return a VEC of all matching symtabs. */
2073 static VEC (symtab_p) *
2074 collect_symtabs_from_filename (const char *file)
2076 struct symtab_collector collector;
2077 struct cleanup *cleanups;
2078 struct program_space *pspace;
2080 collector.symtabs = NULL;
2081 collector.symtab_table = htab_create (1, htab_hash_pointer, htab_eq_pointer,
2083 cleanups = make_cleanup_htab_delete (collector.symtab_table);
2085 /* Find that file's data. */
2086 ALL_PSPACES (pspace)
2088 if (pspace->executing_startup)
2091 set_current_program_space (pspace);
2092 iterate_over_symtabs (file, add_symtabs_to_list, &collector);
2095 do_cleanups (cleanups);
2096 return collector.symtabs;
2099 /* Return all the symtabs associated to the filename given by the
2100 substring of *ARGPTR ending at P, and advance ARGPTR past that
2103 static VEC (symtab_p) *
2104 symtabs_from_filename (char **argptr, char *p, int is_quote_enclosed,
2105 char **user_filename)
2109 struct cleanup *outer;
2110 VEC (symtab_p) *result;
2113 while (p != *argptr && p[-1] == ' ')
2115 if ((*p == '"') && is_quote_enclosed)
2117 copy = xmalloc (p - *argptr + 1);
2118 outer = make_cleanup (xfree, copy);
2119 memcpy (copy, *argptr, p - *argptr);
2120 /* It may have the ending quote right after the file name. */
2121 if ((is_quote_enclosed && copy[p - *argptr - 1] == '"')
2122 || copy[p - *argptr - 1] == '\'')
2123 copy[p - *argptr - 1] = 0;
2125 copy[p - *argptr] = 0;
2127 result = collect_symtabs_from_filename (copy);
2129 if (VEC_empty (symtab_p, result))
2131 if (!have_full_symbols () && !have_partial_symbols ())
2132 throw_error (NOT_FOUND_ERROR,
2133 _("No symbol table is loaded. "
2134 "Use the \"file\" command."));
2135 throw_error (NOT_FOUND_ERROR, _("No source file named %s."), copy);
2138 /* Discard the file name from the arg. */
2142 *argptr = skip_spaces (p1 + 1);
2144 discard_cleanups (outer);
2145 *user_filename = copy;
2149 /* A callback used by iterate_over_all_matching_symtabs that collects
2150 symbols for find_function_symbols. */
2153 collect_function_symbols (struct symbol *sym, void *arg)
2155 VEC (symbolp) **syms = arg;
2157 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
2158 VEC_safe_push (symbolp, *syms, sym);
2163 /* Look up a function symbol in *ARGPTR. If found, advance *ARGPTR
2164 and return the symbol. If not found, return NULL. */
2166 static VEC (symbolp) *
2167 find_function_symbols (char **argptr, char *p, int is_quote_enclosed,
2168 char **user_function)
2172 VEC (symbolp) *result = NULL;
2175 while (p != *argptr && p[-1] == ' ')
2177 if ((*p == '"') && is_quote_enclosed)
2179 copy = (char *) xmalloc (p - *argptr + 1);
2180 *user_function = copy;
2181 memcpy (copy, *argptr, p - *argptr);
2182 /* It may have the ending quote right after the file name. */
2183 if ((is_quote_enclosed && copy[p - *argptr - 1] == '"')
2184 || copy[p - *argptr - 1] == '\'')
2185 copy[p - *argptr - 1] = 0;
2187 copy[p - *argptr] = 0;
2189 iterate_over_all_matching_symtabs (copy, VAR_DOMAIN,
2190 collect_function_symbols, &result, NULL);
2192 if (VEC_empty (symbolp, result))
2193 VEC_free (symbolp, result);
2196 /* Discard the file name from the arg. */
2197 *argptr = skip_spaces (p1 + 1);
2205 /* A helper for decode_all_digits that handles the 'list_mode' case. */
2208 decode_digits_list_mode (struct linespec_state *self,
2209 struct symtabs_and_lines *values,
2210 struct symtab_and_line val)
2215 gdb_assert (self->list_mode);
2217 for (ix = 0; VEC_iterate (symtab_p, self->file_symtabs, ix, elt); ++ix)
2219 /* The logic above should ensure this. */
2220 gdb_assert (elt != NULL);
2222 set_current_program_space (SYMTAB_PSPACE (elt));
2224 /* Simplistic search just for the list command. */
2225 val.symtab = find_line_symtab (elt, val.line, NULL, NULL);
2226 if (val.symtab == NULL)
2228 val.pspace = SYMTAB_PSPACE (elt);
2230 val.explicit_line = 1;
2232 add_sal_to_sals (self, values, &val, NULL);
2236 /* A helper for decode_all_digits that iterates over the symtabs,
2237 adding lines to the VEC. */
2240 decode_digits_ordinary (struct linespec_state *self,
2242 struct symtabs_and_lines *sals,
2243 struct linetable_entry **best_entry)
2248 for (ix = 0; VEC_iterate (symtab_p, self->file_symtabs, ix, elt); ++ix)
2251 VEC (CORE_ADDR) *pcs;
2254 /* The logic above should ensure this. */
2255 gdb_assert (elt != NULL);
2257 set_current_program_space (SYMTAB_PSPACE (elt));
2259 pcs = find_pcs_for_symtab_line (elt, line, best_entry);
2260 for (i = 0; VEC_iterate (CORE_ADDR, pcs, i, pc); ++i)
2262 struct symtab_and_line sal;
2265 sal.pspace = SYMTAB_PSPACE (elt);
2269 add_sal_to_sals_basic (sals, &sal);
2272 VEC_free (CORE_ADDR, pcs);
2276 /* This decodes a line where the argument is all digits (possibly
2277 preceded by a sign). Q should point to the end of those digits;
2278 the other arguments are as usual. */
2280 static struct symtabs_and_lines
2281 decode_all_digits (struct linespec_state *self,
2285 struct symtabs_and_lines values;
2286 struct symtab_and_line val;
2287 int use_default = 0;
2288 char *saved_arg = *argptr;
2300 /* This is where we need to make sure that we have good defaults.
2301 We must guarantee that this section of code is never executed
2302 when we are called with just a function name, since
2303 set_default_source_symtab_and_line uses
2304 select_source_symtab that calls us with such an argument. */
2306 if (VEC_length (symtab_p, self->file_symtabs) == 1
2307 && VEC_index (symtab_p, self->file_symtabs, 0) == NULL)
2309 set_current_program_space (self->program_space);
2311 /* Make sure we have at least a default source file. */
2312 set_default_source_symtab_and_line ();
2313 initialize_defaults (&self->default_symtab, &self->default_line);
2314 VEC_pop (symtab_p, self->file_symtabs);
2315 VEC_free (symtab_p, self->file_symtabs);
2317 = collect_symtabs_from_filename (self->default_symtab->filename);
2321 if (**argptr == '+')
2322 sign = plus, (*argptr)++;
2323 else if (**argptr == '-')
2324 sign = minus, (*argptr)++;
2325 val.line = atoi (*argptr);
2332 val.line = self->default_line + val.line;
2338 val.line = self->default_line - val.line;
2343 break; /* No need to adjust val.line. */
2346 *argptr = skip_spaces (q);
2348 if (self->list_mode)
2349 decode_digits_list_mode (self, &values, val);
2352 struct linetable_entry *best_entry = NULL;
2354 struct block **blocks;
2355 struct cleanup *cleanup;
2356 struct symtabs_and_lines intermediate_results;
2359 intermediate_results.sals = NULL;
2360 intermediate_results.nelts = 0;
2362 decode_digits_ordinary (self, val.line, &intermediate_results,
2364 if (intermediate_results.nelts == 0 && best_entry != NULL)
2365 decode_digits_ordinary (self, best_entry->line, &intermediate_results,
2368 cleanup = make_cleanup (xfree, intermediate_results.sals);
2370 /* For optimized code, compiler can scatter one source line
2371 accross disjoint ranges of PC values, even when no duplicate
2372 functions or inline functions are involved. For example,
2373 'for (;;)' inside non-template non-inline non-ctor-or-dtor
2374 function can result in two PC ranges. In this case, we don't
2375 want to set breakpoint on first PC of each range. To filter
2376 such cases, we use containing blocks -- for each PC found
2377 above we see if there are other PCs that are in the same
2378 block. If yes, the other PCs are filtered out. */
2380 filter = xmalloc (intermediate_results.nelts * sizeof (int));
2381 make_cleanup (xfree, filter);
2382 blocks = xmalloc (intermediate_results.nelts * sizeof (struct block *));
2383 make_cleanup (xfree, blocks);
2385 for (i = 0; i < intermediate_results.nelts; ++i)
2387 set_current_program_space (intermediate_results.sals[i].pspace);
2390 blocks[i] = block_for_pc_sect (intermediate_results.sals[i].pc,
2391 intermediate_results.sals[i].section);
2394 for (i = 0; i < intermediate_results.nelts; ++i)
2396 if (blocks[i] != NULL)
2397 for (j = i + 1; j < intermediate_results.nelts; ++j)
2399 if (blocks[j] == blocks[i])
2407 for (i = 0; i < intermediate_results.nelts; ++i)
2410 struct symbol *sym = (blocks[i]
2411 ? block_containing_function (blocks[i])
2414 if (self->funfirstline)
2415 skip_prologue_sal (&intermediate_results.sals[i]);
2416 /* Make sure the line matches the request, not what was
2418 intermediate_results.sals[i].line = val.line;
2419 add_sal_to_sals (self, &values, &intermediate_results.sals[i],
2420 sym ? SYMBOL_NATURAL_NAME (sym) : NULL);
2423 do_cleanups (cleanup);
2426 if (values.nelts == 0)
2428 if (self->user_filename)
2429 throw_error (NOT_FOUND_ERROR, _("No line %d in file \"%s\"."),
2430 val.line, self->user_filename);
2432 throw_error (NOT_FOUND_ERROR, _("No line %d in the current file."),
2436 if (self->canonical)
2438 char *copy = savestring (saved_arg, q - saved_arg);
2440 self->canonical->pre_expanded = 1;
2441 gdb_assert (self->user_filename || use_default);
2442 self->canonical->addr_string
2443 = xstrprintf ("%s:%s", (self->user_filename
2444 ? self->user_filename
2445 : self->default_symtab->filename),
2455 /* Decode a linespec starting with a dollar sign. */
2457 static struct symtabs_and_lines
2458 decode_dollar (struct linespec_state *self, char *copy)
2462 struct symtabs_and_lines values;
2463 struct symtab_and_line val;
2466 struct minimal_symbol *msymbol;
2470 p = (copy[1] == '$') ? copy + 2 : copy + 1;
2471 while (*p >= '0' && *p <= '9')
2473 if (!*p) /* Reached end of token without hitting non-digit. */
2475 /* We have a value history reference. */
2476 struct value *val_history;
2478 sscanf ((copy[1] == '$') ? copy + 2 : copy + 1, "%d", &index);
2479 val_history = access_value_history ((copy[1] == '$') ? -index : index);
2480 if (TYPE_CODE (value_type (val_history)) != TYPE_CODE_INT)
2481 error (_("History values used in line "
2482 "specs must have integer values."));
2483 valx = value_as_long (val_history);
2487 /* Not all digits -- may be user variable/function or a
2488 convenience variable. */
2490 volatile struct gdb_exception exc;
2492 /* Avoid "may be used uninitialized" warning. */
2496 TRY_CATCH (exc, RETURN_MASK_ERROR)
2498 values = decode_variable (self, copy);
2501 if (exc.reason == 0)
2504 if (exc.error != NOT_FOUND_ERROR)
2505 throw_exception (exc);
2507 /* Not a user variable or function -- must be convenience variable. */
2508 if (!get_internalvar_integer (lookup_internalvar (copy + 1), &valx))
2509 error (_("Convenience variables used in line "
2510 "specs must have integer values."));
2518 for (ix = 0; VEC_iterate (symtab_p, self->file_symtabs, ix, elt); ++ix)
2522 elt = self->default_symtab;
2523 set_current_program_space (self->program_space);
2526 set_current_program_space (SYMTAB_PSPACE (elt));
2528 /* Either history value or convenience value from above, in valx. */
2532 val.pspace = elt ? SYMTAB_PSPACE (elt) : current_program_space;
2534 add_sal_to_sals (self, &values, &val, NULL);
2537 if (self->canonical)
2539 self->canonical->pre_expanded = 1;
2540 if (self->user_filename)
2541 self->canonical->addr_string = xstrprintf ("%s:%s",
2542 self->user_filename, copy);
2544 self->canonical->addr_string = xstrdup (copy);
2552 /* A helper for decode_line_1 that tries to find a label. The label
2553 is searched for in the current block.
2554 FUNCTION_SYMBOLS is a list of the enclosing functions; or NULL if none
2556 COPY is the name of the label to find.
2557 CANONICAL is the same as the "canonical" argument to decode_line_1.
2558 RESULT is a pointer to a symtabs_and_lines structure which will be
2559 filled in on success.
2560 This function returns 1 if a label was found, 0 otherwise. */
2563 decode_label (struct linespec_state *self,
2564 VEC (symbolp) *function_symbols, char *copy,
2565 struct symtabs_and_lines *result)
2567 struct symbol *fn_sym;
2570 if (function_symbols == NULL)
2572 struct block *block;
2574 struct symtab_and_line sal;
2575 struct symtabs_and_lines values;
2580 set_current_program_space (self->program_space);
2581 block = get_search_block (NULL);
2584 block && !BLOCK_FUNCTION (block);
2585 block = BLOCK_SUPERBLOCK (block))
2589 fn_sym = BLOCK_FUNCTION (block);
2591 sym = lookup_symbol (copy, block, LABEL_DOMAIN, 0);
2596 symbol_to_sal (&sal, self->funfirstline, sym);
2597 add_sal_to_sals (self, &values, &sal,
2598 SYMBOL_NATURAL_NAME (fn_sym));
2600 if (self->canonical)
2602 self->canonical->special_display = 1;
2603 self->canonical->addr_string
2604 = xstrprintf ("%s:%s", SYMBOL_NATURAL_NAME (fn_sym),
2613 result->sals = NULL;
2616 for (ix = 0; VEC_iterate (symbolp, function_symbols, ix, fn_sym); ++ix)
2618 struct block *block;
2621 set_current_program_space (SYMTAB_PSPACE (SYMBOL_SYMTAB (fn_sym)));
2622 block = SYMBOL_BLOCK_VALUE (fn_sym);
2623 sym = lookup_symbol (copy, block, LABEL_DOMAIN, 0);
2627 struct symtab_and_line sal;
2630 symbol_to_sal (&sal, self->funfirstline, sym);
2631 symname = xstrprintf ("%s:%s",
2632 SYMBOL_NATURAL_NAME (fn_sym),
2633 SYMBOL_NATURAL_NAME (sym));
2634 add_sal_to_sals (self, result, &sal, symname);
2639 if (self->canonical && result->nelts > 0)
2641 self->canonical->pre_expanded = 1;
2642 self->canonical->special_display = 1;
2644 gdb_assert (self->user_function);
2645 self->canonical->addr_string
2646 = xstrprintf ("%s:%s", self->user_function, copy);
2649 return result->nelts > 0;
2652 /* A callback used to possibly add a symbol to the results. */
2655 collect_symbols (struct symbol *sym, void *data)
2657 struct collect_info *info = data;
2658 struct symtab_and_line sal;
2660 if (symbol_to_sal (&sal, info->state->funfirstline, sym)
2661 && maybe_add_address (info->state->addr_set,
2662 SYMTAB_PSPACE (SYMBOL_SYMTAB (sym)),
2664 add_sal_to_sals (info->state, &info->result, &sal,
2665 SYMBOL_NATURAL_NAME (sym));
2670 /* We've found a minimal symbol MSYMBOL to associate with our
2671 linespec; add it to the result symtabs_and_lines. */
2674 minsym_found (struct linespec_state *self, struct objfile *objfile,
2675 struct minimal_symbol *msymbol,
2676 struct symtabs_and_lines *result)
2678 struct gdbarch *gdbarch = get_objfile_arch (objfile);
2680 struct symtab_and_line sal;
2682 sal = find_pc_sect_line (SYMBOL_VALUE_ADDRESS (msymbol),
2683 (struct obj_section *) 0, 0);
2684 sal.section = SYMBOL_OBJ_SECTION (msymbol);
2686 /* The minimal symbol might point to a function descriptor;
2687 resolve it to the actual code address instead. */
2688 pc = gdbarch_convert_from_func_ptr_addr (gdbarch, sal.pc, ¤t_target);
2690 sal = find_pc_sect_line (pc, NULL, 0);
2692 if (self->funfirstline)
2693 skip_prologue_sal (&sal);
2695 if (maybe_add_address (self->addr_set, objfile->pspace, sal.pc))
2696 add_sal_to_sals (self, result, &sal, SYMBOL_NATURAL_NAME (msymbol));
2699 /* A helper struct which just holds a minimal symbol and the object
2700 file from which it came. */
2702 typedef struct minsym_and_objfile
2704 struct minimal_symbol *minsym;
2705 struct objfile *objfile;
2706 } minsym_and_objfile_d;
2708 DEF_VEC_O (minsym_and_objfile_d);
2710 /* A helper struct to pass some data through
2711 iterate_over_minimal_symbols. */
2713 struct collect_minsyms
2715 /* The objfile we're examining. */
2716 struct objfile *objfile;
2718 /* The funfirstline setting from the initial call. */
2721 /* The list_mode setting from the initial call. */
2724 /* The resulting symbols. */
2725 VEC (minsym_and_objfile_d) *msyms;
2728 /* A helper function to classify a minimal_symbol_type according to
2732 classify_mtype (enum minimal_symbol_type t)
2739 /* Intermediate priority. */
2742 case mst_solib_trampoline:
2743 /* Lowest priority. */
2747 /* Highest priority. */
2752 /* Callback for qsort that sorts symbols by priority. */
2755 compare_msyms (const void *a, const void *b)
2757 const minsym_and_objfile_d *moa = a;
2758 const minsym_and_objfile_d *mob = b;
2759 enum minimal_symbol_type ta = MSYMBOL_TYPE (moa->minsym);
2760 enum minimal_symbol_type tb = MSYMBOL_TYPE (mob->minsym);
2762 return classify_mtype (ta) - classify_mtype (tb);
2765 /* Callback for iterate_over_minimal_symbols that adds the symbol to
2769 add_minsym (struct minimal_symbol *minsym, void *d)
2771 struct collect_minsyms *info = d;
2772 minsym_and_objfile_d mo;
2774 /* Exclude data symbols when looking for breakpoint locations. */
2775 if (!info->list_mode)
2776 switch (minsym->type)
2778 case mst_slot_got_plt:
2785 /* Make sure this minsym is not a function descriptor
2786 before we decide to discard it. */
2787 struct gdbarch *gdbarch = info->objfile->gdbarch;
2788 CORE_ADDR addr = gdbarch_convert_from_func_ptr_addr
2789 (gdbarch, SYMBOL_VALUE_ADDRESS (minsym),
2792 if (addr == SYMBOL_VALUE_ADDRESS (minsym))
2798 mo.objfile = info->objfile;
2799 VEC_safe_push (minsym_and_objfile_d, info->msyms, &mo);
2802 /* Search minimal symbols in all objfiles for NAME. If SEARCH_PSPACE
2803 is not NULL, the search is restricted to just that program
2807 search_minsyms_for_name (struct collect_info *info, const char *name,
2808 struct program_space *search_pspace)
2810 struct objfile *objfile;
2811 struct program_space *pspace;
2813 ALL_PSPACES (pspace)
2815 struct collect_minsyms local;
2816 struct cleanup *cleanup;
2818 if (search_pspace != NULL && search_pspace != pspace)
2820 if (pspace->executing_startup)
2823 set_current_program_space (pspace);
2825 memset (&local, 0, sizeof (local));
2826 local.funfirstline = info->state->funfirstline;
2827 local.list_mode = info->state->list_mode;
2829 cleanup = make_cleanup (VEC_cleanup (minsym_and_objfile_d),
2832 ALL_OBJFILES (objfile)
2834 local.objfile = objfile;
2835 iterate_over_minimal_symbols (objfile, name, add_minsym, &local);
2838 if (!VEC_empty (minsym_and_objfile_d, local.msyms))
2842 minsym_and_objfile_d *item;
2844 qsort (VEC_address (minsym_and_objfile_d, local.msyms),
2845 VEC_length (minsym_and_objfile_d, local.msyms),
2846 sizeof (minsym_and_objfile_d),
2849 /* Now the minsyms are in classification order. So, we walk
2850 over them and process just the minsyms with the same
2851 classification as the very first minsym in the list. */
2852 item = VEC_index (minsym_and_objfile_d, local.msyms, 0);
2853 classification = classify_mtype (MSYMBOL_TYPE (item->minsym));
2856 VEC_iterate (minsym_and_objfile_d, local.msyms, ix, item);
2859 if (classify_mtype (MSYMBOL_TYPE (item->minsym)) != classification)
2862 minsym_found (info->state, item->objfile, item->minsym,
2867 do_cleanups (cleanup);
2871 /* A helper function to add all symbols matching NAME to INFO. If
2872 PSPACE is not NULL, the search is restricted to just that program
2876 add_matching_symbols_to_info (const char *name,
2877 struct collect_info *info,
2878 struct program_space *pspace)
2883 for (ix = 0; VEC_iterate (symtab_p, info->state->file_symtabs, ix, elt); ++ix)
2889 iterate_over_all_matching_symtabs (name, VAR_DOMAIN,
2890 collect_symbols, info,
2892 search_minsyms_for_name (info, name, pspace);
2894 else if (pspace == NULL || pspace == SYMTAB_PSPACE (elt))
2896 /* Program spaces that are executing startup should have
2897 been filtered out earlier. */
2898 gdb_assert (!SYMTAB_PSPACE (elt)->executing_startup);
2899 set_current_program_space (SYMTAB_PSPACE (elt));
2900 LA_ITERATE_OVER_SYMBOLS (get_search_block (elt), name,
2901 VAR_DOMAIN, collect_symbols,
2907 /* Decode a linespec that's a variable. If FILE_SYMTAB is non-NULL,
2908 look in that symtab's static variables first. */
2910 static struct symtabs_and_lines
2911 decode_variable (struct linespec_state *self, char *copy)
2913 struct collect_info info;
2914 const char *lookup_name;
2916 struct cleanup *cleanup;
2919 info.result.sals = NULL;
2920 info.result.nelts = 0;
2922 cleanup = demangle_for_lookup (copy, current_language->la_language,
2924 if (current_language->la_language == language_ada)
2926 /* In Ada, the symbol lookups are performed using the encoded
2927 name rather than the demangled name. */
2928 lookup_name = ada_name_for_lookup (copy);
2929 make_cleanup (xfree, (void *) lookup_name);
2932 canon = cp_canonicalize_string_no_typedefs (lookup_name);
2935 make_cleanup (xfree, canon);
2936 lookup_name = canon;
2939 add_matching_symbols_to_info (lookup_name, &info, NULL);
2941 if (info.result.nelts > 0)
2943 if (self->canonical)
2945 self->canonical->pre_expanded = 1;
2946 if (self->user_filename)
2947 self->canonical->addr_string
2948 = xstrprintf ("%s:%s", self->user_filename, copy);
2950 self->canonical->addr_string = xstrdup (copy);
2955 if (!have_full_symbols ()
2956 && !have_partial_symbols ()
2957 && !have_minimal_symbols ())
2958 throw_error (NOT_FOUND_ERROR,
2959 _("No symbol table is loaded. Use the \"file\" command."));
2960 if (self->user_filename)
2961 throw_error (NOT_FOUND_ERROR, _("Function \"%s\" not defined in \"%s\"."),
2962 copy, self->user_filename);
2964 throw_error (NOT_FOUND_ERROR, _("Function \"%s\" not defined."), copy);
2970 /* Now come some functions that are called from multiple places within
2974 symbol_to_sal (struct symtab_and_line *result,
2975 int funfirstline, struct symbol *sym)
2977 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
2979 *result = find_function_start_sal (sym, funfirstline);
2984 if (SYMBOL_CLASS (sym) == LOC_LABEL && SYMBOL_VALUE_ADDRESS (sym) != 0)
2987 result->symtab = SYMBOL_SYMTAB (sym);
2988 result->line = SYMBOL_LINE (sym);
2989 result->pc = SYMBOL_VALUE_ADDRESS (sym);
2990 result->pspace = SYMTAB_PSPACE (SYMBOL_SYMTAB (sym));
2991 result->explicit_pc = 1;
2994 else if (funfirstline)
2998 else if (SYMBOL_LINE (sym) != 0)
3000 /* We know its line number. */
3002 result->symtab = SYMBOL_SYMTAB (sym);
3003 result->line = SYMBOL_LINE (sym);
3004 result->pspace = SYMTAB_PSPACE (SYMBOL_SYMTAB (sym));
3012 /* See the comment in linespec.h. */
3015 init_linespec_result (struct linespec_result *lr)
3017 memset (lr, 0, sizeof (*lr));
3020 /* See the comment in linespec.h. */
3023 destroy_linespec_result (struct linespec_result *ls)
3026 struct linespec_sals *lsal;
3028 xfree (ls->addr_string);
3029 for (i = 0; VEC_iterate (linespec_sals, ls->sals, i, lsal); ++i)
3031 xfree (lsal->canonical);
3032 xfree (lsal->sals.sals);
3034 VEC_free (linespec_sals, ls->sals);
3037 /* Cleanup function for a linespec_result. */
3040 cleanup_linespec_result (void *a)
3042 destroy_linespec_result (a);
3045 /* See the comment in linespec.h. */
3048 make_cleanup_destroy_linespec_result (struct linespec_result *ls)
3050 return make_cleanup (cleanup_linespec_result, ls);