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