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