Commit | Line | Data |
---|---|---|
50641945 | 1 | /* Parser for linespec for the GNU debugger, GDB. |
05ff989b | 2 | |
32d0add0 | 3 | Copyright (C) 1986-2015 Free Software Foundation, Inc. |
50641945 FN |
4 | |
5 | This file is part of GDB. | |
6 | ||
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 | |
a9762ec7 | 9 | the Free Software Foundation; either version 3 of the License, or |
50641945 FN |
10 | (at your option) any later version. |
11 | ||
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. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
a9762ec7 | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
50641945 FN |
19 | |
20 | #include "defs.h" | |
21 | #include "symtab.h" | |
c5f0f3d0 FN |
22 | #include "frame.h" |
23 | #include "command.h" | |
50641945 FN |
24 | #include "symfile.h" |
25 | #include "objfiles.h" | |
0378c332 | 26 | #include "source.h" |
50641945 | 27 | #include "demangle.h" |
c5f0f3d0 FN |
28 | #include "value.h" |
29 | #include "completer.h" | |
015a42b4 | 30 | #include "cp-abi.h" |
12907978 | 31 | #include "cp-support.h" |
c38da1af | 32 | #include "parser-defs.h" |
fe898f56 | 33 | #include "block.h" |
d2630e69 | 34 | #include "objc-lang.h" |
b9362cc7 | 35 | #include "linespec.h" |
53c5240f | 36 | #include "language.h" |
dc67126b NR |
37 | #include "interps.h" |
38 | #include "mi/mi-cmds.h" | |
bccdca4a | 39 | #include "target.h" |
94af9270 | 40 | #include "arch-utils.h" |
c00f8484 KS |
41 | #include <ctype.h> |
42 | #include "cli/cli-utils.h" | |
731971ed | 43 | #include "filenames.h" |
f8eba3c6 | 44 | #include "ada-lang.h" |
39cf75f7 | 45 | #include "stack.h" |
f00aae0f | 46 | #include "location.h" |
f8eba3c6 | 47 | |
f8eba3c6 TT |
48 | typedef struct symbol *symbolp; |
49 | DEF_VEC_P (symbolp); | |
50 | ||
51 | typedef struct type *typep; | |
52 | DEF_VEC_P (typep); | |
53 | ||
54 | /* An address entry is used to ensure that any given location is only | |
55 | added to the result a single time. It holds an address and the | |
56 | program space from which the address came. */ | |
57 | ||
58 | struct address_entry | |
59 | { | |
60 | struct program_space *pspace; | |
61 | CORE_ADDR addr; | |
62 | }; | |
63 | ||
f60e2d5c | 64 | typedef struct bound_minimal_symbol bound_minimal_symbol_d; |
40e084e1 | 65 | |
f60e2d5c | 66 | DEF_VEC_O (bound_minimal_symbol_d); |
40e084e1 | 67 | |
40e084e1 KS |
68 | /* A linespec. Elements of this structure are filled in by a parser |
69 | (either parse_linespec or some other function). The structure is | |
70 | then converted into SALs by convert_linespec_to_sals. */ | |
71 | ||
72 | struct linespec | |
73 | { | |
00e52e53 | 74 | /* An explicit location describing the SaLs. */ |
67994074 | 75 | struct explicit_location explicit_loc; |
40e084e1 KS |
76 | |
77 | /* The list of symtabs to search to which to limit the search. May not | |
00e52e53 KS |
78 | be NULL. If explicit.SOURCE_FILENAME is NULL (no user-specified |
79 | filename), FILE_SYMTABS should contain one single NULL member. This | |
80 | will cause the code to use the default symtab. */ | |
ec94af83 | 81 | VEC (symtab_ptr) *file_symtabs; |
40e084e1 | 82 | |
40e084e1 KS |
83 | /* A list of matching function symbols and minimal symbols. Both lists |
84 | may be NULL if no matching symbols were found. */ | |
85 | VEC (symbolp) *function_symbols; | |
f60e2d5c | 86 | VEC (bound_minimal_symbol_d) *minimal_symbols; |
40e084e1 | 87 | |
40e084e1 KS |
88 | /* A structure of matching label symbols and the corresponding |
89 | function symbol in which the label was found. Both may be NULL | |
90 | or both must be non-NULL. */ | |
91 | struct | |
92 | { | |
93 | VEC (symbolp) *label_symbols; | |
94 | VEC (symbolp) *function_symbols; | |
95 | } labels; | |
40e084e1 KS |
96 | }; |
97 | typedef struct linespec *linespec_p; | |
98 | ||
33f448b1 JK |
99 | /* A canonical linespec represented as a symtab-related string. |
100 | ||
101 | Each entry represents the "SYMTAB:SUFFIX" linespec string. | |
102 | SYMTAB can be converted for example by symtab_to_fullname or | |
103 | symtab_to_filename_for_display as needed. */ | |
104 | ||
105 | struct linespec_canonical_name | |
106 | { | |
107 | /* Remaining text part of the linespec string. */ | |
108 | char *suffix; | |
109 | ||
110 | /* If NULL then SUFFIX is the whole linespec string. */ | |
111 | struct symtab *symtab; | |
112 | }; | |
113 | ||
f8eba3c6 TT |
114 | /* An instance of this is used to keep all state while linespec |
115 | operates. This instance is passed around as a 'this' pointer to | |
116 | the various implementation methods. */ | |
117 | ||
118 | struct linespec_state | |
119 | { | |
40e084e1 KS |
120 | /* The language in use during linespec processing. */ |
121 | const struct language_defn *language; | |
122 | ||
f8eba3c6 TT |
123 | /* The program space as seen when the module was entered. */ |
124 | struct program_space *program_space; | |
125 | ||
126 | /* The default symtab to use, if no other symtab is specified. */ | |
127 | struct symtab *default_symtab; | |
128 | ||
129 | /* The default line to use. */ | |
130 | int default_line; | |
131 | ||
f8eba3c6 TT |
132 | /* The 'funfirstline' value that was passed in to decode_line_1 or |
133 | decode_line_full. */ | |
134 | int funfirstline; | |
135 | ||
136 | /* Nonzero if we are running in 'list' mode; see decode_line_list. */ | |
137 | int list_mode; | |
138 | ||
139 | /* The 'canonical' value passed to decode_line_full, or NULL. */ | |
140 | struct linespec_result *canonical; | |
141 | ||
142 | /* Canonical strings that mirror the symtabs_and_lines result. */ | |
33f448b1 | 143 | struct linespec_canonical_name *canonical_names; |
f8eba3c6 TT |
144 | |
145 | /* This is a set of address_entry objects which is used to prevent | |
146 | duplicate symbols from being entered into the result. */ | |
147 | htab_t addr_set; | |
00e52e53 KS |
148 | |
149 | /* Are we building a linespec? */ | |
150 | int is_linespec; | |
f8eba3c6 TT |
151 | }; |
152 | ||
153 | /* This is a helper object that is used when collecting symbols into a | |
154 | result. */ | |
155 | ||
156 | struct collect_info | |
157 | { | |
158 | /* The linespec object in use. */ | |
159 | struct linespec_state *state; | |
160 | ||
40e084e1 | 161 | /* A list of symtabs to which to restrict matches. */ |
ec94af83 | 162 | VEC (symtab_ptr) *file_symtabs; |
40e084e1 | 163 | |
f8eba3c6 | 164 | /* The result being accumulated. */ |
40e084e1 KS |
165 | struct |
166 | { | |
167 | VEC (symbolp) *symbols; | |
f60e2d5c | 168 | VEC (bound_minimal_symbol_d) *minimal_symbols; |
40e084e1 | 169 | } result; |
f8eba3c6 | 170 | }; |
50641945 | 171 | |
40e084e1 | 172 | /* Token types */ |
50641945 | 173 | |
40e084e1 KS |
174 | enum ls_token_type |
175 | { | |
176 | /* A keyword */ | |
177 | LSTOKEN_KEYWORD = 0, | |
44fe14ab | 178 | |
40e084e1 KS |
179 | /* A colon "separator" */ |
180 | LSTOKEN_COLON, | |
44fe14ab | 181 | |
40e084e1 KS |
182 | /* A string */ |
183 | LSTOKEN_STRING, | |
0960f083 | 184 | |
40e084e1 KS |
185 | /* A number */ |
186 | LSTOKEN_NUMBER, | |
187 | ||
188 | /* A comma */ | |
189 | LSTOKEN_COMMA, | |
190 | ||
191 | /* EOI (end of input) */ | |
192 | LSTOKEN_EOI, | |
193 | ||
194 | /* Consumed token */ | |
195 | LSTOKEN_CONSUMED | |
196 | }; | |
197 | typedef enum ls_token_type linespec_token_type; | |
198 | ||
199 | /* List of keywords */ | |
200 | ||
201 | static const char * const linespec_keywords[] = { "if", "thread", "task" }; | |
0578b14e | 202 | #define IF_KEYWORD_INDEX 0 |
40e084e1 KS |
203 | |
204 | /* A token of the linespec lexer */ | |
205 | ||
206 | struct ls_token | |
207 | { | |
208 | /* The type of the token */ | |
209 | linespec_token_type type; | |
210 | ||
211 | /* Data for the token */ | |
212 | union | |
213 | { | |
214 | /* A string, given as a stoken */ | |
215 | struct stoken string; | |
216 | ||
217 | /* A keyword */ | |
218 | const char *keyword; | |
219 | } data; | |
220 | }; | |
221 | typedef struct ls_token linespec_token; | |
222 | ||
223 | #define LS_TOKEN_STOKEN(TOK) (TOK).data.string | |
224 | #define LS_TOKEN_KEYWORD(TOK) (TOK).data.keyword | |
225 | ||
226 | /* An instance of the linespec parser. */ | |
227 | ||
228 | struct ls_parser | |
229 | { | |
230 | /* Lexer internal data */ | |
231 | struct | |
232 | { | |
233 | /* Save head of input stream. */ | |
d7561cbb | 234 | const char *saved_arg; |
d2630e69 | 235 | |
40e084e1 | 236 | /* Head of the input stream. */ |
f00aae0f KS |
237 | const char *stream; |
238 | #define PARSER_STREAM(P) ((P)->lexer.stream) | |
614b3b14 | 239 | |
40e084e1 KS |
240 | /* The current token. */ |
241 | linespec_token current; | |
242 | } lexer; | |
93d91629 | 243 | |
40e084e1 KS |
244 | /* Is the entire linespec quote-enclosed? */ |
245 | int is_quote_enclosed; | |
246 | ||
247 | /* The state of the parse. */ | |
248 | struct linespec_state state; | |
249 | #define PARSER_STATE(PPTR) (&(PPTR)->state) | |
4224873a | 250 | |
40e084e1 KS |
251 | /* The result of the parse. */ |
252 | struct linespec result; | |
253 | #define PARSER_RESULT(PPTR) (&(PPTR)->result) | |
254 | }; | |
255 | typedef struct ls_parser linespec_parser; | |
50641945 | 256 | |
00e52e53 KS |
257 | /* A convenience macro for accessing the explicit location result of |
258 | the parser. */ | |
67994074 | 259 | #define PARSER_EXPLICIT(PPTR) (&PARSER_RESULT ((PPTR))->explicit_loc) |
00e52e53 | 260 | |
40e084e1 | 261 | /* Prototypes for local functions. */ |
50641945 | 262 | |
4eeaa230 DE |
263 | static void iterate_over_file_blocks (struct symtab *symtab, |
264 | const char *name, domain_enum domain, | |
265 | symbol_found_callback_ftype *callback, | |
266 | void *data); | |
267 | ||
40e084e1 KS |
268 | static void initialize_defaults (struct symtab **default_symtab, |
269 | int *default_line); | |
50641945 | 270 | |
a06efdd6 | 271 | CORE_ADDR linespec_expression_to_pc (const char **exp_ptr); |
aee8d8ba | 272 | |
40e084e1 KS |
273 | static struct symtabs_and_lines decode_objc (struct linespec_state *self, |
274 | linespec_p ls, | |
f00aae0f | 275 | const char *arg); |
aee8d8ba | 276 | |
ec94af83 | 277 | static VEC (symtab_ptr) *symtabs_from_filename (const char *); |
50641945 | 278 | |
40e084e1 KS |
279 | static VEC (symbolp) *find_label_symbols (struct linespec_state *self, |
280 | VEC (symbolp) *function_symbols, | |
281 | VEC (symbolp) **label_funcs_ret, | |
282 | const char *name); | |
50641945 | 283 | |
b1ae631a | 284 | static void find_linespec_symbols (struct linespec_state *self, |
ec94af83 | 285 | VEC (symtab_ptr) *file_symtabs, |
b1ae631a DE |
286 | const char *name, |
287 | VEC (symbolp) **symbols, | |
f60e2d5c | 288 | VEC (bound_minimal_symbol_d) **minsyms); |
f8eba3c6 | 289 | |
40e084e1 KS |
290 | static struct line_offset |
291 | linespec_parse_variable (struct linespec_state *self, | |
292 | const char *variable); | |
889f28e2 | 293 | |
f8eba3c6 TT |
294 | static int symbol_to_sal (struct symtab_and_line *result, |
295 | int funfirstline, struct symbol *sym); | |
50641945 | 296 | |
f8eba3c6 TT |
297 | static void add_matching_symbols_to_info (const char *name, |
298 | struct collect_info *info, | |
299 | struct program_space *pspace); | |
f3c39e76 | 300 | |
f8eba3c6 TT |
301 | static void add_all_symbol_names_from_pspace (struct collect_info *info, |
302 | struct program_space *pspace, | |
303 | VEC (const_char_ptr) *names); | |
9ef07c8c | 304 | |
ec94af83 | 305 | static VEC (symtab_ptr) *collect_symtabs_from_filename (const char *file); |
84fba31b | 306 | |
40e084e1 KS |
307 | static void decode_digits_ordinary (struct linespec_state *self, |
308 | linespec_p ls, | |
309 | int line, | |
310 | struct symtabs_and_lines *sals, | |
311 | struct linetable_entry **best_entry); | |
14e91ac5 | 312 | |
40e084e1 KS |
313 | static void decode_digits_list_mode (struct linespec_state *self, |
314 | linespec_p ls, | |
315 | struct symtabs_and_lines *values, | |
316 | struct symtab_and_line val); | |
0f5238ed | 317 | |
40e084e1 KS |
318 | static void minsym_found (struct linespec_state *self, struct objfile *objfile, |
319 | struct minimal_symbol *msymbol, | |
320 | struct symtabs_and_lines *result); | |
bca02a8a | 321 | |
40e084e1 | 322 | static int compare_symbols (const void *a, const void *b); |
413dad4d | 323 | |
40e084e1 | 324 | static int compare_msymbols (const void *a, const void *b); |
413dad4d | 325 | |
40e084e1 KS |
326 | /* Permitted quote characters for the parser. This is different from the |
327 | completer's quote characters to allow backward compatibility with the | |
328 | previous parser. */ | |
329 | static const char *const linespec_quote_characters = "\"\'"; | |
f8eba3c6 | 330 | |
40e084e1 KS |
331 | /* Lexer functions. */ |
332 | ||
333 | /* Lex a number from the input in PARSER. This only supports | |
dd3818c8 KS |
334 | decimal numbers. |
335 | ||
d7cbec71 | 336 | Return true if input is decimal numbers. Return false if not. */ |
40e084e1 | 337 | |
d7cbec71 HZ |
338 | static int |
339 | linespec_lexer_lex_number (linespec_parser *parser, linespec_token *tokenp) | |
40e084e1 | 340 | { |
d7cbec71 HZ |
341 | tokenp->type = LSTOKEN_NUMBER; |
342 | LS_TOKEN_STOKEN (*tokenp).length = 0; | |
343 | LS_TOKEN_STOKEN (*tokenp).ptr = PARSER_STREAM (parser); | |
40e084e1 KS |
344 | |
345 | /* Keep any sign at the start of the stream. */ | |
346 | if (*PARSER_STREAM (parser) == '+' || *PARSER_STREAM (parser) == '-') | |
347 | { | |
d7cbec71 | 348 | ++LS_TOKEN_STOKEN (*tokenp).length; |
40e084e1 KS |
349 | ++(PARSER_STREAM (parser)); |
350 | } | |
351 | ||
352 | while (isdigit (*PARSER_STREAM (parser))) | |
353 | { | |
d7cbec71 | 354 | ++LS_TOKEN_STOKEN (*tokenp).length; |
40e084e1 | 355 | ++(PARSER_STREAM (parser)); |
f8eba3c6 | 356 | } |
40e084e1 | 357 | |
dd3818c8 | 358 | /* If the next character in the input buffer is not a space, comma, |
eff9c3e6 | 359 | quote, or colon, this input does not represent a number. */ |
dd3818c8 KS |
360 | if (*PARSER_STREAM (parser) != '\0' |
361 | && !isspace (*PARSER_STREAM (parser)) && *PARSER_STREAM (parser) != ',' | |
eff9c3e6 KS |
362 | && *PARSER_STREAM (parser) != ':' |
363 | && !strchr (linespec_quote_characters, *PARSER_STREAM (parser))) | |
d7cbec71 HZ |
364 | { |
365 | PARSER_STREAM (parser) = LS_TOKEN_STOKEN (*tokenp).ptr; | |
366 | return 0; | |
367 | } | |
368 | ||
369 | return 1; | |
f8eba3c6 TT |
370 | } |
371 | ||
32b40af9 | 372 | /* See linespec.h. */ |
f8eba3c6 | 373 | |
0578b14e | 374 | const char * |
40e084e1 | 375 | linespec_lexer_lex_keyword (const char *p) |
f8eba3c6 | 376 | { |
40e084e1 | 377 | int i; |
f8eba3c6 | 378 | |
40e084e1 KS |
379 | if (p != NULL) |
380 | { | |
381 | for (i = 0; i < ARRAY_SIZE (linespec_keywords); ++i) | |
382 | { | |
383 | int len = strlen (linespec_keywords[i]); | |
384 | ||
385 | /* If P begins with one of the keywords and the next | |
0578b14e KS |
386 | character is whitespace, we may have found a keyword. |
387 | It is only a keyword if it is not followed by another | |
388 | keyword. */ | |
40e084e1 | 389 | if (strncmp (p, linespec_keywords[i], len) == 0 |
0578b14e KS |
390 | && isspace (p[len])) |
391 | { | |
392 | int j; | |
393 | ||
394 | /* Special case: "if" ALWAYS stops the lexer, since it | |
395 | is not possible to predict what is going to appear in | |
396 | the condition, which can only be parsed after SaLs have | |
397 | been found. */ | |
398 | if (i != IF_KEYWORD_INDEX) | |
399 | { | |
400 | p += len; | |
401 | p = skip_spaces_const (p); | |
402 | for (j = 0; j < ARRAY_SIZE (linespec_keywords); ++j) | |
403 | { | |
404 | int nextlen = strlen (linespec_keywords[j]); | |
405 | ||
406 | if (strncmp (p, linespec_keywords[j], nextlen) == 0 | |
407 | && isspace (p[nextlen])) | |
408 | return NULL; | |
409 | } | |
410 | } | |
411 | ||
412 | return linespec_keywords[i]; | |
413 | } | |
40e084e1 KS |
414 | } |
415 | } | |
416 | ||
417 | return NULL; | |
f8eba3c6 TT |
418 | } |
419 | ||
87f0e720 | 420 | /* See description in linespec.h. */ |
f8eba3c6 | 421 | |
87f0e720 | 422 | int |
40e084e1 | 423 | is_ada_operator (const char *string) |
f8eba3c6 | 424 | { |
40e084e1 | 425 | const struct ada_opname_map *mapping; |
f8eba3c6 | 426 | |
40e084e1 KS |
427 | for (mapping = ada_opname_table; |
428 | mapping->encoded != NULL | |
61012eef | 429 | && !startswith (string, mapping->decoded); ++mapping) |
40e084e1 KS |
430 | ; |
431 | ||
432 | return mapping->decoded == NULL ? 0 : strlen (mapping->decoded); | |
f8eba3c6 TT |
433 | } |
434 | ||
40e084e1 KS |
435 | /* Find QUOTE_CHAR in STRING, accounting for the ':' terminal. Return |
436 | the location of QUOTE_CHAR, or NULL if not found. */ | |
f8eba3c6 | 437 | |
40e084e1 KS |
438 | static const char * |
439 | skip_quote_char (const char *string, char quote_char) | |
f8eba3c6 | 440 | { |
40e084e1 | 441 | const char *p, *last; |
f8eba3c6 | 442 | |
40e084e1 KS |
443 | p = last = find_toplevel_char (string, quote_char); |
444 | while (p && *p != '\0' && *p != ':') | |
445 | { | |
446 | p = find_toplevel_char (p, quote_char); | |
447 | if (p != NULL) | |
448 | last = p++; | |
449 | } | |
f8eba3c6 | 450 | |
40e084e1 | 451 | return last; |
f8eba3c6 | 452 | } |
50641945 | 453 | |
40e084e1 KS |
454 | /* Make a writable copy of the string given in TOKEN, trimming |
455 | any trailing whitespace. */ | |
50641945 | 456 | |
40e084e1 KS |
457 | static char * |
458 | copy_token_string (linespec_token token) | |
50641945 | 459 | { |
40e084e1 | 460 | char *str, *s; |
e0881a8e | 461 | |
40e084e1 KS |
462 | if (token.type == LSTOKEN_KEYWORD) |
463 | return xstrdup (LS_TOKEN_KEYWORD (token)); | |
255e7dbf | 464 | |
40e084e1 KS |
465 | str = savestring (LS_TOKEN_STOKEN (token).ptr, |
466 | LS_TOKEN_STOKEN (token).length); | |
467 | s = remove_trailing_whitespace (str, str + LS_TOKEN_STOKEN (token).length); | |
468 | *s = '\0'; | |
e0881a8e | 469 | |
40e084e1 KS |
470 | return str; |
471 | } | |
255e7dbf | 472 | |
40e084e1 | 473 | /* Does P represent the end of a quote-enclosed linespec? */ |
f3a5f1de | 474 | |
40e084e1 KS |
475 | static int |
476 | is_closing_quote_enclosed (const char *p) | |
477 | { | |
478 | if (strchr (linespec_quote_characters, *p)) | |
479 | ++p; | |
480 | p = skip_spaces ((char *) p); | |
481 | return (*p == '\0' || linespec_lexer_lex_keyword (p)); | |
50641945 FN |
482 | } |
483 | ||
40e084e1 KS |
484 | /* Find the end of the parameter list that starts with *INPUT. |
485 | This helper function assists with lexing string segments | |
486 | which might contain valid (non-terminating) commas. */ | |
481860b3 | 487 | |
d7561cbb KS |
488 | static const char * |
489 | find_parameter_list_end (const char *input) | |
481860b3 | 490 | { |
40e084e1 KS |
491 | char end_char, start_char; |
492 | int depth; | |
d7561cbb | 493 | const char *p; |
481860b3 | 494 | |
40e084e1 KS |
495 | start_char = *input; |
496 | if (start_char == '(') | |
497 | end_char = ')'; | |
498 | else if (start_char == '<') | |
499 | end_char = '>'; | |
500 | else | |
501 | return NULL; | |
481860b3 | 502 | |
40e084e1 KS |
503 | p = input; |
504 | depth = 0; | |
505 | while (*p) | |
481860b3 | 506 | { |
40e084e1 KS |
507 | if (*p == start_char) |
508 | ++depth; | |
509 | else if (*p == end_char) | |
510 | { | |
511 | if (--depth == 0) | |
512 | { | |
513 | ++p; | |
514 | break; | |
515 | } | |
516 | } | |
517 | ++p; | |
481860b3 | 518 | } |
40e084e1 KS |
519 | |
520 | return p; | |
481860b3 GB |
521 | } |
522 | ||
74ccd7f5 | 523 | |
40e084e1 KS |
524 | /* Lex a string from the input in PARSER. */ |
525 | ||
526 | static linespec_token | |
527 | linespec_lexer_lex_string (linespec_parser *parser) | |
74ccd7f5 | 528 | { |
40e084e1 | 529 | linespec_token token; |
d7561cbb | 530 | const char *start = PARSER_STREAM (parser); |
74ccd7f5 | 531 | |
40e084e1 | 532 | token.type = LSTOKEN_STRING; |
74ccd7f5 | 533 | |
40e084e1 KS |
534 | /* If the input stream starts with a quote character, skip to the next |
535 | quote character, regardless of the content. */ | |
536 | if (strchr (linespec_quote_characters, *PARSER_STREAM (parser))) | |
537 | { | |
538 | const char *end; | |
539 | char quote_char = *PARSER_STREAM (parser); | |
50641945 | 540 | |
40e084e1 KS |
541 | /* Special case: Ada operators. */ |
542 | if (PARSER_STATE (parser)->language->la_language == language_ada | |
543 | && quote_char == '\"') | |
544 | { | |
545 | int len = is_ada_operator (PARSER_STREAM (parser)); | |
50641945 | 546 | |
40e084e1 KS |
547 | if (len != 0) |
548 | { | |
549 | /* The input is an Ada operator. Return the quoted string | |
550 | as-is. */ | |
551 | LS_TOKEN_STOKEN (token).ptr = PARSER_STREAM (parser); | |
552 | LS_TOKEN_STOKEN (token).length = len; | |
553 | PARSER_STREAM (parser) += len; | |
554 | return token; | |
555 | } | |
f8eba3c6 | 556 | |
40e084e1 KS |
557 | /* The input does not represent an Ada operator -- fall through |
558 | to normal quoted string handling. */ | |
559 | } | |
f8eba3c6 | 560 | |
40e084e1 KS |
561 | /* Skip past the beginning quote. */ |
562 | ++(PARSER_STREAM (parser)); | |
74ccd7f5 | 563 | |
40e084e1 KS |
564 | /* Mark the start of the string. */ |
565 | LS_TOKEN_STOKEN (token).ptr = PARSER_STREAM (parser); | |
f8eba3c6 | 566 | |
40e084e1 KS |
567 | /* Skip to the ending quote. */ |
568 | end = skip_quote_char (PARSER_STREAM (parser), quote_char); | |
569 | ||
570 | /* Error if the input did not terminate properly. */ | |
571 | if (end == NULL) | |
572 | error (_("unmatched quote")); | |
573 | ||
574 | /* Skip over the ending quote and mark the length of the string. */ | |
575 | PARSER_STREAM (parser) = (char *) ++end; | |
576 | LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - 2 - start; | |
577 | } | |
578 | else | |
579 | { | |
d7561cbb | 580 | const char *p; |
40e084e1 KS |
581 | |
582 | /* Otherwise, only identifier characters are permitted. | |
583 | Spaces are the exception. In general, we keep spaces, | |
584 | but only if the next characters in the input do not resolve | |
585 | to one of the keywords. | |
586 | ||
587 | This allows users to forgo quoting CV-qualifiers, template arguments, | |
588 | and similar common language constructs. */ | |
589 | ||
590 | while (1) | |
591 | { | |
592 | if (isspace (*PARSER_STREAM (parser))) | |
593 | { | |
d7561cbb | 594 | p = skip_spaces_const (PARSER_STREAM (parser)); |
7c09e5a0 DE |
595 | /* When we get here we know we've found something followed by |
596 | a space (we skip over parens and templates below). | |
597 | So if we find a keyword now, we know it is a keyword and not, | |
598 | say, a function name. */ | |
40e084e1 KS |
599 | if (linespec_lexer_lex_keyword (p) != NULL) |
600 | { | |
601 | LS_TOKEN_STOKEN (token).ptr = start; | |
602 | LS_TOKEN_STOKEN (token).length | |
603 | = PARSER_STREAM (parser) - start; | |
604 | return token; | |
605 | } | |
606 | ||
607 | /* Advance past the whitespace. */ | |
608 | PARSER_STREAM (parser) = p; | |
609 | } | |
610 | ||
611 | /* If the next character is EOI or (single) ':', the | |
612 | string is complete; return the token. */ | |
613 | if (*PARSER_STREAM (parser) == 0) | |
614 | { | |
615 | LS_TOKEN_STOKEN (token).ptr = start; | |
616 | LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - start; | |
617 | return token; | |
618 | } | |
619 | else if (PARSER_STREAM (parser)[0] == ':') | |
620 | { | |
621 | /* Do not tokenize the C++ scope operator. */ | |
622 | if (PARSER_STREAM (parser)[1] == ':') | |
623 | ++(PARSER_STREAM (parser)); | |
624 | ||
625 | /* Do not tokenify if the input length so far is one | |
626 | (i.e, a single-letter drive name) and the next character | |
627 | is a directory separator. This allows Windows-style | |
628 | paths to be recognized as filenames without quoting it. */ | |
629 | else if ((PARSER_STREAM (parser) - start) != 1 | |
630 | || !IS_DIR_SEPARATOR (PARSER_STREAM (parser)[1])) | |
631 | { | |
632 | LS_TOKEN_STOKEN (token).ptr = start; | |
633 | LS_TOKEN_STOKEN (token).length | |
634 | = PARSER_STREAM (parser) - start; | |
635 | return token; | |
636 | } | |
637 | } | |
638 | /* Special case: permit quote-enclosed linespecs. */ | |
639 | else if (parser->is_quote_enclosed | |
640 | && strchr (linespec_quote_characters, | |
641 | *PARSER_STREAM (parser)) | |
642 | && is_closing_quote_enclosed (PARSER_STREAM (parser))) | |
643 | { | |
644 | LS_TOKEN_STOKEN (token).ptr = start; | |
645 | LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - start; | |
646 | return token; | |
647 | } | |
648 | /* Because commas may terminate a linespec and appear in | |
649 | the middle of valid string input, special cases for | |
650 | '<' and '(' are necessary. */ | |
651 | else if (*PARSER_STREAM (parser) == '<' | |
652 | || *PARSER_STREAM (parser) == '(') | |
653 | { | |
d7561cbb | 654 | const char *p; |
40e084e1 KS |
655 | |
656 | p = find_parameter_list_end (PARSER_STREAM (parser)); | |
657 | if (p != NULL) | |
658 | { | |
659 | PARSER_STREAM (parser) = p; | |
660 | continue; | |
661 | } | |
662 | } | |
663 | /* Commas are terminators, but not if they are part of an | |
664 | operator name. */ | |
665 | else if (*PARSER_STREAM (parser) == ',') | |
666 | { | |
667 | if ((PARSER_STATE (parser)->language->la_language | |
668 | == language_cplus) | |
669 | && (PARSER_STREAM (parser) - start) > 8 | |
670 | /* strlen ("operator") */) | |
671 | { | |
acaa662f | 672 | const char *p = strstr (start, "operator"); |
40e084e1 KS |
673 | |
674 | if (p != NULL && is_operator_name (p)) | |
675 | { | |
676 | /* This is an operator name. Keep going. */ | |
677 | ++(PARSER_STREAM (parser)); | |
678 | continue; | |
679 | } | |
680 | } | |
681 | ||
682 | /* Comma terminates the string. */ | |
683 | LS_TOKEN_STOKEN (token).ptr = start; | |
684 | LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - start; | |
685 | return token; | |
686 | } | |
687 | ||
688 | /* Advance the stream. */ | |
689 | ++(PARSER_STREAM (parser)); | |
690 | } | |
691 | } | |
692 | ||
693 | return token; | |
694 | } | |
695 | ||
696 | /* Lex a single linespec token from PARSER. */ | |
697 | ||
698 | static linespec_token | |
699 | linespec_lexer_lex_one (linespec_parser *parser) | |
700 | { | |
701 | const char *keyword; | |
702 | ||
703 | if (parser->lexer.current.type == LSTOKEN_CONSUMED) | |
704 | { | |
705 | /* Skip any whitespace. */ | |
d7561cbb | 706 | PARSER_STREAM (parser) = skip_spaces_const (PARSER_STREAM (parser)); |
40e084e1 | 707 | |
7c09e5a0 | 708 | /* Check for a keyword, they end the linespec. */ |
0578b14e | 709 | keyword = linespec_lexer_lex_keyword (PARSER_STREAM (parser)); |
40e084e1 KS |
710 | if (keyword != NULL) |
711 | { | |
712 | parser->lexer.current.type = LSTOKEN_KEYWORD; | |
713 | LS_TOKEN_KEYWORD (parser->lexer.current) = keyword; | |
0578b14e KS |
714 | /* We do not advance the stream here intentionally: |
715 | we would like lexing to stop when a keyword is seen. | |
716 | ||
717 | PARSER_STREAM (parser) += strlen (keyword); */ | |
718 | ||
40e084e1 KS |
719 | return parser->lexer.current; |
720 | } | |
721 | ||
722 | /* Handle other tokens. */ | |
723 | switch (*PARSER_STREAM (parser)) | |
724 | { | |
725 | case 0: | |
726 | parser->lexer.current.type = LSTOKEN_EOI; | |
727 | break; | |
728 | ||
729 | case '+': case '-': | |
730 | case '0': case '1': case '2': case '3': case '4': | |
731 | case '5': case '6': case '7': case '8': case '9': | |
d7cbec71 HZ |
732 | if (!linespec_lexer_lex_number (parser, &(parser->lexer.current))) |
733 | parser->lexer.current = linespec_lexer_lex_string (parser); | |
40e084e1 KS |
734 | break; |
735 | ||
736 | case ':': | |
737 | /* If we have a scope operator, lex the input as a string. | |
738 | Otherwise, return LSTOKEN_COLON. */ | |
739 | if (PARSER_STREAM (parser)[1] == ':') | |
740 | parser->lexer.current = linespec_lexer_lex_string (parser); | |
741 | else | |
742 | { | |
743 | parser->lexer.current.type = LSTOKEN_COLON; | |
744 | ++(PARSER_STREAM (parser)); | |
745 | } | |
746 | break; | |
747 | ||
748 | case '\'': case '\"': | |
749 | /* Special case: permit quote-enclosed linespecs. */ | |
750 | if (parser->is_quote_enclosed | |
751 | && is_closing_quote_enclosed (PARSER_STREAM (parser))) | |
752 | { | |
753 | ++(PARSER_STREAM (parser)); | |
754 | parser->lexer.current.type = LSTOKEN_EOI; | |
755 | } | |
756 | else | |
757 | parser->lexer.current = linespec_lexer_lex_string (parser); | |
758 | break; | |
759 | ||
760 | case ',': | |
761 | parser->lexer.current.type = LSTOKEN_COMMA; | |
762 | LS_TOKEN_STOKEN (parser->lexer.current).ptr | |
763 | = PARSER_STREAM (parser); | |
764 | LS_TOKEN_STOKEN (parser->lexer.current).length = 1; | |
765 | ++(PARSER_STREAM (parser)); | |
766 | break; | |
767 | ||
768 | default: | |
769 | /* If the input is not a number, it must be a string. | |
770 | [Keywords were already considered above.] */ | |
771 | parser->lexer.current = linespec_lexer_lex_string (parser); | |
772 | break; | |
773 | } | |
774 | } | |
775 | ||
776 | return parser->lexer.current; | |
777 | } | |
778 | ||
779 | /* Consume the current token and return the next token in PARSER's | |
780 | input stream. */ | |
781 | ||
782 | static linespec_token | |
783 | linespec_lexer_consume_token (linespec_parser *parser) | |
784 | { | |
785 | parser->lexer.current.type = LSTOKEN_CONSUMED; | |
786 | return linespec_lexer_lex_one (parser); | |
787 | } | |
788 | ||
789 | /* Return the next token without consuming the current token. */ | |
790 | ||
791 | static linespec_token | |
792 | linespec_lexer_peek_token (linespec_parser *parser) | |
793 | { | |
794 | linespec_token next; | |
d7561cbb | 795 | const char *saved_stream = PARSER_STREAM (parser); |
40e084e1 KS |
796 | linespec_token saved_token = parser->lexer.current; |
797 | ||
798 | next = linespec_lexer_consume_token (parser); | |
799 | PARSER_STREAM (parser) = saved_stream; | |
800 | parser->lexer.current = saved_token; | |
801 | return next; | |
802 | } | |
803 | ||
804 | /* Helper functions. */ | |
805 | ||
806 | /* Add SAL to SALS. */ | |
807 | ||
808 | static void | |
809 | add_sal_to_sals_basic (struct symtabs_and_lines *sals, | |
810 | struct symtab_and_line *sal) | |
811 | { | |
812 | ++sals->nelts; | |
224c3ddb | 813 | sals->sals = XRESIZEVEC (struct symtab_and_line, sals->sals, sals->nelts); |
40e084e1 KS |
814 | sals->sals[sals->nelts - 1] = *sal; |
815 | } | |
816 | ||
817 | /* Add SAL to SALS, and also update SELF->CANONICAL_NAMES to reflect | |
818 | the new sal, if needed. If not NULL, SYMNAME is the name of the | |
66f1999b KS |
819 | symbol to use when constructing the new canonical name. |
820 | ||
821 | If LITERAL_CANONICAL is non-zero, SYMNAME will be used as the | |
822 | canonical name for the SAL. */ | |
40e084e1 KS |
823 | |
824 | static void | |
825 | add_sal_to_sals (struct linespec_state *self, | |
826 | struct symtabs_and_lines *sals, | |
827 | struct symtab_and_line *sal, | |
66f1999b | 828 | const char *symname, int literal_canonical) |
40e084e1 KS |
829 | { |
830 | add_sal_to_sals_basic (sals, sal); | |
831 | ||
832 | if (self->canonical) | |
833 | { | |
33f448b1 | 834 | struct linespec_canonical_name *canonical; |
40e084e1 | 835 | |
224c3ddb SM |
836 | self->canonical_names = XRESIZEVEC (struct linespec_canonical_name, |
837 | self->canonical_names, sals->nelts); | |
33f448b1 | 838 | canonical = &self->canonical_names[sals->nelts - 1]; |
4e04028d | 839 | if (!literal_canonical && sal->symtab) |
40e084e1 | 840 | { |
05cba821 | 841 | const char *fullname = symtab_to_fullname (sal->symtab); |
40e084e1 KS |
842 | |
843 | /* Note that the filter doesn't have to be a valid linespec | |
844 | input. We only apply the ":LINE" treatment to Ada for | |
845 | the time being. */ | |
846 | if (symname != NULL && sal->line != 0 | |
847 | && self->language->la_language == language_ada) | |
33f448b1 | 848 | canonical->suffix = xstrprintf ("%s:%d", symname, sal->line); |
40e084e1 | 849 | else if (symname != NULL) |
33f448b1 | 850 | canonical->suffix = xstrdup (symname); |
40e084e1 | 851 | else |
33f448b1 JK |
852 | canonical->suffix = xstrprintf ("%d", sal->line); |
853 | canonical->symtab = sal->symtab; | |
854 | } | |
855 | else | |
856 | { | |
857 | if (symname != NULL) | |
858 | canonical->suffix = xstrdup (symname); | |
859 | else | |
e617b069 | 860 | canonical->suffix = xstrdup ("<unknown>"); |
33f448b1 | 861 | canonical->symtab = NULL; |
40e084e1 | 862 | } |
40e084e1 KS |
863 | } |
864 | } | |
865 | ||
866 | /* A hash function for address_entry. */ | |
867 | ||
868 | static hashval_t | |
869 | hash_address_entry (const void *p) | |
870 | { | |
9a3c8263 | 871 | const struct address_entry *aep = (const struct address_entry *) p; |
40e084e1 KS |
872 | hashval_t hash; |
873 | ||
874 | hash = iterative_hash_object (aep->pspace, 0); | |
875 | return iterative_hash_object (aep->addr, hash); | |
876 | } | |
877 | ||
878 | /* An equality function for address_entry. */ | |
879 | ||
880 | static int | |
881 | eq_address_entry (const void *a, const void *b) | |
882 | { | |
9a3c8263 SM |
883 | const struct address_entry *aea = (const struct address_entry *) a; |
884 | const struct address_entry *aeb = (const struct address_entry *) b; | |
40e084e1 KS |
885 | |
886 | return aea->pspace == aeb->pspace && aea->addr == aeb->addr; | |
887 | } | |
888 | ||
889 | /* Check whether the address, represented by PSPACE and ADDR, is | |
890 | already in the set. If so, return 0. Otherwise, add it and return | |
891 | 1. */ | |
892 | ||
893 | static int | |
894 | maybe_add_address (htab_t set, struct program_space *pspace, CORE_ADDR addr) | |
895 | { | |
896 | struct address_entry e, *p; | |
897 | void **slot; | |
898 | ||
899 | e.pspace = pspace; | |
900 | e.addr = addr; | |
901 | slot = htab_find_slot (set, &e, INSERT); | |
902 | if (*slot) | |
903 | return 0; | |
904 | ||
905 | p = XNEW (struct address_entry); | |
906 | memcpy (p, &e, sizeof (struct address_entry)); | |
907 | *slot = p; | |
908 | ||
909 | return 1; | |
910 | } | |
911 | ||
912 | /* A callback function and the additional data to call it with. */ | |
913 | ||
914 | struct symbol_and_data_callback | |
915 | { | |
916 | /* The callback to use. */ | |
917 | symbol_found_callback_ftype *callback; | |
918 | ||
919 | /* Data to be passed to the callback. */ | |
920 | void *data; | |
921 | }; | |
922 | ||
923 | /* A helper for iterate_over_all_matching_symtabs that is used to | |
924 | restrict calls to another callback to symbols representing inline | |
925 | symbols only. */ | |
926 | ||
927 | static int | |
928 | iterate_inline_only (struct symbol *sym, void *d) | |
929 | { | |
930 | if (SYMBOL_INLINED (sym)) | |
931 | { | |
9a3c8263 SM |
932 | struct symbol_and_data_callback *cad |
933 | = (struct symbol_and_data_callback *) d; | |
40e084e1 KS |
934 | |
935 | return cad->callback (sym, cad->data); | |
936 | } | |
937 | return 1; /* Continue iterating. */ | |
938 | } | |
939 | ||
940 | /* Some data for the expand_symtabs_matching callback. */ | |
941 | ||
942 | struct symbol_matcher_data | |
943 | { | |
944 | /* The lookup name against which symbol name should be compared. */ | |
945 | const char *lookup_name; | |
946 | ||
947 | /* The routine to be used for comparison. */ | |
948 | symbol_name_cmp_ftype symbol_name_cmp; | |
949 | }; | |
950 | ||
951 | /* A helper for iterate_over_all_matching_symtabs that is passed as a | |
952 | callback to the expand_symtabs_matching method. */ | |
953 | ||
954 | static int | |
955 | iterate_name_matcher (const char *name, void *d) | |
956 | { | |
9a3c8263 SM |
957 | const struct symbol_matcher_data *data |
958 | = (const struct symbol_matcher_data *) d; | |
40e084e1 | 959 | |
642a8d80 | 960 | if (data->symbol_name_cmp (name, data->lookup_name) == 0) |
40e084e1 KS |
961 | return 1; /* Expand this symbol's symbol table. */ |
962 | return 0; /* Skip this symbol. */ | |
963 | } | |
964 | ||
965 | /* A helper that walks over all matching symtabs in all objfiles and | |
966 | calls CALLBACK for each symbol matching NAME. If SEARCH_PSPACE is | |
967 | not NULL, then the search is restricted to just that program | |
968 | space. If INCLUDE_INLINE is nonzero then symbols representing | |
969 | inlined instances of functions will be included in the result. */ | |
970 | ||
971 | static void | |
972 | iterate_over_all_matching_symtabs (struct linespec_state *state, | |
973 | const char *name, | |
974 | const domain_enum domain, | |
975 | symbol_found_callback_ftype *callback, | |
976 | void *data, | |
977 | struct program_space *search_pspace, | |
978 | int include_inline) | |
979 | { | |
980 | struct objfile *objfile; | |
981 | struct program_space *pspace; | |
982 | struct symbol_matcher_data matcher_data; | |
983 | ||
984 | matcher_data.lookup_name = name; | |
985 | matcher_data.symbol_name_cmp = | |
986 | state->language->la_get_symbol_name_cmp != NULL | |
987 | ? state->language->la_get_symbol_name_cmp (name) | |
988 | : strcmp_iw; | |
989 | ||
990 | ALL_PSPACES (pspace) | |
991 | { | |
992 | if (search_pspace != NULL && search_pspace != pspace) | |
993 | continue; | |
994 | if (pspace->executing_startup) | |
f8eba3c6 TT |
995 | continue; |
996 | ||
997 | set_current_program_space (pspace); | |
50641945 | 998 | |
f8eba3c6 TT |
999 | ALL_OBJFILES (objfile) |
1000 | { | |
43f3e411 | 1001 | struct compunit_symtab *cu; |
f8eba3c6 TT |
1002 | |
1003 | if (objfile->sf) | |
1004 | objfile->sf->qf->expand_symtabs_matching (objfile, NULL, | |
1005 | iterate_name_matcher, | |
276d885b | 1006 | NULL, ALL_DOMAIN, |
74ccd7f5 | 1007 | &matcher_data); |
f8eba3c6 | 1008 | |
43f3e411 | 1009 | ALL_OBJFILE_COMPUNITS (objfile, cu) |
f8eba3c6 | 1010 | { |
43f3e411 DE |
1011 | struct symtab *symtab = COMPUNIT_FILETABS (cu); |
1012 | ||
4eeaa230 | 1013 | iterate_over_file_blocks (symtab, name, domain, callback, data); |
481860b3 | 1014 | |
d790cf0a DE |
1015 | if (include_inline) |
1016 | { | |
1017 | struct symbol_and_data_callback cad = { callback, data }; | |
4eeaa230 | 1018 | struct block *block; |
d790cf0a | 1019 | int i; |
481860b3 | 1020 | |
d790cf0a | 1021 | for (i = FIRST_LOCAL_BLOCK; |
439247b6 DE |
1022 | i < BLOCKVECTOR_NBLOCKS (SYMTAB_BLOCKVECTOR (symtab)); |
1023 | i++) | |
d790cf0a | 1024 | { |
439247b6 | 1025 | block = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab), i); |
4ae24af0 JB |
1026 | state->language->la_iterate_over_symbols |
1027 | (block, name, domain, iterate_inline_only, &cad); | |
481860b3 | 1028 | } |
f8eba3c6 TT |
1029 | } |
1030 | } | |
1031 | } | |
1032 | } | |
50641945 FN |
1033 | } |
1034 | ||
4eeaa230 DE |
1035 | /* Returns the block to be used for symbol searches from |
1036 | the current location. */ | |
e8eb7bc5 | 1037 | |
3977b71f | 1038 | static const struct block * |
e482a1a7 | 1039 | get_current_search_block (void) |
e8eb7bc5 | 1040 | { |
3977b71f | 1041 | const struct block *block; |
4eeaa230 | 1042 | enum language save_language; |
e8eb7bc5 | 1043 | |
4eeaa230 DE |
1044 | /* get_selected_block can change the current language when there is |
1045 | no selected frame yet. */ | |
1046 | save_language = current_language->la_language; | |
1047 | block = get_selected_block (0); | |
1048 | set_language (save_language); | |
e8eb7bc5 KS |
1049 | |
1050 | return block; | |
1051 | } | |
1052 | ||
4eeaa230 DE |
1053 | /* Iterate over static and global blocks. */ |
1054 | ||
1055 | static void | |
1056 | iterate_over_file_blocks (struct symtab *symtab, | |
1057 | const char *name, domain_enum domain, | |
1058 | symbol_found_callback_ftype *callback, void *data) | |
1059 | { | |
1060 | struct block *block; | |
1061 | ||
439247b6 | 1062 | for (block = BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab), STATIC_BLOCK); |
4eeaa230 DE |
1063 | block != NULL; |
1064 | block = BLOCK_SUPERBLOCK (block)) | |
1065 | LA_ITERATE_OVER_SYMBOLS (block, name, domain, callback, data); | |
1066 | } | |
1067 | ||
f8eba3c6 | 1068 | /* A helper for find_method. This finds all methods in type T which |
40e084e1 | 1069 | match NAME. It adds matching symbol names to RESULT_NAMES, and |
f8eba3c6 | 1070 | adds T's direct superclasses to SUPERCLASSES. */ |
50641945 | 1071 | |
f8eba3c6 TT |
1072 | static void |
1073 | find_methods (struct type *t, const char *name, | |
1074 | VEC (const_char_ptr) **result_names, | |
1075 | VEC (typep) **superclasses) | |
50641945 | 1076 | { |
50641945 | 1077 | int ibase; |
0d5cff50 | 1078 | const char *class_name = type_name_no_tag (t); |
c00f8484 | 1079 | |
50641945 FN |
1080 | /* Ignore this class if it doesn't have a name. This is ugly, but |
1081 | unless we figure out how to get the physname without the name of | |
1082 | the class, then the loop can't do any good. */ | |
f8eba3c6 | 1083 | if (class_name) |
50641945 FN |
1084 | { |
1085 | int method_counter; | |
1086 | ||
f168693b | 1087 | t = check_typedef (t); |
50641945 FN |
1088 | |
1089 | /* Loop over each method name. At this level, all overloads of a name | |
1090 | are counted as a single name. There is an inner loop which loops over | |
1091 | each overload. */ | |
1092 | ||
1093 | for (method_counter = TYPE_NFN_FIELDS (t) - 1; | |
1094 | method_counter >= 0; | |
1095 | --method_counter) | |
1096 | { | |
0d5cff50 | 1097 | const char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter); |
50641945 FN |
1098 | char dem_opname[64]; |
1099 | ||
61012eef GB |
1100 | if (startswith (method_name, "__") || |
1101 | startswith (method_name, "op") || | |
1102 | startswith (method_name, "type")) | |
50641945 FN |
1103 | { |
1104 | if (cplus_demangle_opname (method_name, dem_opname, DMGL_ANSI)) | |
1105 | method_name = dem_opname; | |
1106 | else if (cplus_demangle_opname (method_name, dem_opname, 0)) | |
1107 | method_name = dem_opname; | |
1108 | } | |
1109 | ||
f8eba3c6 TT |
1110 | if (strcmp_iw (method_name, name) == 0) |
1111 | { | |
1112 | int field_counter; | |
aee8d8ba | 1113 | |
f8eba3c6 TT |
1114 | for (field_counter = (TYPE_FN_FIELDLIST_LENGTH (t, method_counter) |
1115 | - 1); | |
1116 | field_counter >= 0; | |
1117 | --field_counter) | |
1118 | { | |
1119 | struct fn_field *f; | |
1120 | const char *phys_name; | |
1121 | ||
1122 | f = TYPE_FN_FIELDLIST1 (t, method_counter); | |
1123 | if (TYPE_FN_FIELD_STUB (f, field_counter)) | |
1124 | continue; | |
1125 | phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter); | |
1126 | VEC_safe_push (const_char_ptr, *result_names, phys_name); | |
1127 | } | |
1128 | } | |
aee8d8ba DC |
1129 | } |
1130 | } | |
1131 | ||
f8eba3c6 TT |
1132 | for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++) |
1133 | VEC_safe_push (typep, *superclasses, TYPE_BASECLASS (t, ibase)); | |
50641945 FN |
1134 | } |
1135 | ||
50641945 FN |
1136 | /* Find an instance of the character C in the string S that is outside |
1137 | of all parenthesis pairs, single-quoted strings, and double-quoted | |
8120c9d5 EZ |
1138 | strings. Also, ignore the char within a template name, like a ',' |
1139 | within foo<int, int>. */ | |
1140 | ||
87f0e720 | 1141 | const char * |
40e084e1 | 1142 | find_toplevel_char (const char *s, char c) |
50641945 FN |
1143 | { |
1144 | int quoted = 0; /* zero if we're not in quotes; | |
1145 | '"' if we're in a double-quoted string; | |
1146 | '\'' if we're in a single-quoted string. */ | |
a04257e6 | 1147 | int depth = 0; /* Number of unclosed parens we've seen. */ |
40e084e1 | 1148 | const char *scan; |
50641945 FN |
1149 | |
1150 | for (scan = s; *scan; scan++) | |
1151 | { | |
1152 | if (quoted) | |
1153 | { | |
1154 | if (*scan == quoted) | |
1155 | quoted = 0; | |
1156 | else if (*scan == '\\' && *(scan + 1)) | |
1157 | scan++; | |
1158 | } | |
1159 | else if (*scan == c && ! quoted && depth == 0) | |
1160 | return scan; | |
1161 | else if (*scan == '"' || *scan == '\'') | |
1162 | quoted = *scan; | |
8120c9d5 | 1163 | else if (*scan == '(' || *scan == '<') |
50641945 | 1164 | depth++; |
8120c9d5 | 1165 | else if ((*scan == ')' || *scan == '>') && depth > 0) |
50641945 FN |
1166 | depth--; |
1167 | } | |
1168 | ||
1169 | return 0; | |
1170 | } | |
1171 | ||
40e084e1 KS |
1172 | /* The string equivalent of find_toplevel_char. Returns a pointer |
1173 | to the location of NEEDLE in HAYSTACK, ignoring any occurrences | |
1174 | inside "()" and "<>". Returns NULL if NEEDLE was not found. */ | |
889f28e2 | 1175 | |
40e084e1 KS |
1176 | static const char * |
1177 | find_toplevel_string (const char *haystack, const char *needle) | |
889f28e2 | 1178 | { |
40e084e1 KS |
1179 | const char *s = haystack; |
1180 | ||
1181 | do | |
1182 | { | |
1183 | s = find_toplevel_char (s, *needle); | |
1184 | ||
1185 | if (s != NULL) | |
1186 | { | |
1187 | /* Found first char in HAYSTACK; check rest of string. */ | |
61012eef | 1188 | if (startswith (s, needle)) |
40e084e1 KS |
1189 | return s; |
1190 | ||
1191 | /* Didn't find it; loop over HAYSTACK, looking for the next | |
1192 | instance of the first character of NEEDLE. */ | |
1193 | ++s; | |
1194 | } | |
1195 | } | |
1196 | while (s != NULL && *s != '\0'); | |
1197 | ||
1198 | /* NEEDLE was not found in HAYSTACK. */ | |
1199 | return NULL; | |
889f28e2 AF |
1200 | } |
1201 | ||
33f448b1 JK |
1202 | /* Convert CANONICAL to its string representation using |
1203 | symtab_to_fullname for SYMTAB. The caller must xfree the result. */ | |
1204 | ||
1205 | static char * | |
1206 | canonical_to_fullform (const struct linespec_canonical_name *canonical) | |
1207 | { | |
1208 | if (canonical->symtab == NULL) | |
1209 | return xstrdup (canonical->suffix); | |
1210 | else | |
1211 | return xstrprintf ("%s:%s", symtab_to_fullname (canonical->symtab), | |
1212 | canonical->suffix); | |
1213 | } | |
1214 | ||
f8eba3c6 TT |
1215 | /* Given FILTERS, a list of canonical names, filter the sals in RESULT |
1216 | and store the result in SELF->CANONICAL. */ | |
50641945 | 1217 | |
f8eba3c6 TT |
1218 | static void |
1219 | filter_results (struct linespec_state *self, | |
1220 | struct symtabs_and_lines *result, | |
1221 | VEC (const_char_ptr) *filters) | |
1222 | { | |
1223 | int i; | |
1224 | const char *name; | |
1225 | ||
1226 | for (i = 0; VEC_iterate (const_char_ptr, filters, i, name); ++i) | |
1227 | { | |
1228 | struct linespec_sals lsal; | |
1229 | int j; | |
1230 | ||
1231 | memset (&lsal, 0, sizeof (lsal)); | |
1232 | ||
1233 | for (j = 0; j < result->nelts; ++j) | |
1234 | { | |
33f448b1 JK |
1235 | const struct linespec_canonical_name *canonical; |
1236 | char *fullform; | |
1237 | struct cleanup *cleanup; | |
1238 | ||
1239 | canonical = &self->canonical_names[j]; | |
1240 | fullform = canonical_to_fullform (canonical); | |
1241 | cleanup = make_cleanup (xfree, fullform); | |
1242 | ||
1243 | if (strcmp (name, fullform) == 0) | |
f8eba3c6 | 1244 | add_sal_to_sals_basic (&lsal.sals, &result->sals[j]); |
33f448b1 JK |
1245 | |
1246 | do_cleanups (cleanup); | |
f8eba3c6 TT |
1247 | } |
1248 | ||
1249 | if (lsal.sals.nelts > 0) | |
1250 | { | |
1251 | lsal.canonical = xstrdup (name); | |
1252 | VEC_safe_push (linespec_sals, self->canonical->sals, &lsal); | |
1253 | } | |
1254 | } | |
1255 | ||
1256 | self->canonical->pre_expanded = 0; | |
1257 | } | |
1258 | ||
1259 | /* Store RESULT into SELF->CANONICAL. */ | |
1260 | ||
1261 | static void | |
1262 | convert_results_to_lsals (struct linespec_state *self, | |
1263 | struct symtabs_and_lines *result) | |
50641945 | 1264 | { |
f8eba3c6 TT |
1265 | struct linespec_sals lsal; |
1266 | ||
1267 | lsal.canonical = NULL; | |
1268 | lsal.sals = *result; | |
1269 | VEC_safe_push (linespec_sals, self->canonical->sals, &lsal); | |
1270 | } | |
1271 | ||
33f448b1 JK |
1272 | /* A structure that contains two string representations of a struct |
1273 | linespec_canonical_name: | |
1274 | - one where the the symtab's fullname is used; | |
1275 | - one where the filename followed the "set filename-display" | |
1276 | setting. */ | |
1277 | ||
1278 | struct decode_line_2_item | |
1279 | { | |
1280 | /* The form using symtab_to_fullname. | |
1281 | It must be xfree'ed after use. */ | |
1282 | char *fullform; | |
1283 | ||
1284 | /* The form using symtab_to_filename_for_display. | |
1285 | It must be xfree'ed after use. */ | |
1286 | char *displayform; | |
1287 | ||
1288 | /* Field is initialized to zero and it is set to one if the user | |
1289 | requested breakpoint for this entry. */ | |
1290 | unsigned int selected : 1; | |
1291 | }; | |
1292 | ||
1293 | /* Helper for qsort to sort decode_line_2_item entries by DISPLAYFORM and | |
1294 | secondarily by FULLFORM. */ | |
1295 | ||
1296 | static int | |
1297 | decode_line_2_compare_items (const void *ap, const void *bp) | |
1298 | { | |
9a3c8263 SM |
1299 | const struct decode_line_2_item *a = (const struct decode_line_2_item *) ap; |
1300 | const struct decode_line_2_item *b = (const struct decode_line_2_item *) bp; | |
33f448b1 JK |
1301 | int retval; |
1302 | ||
1303 | retval = strcmp (a->displayform, b->displayform); | |
1304 | if (retval != 0) | |
1305 | return retval; | |
1306 | ||
1307 | return strcmp (a->fullform, b->fullform); | |
1308 | } | |
1309 | ||
f8eba3c6 TT |
1310 | /* Handle multiple results in RESULT depending on SELECT_MODE. This |
1311 | will either return normally, throw an exception on multiple | |
1312 | results, or present a menu to the user. On return, the SALS vector | |
1313 | in SELF->CANONICAL is set up properly. */ | |
1314 | ||
1315 | static void | |
1316 | decode_line_2 (struct linespec_state *self, | |
1317 | struct symtabs_and_lines *result, | |
1318 | const char *select_mode) | |
1319 | { | |
f8eba3c6 | 1320 | char *args, *prompt; |
50641945 | 1321 | int i; |
50641945 | 1322 | struct cleanup *old_chain; |
33f448b1 | 1323 | VEC (const_char_ptr) *filters = NULL; |
f8eba3c6 | 1324 | struct get_number_or_range_state state; |
33f448b1 JK |
1325 | struct decode_line_2_item *items; |
1326 | int items_count; | |
50641945 | 1327 | |
f8eba3c6 TT |
1328 | gdb_assert (select_mode != multiple_symbols_all); |
1329 | gdb_assert (self->canonical != NULL); | |
33f448b1 JK |
1330 | gdb_assert (result->nelts >= 1); |
1331 | ||
1332 | old_chain = make_cleanup (VEC_cleanup (const_char_ptr), &filters); | |
50641945 | 1333 | |
33f448b1 JK |
1334 | /* Prepare ITEMS array. */ |
1335 | items_count = result->nelts; | |
8d749320 | 1336 | items = XNEWVEC (struct decode_line_2_item, items_count); |
33f448b1 JK |
1337 | make_cleanup (xfree, items); |
1338 | for (i = 0; i < items_count; ++i) | |
50641945 | 1339 | { |
33f448b1 JK |
1340 | const struct linespec_canonical_name *canonical; |
1341 | struct decode_line_2_item *item; | |
1342 | ||
1343 | canonical = &self->canonical_names[i]; | |
1344 | gdb_assert (canonical->suffix != NULL); | |
1345 | item = &items[i]; | |
f8eba3c6 | 1346 | |
33f448b1 JK |
1347 | item->fullform = canonical_to_fullform (canonical); |
1348 | make_cleanup (xfree, item->fullform); | |
1349 | ||
1350 | if (canonical->symtab == NULL) | |
1351 | item->displayform = canonical->suffix; | |
1352 | else | |
f8eba3c6 | 1353 | { |
33f448b1 JK |
1354 | const char *fn_for_display; |
1355 | ||
1356 | fn_for_display = symtab_to_filename_for_display (canonical->symtab); | |
1357 | item->displayform = xstrprintf ("%s:%s", fn_for_display, | |
1358 | canonical->suffix); | |
1359 | make_cleanup (xfree, item->displayform); | |
f8eba3c6 TT |
1360 | } |
1361 | ||
33f448b1 | 1362 | item->selected = 0; |
50641945 FN |
1363 | } |
1364 | ||
33f448b1 JK |
1365 | /* Sort the list of method names. */ |
1366 | qsort (items, items_count, sizeof (*items), decode_line_2_compare_items); | |
1367 | ||
1368 | /* Remove entries with the same FULLFORM. */ | |
1369 | if (items_count >= 2) | |
1370 | { | |
1371 | struct decode_line_2_item *dst, *src; | |
1372 | ||
1373 | dst = items; | |
1374 | for (src = &items[1]; src < &items[items_count]; src++) | |
1375 | if (strcmp (src->fullform, dst->fullform) != 0) | |
1376 | *++dst = *src; | |
1377 | items_count = dst + 1 - items; | |
1378 | } | |
1379 | ||
1380 | if (select_mode == multiple_symbols_cancel && items_count > 1) | |
f8eba3c6 TT |
1381 | error (_("canceled because the command is ambiguous\n" |
1382 | "See set/show multiple-symbol.")); | |
1383 | ||
33f448b1 | 1384 | if (select_mode == multiple_symbols_all || items_count == 1) |
50641945 | 1385 | { |
f8eba3c6 TT |
1386 | do_cleanups (old_chain); |
1387 | convert_results_to_lsals (self, result); | |
1388 | return; | |
50641945 FN |
1389 | } |
1390 | ||
f8eba3c6 | 1391 | printf_unfiltered (_("[0] cancel\n[1] all\n")); |
33f448b1 JK |
1392 | for (i = 0; i < items_count; i++) |
1393 | printf_unfiltered ("[%d] %s\n", i + 2, items[i].displayform); | |
f8eba3c6 TT |
1394 | |
1395 | prompt = getenv ("PS2"); | |
1396 | if (prompt == NULL) | |
50641945 | 1397 | { |
f8eba3c6 | 1398 | prompt = "> "; |
50641945 | 1399 | } |
f8eba3c6 | 1400 | args = command_line_input (prompt, 0, "overload-choice"); |
50641945 FN |
1401 | |
1402 | if (args == 0 || *args == 0) | |
e2e0b3e5 | 1403 | error_no_arg (_("one or more choice numbers")); |
50641945 | 1404 | |
f8eba3c6 TT |
1405 | init_number_or_range (&state, args); |
1406 | while (!state.finished) | |
50641945 FN |
1407 | { |
1408 | int num; | |
1409 | ||
f8eba3c6 | 1410 | num = get_number_or_range (&state); |
50641945 FN |
1411 | |
1412 | if (num == 0) | |
8a3fe4f8 | 1413 | error (_("canceled")); |
50641945 FN |
1414 | else if (num == 1) |
1415 | { | |
f8eba3c6 TT |
1416 | /* We intentionally make this result in a single breakpoint, |
1417 | contrary to what older versions of gdb did. The | |
1418 | rationale is that this lets a user get the | |
1419 | multiple_symbols_all behavior even with the 'ask' | |
1420 | setting; and he can get separate breakpoints by entering | |
1421 | "2-57" at the query. */ | |
1422 | do_cleanups (old_chain); | |
1423 | convert_results_to_lsals (self, result); | |
1424 | return; | |
50641945 FN |
1425 | } |
1426 | ||
f8eba3c6 | 1427 | num -= 2; |
33f448b1 | 1428 | if (num >= items_count) |
f8eba3c6 | 1429 | printf_unfiltered (_("No choice number %d.\n"), num); |
50641945 FN |
1430 | else |
1431 | { | |
33f448b1 | 1432 | struct decode_line_2_item *item = &items[num]; |
f8eba3c6 | 1433 | |
33f448b1 | 1434 | if (!item->selected) |
50641945 | 1435 | { |
33f448b1 JK |
1436 | VEC_safe_push (const_char_ptr, filters, item->fullform); |
1437 | item->selected = 1; | |
50641945 FN |
1438 | } |
1439 | else | |
1440 | { | |
3e43a32a | 1441 | printf_unfiltered (_("duplicate request for %d ignored.\n"), |
f6f99966 | 1442 | num + 2); |
50641945 FN |
1443 | } |
1444 | } | |
50641945 | 1445 | } |
f8eba3c6 TT |
1446 | |
1447 | filter_results (self, result, filters); | |
1448 | do_cleanups (old_chain); | |
50641945 | 1449 | } |
94af9270 | 1450 | |
40e084e1 | 1451 | \f |
3d50dd94 | 1452 | |
40e084e1 KS |
1453 | /* The parser of linespec itself. */ |
1454 | ||
1455 | /* Throw an appropriate error when SYMBOL is not found (optionally in | |
1456 | FILENAME). */ | |
1457 | ||
1458 | static void ATTRIBUTE_NORETURN | |
5d94e27b | 1459 | symbol_not_found_error (const char *symbol, const char *filename) |
3d50dd94 | 1460 | { |
40e084e1 KS |
1461 | if (symbol == NULL) |
1462 | symbol = ""; | |
1463 | ||
1464 | if (!have_full_symbols () | |
1465 | && !have_partial_symbols () | |
1466 | && !have_minimal_symbols ()) | |
1467 | throw_error (NOT_FOUND_ERROR, | |
1468 | _("No symbol table is loaded. Use the \"file\" command.")); | |
1469 | ||
1470 | /* If SYMBOL starts with '$', the user attempted to either lookup | |
1471 | a function/variable in his code starting with '$' or an internal | |
1472 | variable of that name. Since we do not know which, be concise and | |
1473 | explain both possibilities. */ | |
1474 | if (*symbol == '$') | |
1475 | { | |
1476 | if (filename) | |
1477 | throw_error (NOT_FOUND_ERROR, | |
1478 | _("Undefined convenience variable or function \"%s\" " | |
1479 | "not defined in \"%s\"."), symbol, filename); | |
1480 | else | |
1481 | throw_error (NOT_FOUND_ERROR, | |
1482 | _("Undefined convenience variable or function \"%s\" " | |
1483 | "not defined."), symbol); | |
1484 | } | |
1485 | else | |
1486 | { | |
1487 | if (filename) | |
1488 | throw_error (NOT_FOUND_ERROR, | |
1489 | _("Function \"%s\" not defined in \"%s\"."), | |
1490 | symbol, filename); | |
1491 | else | |
1492 | throw_error (NOT_FOUND_ERROR, | |
1493 | _("Function \"%s\" not defined."), symbol); | |
1494 | } | |
3d50dd94 JK |
1495 | } |
1496 | ||
40e084e1 KS |
1497 | /* Throw an appropriate error when an unexpected token is encountered |
1498 | in the input. */ | |
94af9270 | 1499 | |
40e084e1 KS |
1500 | static void ATTRIBUTE_NORETURN |
1501 | unexpected_linespec_error (linespec_parser *parser) | |
94af9270 | 1502 | { |
40e084e1 KS |
1503 | linespec_token token; |
1504 | static const char * token_type_strings[] | |
1505 | = {"keyword", "colon", "string", "number", "comma", "end of input"}; | |
94af9270 | 1506 | |
40e084e1 KS |
1507 | /* Get the token that generated the error. */ |
1508 | token = linespec_lexer_lex_one (parser); | |
94af9270 | 1509 | |
40e084e1 KS |
1510 | /* Finally, throw the error. */ |
1511 | if (token.type == LSTOKEN_STRING || token.type == LSTOKEN_NUMBER | |
1512 | || token.type == LSTOKEN_KEYWORD) | |
94af9270 | 1513 | { |
40e084e1 KS |
1514 | char *string; |
1515 | struct cleanup *cleanup; | |
1516 | ||
1517 | string = copy_token_string (token); | |
1518 | cleanup = make_cleanup (xfree, string); | |
1519 | throw_error (GENERIC_ERROR, | |
1520 | _("malformed linespec error: unexpected %s, \"%s\""), | |
1521 | token_type_strings[token.type], string); | |
1522 | } | |
1523 | else | |
1524 | throw_error (GENERIC_ERROR, | |
1525 | _("malformed linespec error: unexpected %s"), | |
1526 | token_type_strings[token.type]); | |
1527 | } | |
1528 | ||
00e52e53 KS |
1529 | /* Throw an undefined label error. */ |
1530 | ||
1531 | static void ATTRIBUTE_NORETURN | |
1532 | undefined_label_error (const char *function, const char *label) | |
1533 | { | |
1534 | if (function != NULL) | |
1535 | throw_error (NOT_FOUND_ERROR, | |
1536 | _("No label \"%s\" defined in function \"%s\"."), | |
1537 | label, function); | |
1538 | else | |
1539 | throw_error (NOT_FOUND_ERROR, | |
1540 | _("No label \"%s\" defined in current function."), | |
1541 | label); | |
1542 | } | |
1543 | ||
1544 | /* Throw a source file not found error. */ | |
1545 | ||
1546 | static void ATTRIBUTE_NORETURN | |
1547 | source_file_not_found_error (const char *name) | |
1548 | { | |
1549 | throw_error (NOT_FOUND_ERROR, _("No source file named %s."), name); | |
1550 | } | |
1551 | ||
87f0e720 | 1552 | /* See description in linespec.h. */ |
40e084e1 | 1553 | |
87f0e720 | 1554 | struct line_offset |
09cf2b22 | 1555 | linespec_parse_line_offset (const char *string) |
40e084e1 | 1556 | { |
87f0e720 | 1557 | const char *start = string; |
40e084e1 KS |
1558 | struct line_offset line_offset = {0, LINE_OFFSET_NONE}; |
1559 | ||
1560 | if (*string == '+') | |
1561 | { | |
1562 | line_offset.sign = LINE_OFFSET_PLUS; | |
1563 | ++string; | |
1564 | } | |
1565 | else if (*string == '-') | |
1566 | { | |
1567 | line_offset.sign = LINE_OFFSET_MINUS; | |
1568 | ++string; | |
1569 | } | |
1570 | ||
87f0e720 KS |
1571 | if (*string != '\0' && !isdigit (*string)) |
1572 | error (_("malformed line offset: \"%s\""), start); | |
1573 | ||
40e084e1 KS |
1574 | /* Right now, we only allow base 10 for offsets. */ |
1575 | line_offset.offset = atoi (string); | |
1576 | return line_offset; | |
1577 | } | |
1578 | ||
1579 | /* Parse the basic_spec in PARSER's input. */ | |
1580 | ||
1581 | static void | |
1582 | linespec_parse_basic (linespec_parser *parser) | |
1583 | { | |
1584 | char *name; | |
1585 | linespec_token token; | |
1586 | VEC (symbolp) *symbols, *labels; | |
f60e2d5c | 1587 | VEC (bound_minimal_symbol_d) *minimal_symbols; |
40e084e1 KS |
1588 | struct cleanup *cleanup; |
1589 | ||
1590 | /* Get the next token. */ | |
1591 | token = linespec_lexer_lex_one (parser); | |
1592 | ||
1593 | /* If it is EOI or KEYWORD, issue an error. */ | |
1594 | if (token.type == LSTOKEN_KEYWORD || token.type == LSTOKEN_EOI) | |
1595 | unexpected_linespec_error (parser); | |
1596 | /* If it is a LSTOKEN_NUMBER, we have an offset. */ | |
1597 | else if (token.type == LSTOKEN_NUMBER) | |
1598 | { | |
1599 | /* Record the line offset and get the next token. */ | |
1600 | name = copy_token_string (token); | |
1601 | cleanup = make_cleanup (xfree, name); | |
00e52e53 | 1602 | PARSER_EXPLICIT (parser)->line_offset = linespec_parse_line_offset (name); |
40e084e1 KS |
1603 | do_cleanups (cleanup); |
1604 | ||
1605 | /* Get the next token. */ | |
1606 | token = linespec_lexer_consume_token (parser); | |
1607 | ||
1608 | /* If the next token is a comma, stop parsing and return. */ | |
1609 | if (token.type == LSTOKEN_COMMA) | |
1610 | return; | |
1611 | ||
1612 | /* If the next token is anything but EOI or KEYWORD, issue | |
1613 | an error. */ | |
1614 | if (token.type != LSTOKEN_KEYWORD && token.type != LSTOKEN_EOI) | |
1615 | unexpected_linespec_error (parser); | |
1616 | } | |
1617 | ||
1618 | if (token.type == LSTOKEN_KEYWORD || token.type == LSTOKEN_EOI) | |
1619 | return; | |
1620 | ||
1621 | /* Next token must be LSTOKEN_STRING. */ | |
1622 | if (token.type != LSTOKEN_STRING) | |
1623 | unexpected_linespec_error (parser); | |
1624 | ||
1625 | /* The current token will contain the name of a function, method, | |
1626 | or label. */ | |
1627 | name = copy_token_string (token); | |
1628 | cleanup = make_cleanup (xfree, name); | |
1629 | ||
1630 | /* Try looking it up as a function/method. */ | |
1631 | find_linespec_symbols (PARSER_STATE (parser), | |
1632 | PARSER_RESULT (parser)->file_symtabs, name, | |
1633 | &symbols, &minimal_symbols); | |
1634 | ||
1635 | if (symbols != NULL || minimal_symbols != NULL) | |
1636 | { | |
1637 | PARSER_RESULT (parser)->function_symbols = symbols; | |
1638 | PARSER_RESULT (parser)->minimal_symbols = minimal_symbols; | |
00e52e53 | 1639 | PARSER_EXPLICIT (parser)->function_name = name; |
40e084e1 KS |
1640 | symbols = NULL; |
1641 | discard_cleanups (cleanup); | |
1642 | } | |
1643 | else | |
1644 | { | |
1645 | /* NAME was not a function or a method. So it must be a label | |
b4013987 | 1646 | name or user specified variable like "break foo.c:$zippo". */ |
40e084e1 KS |
1647 | labels = find_label_symbols (PARSER_STATE (parser), NULL, |
1648 | &symbols, name); | |
1649 | if (labels != NULL) | |
94af9270 | 1650 | { |
40e084e1 KS |
1651 | PARSER_RESULT (parser)->labels.label_symbols = labels; |
1652 | PARSER_RESULT (parser)->labels.function_symbols = symbols; | |
00e52e53 | 1653 | PARSER_EXPLICIT (parser)->label_name = name; |
40e084e1 KS |
1654 | symbols = NULL; |
1655 | discard_cleanups (cleanup); | |
1656 | } | |
b4013987 AA |
1657 | else if (token.type == LSTOKEN_STRING |
1658 | && *LS_TOKEN_STOKEN (token).ptr == '$') | |
1659 | { | |
1660 | /* User specified a convenience variable or history value. */ | |
00e52e53 | 1661 | PARSER_EXPLICIT (parser)->line_offset |
b4013987 AA |
1662 | = linespec_parse_variable (PARSER_STATE (parser), name); |
1663 | ||
00e52e53 | 1664 | if (PARSER_EXPLICIT (parser)->line_offset.sign == LINE_OFFSET_UNKNOWN) |
b4013987 AA |
1665 | { |
1666 | /* The user-specified variable was not valid. Do not | |
1667 | throw an error here. parse_linespec will do it for us. */ | |
00e52e53 | 1668 | PARSER_EXPLICIT (parser)->function_name = name; |
b4013987 AA |
1669 | discard_cleanups (cleanup); |
1670 | return; | |
1671 | } | |
c888a17d KS |
1672 | |
1673 | /* The convenience variable/history value parsed correctly. | |
1674 | NAME is no longer needed. */ | |
1675 | do_cleanups (cleanup); | |
b4013987 | 1676 | } |
40e084e1 KS |
1677 | else |
1678 | { | |
1679 | /* The name is also not a label. Abort parsing. Do not throw | |
1680 | an error here. parse_linespec will do it for us. */ | |
1681 | ||
1682 | /* Save a copy of the name we were trying to lookup. */ | |
00e52e53 | 1683 | PARSER_EXPLICIT (parser)->function_name = name; |
40e084e1 KS |
1684 | discard_cleanups (cleanup); |
1685 | return; | |
1686 | } | |
1687 | } | |
1688 | ||
1689 | /* Get the next token. */ | |
1690 | token = linespec_lexer_consume_token (parser); | |
1691 | ||
1692 | if (token.type == LSTOKEN_COLON) | |
1693 | { | |
1694 | /* User specified a label or a lineno. */ | |
1695 | token = linespec_lexer_consume_token (parser); | |
1696 | ||
1697 | if (token.type == LSTOKEN_NUMBER) | |
1698 | { | |
1699 | /* User specified an offset. Record the line offset and | |
1700 | get the next token. */ | |
1701 | name = copy_token_string (token); | |
1702 | cleanup = make_cleanup (xfree, name); | |
00e52e53 | 1703 | PARSER_EXPLICIT (parser)->line_offset |
40e084e1 KS |
1704 | = linespec_parse_line_offset (name); |
1705 | do_cleanups (cleanup); | |
1706 | ||
1707 | /* Ge the next token. */ | |
1708 | token = linespec_lexer_consume_token (parser); | |
1709 | } | |
1710 | else if (token.type == LSTOKEN_STRING) | |
1711 | { | |
1712 | /* Grab a copy of the label's name and look it up. */ | |
1713 | name = copy_token_string (token); | |
1714 | cleanup = make_cleanup (xfree, name); | |
1715 | labels = find_label_symbols (PARSER_STATE (parser), | |
1716 | PARSER_RESULT (parser)->function_symbols, | |
1717 | &symbols, name); | |
1718 | ||
1719 | if (labels != NULL) | |
94af9270 | 1720 | { |
40e084e1 KS |
1721 | PARSER_RESULT (parser)->labels.label_symbols = labels; |
1722 | PARSER_RESULT (parser)->labels.function_symbols = symbols; | |
00e52e53 | 1723 | PARSER_EXPLICIT (parser)->label_name = name; |
40e084e1 KS |
1724 | symbols = NULL; |
1725 | discard_cleanups (cleanup); | |
1726 | } | |
1727 | else | |
1728 | { | |
1729 | /* We don't know what it was, but it isn't a label. */ | |
00e52e53 KS |
1730 | undefined_label_error (PARSER_EXPLICIT (parser)->function_name, |
1731 | name); | |
40e084e1 KS |
1732 | } |
1733 | ||
1734 | /* Check for a line offset. */ | |
1735 | token = linespec_lexer_consume_token (parser); | |
1736 | if (token.type == LSTOKEN_COLON) | |
1737 | { | |
1738 | /* Get the next token. */ | |
1739 | token = linespec_lexer_consume_token (parser); | |
1740 | ||
1741 | /* It must be a line offset. */ | |
1742 | if (token.type != LSTOKEN_NUMBER) | |
1743 | unexpected_linespec_error (parser); | |
1744 | ||
1745 | /* Record the lione offset and get the next token. */ | |
1746 | name = copy_token_string (token); | |
1747 | cleanup = make_cleanup (xfree, name); | |
1748 | ||
00e52e53 | 1749 | PARSER_EXPLICIT (parser)->line_offset |
40e084e1 KS |
1750 | = linespec_parse_line_offset (name); |
1751 | do_cleanups (cleanup); | |
1752 | ||
1753 | /* Get the next token. */ | |
1754 | token = linespec_lexer_consume_token (parser); | |
94af9270 KS |
1755 | } |
1756 | } | |
40e084e1 KS |
1757 | else |
1758 | { | |
1759 | /* Trailing ':' in the input. Issue an error. */ | |
1760 | unexpected_linespec_error (parser); | |
1761 | } | |
94af9270 | 1762 | } |
40e084e1 | 1763 | } |
94af9270 | 1764 | |
40e084e1 | 1765 | /* Canonicalize the linespec contained in LS. The result is saved into |
00e52e53 KS |
1766 | STATE->canonical. This function handles both linespec and explicit |
1767 | locations. */ | |
40e084e1 KS |
1768 | |
1769 | static void | |
f00aae0f | 1770 | canonicalize_linespec (struct linespec_state *state, const linespec_p ls) |
40e084e1 | 1771 | { |
00e52e53 | 1772 | struct event_location *canon; |
67994074 | 1773 | struct explicit_location *explicit_loc; |
f00aae0f | 1774 | |
40e084e1 KS |
1775 | /* If canonicalization was not requested, no need to do anything. */ |
1776 | if (!state->canonical) | |
1777 | return; | |
1778 | ||
00e52e53 | 1779 | /* Save everything as an explicit location. */ |
67994074 KS |
1780 | canon = state->canonical->location |
1781 | = new_explicit_location (&ls->explicit_loc); | |
1782 | explicit_loc = get_explicit_location (canon); | |
40e084e1 | 1783 | |
67994074 | 1784 | if (explicit_loc->label_name != NULL) |
a06efdd6 | 1785 | { |
00e52e53 | 1786 | state->canonical->special_display = 1; |
40e084e1 | 1787 | |
67994074 | 1788 | if (explicit_loc->function_name == NULL) |
40e084e1 | 1789 | { |
a06efdd6 KS |
1790 | struct symbol *s; |
1791 | ||
1792 | /* No function was specified, so add the symbol name. */ | |
1793 | gdb_assert (ls->labels.function_symbols != NULL | |
1794 | && (VEC_length (symbolp, ls->labels.function_symbols) | |
1795 | == 1)); | |
1796 | s = VEC_index (symbolp, ls->labels.function_symbols, 0); | |
67994074 | 1797 | explicit_loc->function_name = xstrdup (SYMBOL_NATURAL_NAME (s)); |
40e084e1 | 1798 | } |
a06efdd6 | 1799 | } |
40e084e1 | 1800 | |
00e52e53 KS |
1801 | /* If this location originally came from a linespec, save a string |
1802 | representation of it for display and saving to file. */ | |
1803 | if (state->is_linespec) | |
a06efdd6 | 1804 | { |
67994074 | 1805 | char *linespec = explicit_location_to_linespec (explicit_loc); |
a06efdd6 | 1806 | |
00e52e53 KS |
1807 | set_event_location_string (canon, linespec); |
1808 | xfree (linespec); | |
1809 | } | |
94af9270 | 1810 | } |
c00f8484 | 1811 | |
40e084e1 | 1812 | /* Given a line offset in LS, construct the relevant SALs. */ |
c00f8484 | 1813 | |
40e084e1 KS |
1814 | static struct symtabs_and_lines |
1815 | create_sals_line_offset (struct linespec_state *self, | |
1816 | linespec_p ls) | |
c00f8484 | 1817 | { |
40e084e1 KS |
1818 | struct symtabs_and_lines values; |
1819 | struct symtab_and_line val; | |
1820 | int use_default = 0; | |
c00f8484 | 1821 | |
40e084e1 KS |
1822 | init_sal (&val); |
1823 | values.sals = NULL; | |
1824 | values.nelts = 0; | |
1825 | ||
1826 | /* This is where we need to make sure we have good defaults. | |
1827 | We must guarantee that this section of code is never executed | |
2e47c6ca | 1828 | when we are called with just a function name, since |
40e084e1 KS |
1829 | set_default_source_symtab_and_line uses |
1830 | select_source_symtab that calls us with such an argument. */ | |
1831 | ||
ec94af83 DE |
1832 | if (VEC_length (symtab_ptr, ls->file_symtabs) == 1 |
1833 | && VEC_index (symtab_ptr, ls->file_symtabs, 0) == NULL) | |
3d50dd94 | 1834 | { |
05cba821 JK |
1835 | const char *fullname; |
1836 | ||
40e084e1 | 1837 | set_current_program_space (self->program_space); |
c00f8484 | 1838 | |
40e084e1 KS |
1839 | /* Make sure we have at least a default source line. */ |
1840 | set_default_source_symtab_and_line (); | |
1841 | initialize_defaults (&self->default_symtab, &self->default_line); | |
05cba821 | 1842 | fullname = symtab_to_fullname (self->default_symtab); |
ec94af83 DE |
1843 | VEC_pop (symtab_ptr, ls->file_symtabs); |
1844 | VEC_free (symtab_ptr, ls->file_symtabs); | |
05cba821 | 1845 | ls->file_symtabs = collect_symtabs_from_filename (fullname); |
40e084e1 KS |
1846 | use_default = 1; |
1847 | } | |
c00f8484 | 1848 | |
67994074 KS |
1849 | val.line = ls->explicit_loc.line_offset.offset; |
1850 | switch (ls->explicit_loc.line_offset.sign) | |
40e084e1 KS |
1851 | { |
1852 | case LINE_OFFSET_PLUS: | |
67994074 | 1853 | if (ls->explicit_loc.line_offset.offset == 0) |
40e084e1 KS |
1854 | val.line = 5; |
1855 | if (use_default) | |
1856 | val.line = self->default_line + val.line; | |
1857 | break; | |
1858 | ||
1859 | case LINE_OFFSET_MINUS: | |
67994074 | 1860 | if (ls->explicit_loc.line_offset.offset == 0) |
40e084e1 KS |
1861 | val.line = 15; |
1862 | if (use_default) | |
1863 | val.line = self->default_line - val.line; | |
1864 | else | |
1865 | val.line = -val.line; | |
1866 | break; | |
1867 | ||
1868 | case LINE_OFFSET_NONE: | |
1869 | break; /* No need to adjust val.line. */ | |
1870 | } | |
1871 | ||
1872 | if (self->list_mode) | |
1873 | decode_digits_list_mode (self, ls, &values, val); | |
1874 | else | |
1875 | { | |
1876 | struct linetable_entry *best_entry = NULL; | |
1877 | int *filter; | |
3977b71f | 1878 | const struct block **blocks; |
40e084e1 KS |
1879 | struct cleanup *cleanup; |
1880 | struct symtabs_and_lines intermediate_results; | |
1881 | int i, j; | |
1882 | ||
1883 | intermediate_results.sals = NULL; | |
1884 | intermediate_results.nelts = 0; | |
1885 | ||
1886 | decode_digits_ordinary (self, ls, val.line, &intermediate_results, | |
1887 | &best_entry); | |
1888 | if (intermediate_results.nelts == 0 && best_entry != NULL) | |
1889 | decode_digits_ordinary (self, ls, best_entry->line, | |
1890 | &intermediate_results, &best_entry); | |
1891 | ||
1892 | cleanup = make_cleanup (xfree, intermediate_results.sals); | |
1893 | ||
1894 | /* For optimized code, the compiler can scatter one source line | |
1895 | across disjoint ranges of PC values, even when no duplicate | |
1896 | functions or inline functions are involved. For example, | |
1897 | 'for (;;)' inside a non-template, non-inline, and non-ctor-or-dtor | |
1898 | function can result in two PC ranges. In this case, we don't | |
1899 | want to set a breakpoint on the first PC of each range. To filter | |
1900 | such cases, we use containing blocks -- for each PC found | |
1901 | above, we see if there are other PCs that are in the same | |
1902 | block. If yes, the other PCs are filtered out. */ | |
1903 | ||
1904 | filter = XNEWVEC (int, intermediate_results.nelts); | |
1905 | make_cleanup (xfree, filter); | |
3977b71f | 1906 | blocks = XNEWVEC (const struct block *, intermediate_results.nelts); |
40e084e1 KS |
1907 | make_cleanup (xfree, blocks); |
1908 | ||
1909 | for (i = 0; i < intermediate_results.nelts; ++i) | |
3d50dd94 | 1910 | { |
40e084e1 | 1911 | set_current_program_space (intermediate_results.sals[i].pspace); |
c00f8484 | 1912 | |
40e084e1 KS |
1913 | filter[i] = 1; |
1914 | blocks[i] = block_for_pc_sect (intermediate_results.sals[i].pc, | |
1915 | intermediate_results.sals[i].section); | |
3d50dd94 | 1916 | } |
c00f8484 | 1917 | |
40e084e1 KS |
1918 | for (i = 0; i < intermediate_results.nelts; ++i) |
1919 | { | |
1920 | if (blocks[i] != NULL) | |
1921 | for (j = i + 1; j < intermediate_results.nelts; ++j) | |
1922 | { | |
1923 | if (blocks[j] == blocks[i]) | |
1924 | { | |
1925 | filter[j] = 0; | |
1926 | break; | |
1927 | } | |
1928 | } | |
1929 | } | |
c00f8484 | 1930 | |
40e084e1 KS |
1931 | for (i = 0; i < intermediate_results.nelts; ++i) |
1932 | if (filter[i]) | |
1933 | { | |
1934 | struct symbol *sym = (blocks[i] | |
1935 | ? block_containing_function (blocks[i]) | |
1936 | : NULL); | |
3d50dd94 | 1937 | |
40e084e1 KS |
1938 | if (self->funfirstline) |
1939 | skip_prologue_sal (&intermediate_results.sals[i]); | |
1940 | /* Make sure the line matches the request, not what was | |
1941 | found. */ | |
1942 | intermediate_results.sals[i].line = val.line; | |
1943 | add_sal_to_sals (self, &values, &intermediate_results.sals[i], | |
66f1999b | 1944 | sym ? SYMBOL_NATURAL_NAME (sym) : NULL, 0); |
40e084e1 | 1945 | } |
3d50dd94 | 1946 | |
40e084e1 | 1947 | do_cleanups (cleanup); |
f17170e5 | 1948 | } |
c00f8484 | 1949 | |
40e084e1 KS |
1950 | if (values.nelts == 0) |
1951 | { | |
67994074 | 1952 | if (ls->explicit_loc.source_filename) |
40e084e1 | 1953 | throw_error (NOT_FOUND_ERROR, _("No line %d in file \"%s\"."), |
67994074 | 1954 | val.line, ls->explicit_loc.source_filename); |
40e084e1 KS |
1955 | else |
1956 | throw_error (NOT_FOUND_ERROR, _("No line %d in the current file."), | |
1957 | val.line); | |
1958 | } | |
3d50dd94 | 1959 | |
40e084e1 | 1960 | return values; |
c00f8484 KS |
1961 | } |
1962 | ||
a06efdd6 KS |
1963 | /* Convert the given ADDRESS into SaLs. */ |
1964 | ||
1965 | static struct symtabs_and_lines | |
1966 | convert_address_location_to_sals (struct linespec_state *self, | |
1967 | CORE_ADDR address) | |
1968 | { | |
1969 | struct symtab_and_line sal; | |
1970 | struct symtabs_and_lines sals = {NULL, 0}; | |
1971 | ||
1972 | sal = find_pc_line (address, 0); | |
1973 | sal.pc = address; | |
1974 | sal.section = find_pc_overlay (address); | |
1975 | sal.explicit_pc = 1; | |
1976 | add_sal_to_sals (self, &sals, &sal, core_addr_to_string (address), 1); | |
1977 | ||
1978 | return sals; | |
1979 | } | |
1980 | ||
40e084e1 KS |
1981 | /* Create and return SALs from the linespec LS. */ |
1982 | ||
1983 | static struct symtabs_and_lines | |
1984 | convert_linespec_to_sals (struct linespec_state *state, linespec_p ls) | |
1985 | { | |
1986 | struct symtabs_and_lines sals = {NULL, 0}; | |
1987 | ||
a06efdd6 | 1988 | if (ls->labels.label_symbols != NULL) |
40e084e1 KS |
1989 | { |
1990 | /* We have just a bunch of functions/methods or labels. */ | |
1991 | int i; | |
1992 | struct symtab_and_line sal; | |
1993 | struct symbol *sym; | |
1994 | ||
1995 | for (i = 0; VEC_iterate (symbolp, ls->labels.label_symbols, i, sym); ++i) | |
1996 | { | |
08be3fe3 | 1997 | struct program_space *pspace = SYMTAB_PSPACE (symbol_symtab (sym)); |
fdbb204b TT |
1998 | |
1999 | if (symbol_to_sal (&sal, state->funfirstline, sym) | |
2000 | && maybe_add_address (state->addr_set, pspace, sal.pc)) | |
64b92e45 KS |
2001 | add_sal_to_sals (state, &sals, &sal, |
2002 | SYMBOL_NATURAL_NAME (sym), 0); | |
40e084e1 KS |
2003 | } |
2004 | } | |
2005 | else if (ls->function_symbols != NULL || ls->minimal_symbols != NULL) | |
2006 | { | |
2007 | /* We have just a bunch of functions and/or methods. */ | |
2008 | int i; | |
2009 | struct symtab_and_line sal; | |
2010 | struct symbol *sym; | |
f60e2d5c | 2011 | bound_minimal_symbol_d *elem; |
40e084e1 KS |
2012 | struct program_space *pspace; |
2013 | ||
2014 | if (ls->function_symbols != NULL) | |
2015 | { | |
2016 | /* Sort symbols so that symbols with the same program space are next | |
2017 | to each other. */ | |
2018 | qsort (VEC_address (symbolp, ls->function_symbols), | |
2019 | VEC_length (symbolp, ls->function_symbols), | |
2020 | sizeof (symbolp), compare_symbols); | |
2021 | ||
2022 | for (i = 0; VEC_iterate (symbolp, ls->function_symbols, i, sym); ++i) | |
2023 | { | |
08be3fe3 | 2024 | pspace = SYMTAB_PSPACE (symbol_symtab (sym)); |
40e084e1 | 2025 | set_current_program_space (pspace); |
64b92e45 KS |
2026 | if (symbol_to_sal (&sal, state->funfirstline, sym) |
2027 | && maybe_add_address (state->addr_set, pspace, sal.pc)) | |
66f1999b KS |
2028 | add_sal_to_sals (state, &sals, &sal, |
2029 | SYMBOL_NATURAL_NAME (sym), 0); | |
40e084e1 KS |
2030 | } |
2031 | } | |
2032 | ||
2033 | if (ls->minimal_symbols != NULL) | |
2034 | { | |
2035 | /* Sort minimal symbols by program space, too. */ | |
f60e2d5c TT |
2036 | qsort (VEC_address (bound_minimal_symbol_d, ls->minimal_symbols), |
2037 | VEC_length (bound_minimal_symbol_d, ls->minimal_symbols), | |
2038 | sizeof (bound_minimal_symbol_d), compare_msymbols); | |
40e084e1 KS |
2039 | |
2040 | for (i = 0; | |
f60e2d5c TT |
2041 | VEC_iterate (bound_minimal_symbol_d, ls->minimal_symbols, |
2042 | i, elem); | |
40e084e1 KS |
2043 | ++i) |
2044 | { | |
001822aa | 2045 | pspace = elem->objfile->pspace; |
40e084e1 KS |
2046 | set_current_program_space (pspace); |
2047 | minsym_found (state, elem->objfile, elem->minsym, &sals); | |
2048 | } | |
2049 | } | |
2050 | } | |
67994074 | 2051 | else if (ls->explicit_loc.line_offset.sign != LINE_OFFSET_UNKNOWN) |
40e084e1 KS |
2052 | { |
2053 | /* Only an offset was specified. */ | |
2054 | sals = create_sals_line_offset (state, ls); | |
2055 | ||
2056 | /* Make sure we have a filename for canonicalization. */ | |
67994074 | 2057 | if (ls->explicit_loc.source_filename == NULL) |
05cba821 JK |
2058 | { |
2059 | const char *fullname = symtab_to_fullname (state->default_symtab); | |
2060 | ||
e93ba630 JK |
2061 | /* It may be more appropriate to keep DEFAULT_SYMTAB in its symtab |
2062 | form so that displaying SOURCE_FILENAME can follow the current | |
2063 | FILENAME_DISPLAY_STRING setting. But as it is used only rarely | |
2064 | it has been kept for code simplicity only in absolute form. */ | |
67994074 | 2065 | ls->explicit_loc.source_filename = xstrdup (fullname); |
05cba821 | 2066 | } |
40e084e1 KS |
2067 | } |
2068 | else | |
2069 | { | |
2070 | /* We haven't found any results... */ | |
2071 | return sals; | |
2072 | } | |
2073 | ||
2074 | canonicalize_linespec (state, ls); | |
2075 | ||
2076 | if (sals.nelts > 0 && state->canonical != NULL) | |
2077 | state->canonical->pre_expanded = 1; | |
2078 | ||
2079 | return sals; | |
2080 | } | |
50641945 | 2081 | |
67994074 | 2082 | /* Convert the explicit location EXPLICIT_LOC into SaLs. */ |
00e52e53 KS |
2083 | |
2084 | static struct symtabs_and_lines | |
2085 | convert_explicit_location_to_sals (struct linespec_state *self, | |
2086 | linespec_p result, | |
67994074 | 2087 | const struct explicit_location *explicit_loc) |
00e52e53 KS |
2088 | { |
2089 | VEC (symbolp) *symbols, *labels; | |
2090 | VEC (bound_minimal_symbol_d) *minimal_symbols; | |
2091 | ||
67994074 | 2092 | if (explicit_loc->source_filename != NULL) |
00e52e53 KS |
2093 | { |
2094 | TRY | |
2095 | { | |
2096 | result->file_symtabs | |
67994074 | 2097 | = symtabs_from_filename (explicit_loc->source_filename); |
00e52e53 KS |
2098 | } |
2099 | CATCH (except, RETURN_MASK_ERROR) | |
2100 | { | |
67994074 | 2101 | source_file_not_found_error (explicit_loc->source_filename); |
00e52e53 KS |
2102 | } |
2103 | END_CATCH | |
67994074 KS |
2104 | result->explicit_loc.source_filename |
2105 | = xstrdup (explicit_loc->source_filename); | |
00e52e53 KS |
2106 | } |
2107 | else | |
2108 | { | |
2109 | /* A NULL entry means to use the default symtab. */ | |
2110 | VEC_safe_push (symtab_ptr, result->file_symtabs, NULL); | |
2111 | } | |
2112 | ||
67994074 | 2113 | if (explicit_loc->function_name != NULL) |
00e52e53 KS |
2114 | { |
2115 | find_linespec_symbols (self, result->file_symtabs, | |
67994074 | 2116 | explicit_loc->function_name, &symbols, |
00e52e53 KS |
2117 | &minimal_symbols); |
2118 | ||
2119 | if (symbols == NULL && minimal_symbols == NULL) | |
67994074 KS |
2120 | symbol_not_found_error (explicit_loc->function_name, |
2121 | result->explicit_loc.source_filename); | |
00e52e53 | 2122 | |
67994074 KS |
2123 | result->explicit_loc.function_name |
2124 | = xstrdup (explicit_loc->function_name); | |
00e52e53 KS |
2125 | result->function_symbols = symbols; |
2126 | result->minimal_symbols = minimal_symbols; | |
2127 | } | |
2128 | ||
67994074 | 2129 | if (explicit_loc->label_name != NULL) |
00e52e53 KS |
2130 | { |
2131 | symbols = NULL; | |
2132 | labels = find_label_symbols (self, result->function_symbols, | |
67994074 | 2133 | &symbols, explicit_loc->label_name); |
00e52e53 KS |
2134 | |
2135 | if (labels == NULL) | |
67994074 KS |
2136 | undefined_label_error (result->explicit_loc.function_name, |
2137 | explicit_loc->label_name); | |
00e52e53 | 2138 | |
67994074 | 2139 | result->explicit_loc.label_name = xstrdup (explicit_loc->label_name); |
00e52e53 KS |
2140 | result->labels.label_symbols = labels; |
2141 | result->labels.function_symbols = symbols; | |
2142 | } | |
2143 | ||
67994074 KS |
2144 | if (explicit_loc->line_offset.sign != LINE_OFFSET_UNKNOWN) |
2145 | result->explicit_loc.line_offset = explicit_loc->line_offset; | |
00e52e53 KS |
2146 | |
2147 | return convert_linespec_to_sals (self, result); | |
2148 | } | |
2149 | ||
40e084e1 | 2150 | /* Parse a string that specifies a linespec. |
50641945 | 2151 | |
40e084e1 | 2152 | The basic grammar of linespecs: |
50641945 | 2153 | |
a06efdd6 | 2154 | linespec -> var_spec | basic_spec |
40e084e1 | 2155 | var_spec -> '$' (STRING | NUMBER) |
50641945 | 2156 | |
40e084e1 KS |
2157 | basic_spec -> file_offset_spec | function_spec | label_spec |
2158 | file_offset_spec -> opt_file_spec offset_spec | |
2159 | function_spec -> opt_file_spec function_name_spec opt_label_spec | |
2160 | label_spec -> label_name_spec | |
50641945 | 2161 | |
40e084e1 KS |
2162 | opt_file_spec -> "" | file_name_spec ':' |
2163 | opt_label_spec -> "" | ':' label_name_spec | |
2164 | ||
2165 | file_name_spec -> STRING | |
2166 | function_name_spec -> STRING | |
2167 | label_name_spec -> STRING | |
2168 | function_name_spec -> STRING | |
2169 | offset_spec -> NUMBER | |
2170 | -> '+' NUMBER | |
2171 | -> '-' NUMBER | |
2172 | ||
2173 | This may all be followed by several keywords such as "if EXPR", | |
2174 | which we ignore. | |
2175 | ||
2176 | A comma will terminate parsing. | |
2177 | ||
2178 | The function may be an undebuggable function found in minimal symbol table. | |
50641945 FN |
2179 | |
2180 | If the argument FUNFIRSTLINE is nonzero, we want the first line | |
2181 | of real code inside a function when a function is specified, and it is | |
2182 | not OK to specify a variable or type to get its line number. | |
2183 | ||
2184 | DEFAULT_SYMTAB specifies the file to use if none is specified. | |
2185 | It defaults to current_source_symtab. | |
2186 | DEFAULT_LINE specifies the line number to use for relative | |
2187 | line numbers (that start with signs). Defaults to current_source_line. | |
2188 | If CANONICAL is non-NULL, store an array of strings containing the canonical | |
1777feb0 | 2189 | line specs there if necessary. Currently overloaded member functions and |
50641945 | 2190 | line numbers or static functions without a filename yield a canonical |
1777feb0 | 2191 | line spec. The array and the line spec strings are allocated on the heap, |
50641945 FN |
2192 | it is the callers responsibility to free them. |
2193 | ||
2194 | Note that it is possible to return zero for the symtab | |
2195 | if no file is validly specified. Callers must check that. | |
58438ac1 | 2196 | Also, the line number returned may be invalid. */ |
50641945 | 2197 | |
f00aae0f | 2198 | /* Parse the linespec in ARG. */ |
50641945 | 2199 | |
ad32032e | 2200 | static struct symtabs_and_lines |
f00aae0f | 2201 | parse_linespec (linespec_parser *parser, const char *arg) |
50641945 | 2202 | { |
40e084e1 KS |
2203 | linespec_token token; |
2204 | struct symtabs_and_lines values; | |
7556d4a4 | 2205 | struct gdb_exception file_exception = exception_none; |
40e084e1 KS |
2206 | struct cleanup *cleanup; |
2207 | ||
2208 | /* A special case to start. It has become quite popular for | |
2209 | IDEs to work around bugs in the previous parser by quoting | |
2210 | the entire linespec, so we attempt to deal with this nicely. */ | |
2211 | parser->is_quote_enclosed = 0; | |
f00aae0f KS |
2212 | if (!is_ada_operator (arg) |
2213 | && strchr (linespec_quote_characters, *arg) != NULL) | |
40e084e1 KS |
2214 | { |
2215 | const char *end; | |
9ef07c8c | 2216 | |
f00aae0f | 2217 | end = skip_quote_char (arg + 1, *arg); |
40e084e1 | 2218 | if (end != NULL && is_closing_quote_enclosed (end)) |
136e1c30 | 2219 | { |
f00aae0f | 2220 | /* Here's the special case. Skip ARG past the initial |
40e084e1 | 2221 | quote. */ |
f00aae0f | 2222 | ++arg; |
40e084e1 | 2223 | parser->is_quote_enclosed = 1; |
136e1c30 DE |
2224 | } |
2225 | } | |
e8eb7bc5 | 2226 | |
f00aae0f KS |
2227 | parser->lexer.saved_arg = arg; |
2228 | parser->lexer.stream = arg; | |
d2630e69 | 2229 | |
40e084e1 KS |
2230 | /* Initialize the default symtab and line offset. */ |
2231 | initialize_defaults (&PARSER_STATE (parser)->default_symtab, | |
2232 | &PARSER_STATE (parser)->default_line); | |
d2630e69 | 2233 | |
40e084e1 | 2234 | /* Objective-C shortcut. */ |
f00aae0f | 2235 | values = decode_objc (PARSER_STATE (parser), PARSER_RESULT (parser), arg); |
40e084e1 KS |
2236 | if (values.sals != NULL) |
2237 | return values; | |
e0881a8e | 2238 | |
40e084e1 | 2239 | /* Start parsing. */ |
d2630e69 | 2240 | |
40e084e1 KS |
2241 | /* Get the first token. */ |
2242 | token = linespec_lexer_lex_one (parser); | |
50641945 | 2243 | |
40e084e1 | 2244 | /* It must be either LSTOKEN_STRING or LSTOKEN_NUMBER. */ |
a06efdd6 | 2245 | if (token.type == LSTOKEN_STRING && *LS_TOKEN_STOKEN (token).ptr == '$') |
40e084e1 KS |
2246 | { |
2247 | char *var; | |
50641945 | 2248 | |
40e084e1 | 2249 | /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB. */ |
ec94af83 | 2250 | VEC_safe_push (symtab_ptr, PARSER_RESULT (parser)->file_symtabs, NULL); |
dcf9f4ab | 2251 | |
40e084e1 KS |
2252 | /* User specified a convenience variable or history value. */ |
2253 | var = copy_token_string (token); | |
2254 | cleanup = make_cleanup (xfree, var); | |
00e52e53 | 2255 | PARSER_EXPLICIT (parser)->line_offset |
40e084e1 | 2256 | = linespec_parse_variable (PARSER_STATE (parser), var); |
cf4ded82 | 2257 | do_cleanups (cleanup); |
f8eba3c6 | 2258 | |
40e084e1 KS |
2259 | /* If a line_offset wasn't found (VAR is the name of a user |
2260 | variable/function), then skip to normal symbol processing. */ | |
00e52e53 | 2261 | if (PARSER_EXPLICIT (parser)->line_offset.sign != LINE_OFFSET_UNKNOWN) |
40e084e1 | 2262 | { |
40e084e1 KS |
2263 | /* Consume this token. */ |
2264 | linespec_lexer_consume_token (parser); | |
dcf9f4ab | 2265 | |
40e084e1 | 2266 | goto convert_to_sals; |
50641945 | 2267 | } |
40e084e1 KS |
2268 | } |
2269 | else if (token.type != LSTOKEN_STRING && token.type != LSTOKEN_NUMBER) | |
2270 | unexpected_linespec_error (parser); | |
50641945 | 2271 | |
40e084e1 KS |
2272 | /* Shortcut: If the next token is not LSTOKEN_COLON, we know that |
2273 | this token cannot represent a filename. */ | |
2274 | token = linespec_lexer_peek_token (parser); | |
0e0b460e | 2275 | |
40e084e1 | 2276 | if (token.type == LSTOKEN_COLON) |
0e0b460e | 2277 | { |
40e084e1 | 2278 | char *user_filename; |
0e0b460e | 2279 | |
40e084e1 KS |
2280 | /* Get the current token again and extract the filename. */ |
2281 | token = linespec_lexer_lex_one (parser); | |
2282 | user_filename = copy_token_string (token); | |
50641945 | 2283 | |
40e084e1 | 2284 | /* Check if the input is a filename. */ |
492d29ea | 2285 | TRY |
40e084e1 KS |
2286 | { |
2287 | PARSER_RESULT (parser)->file_symtabs | |
2288 | = symtabs_from_filename (user_filename); | |
2289 | } | |
492d29ea | 2290 | CATCH (ex, RETURN_MASK_ERROR) |
7556d4a4 PA |
2291 | { |
2292 | file_exception = ex; | |
2293 | } | |
492d29ea | 2294 | END_CATCH |
50641945 | 2295 | |
40e084e1 KS |
2296 | if (file_exception.reason >= 0) |
2297 | { | |
2298 | /* Symtabs were found for the file. Record the filename. */ | |
00e52e53 | 2299 | PARSER_EXPLICIT (parser)->source_filename = user_filename; |
f8eba3c6 | 2300 | |
40e084e1 KS |
2301 | /* Get the next token. */ |
2302 | token = linespec_lexer_consume_token (parser); | |
50641945 | 2303 | |
40e084e1 KS |
2304 | /* This is LSTOKEN_COLON; consume it. */ |
2305 | linespec_lexer_consume_token (parser); | |
2306 | } | |
2307 | else | |
2308 | { | |
2309 | /* No symtabs found -- discard user_filename. */ | |
2310 | xfree (user_filename); | |
50641945 | 2311 | |
40e084e1 | 2312 | /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB. */ |
ec94af83 | 2313 | VEC_safe_push (symtab_ptr, PARSER_RESULT (parser)->file_symtabs, NULL); |
40e084e1 | 2314 | } |
50641945 | 2315 | } |
40e084e1 KS |
2316 | /* If the next token is not EOI, KEYWORD, or COMMA, issue an error. */ |
2317 | else if (token.type != LSTOKEN_EOI && token.type != LSTOKEN_KEYWORD | |
2318 | && token.type != LSTOKEN_COMMA) | |
d2630e69 | 2319 | { |
40e084e1 KS |
2320 | /* TOKEN is the _next_ token, not the one currently in the parser. |
2321 | Consuming the token will give the correct error message. */ | |
2322 | linespec_lexer_consume_token (parser); | |
2323 | unexpected_linespec_error (parser); | |
d2630e69 | 2324 | } |
50641945 FN |
2325 | else |
2326 | { | |
40e084e1 | 2327 | /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB. */ |
ec94af83 | 2328 | VEC_safe_push (symtab_ptr, PARSER_RESULT (parser)->file_symtabs, NULL); |
50641945 | 2329 | } |
50641945 | 2330 | |
40e084e1 KS |
2331 | /* Parse the rest of the linespec. */ |
2332 | linespec_parse_basic (parser); | |
50641945 | 2333 | |
40e084e1 KS |
2334 | if (PARSER_RESULT (parser)->function_symbols == NULL |
2335 | && PARSER_RESULT (parser)->labels.label_symbols == NULL | |
00e52e53 | 2336 | && PARSER_EXPLICIT (parser)->line_offset.sign == LINE_OFFSET_UNKNOWN |
40e084e1 | 2337 | && PARSER_RESULT (parser)->minimal_symbols == NULL) |
f8eba3c6 | 2338 | { |
40e084e1 KS |
2339 | /* The linespec didn't parse. Re-throw the file exception if |
2340 | there was one. */ | |
2341 | if (file_exception.reason < 0) | |
2342 | throw_exception (file_exception); | |
0f5238ed | 2343 | |
40e084e1 | 2344 | /* Otherwise, the symbol is not found. */ |
00e52e53 KS |
2345 | symbol_not_found_error (PARSER_EXPLICIT (parser)->function_name, |
2346 | PARSER_EXPLICIT (parser)->source_filename); | |
0f5238ed TT |
2347 | } |
2348 | ||
40e084e1 | 2349 | convert_to_sals: |
9ef07c8c | 2350 | |
40e084e1 KS |
2351 | /* Get the last token and record how much of the input was parsed, |
2352 | if necessary. */ | |
2353 | token = linespec_lexer_lex_one (parser); | |
2354 | if (token.type != LSTOKEN_EOI && token.type != LSTOKEN_KEYWORD) | |
2355 | PARSER_STREAM (parser) = LS_TOKEN_STOKEN (token).ptr; | |
50641945 | 2356 | |
40e084e1 KS |
2357 | /* Convert the data in PARSER_RESULT to SALs. */ |
2358 | values = convert_linespec_to_sals (PARSER_STATE (parser), | |
2359 | PARSER_RESULT (parser)); | |
f8eba3c6 | 2360 | |
40e084e1 | 2361 | return values; |
413dad4d | 2362 | } |
50641945 | 2363 | |
40e084e1 | 2364 | |
f8eba3c6 | 2365 | /* A constructor for linespec_state. */ |
44fe14ab | 2366 | |
f8eba3c6 TT |
2367 | static void |
2368 | linespec_state_constructor (struct linespec_state *self, | |
40e084e1 | 2369 | int flags, const struct language_defn *language, |
f8eba3c6 TT |
2370 | struct symtab *default_symtab, |
2371 | int default_line, | |
2372 | struct linespec_result *canonical) | |
2373 | { | |
2374 | memset (self, 0, sizeof (*self)); | |
40e084e1 | 2375 | self->language = language; |
f8eba3c6 TT |
2376 | self->funfirstline = (flags & DECODE_LINE_FUNFIRSTLINE) ? 1 : 0; |
2377 | self->list_mode = (flags & DECODE_LINE_LIST_MODE) ? 1 : 0; | |
2378 | self->default_symtab = default_symtab; | |
2379 | self->default_line = default_line; | |
2380 | self->canonical = canonical; | |
2381 | self->program_space = current_program_space; | |
2382 | self->addr_set = htab_create_alloc (10, hash_address_entry, eq_address_entry, | |
2383 | xfree, xcalloc, xfree); | |
00e52e53 | 2384 | self->is_linespec = 0; |
f8eba3c6 | 2385 | } |
44fe14ab | 2386 | |
40e084e1 | 2387 | /* Initialize a new linespec parser. */ |
44fe14ab DC |
2388 | |
2389 | static void | |
40e084e1 KS |
2390 | linespec_parser_new (linespec_parser *parser, |
2391 | int flags, const struct language_defn *language, | |
2392 | struct symtab *default_symtab, | |
2393 | int default_line, | |
2394 | struct linespec_result *canonical) | |
44fe14ab | 2395 | { |
f00aae0f | 2396 | memset (parser, 0, sizeof (linespec_parser)); |
40e084e1 KS |
2397 | parser->lexer.current.type = LSTOKEN_CONSUMED; |
2398 | memset (PARSER_RESULT (parser), 0, sizeof (struct linespec)); | |
00e52e53 | 2399 | PARSER_EXPLICIT (parser)->line_offset.sign = LINE_OFFSET_UNKNOWN; |
40e084e1 KS |
2400 | linespec_state_constructor (PARSER_STATE (parser), flags, language, |
2401 | default_symtab, default_line, canonical); | |
2402 | } | |
2403 | ||
2404 | /* A destructor for linespec_state. */ | |
44fe14ab | 2405 | |
40e084e1 KS |
2406 | static void |
2407 | linespec_state_destructor (struct linespec_state *self) | |
2408 | { | |
f8eba3c6 TT |
2409 | htab_delete (self->addr_set); |
2410 | } | |
44fe14ab | 2411 | |
40e084e1 KS |
2412 | /* Delete a linespec parser. */ |
2413 | ||
2414 | static void | |
2415 | linespec_parser_delete (void *arg) | |
2416 | { | |
2417 | linespec_parser *parser = (linespec_parser *) arg; | |
2418 | ||
00e52e53 KS |
2419 | xfree (PARSER_EXPLICIT (parser)->source_filename); |
2420 | xfree (PARSER_EXPLICIT (parser)->label_name); | |
2421 | xfree (PARSER_EXPLICIT (parser)->function_name); | |
40e084e1 KS |
2422 | |
2423 | if (PARSER_RESULT (parser)->file_symtabs != NULL) | |
ec94af83 | 2424 | VEC_free (symtab_ptr, PARSER_RESULT (parser)->file_symtabs); |
40e084e1 KS |
2425 | |
2426 | if (PARSER_RESULT (parser)->function_symbols != NULL) | |
2427 | VEC_free (symbolp, PARSER_RESULT (parser)->function_symbols); | |
2428 | ||
2429 | if (PARSER_RESULT (parser)->minimal_symbols != NULL) | |
f60e2d5c | 2430 | VEC_free (bound_minimal_symbol_d, PARSER_RESULT (parser)->minimal_symbols); |
40e084e1 KS |
2431 | |
2432 | if (PARSER_RESULT (parser)->labels.label_symbols != NULL) | |
2433 | VEC_free (symbolp, PARSER_RESULT (parser)->labels.label_symbols); | |
2434 | ||
2435 | if (PARSER_RESULT (parser)->labels.function_symbols != NULL) | |
2436 | VEC_free (symbolp, PARSER_RESULT (parser)->labels.function_symbols); | |
2437 | ||
2438 | linespec_state_destructor (PARSER_STATE (parser)); | |
2439 | } | |
2440 | ||
c7c1b3e9 KS |
2441 | /* See description in linespec.h. */ |
2442 | ||
2443 | void | |
2444 | linespec_lex_to_end (char **stringp) | |
2445 | { | |
2446 | linespec_parser parser; | |
2447 | struct cleanup *cleanup; | |
2448 | linespec_token token; | |
c7c1b3e9 KS |
2449 | const char *orig; |
2450 | ||
2451 | if (stringp == NULL || *stringp == NULL) | |
2452 | return; | |
2453 | ||
2454 | linespec_parser_new (&parser, 0, current_language, NULL, 0, NULL); | |
2455 | cleanup = make_cleanup (linespec_parser_delete, &parser); | |
2456 | parser.lexer.saved_arg = *stringp; | |
2457 | PARSER_STREAM (&parser) = orig = *stringp; | |
2458 | ||
2459 | do | |
2460 | { | |
2461 | /* Stop before any comma tokens; we need it to keep it | |
2462 | as the next token in the string. */ | |
2463 | token = linespec_lexer_peek_token (&parser); | |
2464 | if (token.type == LSTOKEN_COMMA) | |
2465 | break; | |
c7c1b3e9 KS |
2466 | token = linespec_lexer_consume_token (&parser); |
2467 | } | |
2468 | while (token.type != LSTOKEN_EOI && token.type != LSTOKEN_KEYWORD); | |
2469 | ||
2470 | *stringp += PARSER_STREAM (&parser) - orig; | |
2471 | do_cleanups (cleanup); | |
2472 | } | |
2473 | ||
f00aae0f KS |
2474 | /* A helper function for decode_line_full and decode_line_1 to |
2475 | turn LOCATION into symtabs_and_lines. */ | |
2476 | ||
2477 | static struct symtabs_and_lines | |
2478 | event_location_to_sals (linespec_parser *parser, | |
2479 | const struct event_location *location) | |
2480 | { | |
2481 | struct symtabs_and_lines result = {NULL, 0}; | |
2482 | ||
2483 | switch (event_location_type (location)) | |
2484 | { | |
2485 | case LINESPEC_LOCATION: | |
2486 | { | |
00e52e53 | 2487 | PARSER_STATE (parser)->is_linespec = 1; |
f00aae0f KS |
2488 | TRY |
2489 | { | |
2490 | result = parse_linespec (parser, get_linespec_location (location)); | |
2491 | } | |
2492 | CATCH (except, RETURN_MASK_ERROR) | |
2493 | { | |
2494 | throw_exception (except); | |
2495 | } | |
2496 | END_CATCH | |
2497 | } | |
2498 | break; | |
2499 | ||
a06efdd6 KS |
2500 | case ADDRESS_LOCATION: |
2501 | result | |
2502 | = convert_address_location_to_sals (PARSER_STATE (parser), | |
2503 | get_address_location (location)); | |
2504 | break; | |
2505 | ||
00e52e53 KS |
2506 | case EXPLICIT_LOCATION: |
2507 | { | |
67994074 | 2508 | const struct explicit_location *explicit_loc; |
00e52e53 | 2509 | |
67994074 | 2510 | explicit_loc = get_explicit_location_const (location); |
00e52e53 KS |
2511 | result = convert_explicit_location_to_sals (PARSER_STATE (parser), |
2512 | PARSER_RESULT (parser), | |
67994074 | 2513 | explicit_loc); |
00e52e53 KS |
2514 | } |
2515 | break; | |
2516 | ||
5b56227b KS |
2517 | case PROBE_LOCATION: |
2518 | /* Probes are handled by their own decoders. */ | |
2519 | gdb_assert_not_reached ("attempt to decode probe location"); | |
2520 | break; | |
2521 | ||
f00aae0f KS |
2522 | default: |
2523 | gdb_assert_not_reached ("unhandled event location type"); | |
2524 | } | |
2525 | ||
2526 | return result; | |
2527 | } | |
2528 | ||
f8eba3c6 | 2529 | /* See linespec.h. */ |
44fe14ab | 2530 | |
f8eba3c6 | 2531 | void |
f00aae0f | 2532 | decode_line_full (const struct event_location *location, int flags, |
f8eba3c6 TT |
2533 | struct symtab *default_symtab, |
2534 | int default_line, struct linespec_result *canonical, | |
2535 | const char *select_mode, | |
2536 | const char *filter) | |
44fe14ab | 2537 | { |
f8eba3c6 | 2538 | struct symtabs_and_lines result; |
f8eba3c6 | 2539 | struct cleanup *cleanups; |
f8eba3c6 | 2540 | VEC (const_char_ptr) *filters = NULL; |
40e084e1 KS |
2541 | linespec_parser parser; |
2542 | struct linespec_state *state; | |
f8eba3c6 TT |
2543 | |
2544 | gdb_assert (canonical != NULL); | |
2545 | /* The filter only makes sense for 'all'. */ | |
2546 | gdb_assert (filter == NULL || select_mode == multiple_symbols_all); | |
2547 | gdb_assert (select_mode == NULL | |
2548 | || select_mode == multiple_symbols_all | |
2549 | || select_mode == multiple_symbols_ask | |
2550 | || select_mode == multiple_symbols_cancel); | |
2551 | gdb_assert ((flags & DECODE_LINE_LIST_MODE) == 0); | |
2552 | ||
40e084e1 KS |
2553 | linespec_parser_new (&parser, flags, current_language, default_symtab, |
2554 | default_line, canonical); | |
2555 | cleanups = make_cleanup (linespec_parser_delete, &parser); | |
f8eba3c6 TT |
2556 | save_current_program_space (); |
2557 | ||
f00aae0f | 2558 | result = event_location_to_sals (&parser, location); |
40e084e1 | 2559 | state = PARSER_STATE (&parser); |
f8eba3c6 TT |
2560 | |
2561 | gdb_assert (result.nelts == 1 || canonical->pre_expanded); | |
f8eba3c6 TT |
2562 | canonical->pre_expanded = 1; |
2563 | ||
66f1999b | 2564 | /* Arrange for allocated canonical names to be freed. */ |
f8eba3c6 TT |
2565 | if (result.nelts > 0) |
2566 | { | |
2567 | int i; | |
2568 | ||
40e084e1 | 2569 | make_cleanup (xfree, state->canonical_names); |
f8eba3c6 TT |
2570 | for (i = 0; i < result.nelts; ++i) |
2571 | { | |
33f448b1 JK |
2572 | gdb_assert (state->canonical_names[i].suffix != NULL); |
2573 | make_cleanup (xfree, state->canonical_names[i].suffix); | |
f8eba3c6 TT |
2574 | } |
2575 | } | |
2576 | ||
2577 | if (select_mode == NULL) | |
2578 | { | |
2579 | if (ui_out_is_mi_like_p (interp_ui_out (top_level_interpreter ()))) | |
2580 | select_mode = multiple_symbols_all; | |
2581 | else | |
2582 | select_mode = multiple_symbols_select_mode (); | |
2583 | } | |
2584 | ||
2585 | if (select_mode == multiple_symbols_all) | |
2586 | { | |
2587 | if (filter != NULL) | |
2588 | { | |
2589 | make_cleanup (VEC_cleanup (const_char_ptr), &filters); | |
2590 | VEC_safe_push (const_char_ptr, filters, filter); | |
40e084e1 | 2591 | filter_results (state, &result, filters); |
f8eba3c6 TT |
2592 | } |
2593 | else | |
40e084e1 | 2594 | convert_results_to_lsals (state, &result); |
f8eba3c6 TT |
2595 | } |
2596 | else | |
40e084e1 | 2597 | decode_line_2 (state, &result, select_mode); |
f8eba3c6 TT |
2598 | |
2599 | do_cleanups (cleanups); | |
2600 | } | |
2601 | ||
39cf75f7 DE |
2602 | /* See linespec.h. */ |
2603 | ||
f8eba3c6 | 2604 | struct symtabs_and_lines |
f00aae0f | 2605 | decode_line_1 (const struct event_location *location, int flags, |
f8eba3c6 TT |
2606 | struct symtab *default_symtab, |
2607 | int default_line) | |
2608 | { | |
2609 | struct symtabs_and_lines result; | |
40e084e1 | 2610 | linespec_parser parser; |
f8eba3c6 TT |
2611 | struct cleanup *cleanups; |
2612 | ||
40e084e1 KS |
2613 | linespec_parser_new (&parser, flags, current_language, default_symtab, |
2614 | default_line, NULL); | |
2615 | cleanups = make_cleanup (linespec_parser_delete, &parser); | |
f8eba3c6 TT |
2616 | save_current_program_space (); |
2617 | ||
f00aae0f | 2618 | result = event_location_to_sals (&parser, location); |
40e084e1 | 2619 | |
f8eba3c6 TT |
2620 | do_cleanups (cleanups); |
2621 | return result; | |
2622 | } | |
2623 | ||
39cf75f7 DE |
2624 | /* See linespec.h. */ |
2625 | ||
2626 | struct symtabs_and_lines | |
2627 | decode_line_with_current_source (char *string, int flags) | |
2628 | { | |
2629 | struct symtabs_and_lines sals; | |
2630 | struct symtab_and_line cursal; | |
f00aae0f KS |
2631 | struct event_location *location; |
2632 | struct cleanup *cleanup; | |
39cf75f7 DE |
2633 | |
2634 | if (string == 0) | |
2635 | error (_("Empty line specification.")); | |
2636 | ||
2637 | /* We use whatever is set as the current source line. We do not try | |
2638 | and get a default source symtab+line or it will recursively call us! */ | |
2639 | cursal = get_current_source_symtab_and_line (); | |
2640 | ||
f00aae0f KS |
2641 | location = string_to_event_location (&string, current_language); |
2642 | cleanup = make_cleanup_delete_event_location (location); | |
2643 | sals = decode_line_1 (location, flags, | |
39cf75f7 DE |
2644 | cursal.symtab, cursal.line); |
2645 | ||
2646 | if (*string) | |
2647 | error (_("Junk at end of line specification: %s"), string); | |
f00aae0f KS |
2648 | |
2649 | do_cleanups (cleanup); | |
39cf75f7 DE |
2650 | return sals; |
2651 | } | |
2652 | ||
2653 | /* See linespec.h. */ | |
2654 | ||
2655 | struct symtabs_and_lines | |
2656 | decode_line_with_last_displayed (char *string, int flags) | |
2657 | { | |
2658 | struct symtabs_and_lines sals; | |
f00aae0f KS |
2659 | struct event_location *location; |
2660 | struct cleanup *cleanup; | |
39cf75f7 DE |
2661 | |
2662 | if (string == 0) | |
2663 | error (_("Empty line specification.")); | |
2664 | ||
f00aae0f KS |
2665 | location = string_to_event_location (&string, current_language); |
2666 | cleanup = make_cleanup_delete_event_location (location); | |
39cf75f7 | 2667 | if (last_displayed_sal_is_valid ()) |
f00aae0f | 2668 | sals = decode_line_1 (location, flags, |
39cf75f7 DE |
2669 | get_last_displayed_symtab (), |
2670 | get_last_displayed_line ()); | |
2671 | else | |
f00aae0f | 2672 | sals = decode_line_1 (location, flags, (struct symtab *) NULL, 0); |
39cf75f7 DE |
2673 | |
2674 | if (*string) | |
2675 | error (_("Junk at end of line specification: %s"), string); | |
f00aae0f KS |
2676 | |
2677 | do_cleanups (cleanup); | |
39cf75f7 DE |
2678 | return sals; |
2679 | } | |
2680 | ||
f8eba3c6 TT |
2681 | \f |
2682 | ||
2683 | /* First, some functions to initialize stuff at the beggining of the | |
2684 | function. */ | |
2685 | ||
2686 | static void | |
2687 | initialize_defaults (struct symtab **default_symtab, int *default_line) | |
2688 | { | |
2689 | if (*default_symtab == 0) | |
2690 | { | |
2691 | /* Use whatever we have for the default source line. We don't use | |
2692 | get_current_or_default_symtab_and_line as it can recurse and call | |
2693 | us back! */ | |
2694 | struct symtab_and_line cursal = | |
2695 | get_current_source_symtab_and_line (); | |
2696 | ||
2697 | *default_symtab = cursal.symtab; | |
2698 | *default_line = cursal.line; | |
2699 | } | |
2700 | } | |
2701 | ||
2702 | \f | |
2703 | ||
40e084e1 KS |
2704 | /* Evaluate the expression pointed to by EXP_PTR into a CORE_ADDR, |
2705 | advancing EXP_PTR past any parsed text. */ | |
f8eba3c6 | 2706 | |
a06efdd6 | 2707 | CORE_ADDR |
bbc13ae3 | 2708 | linespec_expression_to_pc (const char **exp_ptr) |
f8eba3c6 | 2709 | { |
f8eba3c6 TT |
2710 | if (current_program_space->executing_startup) |
2711 | /* The error message doesn't really matter, because this case | |
2712 | should only hit during breakpoint reset. */ | |
2713 | throw_error (NOT_FOUND_ERROR, _("cannot evaluate expressions while " | |
2714 | "program space is in startup")); | |
2715 | ||
40e084e1 KS |
2716 | (*exp_ptr)++; |
2717 | return value_as_address (parse_to_comma_and_eval (exp_ptr)); | |
0960f083 DC |
2718 | } |
2719 | ||
2720 | \f | |
2721 | ||
d2630e69 AF |
2722 | /* Here's where we recognise an Objective-C Selector. An Objective C |
2723 | selector may be implemented by more than one class, therefore it | |
2724 | may represent more than one method/function. This gives us a | |
2725 | situation somewhat analogous to C++ overloading. If there's more | |
2726 | than one method that could represent the selector, then use some of | |
2727 | the existing C++ code to let the user choose one. */ | |
2728 | ||
f8eba3c6 | 2729 | static struct symtabs_and_lines |
f00aae0f | 2730 | decode_objc (struct linespec_state *self, linespec_p ls, const char *arg) |
d2630e69 | 2731 | { |
f8eba3c6 TT |
2732 | struct collect_info info; |
2733 | VEC (const_char_ptr) *symbol_names = NULL; | |
40e084e1 | 2734 | struct symtabs_and_lines values; |
d7561cbb | 2735 | const char *new_argptr; |
f8eba3c6 TT |
2736 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (const_char_ptr), |
2737 | &symbol_names); | |
2738 | ||
2739 | info.state = self; | |
40e084e1 | 2740 | info.file_symtabs = NULL; |
ec94af83 DE |
2741 | VEC_safe_push (symtab_ptr, info.file_symtabs, NULL); |
2742 | make_cleanup (VEC_cleanup (symtab_ptr), &info.file_symtabs); | |
40e084e1 KS |
2743 | info.result.symbols = NULL; |
2744 | info.result.minimal_symbols = NULL; | |
2745 | values.nelts = 0; | |
2746 | values.sals = NULL; | |
f8eba3c6 | 2747 | |
f00aae0f | 2748 | new_argptr = find_imps (arg, &symbol_names); |
f8eba3c6 TT |
2749 | if (VEC_empty (const_char_ptr, symbol_names)) |
2750 | { | |
2751 | do_cleanups (cleanup); | |
40e084e1 | 2752 | return values; |
f8eba3c6 | 2753 | } |
d2630e69 | 2754 | |
f8eba3c6 | 2755 | add_all_symbol_names_from_pspace (&info, NULL, symbol_names); |
d2630e69 | 2756 | |
40e084e1 | 2757 | if (!VEC_empty (symbolp, info.result.symbols) |
f60e2d5c | 2758 | || !VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols)) |
d2630e69 | 2759 | { |
f8eba3c6 | 2760 | char *saved_arg; |
d2630e69 | 2761 | |
224c3ddb | 2762 | saved_arg = (char *) alloca (new_argptr - arg + 1); |
f00aae0f KS |
2763 | memcpy (saved_arg, arg, new_argptr - arg); |
2764 | saved_arg[new_argptr - arg] = '\0'; | |
d2630e69 | 2765 | |
67994074 | 2766 | ls->explicit_loc.function_name = xstrdup (saved_arg); |
40e084e1 KS |
2767 | ls->function_symbols = info.result.symbols; |
2768 | ls->minimal_symbols = info.result.minimal_symbols; | |
2769 | values = convert_linespec_to_sals (self, ls); | |
2770 | ||
f8eba3c6 | 2771 | if (self->canonical) |
d2630e69 | 2772 | { |
f00aae0f KS |
2773 | char *str; |
2774 | ||
f8eba3c6 | 2775 | self->canonical->pre_expanded = 1; |
f00aae0f | 2776 | |
67994074 | 2777 | if (ls->explicit_loc.source_filename) |
f00aae0f KS |
2778 | { |
2779 | str = xstrprintf ("%s:%s", | |
67994074 | 2780 | ls->explicit_loc.source_filename, saved_arg); |
f00aae0f | 2781 | } |
f8eba3c6 | 2782 | else |
f00aae0f KS |
2783 | str = xstrdup (saved_arg); |
2784 | ||
2785 | make_cleanup (xfree, str); | |
2786 | self->canonical->location = new_linespec_location (&str); | |
d2630e69 | 2787 | } |
d2630e69 AF |
2788 | } |
2789 | ||
f8eba3c6 | 2790 | do_cleanups (cleanup); |
c00f8484 | 2791 | |
40e084e1 | 2792 | return values; |
f8eba3c6 | 2793 | } |
c00f8484 | 2794 | |
f8eba3c6 TT |
2795 | /* An instance of this type is used when collecting prefix symbols for |
2796 | decode_compound. */ | |
17763fd9 | 2797 | |
f8eba3c6 TT |
2798 | struct decode_compound_collector |
2799 | { | |
2800 | /* The result vector. */ | |
2801 | VEC (symbolp) *symbols; | |
3a93a0c2 | 2802 | |
f8eba3c6 TT |
2803 | /* A hash table of all symbols we found. We use this to avoid |
2804 | adding any symbol more than once. */ | |
2805 | htab_t unique_syms; | |
2806 | }; | |
3a93a0c2 | 2807 | |
f8eba3c6 TT |
2808 | /* A callback for iterate_over_symbols that is used by |
2809 | lookup_prefix_sym to collect type symbols. */ | |
c00f8484 | 2810 | |
f8eba3c6 TT |
2811 | static int |
2812 | collect_one_symbol (struct symbol *sym, void *d) | |
2813 | { | |
9a3c8263 SM |
2814 | struct decode_compound_collector *collector |
2815 | = (struct decode_compound_collector *) d; | |
f8eba3c6 TT |
2816 | void **slot; |
2817 | struct type *t; | |
614b3b14 | 2818 | |
f8eba3c6 | 2819 | if (SYMBOL_CLASS (sym) != LOC_TYPEDEF) |
8e704927 | 2820 | return 1; /* Continue iterating. */ |
f8eba3c6 TT |
2821 | |
2822 | t = SYMBOL_TYPE (sym); | |
f168693b | 2823 | t = check_typedef (t); |
f8eba3c6 TT |
2824 | if (TYPE_CODE (t) != TYPE_CODE_STRUCT |
2825 | && TYPE_CODE (t) != TYPE_CODE_UNION | |
2826 | && TYPE_CODE (t) != TYPE_CODE_NAMESPACE) | |
8e704927 | 2827 | return 1; /* Continue iterating. */ |
614b3b14 | 2828 | |
f8eba3c6 TT |
2829 | slot = htab_find_slot (collector->unique_syms, sym, INSERT); |
2830 | if (!*slot) | |
2831 | { | |
2832 | *slot = sym; | |
2833 | VEC_safe_push (symbolp, collector->symbols, sym); | |
2834 | } | |
2835 | ||
8e704927 | 2836 | return 1; /* Continue iterating. */ |
f8eba3c6 | 2837 | } |
93d91629 | 2838 | |
40e084e1 | 2839 | /* Return any symbols corresponding to CLASS_NAME in FILE_SYMTABS. */ |
93d91629 | 2840 | |
f8eba3c6 | 2841 | static VEC (symbolp) * |
ec94af83 | 2842 | lookup_prefix_sym (struct linespec_state *state, VEC (symtab_ptr) *file_symtabs, |
40e084e1 | 2843 | const char *class_name) |
93d91629 | 2844 | { |
f8eba3c6 TT |
2845 | int ix; |
2846 | struct symtab *elt; | |
2847 | struct decode_compound_collector collector; | |
2848 | struct cleanup *outer; | |
2849 | struct cleanup *cleanup; | |
17763fd9 | 2850 | |
f8eba3c6 | 2851 | collector.symbols = NULL; |
40e084e1 | 2852 | outer = make_cleanup (VEC_cleanup (symbolp), &collector.symbols); |
e0881a8e | 2853 | |
f8eba3c6 TT |
2854 | collector.unique_syms = htab_create_alloc (1, htab_hash_pointer, |
2855 | htab_eq_pointer, NULL, | |
2856 | xcalloc, xfree); | |
2857 | cleanup = make_cleanup_htab_delete (collector.unique_syms); | |
e0881a8e | 2858 | |
ec94af83 | 2859 | for (ix = 0; VEC_iterate (symtab_ptr, file_symtabs, ix, elt); ++ix) |
f8eba3c6 TT |
2860 | { |
2861 | if (elt == NULL) | |
2862 | { | |
40e084e1 | 2863 | iterate_over_all_matching_symtabs (state, class_name, STRUCT_DOMAIN, |
f8eba3c6 | 2864 | collect_one_symbol, &collector, |
481860b3 | 2865 | NULL, 0); |
40e084e1 | 2866 | iterate_over_all_matching_symtabs (state, class_name, VAR_DOMAIN, |
f8eba3c6 | 2867 | collect_one_symbol, &collector, |
481860b3 | 2868 | NULL, 0); |
f8eba3c6 TT |
2869 | } |
2870 | else | |
2871 | { | |
f8eba3c6 TT |
2872 | /* Program spaces that are executing startup should have |
2873 | been filtered out earlier. */ | |
2874 | gdb_assert (!SYMTAB_PSPACE (elt)->executing_startup); | |
2875 | set_current_program_space (SYMTAB_PSPACE (elt)); | |
4eeaa230 DE |
2876 | iterate_over_file_blocks (elt, class_name, STRUCT_DOMAIN, |
2877 | collect_one_symbol, &collector); | |
2878 | iterate_over_file_blocks (elt, class_name, VAR_DOMAIN, | |
2879 | collect_one_symbol, &collector); | |
1e5a1abc KS |
2880 | } |
2881 | } | |
2882 | ||
f8eba3c6 TT |
2883 | do_cleanups (cleanup); |
2884 | discard_cleanups (outer); | |
2885 | return collector.symbols; | |
93d91629 DC |
2886 | } |
2887 | ||
40e084e1 KS |
2888 | /* A qsort comparison function for symbols. The resulting order does |
2889 | not actually matter; we just need to be able to sort them so that | |
2890 | symbols with the same program space end up next to each other. */ | |
2891 | ||
2892 | static int | |
2893 | compare_symbols (const void *a, const void *b) | |
2894 | { | |
9a3c8263 SM |
2895 | struct symbol * const *sa = (struct symbol * const*) a; |
2896 | struct symbol * const *sb = (struct symbol * const*) b; | |
40e084e1 KS |
2897 | uintptr_t uia, uib; |
2898 | ||
08be3fe3 DE |
2899 | uia = (uintptr_t) SYMTAB_PSPACE (symbol_symtab (*sa)); |
2900 | uib = (uintptr_t) SYMTAB_PSPACE (symbol_symtab (*sb)); | |
40e084e1 KS |
2901 | |
2902 | if (uia < uib) | |
2903 | return -1; | |
2904 | if (uia > uib) | |
2905 | return 1; | |
2906 | ||
2907 | uia = (uintptr_t) *sa; | |
2908 | uib = (uintptr_t) *sb; | |
2909 | ||
2910 | if (uia < uib) | |
2911 | return -1; | |
2912 | if (uia > uib) | |
2913 | return 1; | |
2914 | ||
2915 | return 0; | |
2916 | } | |
2917 | ||
2918 | /* Like compare_symbols but for minimal symbols. */ | |
4224873a | 2919 | |
f8eba3c6 | 2920 | static int |
40e084e1 | 2921 | compare_msymbols (const void *a, const void *b) |
4224873a | 2922 | { |
9a3c8263 SM |
2923 | const struct bound_minimal_symbol *sa |
2924 | = (const struct bound_minimal_symbol *) a; | |
2925 | const struct bound_minimal_symbol *sb | |
2926 | = (const struct bound_minimal_symbol *) b; | |
f8eba3c6 TT |
2927 | uintptr_t uia, uib; |
2928 | ||
001822aa TT |
2929 | uia = (uintptr_t) sa->objfile->pspace; |
2930 | uib = (uintptr_t) sa->objfile->pspace; | |
f8eba3c6 TT |
2931 | |
2932 | if (uia < uib) | |
2933 | return -1; | |
2934 | if (uia > uib) | |
2935 | return 1; | |
2936 | ||
001822aa TT |
2937 | uia = (uintptr_t) sa->minsym; |
2938 | uib = (uintptr_t) sb->minsym; | |
f8eba3c6 TT |
2939 | |
2940 | if (uia < uib) | |
2941 | return -1; | |
2942 | if (uia > uib) | |
2943 | return 1; | |
2944 | ||
2945 | return 0; | |
2946 | } | |
2947 | ||
2948 | /* Look for all the matching instances of each symbol in NAMES. Only | |
2949 | instances from PSPACE are considered; other program spaces are | |
2950 | handled by our caller. If PSPACE is NULL, then all program spaces | |
2951 | are considered. Results are stored into INFO. */ | |
2952 | ||
2953 | static void | |
2954 | add_all_symbol_names_from_pspace (struct collect_info *info, | |
2955 | struct program_space *pspace, | |
2956 | VEC (const_char_ptr) *names) | |
2957 | { | |
2958 | int ix; | |
2959 | const char *iter; | |
2960 | ||
2961 | for (ix = 0; VEC_iterate (const_char_ptr, names, ix, iter); ++ix) | |
2962 | add_matching_symbols_to_info (iter, info, pspace); | |
2963 | } | |
2964 | ||
2965 | static void | |
2966 | find_superclass_methods (VEC (typep) *superclasses, | |
2967 | const char *name, | |
2968 | VEC (const_char_ptr) **result_names) | |
2969 | { | |
2970 | int old_len = VEC_length (const_char_ptr, *result_names); | |
2971 | VEC (typep) *iter_classes; | |
2972 | struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); | |
2973 | ||
2974 | iter_classes = superclasses; | |
2975 | while (1) | |
2976 | { | |
2977 | VEC (typep) *new_supers = NULL; | |
2978 | int ix; | |
2979 | struct type *t; | |
2980 | ||
2981 | make_cleanup (VEC_cleanup (typep), &new_supers); | |
2982 | for (ix = 0; VEC_iterate (typep, iter_classes, ix, t); ++ix) | |
2983 | find_methods (t, name, result_names, &new_supers); | |
2984 | ||
2985 | if (VEC_length (const_char_ptr, *result_names) != old_len | |
2986 | || VEC_empty (typep, new_supers)) | |
2987 | break; | |
4224873a | 2988 | |
f8eba3c6 TT |
2989 | iter_classes = new_supers; |
2990 | } | |
4224873a | 2991 | |
f8eba3c6 TT |
2992 | do_cleanups (cleanup); |
2993 | } | |
2994 | ||
40e084e1 KS |
2995 | /* This finds the method METHOD_NAME in the class CLASS_NAME whose type is |
2996 | given by one of the symbols in SYM_CLASSES. Matches are returned | |
2997 | in SYMBOLS (for debug symbols) and MINSYMS (for minimal symbols). */ | |
f8eba3c6 | 2998 | |
40e084e1 | 2999 | static void |
ec94af83 | 3000 | find_method (struct linespec_state *self, VEC (symtab_ptr) *file_symtabs, |
40e084e1 KS |
3001 | const char *class_name, const char *method_name, |
3002 | VEC (symbolp) *sym_classes, VEC (symbolp) **symbols, | |
f60e2d5c | 3003 | VEC (bound_minimal_symbol_d) **minsyms) |
f8eba3c6 | 3004 | { |
f8eba3c6 TT |
3005 | struct symbol *sym; |
3006 | struct cleanup *cleanup = make_cleanup (null_cleanup, NULL); | |
3007 | int ix; | |
3008 | int last_result_len; | |
3009 | VEC (typep) *superclass_vec; | |
3010 | VEC (const_char_ptr) *result_names; | |
3011 | struct collect_info info; | |
4224873a | 3012 | |
f8eba3c6 TT |
3013 | /* Sort symbols so that symbols with the same program space are next |
3014 | to each other. */ | |
3015 | qsort (VEC_address (symbolp, sym_classes), | |
3016 | VEC_length (symbolp, sym_classes), | |
3017 | sizeof (symbolp), | |
3018 | compare_symbols); | |
3019 | ||
3020 | info.state = self; | |
40e084e1 KS |
3021 | info.file_symtabs = file_symtabs; |
3022 | info.result.symbols = NULL; | |
3023 | info.result.minimal_symbols = NULL; | |
f8eba3c6 TT |
3024 | |
3025 | /* Iterate over all the types, looking for the names of existing | |
40e084e1 | 3026 | methods matching METHOD_NAME. If we cannot find a direct method in a |
f8eba3c6 TT |
3027 | given program space, then we consider inherited methods; this is |
3028 | not ideal (ideal would be to respect C++ hiding rules), but it | |
3029 | seems good enough and is what GDB has historically done. We only | |
3030 | need to collect the names because later we find all symbols with | |
3031 | those names. This loop is written in a somewhat funny way | |
3032 | because we collect data across the program space before deciding | |
3033 | what to do. */ | |
3034 | superclass_vec = NULL; | |
3035 | make_cleanup (VEC_cleanup (typep), &superclass_vec); | |
3036 | result_names = NULL; | |
3037 | make_cleanup (VEC_cleanup (const_char_ptr), &result_names); | |
3038 | last_result_len = 0; | |
3039 | for (ix = 0; VEC_iterate (symbolp, sym_classes, ix, sym); ++ix) | |
3040 | { | |
3041 | struct type *t; | |
3042 | struct program_space *pspace; | |
3043 | ||
3044 | /* Program spaces that are executing startup should have | |
3045 | been filtered out earlier. */ | |
08be3fe3 DE |
3046 | pspace = SYMTAB_PSPACE (symbol_symtab (sym)); |
3047 | gdb_assert (!pspace->executing_startup); | |
f8eba3c6 TT |
3048 | set_current_program_space (pspace); |
3049 | t = check_typedef (SYMBOL_TYPE (sym)); | |
40e084e1 | 3050 | find_methods (t, method_name, &result_names, &superclass_vec); |
f8eba3c6 TT |
3051 | |
3052 | /* Handle all items from a single program space at once; and be | |
3053 | sure not to miss the last batch. */ | |
3054 | if (ix == VEC_length (symbolp, sym_classes) - 1 | |
3055 | || (pspace | |
08be3fe3 | 3056 | != SYMTAB_PSPACE (symbol_symtab (VEC_index (symbolp, sym_classes, |
f8eba3c6 | 3057 | ix + 1))))) |
4224873a | 3058 | { |
f8eba3c6 TT |
3059 | /* If we did not find a direct implementation anywhere in |
3060 | this program space, consider superclasses. */ | |
3061 | if (VEC_length (const_char_ptr, result_names) == last_result_len) | |
40e084e1 KS |
3062 | find_superclass_methods (superclass_vec, method_name, |
3063 | &result_names); | |
f8eba3c6 TT |
3064 | |
3065 | /* We have a list of candidate symbol names, so now we | |
3066 | iterate over the symbol tables looking for all | |
3067 | matches in this pspace. */ | |
3068 | add_all_symbol_names_from_pspace (&info, pspace, result_names); | |
3069 | ||
3070 | VEC_truncate (typep, superclass_vec, 0); | |
3071 | last_result_len = VEC_length (const_char_ptr, result_names); | |
4224873a | 3072 | } |
4224873a | 3073 | } |
f8eba3c6 | 3074 | |
40e084e1 | 3075 | if (!VEC_empty (symbolp, info.result.symbols) |
f60e2d5c | 3076 | || !VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols)) |
4224873a | 3077 | { |
40e084e1 KS |
3078 | *symbols = info.result.symbols; |
3079 | *minsyms = info.result.minimal_symbols; | |
f8eba3c6 | 3080 | do_cleanups (cleanup); |
40e084e1 | 3081 | return; |
4224873a | 3082 | } |
f8eba3c6 | 3083 | |
40e084e1 KS |
3084 | /* Throw an NOT_FOUND_ERROR. This will be caught by the caller |
3085 | and other attempts to locate the symbol will be made. */ | |
3086 | throw_error (NOT_FOUND_ERROR, _("see caller, this text doesn't matter")); | |
f8eba3c6 TT |
3087 | } |
3088 | ||
3089 | \f | |
3090 | ||
3091 | /* This object is used when collecting all matching symtabs. */ | |
3092 | ||
3093 | struct symtab_collector | |
3094 | { | |
3095 | /* The result vector of symtabs. */ | |
ec94af83 | 3096 | VEC (symtab_ptr) *symtabs; |
f8eba3c6 TT |
3097 | |
3098 | /* This is used to ensure the symtabs are unique. */ | |
3099 | htab_t symtab_table; | |
3100 | }; | |
3101 | ||
3102 | /* Callback for iterate_over_symtabs. */ | |
3103 | ||
3104 | static int | |
3105 | add_symtabs_to_list (struct symtab *symtab, void *d) | |
3106 | { | |
9a3c8263 | 3107 | struct symtab_collector *data = (struct symtab_collector *) d; |
f8eba3c6 TT |
3108 | void **slot; |
3109 | ||
3110 | slot = htab_find_slot (data->symtab_table, symtab, INSERT); | |
3111 | if (!*slot) | |
4224873a | 3112 | { |
f8eba3c6 | 3113 | *slot = symtab; |
ec94af83 | 3114 | VEC_safe_push (symtab_ptr, data->symtabs, symtab); |
4224873a | 3115 | } |
f8eba3c6 TT |
3116 | |
3117 | return 0; | |
4224873a DC |
3118 | } |
3119 | ||
f8eba3c6 TT |
3120 | /* Given a file name, return a VEC of all matching symtabs. */ |
3121 | ||
ec94af83 | 3122 | static VEC (symtab_ptr) * |
f8eba3c6 TT |
3123 | collect_symtabs_from_filename (const char *file) |
3124 | { | |
3125 | struct symtab_collector collector; | |
3126 | struct cleanup *cleanups; | |
3127 | struct program_space *pspace; | |
3128 | ||
3129 | collector.symtabs = NULL; | |
3130 | collector.symtab_table = htab_create (1, htab_hash_pointer, htab_eq_pointer, | |
3131 | NULL); | |
3132 | cleanups = make_cleanup_htab_delete (collector.symtab_table); | |
3133 | ||
3134 | /* Find that file's data. */ | |
3135 | ALL_PSPACES (pspace) | |
3136 | { | |
3137 | if (pspace->executing_startup) | |
3138 | continue; | |
3139 | ||
3140 | set_current_program_space (pspace); | |
3141 | iterate_over_symtabs (file, add_symtabs_to_list, &collector); | |
3142 | } | |
f3c39e76 | 3143 | |
f8eba3c6 TT |
3144 | do_cleanups (cleanups); |
3145 | return collector.symtabs; | |
3146 | } | |
3147 | ||
40e084e1 | 3148 | /* Return all the symtabs associated to the FILENAME. */ |
f8eba3c6 | 3149 | |
ec94af83 | 3150 | static VEC (symtab_ptr) * |
40e084e1 KS |
3151 | symtabs_from_filename (const char *filename) |
3152 | { | |
ec94af83 | 3153 | VEC (symtab_ptr) *result; |
40e084e1 KS |
3154 | |
3155 | result = collect_symtabs_from_filename (filename); | |
f8eba3c6 | 3156 | |
ec94af83 | 3157 | if (VEC_empty (symtab_ptr, result)) |
f8eba3c6 | 3158 | { |
40e084e1 KS |
3159 | if (!have_full_symbols () && !have_partial_symbols ()) |
3160 | throw_error (NOT_FOUND_ERROR, | |
3161 | _("No symbol table is loaded. " | |
3162 | "Use the \"file\" command.")); | |
00e52e53 | 3163 | source_file_not_found_error (filename); |
f8eba3c6 TT |
3164 | } |
3165 | ||
40e084e1 | 3166 | return result; |
84fba31b | 3167 | } |
f3c39e76 | 3168 | |
40e084e1 KS |
3169 | /* Look up a function symbol named NAME in symtabs FILE_SYMTABS. Matching |
3170 | debug symbols are returned in SYMBOLS. Matching minimal symbols are | |
3171 | returned in MINSYMS. */ | |
14e91ac5 | 3172 | |
40e084e1 KS |
3173 | static void |
3174 | find_function_symbols (struct linespec_state *state, | |
ec94af83 | 3175 | VEC (symtab_ptr) *file_symtabs, const char *name, |
40e084e1 | 3176 | VEC (symbolp) **symbols, |
f60e2d5c | 3177 | VEC (bound_minimal_symbol_d) **minsyms) |
14e91ac5 | 3178 | { |
40e084e1 KS |
3179 | struct collect_info info; |
3180 | VEC (const_char_ptr) *symbol_names = NULL; | |
3181 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (const_char_ptr), | |
3182 | &symbol_names); | |
14e91ac5 | 3183 | |
40e084e1 KS |
3184 | info.state = state; |
3185 | info.result.symbols = NULL; | |
3186 | info.result.minimal_symbols = NULL; | |
3187 | info.file_symtabs = file_symtabs; | |
e0881a8e | 3188 | |
40e084e1 | 3189 | /* Try NAME as an Objective-C selector. */ |
d7561cbb | 3190 | find_imps (name, &symbol_names); |
40e084e1 KS |
3191 | if (!VEC_empty (const_char_ptr, symbol_names)) |
3192 | add_all_symbol_names_from_pspace (&info, NULL, symbol_names); | |
3193 | else | |
3194 | add_matching_symbols_to_info (name, &info, NULL); | |
3195 | ||
3196 | do_cleanups (cleanup); | |
3197 | ||
3198 | if (VEC_empty (symbolp, info.result.symbols)) | |
3199 | { | |
3200 | VEC_free (symbolp, info.result.symbols); | |
3201 | *symbols = NULL; | |
14e91ac5 DC |
3202 | } |
3203 | else | |
40e084e1 KS |
3204 | *symbols = info.result.symbols; |
3205 | ||
f60e2d5c | 3206 | if (VEC_empty (bound_minimal_symbol_d, info.result.minimal_symbols)) |
14e91ac5 | 3207 | { |
f60e2d5c | 3208 | VEC_free (bound_minimal_symbol_d, info.result.minimal_symbols); |
40e084e1 KS |
3209 | *minsyms = NULL; |
3210 | } | |
3211 | else | |
3212 | *minsyms = info.result.minimal_symbols; | |
3213 | } | |
3214 | ||
3215 | /* Find all symbols named NAME in FILE_SYMTABS, returning debug symbols | |
3216 | in SYMBOLS and minimal symbols in MINSYMS. */ | |
14e91ac5 | 3217 | |
b1ae631a | 3218 | static void |
40e084e1 | 3219 | find_linespec_symbols (struct linespec_state *state, |
ec94af83 | 3220 | VEC (symtab_ptr) *file_symtabs, |
40e084e1 KS |
3221 | const char *name, |
3222 | VEC (symbolp) **symbols, | |
f60e2d5c | 3223 | VEC (bound_minimal_symbol_d) **minsyms) |
40e084e1 | 3224 | { |
40e084e1 | 3225 | struct cleanup *cleanup; |
cc81e1c6 DE |
3226 | char *canon; |
3227 | const char *lookup_name; | |
f8eba3c6 | 3228 | |
40e084e1 KS |
3229 | cleanup = demangle_for_lookup (name, state->language->la_language, |
3230 | &lookup_name); | |
3231 | if (state->language->la_language == language_ada) | |
3232 | { | |
3233 | /* In Ada, the symbol lookups are performed using the encoded | |
3234 | name rather than the demangled name. */ | |
3235 | lookup_name = ada_name_for_lookup (name); | |
3236 | make_cleanup (xfree, (void *) lookup_name); | |
3237 | } | |
31aba06f | 3238 | |
40e084e1 KS |
3239 | canon = cp_canonicalize_string_no_typedefs (lookup_name); |
3240 | if (canon != NULL) | |
3241 | { | |
3242 | lookup_name = canon; | |
e61727ab | 3243 | make_cleanup (xfree, canon); |
40e084e1 | 3244 | } |
f8eba3c6 | 3245 | |
cc81e1c6 DE |
3246 | /* It's important to not call expand_symtabs_matching unnecessarily |
3247 | as it can really slow things down (by unnecessarily expanding | |
3248 | potentially 1000s of symtabs, which when debugging some apps can | |
3249 | cost 100s of seconds). Avoid this to some extent by *first* calling | |
3250 | find_function_symbols, and only if that doesn't find anything | |
3251 | *then* call find_method. This handles two important cases: | |
3252 | 1) break (anonymous namespace)::foo | |
3253 | 2) break class::method where method is in class (and not a baseclass) */ | |
14e91ac5 | 3254 | |
cc81e1c6 DE |
3255 | find_function_symbols (state, file_symtabs, lookup_name, |
3256 | symbols, minsyms); | |
14e91ac5 | 3257 | |
cc81e1c6 DE |
3258 | /* If we were unable to locate a symbol of the same name, try dividing |
3259 | the name into class and method names and searching the class and its | |
3260 | baseclasses. */ | |
3261 | if (VEC_empty (symbolp, *symbols) | |
f60e2d5c | 3262 | && VEC_empty (bound_minimal_symbol_d, *minsyms)) |
40e084e1 | 3263 | { |
cc81e1c6 DE |
3264 | char *klass, *method; |
3265 | const char *last, *p, *scope_op; | |
3266 | VEC (symbolp) *classes; | |
14e91ac5 | 3267 | |
cc81e1c6 DE |
3268 | /* See if we can find a scope operator and break this symbol |
3269 | name into namespaces${SCOPE_OPERATOR}class_name and method_name. */ | |
3270 | scope_op = "::"; | |
3271 | p = find_toplevel_string (lookup_name, scope_op); | |
3272 | if (p == NULL) | |
3273 | { | |
3274 | /* No C++ scope operator. Try Java. */ | |
3275 | scope_op = "."; | |
3276 | p = find_toplevel_string (lookup_name, scope_op); | |
3277 | } | |
14e91ac5 | 3278 | |
cc81e1c6 DE |
3279 | last = NULL; |
3280 | while (p != NULL) | |
f8eba3c6 | 3281 | { |
cc81e1c6 DE |
3282 | last = p; |
3283 | p = find_toplevel_string (p + strlen (scope_op), scope_op); | |
f8eba3c6 | 3284 | } |
14e91ac5 | 3285 | |
cc81e1c6 DE |
3286 | /* If no scope operator was found, there is nothing more we can do; |
3287 | we already attempted to lookup the entire name as a symbol | |
3288 | and failed. */ | |
3289 | if (last == NULL) | |
40e084e1 KS |
3290 | { |
3291 | do_cleanups (cleanup); | |
3292 | return; | |
3293 | } | |
cc81e1c6 DE |
3294 | |
3295 | /* LOOKUP_NAME points to the class name. | |
3296 | LAST points to the method name. */ | |
224c3ddb | 3297 | klass = XNEWVEC (char, last - lookup_name + 1); |
cc81e1c6 DE |
3298 | make_cleanup (xfree, klass); |
3299 | strncpy (klass, lookup_name, last - lookup_name); | |
3300 | klass[last - lookup_name] = '\0'; | |
3301 | ||
3302 | /* Skip past the scope operator. */ | |
3303 | last += strlen (scope_op); | |
224c3ddb | 3304 | method = XNEWVEC (char, strlen (last) + 1); |
cc81e1c6 DE |
3305 | make_cleanup (xfree, method); |
3306 | strcpy (method, last); | |
3307 | ||
3308 | /* Find a list of classes named KLASS. */ | |
3309 | classes = lookup_prefix_sym (state, file_symtabs, klass); | |
3310 | make_cleanup (VEC_cleanup (symbolp), &classes); | |
3311 | ||
3312 | if (!VEC_empty (symbolp, classes)) | |
3313 | { | |
3314 | /* Now locate a list of suitable methods named METHOD. */ | |
492d29ea | 3315 | TRY |
cc81e1c6 DE |
3316 | { |
3317 | find_method (state, file_symtabs, klass, method, classes, | |
3318 | symbols, minsyms); | |
3319 | } | |
3320 | ||
3321 | /* If successful, we're done. If NOT_FOUND_ERROR | |
3322 | was not thrown, rethrow the exception that we did get. */ | |
492d29ea | 3323 | CATCH (except, RETURN_MASK_ERROR) |
7556d4a4 PA |
3324 | { |
3325 | if (except.error != NOT_FOUND_ERROR) | |
3326 | throw_exception (except); | |
3327 | } | |
492d29ea | 3328 | END_CATCH |
cc81e1c6 | 3329 | } |
f8eba3c6 | 3330 | } |
14e91ac5 | 3331 | |
cc81e1c6 | 3332 | do_cleanups (cleanup); |
14e91ac5 DC |
3333 | } |
3334 | ||
40e084e1 KS |
3335 | /* Return all labels named NAME in FUNCTION_SYMBOLS. Return the |
3336 | actual function symbol in which the label was found in LABEL_FUNC_RET. */ | |
0f5238ed | 3337 | |
40e084e1 KS |
3338 | static VEC (symbolp) * |
3339 | find_label_symbols (struct linespec_state *self, | |
3340 | VEC (symbolp) *function_symbols, | |
3341 | VEC (symbolp) **label_funcs_ret, const char *name) | |
0f5238ed | 3342 | { |
f8eba3c6 | 3343 | int ix; |
3977b71f | 3344 | const struct block *block; |
40e084e1 KS |
3345 | struct symbol *sym; |
3346 | struct symbol *fn_sym; | |
3347 | VEC (symbolp) *result = NULL; | |
9ef07c8c | 3348 | |
f8eba3c6 | 3349 | if (function_symbols == NULL) |
9ef07c8c | 3350 | { |
f8eba3c6 | 3351 | set_current_program_space (self->program_space); |
4eeaa230 | 3352 | block = get_current_search_block (); |
f8eba3c6 | 3353 | |
9ef07c8c TT |
3354 | for (; |
3355 | block && !BLOCK_FUNCTION (block); | |
3356 | block = BLOCK_SUPERBLOCK (block)) | |
3357 | ; | |
3358 | if (!block) | |
40e084e1 | 3359 | return NULL; |
f8eba3c6 TT |
3360 | fn_sym = BLOCK_FUNCTION (block); |
3361 | ||
d12307c1 | 3362 | sym = lookup_symbol (name, block, LABEL_DOMAIN, 0).symbol; |
f8eba3c6 | 3363 | |
40e084e1 KS |
3364 | if (sym != NULL) |
3365 | { | |
3366 | VEC_safe_push (symbolp, result, sym); | |
3367 | VEC_safe_push (symbolp, *label_funcs_ret, fn_sym); | |
3368 | } | |
3369 | } | |
3370 | else | |
3371 | { | |
3372 | for (ix = 0; | |
3373 | VEC_iterate (symbolp, function_symbols, ix, fn_sym); ++ix) | |
f8eba3c6 | 3374 | { |
08be3fe3 | 3375 | set_current_program_space (SYMTAB_PSPACE (symbol_symtab (fn_sym))); |
40e084e1 | 3376 | block = SYMBOL_BLOCK_VALUE (fn_sym); |
d12307c1 | 3377 | sym = lookup_symbol (name, block, LABEL_DOMAIN, 0).symbol; |
40e084e1 KS |
3378 | |
3379 | if (sym != NULL) | |
3380 | { | |
3381 | VEC_safe_push (symbolp, result, sym); | |
3382 | VEC_safe_push (symbolp, *label_funcs_ret, fn_sym); | |
3383 | } | |
f8eba3c6 | 3384 | } |
40e084e1 | 3385 | } |
f8eba3c6 | 3386 | |
40e084e1 KS |
3387 | return result; |
3388 | } | |
f8eba3c6 | 3389 | |
40e084e1 KS |
3390 | \f |
3391 | ||
3392 | /* A helper for create_sals_line_offset that handles the 'list_mode' case. */ | |
3393 | ||
3394 | static void | |
3395 | decode_digits_list_mode (struct linespec_state *self, | |
3396 | linespec_p ls, | |
3397 | struct symtabs_and_lines *values, | |
3398 | struct symtab_and_line val) | |
3399 | { | |
3400 | int ix; | |
3401 | struct symtab *elt; | |
3402 | ||
3403 | gdb_assert (self->list_mode); | |
3404 | ||
ec94af83 | 3405 | for (ix = 0; VEC_iterate (symtab_ptr, ls->file_symtabs, ix, elt); |
40e084e1 KS |
3406 | ++ix) |
3407 | { | |
3408 | /* The logic above should ensure this. */ | |
3409 | gdb_assert (elt != NULL); | |
3410 | ||
3411 | set_current_program_space (SYMTAB_PSPACE (elt)); | |
3412 | ||
3413 | /* Simplistic search just for the list command. */ | |
3414 | val.symtab = find_line_symtab (elt, val.line, NULL, NULL); | |
3415 | if (val.symtab == NULL) | |
3416 | val.symtab = elt; | |
3417 | val.pspace = SYMTAB_PSPACE (elt); | |
3418 | val.pc = 0; | |
3419 | val.explicit_line = 1; | |
3420 | ||
66f1999b | 3421 | add_sal_to_sals (self, values, &val, NULL, 0); |
f8eba3c6 | 3422 | } |
40e084e1 | 3423 | } |
f8eba3c6 | 3424 | |
40e084e1 KS |
3425 | /* A helper for create_sals_line_offset that iterates over the symtabs, |
3426 | adding lines to the VEC. */ | |
3427 | ||
3428 | static void | |
3429 | decode_digits_ordinary (struct linespec_state *self, | |
3430 | linespec_p ls, | |
3431 | int line, | |
3432 | struct symtabs_and_lines *sals, | |
3433 | struct linetable_entry **best_entry) | |
3434 | { | |
3435 | int ix; | |
3436 | struct symtab *elt; | |
f8eba3c6 | 3437 | |
ec94af83 | 3438 | for (ix = 0; VEC_iterate (symtab_ptr, ls->file_symtabs, ix, elt); ++ix) |
f8eba3c6 | 3439 | { |
40e084e1 KS |
3440 | int i; |
3441 | VEC (CORE_ADDR) *pcs; | |
3442 | CORE_ADDR pc; | |
3443 | ||
3444 | /* The logic above should ensure this. */ | |
3445 | gdb_assert (elt != NULL); | |
f8eba3c6 | 3446 | |
40e084e1 | 3447 | set_current_program_space (SYMTAB_PSPACE (elt)); |
f8eba3c6 | 3448 | |
40e084e1 KS |
3449 | pcs = find_pcs_for_symtab_line (elt, line, best_entry); |
3450 | for (i = 0; VEC_iterate (CORE_ADDR, pcs, i, pc); ++i) | |
f8eba3c6 TT |
3451 | { |
3452 | struct symtab_and_line sal; | |
40e084e1 KS |
3453 | |
3454 | init_sal (&sal); | |
3455 | sal.pspace = SYMTAB_PSPACE (elt); | |
3456 | sal.symtab = elt; | |
3457 | sal.line = line; | |
3458 | sal.pc = pc; | |
3459 | add_sal_to_sals_basic (sals, &sal); | |
f8eba3c6 | 3460 | } |
40e084e1 KS |
3461 | |
3462 | VEC_free (CORE_ADDR, pcs); | |
f8eba3c6 | 3463 | } |
40e084e1 KS |
3464 | } |
3465 | ||
3466 | \f | |
3467 | ||
3468 | /* Return the line offset represented by VARIABLE. */ | |
3469 | ||
3470 | static struct line_offset | |
3471 | linespec_parse_variable (struct linespec_state *self, const char *variable) | |
3472 | { | |
3473 | int index = 0; | |
3474 | const char *p; | |
3475 | struct line_offset offset = {0, LINE_OFFSET_NONE}; | |
f8eba3c6 | 3476 | |
40e084e1 KS |
3477 | p = (variable[1] == '$') ? variable + 2 : variable + 1; |
3478 | if (*p == '$') | |
3479 | ++p; | |
3480 | while (*p >= '0' && *p <= '9') | |
3481 | ++p; | |
3482 | if (!*p) /* Reached end of token without hitting non-digit. */ | |
f8eba3c6 | 3483 | { |
40e084e1 KS |
3484 | /* We have a value history reference. */ |
3485 | struct value *val_history; | |
f8eba3c6 | 3486 | |
40e084e1 KS |
3487 | sscanf ((variable[1] == '$') ? variable + 2 : variable + 1, "%d", &index); |
3488 | val_history | |
3489 | = access_value_history ((variable[1] == '$') ? -index : index); | |
3490 | if (TYPE_CODE (value_type (val_history)) != TYPE_CODE_INT) | |
3491 | error (_("History values used in line " | |
3492 | "specs must have integer values.")); | |
3493 | offset.offset = value_as_long (val_history); | |
3494 | } | |
3495 | else | |
3496 | { | |
3497 | /* Not all digits -- may be user variable/function or a | |
3498 | convenience variable. */ | |
3499 | LONGEST valx; | |
3500 | struct internalvar *ivar; | |
3501 | ||
3502 | /* Try it as a convenience variable. If it is not a convenience | |
3503 | variable, return and allow normal symbol lookup to occur. */ | |
3504 | ivar = lookup_only_internalvar (variable + 1); | |
3505 | if (ivar == NULL) | |
3506 | /* No internal variable with that name. Mark the offset | |
3507 | as unknown to allow the name to be looked up as a symbol. */ | |
3508 | offset.sign = LINE_OFFSET_UNKNOWN; | |
3509 | else | |
3510 | { | |
3511 | /* We found a valid variable name. If it is not an integer, | |
3512 | throw an error. */ | |
3513 | if (!get_internalvar_integer (ivar, &valx)) | |
3514 | error (_("Convenience variables used in line " | |
3515 | "specs must have integer values.")); | |
3516 | else | |
3517 | offset.offset = valx; | |
3518 | } | |
f8eba3c6 TT |
3519 | } |
3520 | ||
40e084e1 | 3521 | return offset; |
f8eba3c6 | 3522 | } |
40e084e1 | 3523 | \f |
f8eba3c6 TT |
3524 | |
3525 | /* A callback used to possibly add a symbol to the results. */ | |
3526 | ||
3527 | static int | |
3528 | collect_symbols (struct symbol *sym, void *data) | |
3529 | { | |
9a3c8263 | 3530 | struct collect_info *info = (struct collect_info *) data; |
f8eba3c6 | 3531 | |
40e084e1 KS |
3532 | /* In list mode, add all matching symbols, regardless of class. |
3533 | This allows the user to type "list a_global_variable". */ | |
3534 | if (SYMBOL_CLASS (sym) == LOC_BLOCK || info->state->list_mode) | |
3535 | VEC_safe_push (symbolp, info->result.symbols, sym); | |
8e704927 | 3536 | return 1; /* Continue iterating. */ |
f8eba3c6 TT |
3537 | } |
3538 | ||
40e084e1 | 3539 | /* We've found a minimal symbol MSYMBOL in OBJFILE to associate with our |
6e22494e JK |
3540 | linespec; return the SAL in RESULT. This function should return SALs |
3541 | matching those from find_function_start_sal, otherwise false | |
3542 | multiple-locations breakpoints could be placed. */ | |
f8eba3c6 TT |
3543 | |
3544 | static void | |
3545 | minsym_found (struct linespec_state *self, struct objfile *objfile, | |
3546 | struct minimal_symbol *msymbol, | |
3547 | struct symtabs_and_lines *result) | |
3548 | { | |
3549 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
3550 | CORE_ADDR pc; | |
3551 | struct symtab_and_line sal; | |
3552 | ||
77e371c0 | 3553 | sal = find_pc_sect_line (MSYMBOL_VALUE_ADDRESS (objfile, msymbol), |
f8eba3c6 | 3554 | (struct obj_section *) 0, 0); |
efd66ac6 | 3555 | sal.section = MSYMBOL_OBJ_SECTION (objfile, msymbol); |
f8eba3c6 TT |
3556 | |
3557 | /* The minimal symbol might point to a function descriptor; | |
3558 | resolve it to the actual code address instead. */ | |
3559 | pc = gdbarch_convert_from_func_ptr_addr (gdbarch, sal.pc, ¤t_target); | |
3560 | if (pc != sal.pc) | |
3561 | sal = find_pc_sect_line (pc, NULL, 0); | |
3562 | ||
3563 | if (self->funfirstline) | |
6e22494e JK |
3564 | { |
3565 | if (sal.symtab != NULL | |
3566 | && (COMPUNIT_LOCATIONS_VALID (SYMTAB_COMPUNIT (sal.symtab)) | |
3567 | || SYMTAB_LANGUAGE (sal.symtab) == language_asm)) | |
3568 | { | |
3569 | /* If gdbarch_convert_from_func_ptr_addr does not apply then | |
3570 | sal.SECTION, sal.LINE&co. will stay correct from above. | |
3571 | If gdbarch_convert_from_func_ptr_addr applies then | |
3572 | sal.SECTION is cleared from above and sal.LINE&co. will | |
3573 | stay correct from the last find_pc_sect_line above. */ | |
3574 | sal.pc = MSYMBOL_VALUE_ADDRESS (objfile, msymbol); | |
3575 | sal.pc = gdbarch_convert_from_func_ptr_addr (gdbarch, sal.pc, | |
3576 | ¤t_target); | |
141c5cc4 JK |
3577 | if (gdbarch_skip_entrypoint_p (gdbarch)) |
3578 | sal.pc = gdbarch_skip_entrypoint (gdbarch, sal.pc); | |
6e22494e JK |
3579 | } |
3580 | else | |
3581 | skip_prologue_sal (&sal); | |
3582 | } | |
f8eba3c6 | 3583 | |
07fea4b4 | 3584 | if (maybe_add_address (self->addr_set, objfile->pspace, sal.pc)) |
efd66ac6 | 3585 | add_sal_to_sals (self, result, &sal, MSYMBOL_NATURAL_NAME (msymbol), 0); |
f8eba3c6 TT |
3586 | } |
3587 | ||
39b856a4 TT |
3588 | /* A helper struct to pass some data through |
3589 | iterate_over_minimal_symbols. */ | |
3590 | ||
3591 | struct collect_minsyms | |
3592 | { | |
3593 | /* The objfile we're examining. */ | |
3594 | struct objfile *objfile; | |
3595 | ||
87186c6a MMN |
3596 | /* Only search the given symtab, or NULL to search for all symbols. */ |
3597 | struct symtab *symtab; | |
3598 | ||
39b856a4 TT |
3599 | /* The funfirstline setting from the initial call. */ |
3600 | int funfirstline; | |
3601 | ||
095bcf5e JB |
3602 | /* The list_mode setting from the initial call. */ |
3603 | int list_mode; | |
3604 | ||
39b856a4 | 3605 | /* The resulting symbols. */ |
f60e2d5c | 3606 | VEC (bound_minimal_symbol_d) *msyms; |
39b856a4 TT |
3607 | }; |
3608 | ||
3609 | /* A helper function to classify a minimal_symbol_type according to | |
3610 | priority. */ | |
3611 | ||
3612 | static int | |
3613 | classify_mtype (enum minimal_symbol_type t) | |
3614 | { | |
3615 | switch (t) | |
f8eba3c6 | 3616 | { |
39b856a4 TT |
3617 | case mst_file_text: |
3618 | case mst_file_data: | |
3619 | case mst_file_bss: | |
3620 | /* Intermediate priority. */ | |
3621 | return 1; | |
3622 | ||
3623 | case mst_solib_trampoline: | |
3624 | /* Lowest priority. */ | |
3625 | return 2; | |
3626 | ||
3627 | default: | |
3628 | /* Highest priority. */ | |
3629 | return 0; | |
f8eba3c6 | 3630 | } |
39b856a4 TT |
3631 | } |
3632 | ||
3633 | /* Callback for qsort that sorts symbols by priority. */ | |
3634 | ||
3635 | static int | |
3636 | compare_msyms (const void *a, const void *b) | |
3637 | { | |
9a3c8263 SM |
3638 | const bound_minimal_symbol_d *moa = (const bound_minimal_symbol_d *) a; |
3639 | const bound_minimal_symbol_d *mob = (const bound_minimal_symbol_d *) b; | |
39b856a4 TT |
3640 | enum minimal_symbol_type ta = MSYMBOL_TYPE (moa->minsym); |
3641 | enum minimal_symbol_type tb = MSYMBOL_TYPE (mob->minsym); | |
3642 | ||
3643 | return classify_mtype (ta) - classify_mtype (tb); | |
3644 | } | |
3645 | ||
3646 | /* Callback for iterate_over_minimal_symbols that adds the symbol to | |
3647 | the result. */ | |
3648 | ||
3649 | static void | |
3650 | add_minsym (struct minimal_symbol *minsym, void *d) | |
3651 | { | |
9a3c8263 | 3652 | struct collect_minsyms *info = (struct collect_minsyms *) d; |
f60e2d5c | 3653 | bound_minimal_symbol_d mo; |
39b856a4 | 3654 | |
77e371c0 TT |
3655 | mo.minsym = minsym; |
3656 | mo.objfile = info->objfile; | |
3657 | ||
87186c6a MMN |
3658 | if (info->symtab != NULL) |
3659 | { | |
3660 | CORE_ADDR pc; | |
3661 | struct symtab_and_line sal; | |
3662 | struct gdbarch *gdbarch = get_objfile_arch (info->objfile); | |
3663 | ||
3664 | sal = find_pc_sect_line (MSYMBOL_VALUE_ADDRESS (info->objfile, minsym), | |
3665 | NULL, 0); | |
3666 | sal.section = MSYMBOL_OBJ_SECTION (info->objfile, minsym); | |
3667 | pc | |
3668 | = gdbarch_convert_from_func_ptr_addr (gdbarch, sal.pc, ¤t_target); | |
3669 | if (pc != sal.pc) | |
3670 | sal = find_pc_sect_line (pc, NULL, 0); | |
3671 | ||
3672 | if (info->symtab != sal.symtab) | |
3673 | return; | |
3674 | } | |
3675 | ||
095bcf5e JB |
3676 | /* Exclude data symbols when looking for breakpoint locations. */ |
3677 | if (!info->list_mode) | |
3678 | switch (minsym->type) | |
3679 | { | |
3680 | case mst_slot_got_plt: | |
3681 | case mst_data: | |
3682 | case mst_bss: | |
3683 | case mst_abs: | |
3684 | case mst_file_data: | |
3685 | case mst_file_bss: | |
1a2da5ee JB |
3686 | { |
3687 | /* Make sure this minsym is not a function descriptor | |
3688 | before we decide to discard it. */ | |
df6d5441 | 3689 | struct gdbarch *gdbarch = get_objfile_arch (info->objfile); |
1a2da5ee | 3690 | CORE_ADDR addr = gdbarch_convert_from_func_ptr_addr |
77e371c0 | 3691 | (gdbarch, BMSYMBOL_VALUE_ADDRESS (mo), |
1a2da5ee JB |
3692 | ¤t_target); |
3693 | ||
77e371c0 | 3694 | if (addr == BMSYMBOL_VALUE_ADDRESS (mo)) |
1a2da5ee JB |
3695 | return; |
3696 | } | |
095bcf5e JB |
3697 | } |
3698 | ||
f60e2d5c | 3699 | VEC_safe_push (bound_minimal_symbol_d, info->msyms, &mo); |
f8eba3c6 TT |
3700 | } |
3701 | ||
87186c6a | 3702 | /* Search for minimal symbols called NAME. If SEARCH_PSPACE |
f8eba3c6 | 3703 | is not NULL, the search is restricted to just that program |
87186c6a MMN |
3704 | space. |
3705 | ||
3706 | If SYMTAB is NULL, search all objfiles, otherwise | |
3707 | restrict results to the given SYMTAB. */ | |
f8eba3c6 TT |
3708 | |
3709 | static void | |
3710 | search_minsyms_for_name (struct collect_info *info, const char *name, | |
87186c6a MMN |
3711 | struct program_space *search_pspace, |
3712 | struct symtab *symtab) | |
f8eba3c6 | 3713 | { |
87186c6a MMN |
3714 | struct collect_minsyms local; |
3715 | struct cleanup *cleanup; | |
f8eba3c6 | 3716 | |
87186c6a MMN |
3717 | memset (&local, 0, sizeof (local)); |
3718 | local.funfirstline = info->state->funfirstline; | |
3719 | local.list_mode = info->state->list_mode; | |
3720 | local.symtab = symtab; | |
39b856a4 | 3721 | |
87186c6a | 3722 | cleanup = make_cleanup (VEC_cleanup (bound_minimal_symbol_d), &local.msyms); |
f8eba3c6 | 3723 | |
87186c6a MMN |
3724 | if (symtab == NULL) |
3725 | { | |
3726 | struct program_space *pspace; | |
f8eba3c6 | 3727 | |
87186c6a MMN |
3728 | ALL_PSPACES (pspace) |
3729 | { | |
3730 | struct objfile *objfile; | |
39b856a4 | 3731 | |
87186c6a MMN |
3732 | if (search_pspace != NULL && search_pspace != pspace) |
3733 | continue; | |
3734 | if (pspace->executing_startup) | |
3735 | continue; | |
39b856a4 | 3736 | |
87186c6a MMN |
3737 | set_current_program_space (pspace); |
3738 | ||
3739 | ALL_OBJFILES (objfile) | |
3740 | { | |
3741 | local.objfile = objfile; | |
3742 | iterate_over_minimal_symbols (objfile, name, add_minsym, &local); | |
3743 | } | |
3744 | } | |
3745 | } | |
3746 | else | |
f8eba3c6 | 3747 | { |
87186c6a MMN |
3748 | if (search_pspace == NULL || SYMTAB_PSPACE (symtab) == search_pspace) |
3749 | { | |
3750 | set_current_program_space (SYMTAB_PSPACE (symtab)); | |
3751 | local.objfile = SYMTAB_OBJFILE(symtab); | |
3752 | iterate_over_minimal_symbols (local.objfile, name, add_minsym, | |
3753 | &local); | |
3754 | } | |
9ef07c8c | 3755 | } |
39b856a4 | 3756 | |
f60e2d5c | 3757 | if (!VEC_empty (bound_minimal_symbol_d, local.msyms)) |
39b856a4 TT |
3758 | { |
3759 | int classification; | |
3760 | int ix; | |
f60e2d5c | 3761 | bound_minimal_symbol_d *item; |
39b856a4 | 3762 | |
f60e2d5c TT |
3763 | qsort (VEC_address (bound_minimal_symbol_d, local.msyms), |
3764 | VEC_length (bound_minimal_symbol_d, local.msyms), | |
3765 | sizeof (bound_minimal_symbol_d), | |
39b856a4 TT |
3766 | compare_msyms); |
3767 | ||
3768 | /* Now the minsyms are in classification order. So, we walk | |
3769 | over them and process just the minsyms with the same | |
3770 | classification as the very first minsym in the list. */ | |
f60e2d5c | 3771 | item = VEC_index (bound_minimal_symbol_d, local.msyms, 0); |
39b856a4 TT |
3772 | classification = classify_mtype (MSYMBOL_TYPE (item->minsym)); |
3773 | ||
3774 | for (ix = 0; | |
f60e2d5c | 3775 | VEC_iterate (bound_minimal_symbol_d, local.msyms, ix, item); |
39b856a4 TT |
3776 | ++ix) |
3777 | { | |
3778 | if (classify_mtype (MSYMBOL_TYPE (item->minsym)) != classification) | |
3779 | break; | |
3780 | ||
f60e2d5c | 3781 | VEC_safe_push (bound_minimal_symbol_d, |
40e084e1 | 3782 | info->result.minimal_symbols, item); |
39b856a4 TT |
3783 | } |
3784 | } | |
3785 | ||
3786 | do_cleanups (cleanup); | |
f8eba3c6 TT |
3787 | } |
3788 | ||
3789 | /* A helper function to add all symbols matching NAME to INFO. If | |
3790 | PSPACE is not NULL, the search is restricted to just that program | |
3791 | space. */ | |
0f5238ed | 3792 | |
f8eba3c6 TT |
3793 | static void |
3794 | add_matching_symbols_to_info (const char *name, | |
3795 | struct collect_info *info, | |
3796 | struct program_space *pspace) | |
3797 | { | |
3798 | int ix; | |
3799 | struct symtab *elt; | |
0f5238ed | 3800 | |
ec94af83 | 3801 | for (ix = 0; VEC_iterate (symtab_ptr, info->file_symtabs, ix, elt); ++ix) |
f8eba3c6 | 3802 | { |
f8eba3c6 TT |
3803 | if (elt == NULL) |
3804 | { | |
40e084e1 | 3805 | iterate_over_all_matching_symtabs (info->state, name, VAR_DOMAIN, |
f8eba3c6 | 3806 | collect_symbols, info, |
481860b3 | 3807 | pspace, 1); |
87186c6a | 3808 | search_minsyms_for_name (info, name, pspace, NULL); |
f8eba3c6 TT |
3809 | } |
3810 | else if (pspace == NULL || pspace == SYMTAB_PSPACE (elt)) | |
3811 | { | |
87186c6a MMN |
3812 | int prev_len = VEC_length (symbolp, info->result.symbols); |
3813 | ||
f8eba3c6 TT |
3814 | /* Program spaces that are executing startup should have |
3815 | been filtered out earlier. */ | |
3816 | gdb_assert (!SYMTAB_PSPACE (elt)->executing_startup); | |
3817 | set_current_program_space (SYMTAB_PSPACE (elt)); | |
4eeaa230 DE |
3818 | iterate_over_file_blocks (elt, name, VAR_DOMAIN, |
3819 | collect_symbols, info); | |
87186c6a MMN |
3820 | |
3821 | /* If no new symbols were found in this iteration and this symtab | |
3822 | is in assembler, we might actually be looking for a label for | |
3823 | which we don't have debug info. Check for a minimal symbol in | |
3824 | this case. */ | |
3825 | if (prev_len == VEC_length (symbolp, info->result.symbols) | |
3826 | && elt->language == language_asm) | |
3827 | search_minsyms_for_name (info, name, pspace, elt); | |
f8eba3c6 TT |
3828 | } |
3829 | } | |
0f5238ed TT |
3830 | } |
3831 | ||
14e91ac5 DC |
3832 | \f |
3833 | ||
413dad4d DC |
3834 | /* Now come some functions that are called from multiple places within |
3835 | decode_line_1. */ | |
3836 | ||
f8eba3c6 TT |
3837 | static int |
3838 | symbol_to_sal (struct symtab_and_line *result, | |
3839 | int funfirstline, struct symbol *sym) | |
413dad4d | 3840 | { |
413dad4d | 3841 | if (SYMBOL_CLASS (sym) == LOC_BLOCK) |
50641945 | 3842 | { |
f8eba3c6 TT |
3843 | *result = find_function_start_sal (sym, funfirstline); |
3844 | return 1; | |
50641945 | 3845 | } |
413dad4d DC |
3846 | else |
3847 | { | |
62853458 | 3848 | if (SYMBOL_CLASS (sym) == LOC_LABEL && SYMBOL_VALUE_ADDRESS (sym) != 0) |
413dad4d | 3849 | { |
f8eba3c6 | 3850 | init_sal (result); |
08be3fe3 | 3851 | result->symtab = symbol_symtab (sym); |
f8eba3c6 TT |
3852 | result->line = SYMBOL_LINE (sym); |
3853 | result->pc = SYMBOL_VALUE_ADDRESS (sym); | |
08be3fe3 | 3854 | result->pspace = SYMTAB_PSPACE (result->symtab); |
f8eba3c6 TT |
3855 | result->explicit_pc = 1; |
3856 | return 1; | |
413dad4d | 3857 | } |
62853458 | 3858 | else if (funfirstline) |
dcf9f4ab | 3859 | { |
f8eba3c6 | 3860 | /* Nothing. */ |
dcf9f4ab | 3861 | } |
62853458 TT |
3862 | else if (SYMBOL_LINE (sym) != 0) |
3863 | { | |
3864 | /* We know its line number. */ | |
f8eba3c6 | 3865 | init_sal (result); |
08be3fe3 | 3866 | result->symtab = symbol_symtab (sym); |
f8eba3c6 | 3867 | result->line = SYMBOL_LINE (sym); |
08be3fe3 | 3868 | result->pspace = SYMTAB_PSPACE (result->symtab); |
f8eba3c6 | 3869 | return 1; |
62853458 | 3870 | } |
413dad4d | 3871 | } |
f8eba3c6 TT |
3872 | |
3873 | return 0; | |
413dad4d | 3874 | } |
50641945 | 3875 | |
f8eba3c6 | 3876 | /* See the comment in linespec.h. */ |
50641945 | 3877 | |
f8eba3c6 TT |
3878 | void |
3879 | init_linespec_result (struct linespec_result *lr) | |
413dad4d | 3880 | { |
f8eba3c6 TT |
3881 | memset (lr, 0, sizeof (*lr)); |
3882 | } | |
413dad4d | 3883 | |
f8eba3c6 | 3884 | /* See the comment in linespec.h. */ |
bccdca4a | 3885 | |
f8eba3c6 TT |
3886 | void |
3887 | destroy_linespec_result (struct linespec_result *ls) | |
3888 | { | |
3889 | int i; | |
3890 | struct linespec_sals *lsal; | |
bccdca4a | 3891 | |
f00aae0f | 3892 | delete_event_location (ls->location); |
f8eba3c6 TT |
3893 | for (i = 0; VEC_iterate (linespec_sals, ls->sals, i, lsal); ++i) |
3894 | { | |
3895 | xfree (lsal->canonical); | |
3896 | xfree (lsal->sals.sals); | |
3897 | } | |
3898 | VEC_free (linespec_sals, ls->sals); | |
3899 | } | |
e48883f7 | 3900 | |
f8eba3c6 TT |
3901 | /* Cleanup function for a linespec_result. */ |
3902 | ||
3903 | static void | |
3904 | cleanup_linespec_result (void *a) | |
3905 | { | |
9a3c8263 | 3906 | destroy_linespec_result ((struct linespec_result *) a); |
50641945 | 3907 | } |
7efd8fc2 | 3908 | |
f8eba3c6 TT |
3909 | /* See the comment in linespec.h. */ |
3910 | ||
3911 | struct cleanup * | |
3912 | make_cleanup_destroy_linespec_result (struct linespec_result *ls) | |
7efd8fc2 | 3913 | { |
f8eba3c6 | 3914 | return make_cleanup (cleanup_linespec_result, ls); |
7efd8fc2 | 3915 | } |
87f0e720 KS |
3916 | |
3917 | /* Return the quote characters permitted by the linespec parser. */ | |
3918 | ||
3919 | const char * | |
3920 | get_gdb_linespec_parser_quote_characters (void) | |
3921 | { | |
3922 | return linespec_quote_characters; | |
3923 | } |