1 /* Parser for linespec for the GNU debugger, GDB.
3 Copyright (C) 1986-2017 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
29 #include "completer.h"
31 #include "cp-support.h"
32 #include "parser-defs.h"
34 #include "objc-lang.h"
38 #include "mi/mi-cmds.h"
40 #include "arch-utils.h"
42 #include "cli/cli-utils.h"
43 #include "filenames.h"
47 #include "common/function-view.h"
49 typedef struct symbol
*symbolp
;
52 typedef struct type
*typep
;
55 /* An address entry is used to ensure that any given location is only
56 added to the result a single time. It holds an address and the
57 program space from which the address came. */
61 struct program_space
*pspace
;
65 typedef struct bound_minimal_symbol bound_minimal_symbol_d
;
67 DEF_VEC_O (bound_minimal_symbol_d
);
69 /* A linespec. Elements of this structure are filled in by a parser
70 (either parse_linespec or some other function). The structure is
71 then converted into SALs by convert_linespec_to_sals. */
75 /* An explicit location describing the SaLs. */
76 struct explicit_location explicit_loc
;
78 /* The list of symtabs to search to which to limit the search. May not
79 be NULL. If explicit.SOURCE_FILENAME is NULL (no user-specified
80 filename), FILE_SYMTABS should contain one single NULL member. This
81 will cause the code to use the default symtab. */
82 VEC (symtab_ptr
) *file_symtabs
;
84 /* A list of matching function symbols and minimal symbols. Both lists
85 may be NULL if no matching symbols were found. */
86 VEC (symbolp
) *function_symbols
;
87 VEC (bound_minimal_symbol_d
) *minimal_symbols
;
89 /* A structure of matching label symbols and the corresponding
90 function symbol in which the label was found. Both may be NULL
91 or both must be non-NULL. */
94 VEC (symbolp
) *label_symbols
;
95 VEC (symbolp
) *function_symbols
;
98 typedef struct linespec
*linespec_p
;
100 /* A canonical linespec represented as a symtab-related string.
102 Each entry represents the "SYMTAB:SUFFIX" linespec string.
103 SYMTAB can be converted for example by symtab_to_fullname or
104 symtab_to_filename_for_display as needed. */
106 struct linespec_canonical_name
108 /* Remaining text part of the linespec string. */
111 /* If NULL then SUFFIX is the whole linespec string. */
112 struct symtab
*symtab
;
115 /* An instance of this is used to keep all state while linespec
116 operates. This instance is passed around as a 'this' pointer to
117 the various implementation methods. */
119 struct linespec_state
121 /* The language in use during linespec processing. */
122 const struct language_defn
*language
;
124 /* The program space as seen when the module was entered. */
125 struct program_space
*program_space
;
127 /* If not NULL, the search is restricted to just this program
129 struct program_space
*search_pspace
;
131 /* The default symtab to use, if no other symtab is specified. */
132 struct symtab
*default_symtab
;
134 /* The default line to use. */
137 /* The 'funfirstline' value that was passed in to decode_line_1 or
141 /* Nonzero if we are running in 'list' mode; see decode_line_list. */
144 /* The 'canonical' value passed to decode_line_full, or NULL. */
145 struct linespec_result
*canonical
;
147 /* Canonical strings that mirror the symtabs_and_lines result. */
148 struct linespec_canonical_name
*canonical_names
;
150 /* This is a set of address_entry objects which is used to prevent
151 duplicate symbols from being entered into the result. */
154 /* Are we building a linespec? */
158 /* This is a helper object that is used when collecting symbols into a
163 /* The linespec object in use. */
164 struct linespec_state
*state
;
166 /* A list of symtabs to which to restrict matches. */
167 VEC (symtab_ptr
) *file_symtabs
;
169 /* The result being accumulated. */
172 VEC (symbolp
) *symbols
;
173 VEC (bound_minimal_symbol_d
) *minimal_symbols
;
176 /* Possibly add a symbol to the results. */
177 bool add_symbol (symbol
*sym
);
181 collect_info::add_symbol (symbol
*sym
)
183 /* In list mode, add all matching symbols, regardless of class.
184 This allows the user to type "list a_global_variable". */
185 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
|| this->state
->list_mode
)
186 VEC_safe_push (symbolp
, this->result
.symbols
, sym
);
188 /* Continue iterating. */
199 /* A colon "separator" */
211 /* EOI (end of input) */
217 typedef enum ls_token_type linespec_token_type
;
219 /* List of keywords. This is NULL-terminated so that it can be used
220 as enum completer. */
221 const char * const linespec_keywords
[] = { "if", "thread", "task", NULL
};
222 #define IF_KEYWORD_INDEX 0
224 /* A token of the linespec lexer */
228 /* The type of the token */
229 linespec_token_type type
;
231 /* Data for the token */
234 /* A string, given as a stoken */
235 struct stoken string
;
241 typedef struct ls_token linespec_token
;
243 #define LS_TOKEN_STOKEN(TOK) (TOK).data.string
244 #define LS_TOKEN_KEYWORD(TOK) (TOK).data.keyword
246 /* An instance of the linespec parser. */
250 /* Lexer internal data */
253 /* Save head of input stream. */
254 const char *saved_arg
;
256 /* Head of the input stream. */
258 #define PARSER_STREAM(P) ((P)->lexer.stream)
260 /* The current token. */
261 linespec_token current
;
264 /* Is the entire linespec quote-enclosed? */
265 int is_quote_enclosed
;
267 /* The state of the parse. */
268 struct linespec_state state
;
269 #define PARSER_STATE(PPTR) (&(PPTR)->state)
271 /* The result of the parse. */
272 struct linespec result
;
273 #define PARSER_RESULT(PPTR) (&(PPTR)->result)
275 typedef struct ls_parser linespec_parser
;
277 /* A convenience macro for accessing the explicit location result of
279 #define PARSER_EXPLICIT(PPTR) (&PARSER_RESULT ((PPTR))->explicit_loc)
281 /* Prototypes for local functions. */
283 static void iterate_over_file_blocks
284 (struct symtab
*symtab
, const char *name
, domain_enum domain
,
285 gdb::function_view
<symbol_found_callback_ftype
> callback
);
287 static void initialize_defaults (struct symtab
**default_symtab
,
290 CORE_ADDR
linespec_expression_to_pc (const char **exp_ptr
);
292 static struct symtabs_and_lines
decode_objc (struct linespec_state
*self
,
296 static VEC (symtab_ptr
) *symtabs_from_filename (const char *,
297 struct program_space
*pspace
);
299 static VEC (symbolp
) *find_label_symbols (struct linespec_state
*self
,
300 VEC (symbolp
) *function_symbols
,
301 VEC (symbolp
) **label_funcs_ret
,
303 bool completion_mode
= false);
305 static void find_linespec_symbols (struct linespec_state
*self
,
306 VEC (symtab_ptr
) *file_symtabs
,
308 VEC (symbolp
) **symbols
,
309 VEC (bound_minimal_symbol_d
) **minsyms
);
311 static struct line_offset
312 linespec_parse_variable (struct linespec_state
*self
,
313 const char *variable
);
315 static int symbol_to_sal (struct symtab_and_line
*result
,
316 int funfirstline
, struct symbol
*sym
);
318 static void add_matching_symbols_to_info (const char *name
,
319 struct collect_info
*info
,
320 struct program_space
*pspace
);
322 static void add_all_symbol_names_from_pspace (struct collect_info
*info
,
323 struct program_space
*pspace
,
324 VEC (const_char_ptr
) *names
);
326 static VEC (symtab_ptr
) *
327 collect_symtabs_from_filename (const char *file
,
328 struct program_space
*pspace
);
330 static void decode_digits_ordinary (struct linespec_state
*self
,
333 struct symtabs_and_lines
*sals
,
334 struct linetable_entry
**best_entry
);
336 static void decode_digits_list_mode (struct linespec_state
*self
,
338 struct symtabs_and_lines
*values
,
339 struct symtab_and_line val
);
341 static void minsym_found (struct linespec_state
*self
, struct objfile
*objfile
,
342 struct minimal_symbol
*msymbol
,
343 struct symtabs_and_lines
*result
);
345 static int compare_symbols (const void *a
, const void *b
);
347 static int compare_msymbols (const void *a
, const void *b
);
349 /* Permitted quote characters for the parser. This is different from the
350 completer's quote characters to allow backward compatibility with the
352 static const char *const linespec_quote_characters
= "\"\'";
354 /* Lexer functions. */
356 /* Lex a number from the input in PARSER. This only supports
359 Return true if input is decimal numbers. Return false if not. */
362 linespec_lexer_lex_number (linespec_parser
*parser
, linespec_token
*tokenp
)
364 tokenp
->type
= LSTOKEN_NUMBER
;
365 LS_TOKEN_STOKEN (*tokenp
).length
= 0;
366 LS_TOKEN_STOKEN (*tokenp
).ptr
= PARSER_STREAM (parser
);
368 /* Keep any sign at the start of the stream. */
369 if (*PARSER_STREAM (parser
) == '+' || *PARSER_STREAM (parser
) == '-')
371 ++LS_TOKEN_STOKEN (*tokenp
).length
;
372 ++(PARSER_STREAM (parser
));
375 while (isdigit (*PARSER_STREAM (parser
)))
377 ++LS_TOKEN_STOKEN (*tokenp
).length
;
378 ++(PARSER_STREAM (parser
));
381 /* If the next character in the input buffer is not a space, comma,
382 quote, or colon, this input does not represent a number. */
383 if (*PARSER_STREAM (parser
) != '\0'
384 && !isspace (*PARSER_STREAM (parser
)) && *PARSER_STREAM (parser
) != ','
385 && *PARSER_STREAM (parser
) != ':'
386 && !strchr (linespec_quote_characters
, *PARSER_STREAM (parser
)))
388 PARSER_STREAM (parser
) = LS_TOKEN_STOKEN (*tokenp
).ptr
;
395 /* See linespec.h. */
398 linespec_lexer_lex_keyword (const char *p
)
404 for (i
= 0; linespec_keywords
[i
] != NULL
; ++i
)
406 int len
= strlen (linespec_keywords
[i
]);
408 /* If P begins with one of the keywords and the next
409 character is whitespace, we may have found a keyword.
410 It is only a keyword if it is not followed by another
412 if (strncmp (p
, linespec_keywords
[i
], len
) == 0
417 /* Special case: "if" ALWAYS stops the lexer, since it
418 is not possible to predict what is going to appear in
419 the condition, which can only be parsed after SaLs have
421 if (i
!= IF_KEYWORD_INDEX
)
424 p
= skip_spaces_const (p
);
425 for (j
= 0; linespec_keywords
[j
] != NULL
; ++j
)
427 int nextlen
= strlen (linespec_keywords
[j
]);
429 if (strncmp (p
, linespec_keywords
[j
], nextlen
) == 0
430 && isspace (p
[nextlen
]))
435 return linespec_keywords
[i
];
443 /* See description in linespec.h. */
446 is_ada_operator (const char *string
)
448 const struct ada_opname_map
*mapping
;
450 for (mapping
= ada_opname_table
;
451 mapping
->encoded
!= NULL
452 && !startswith (string
, mapping
->decoded
); ++mapping
)
455 return mapping
->decoded
== NULL
? 0 : strlen (mapping
->decoded
);
458 /* Find QUOTE_CHAR in STRING, accounting for the ':' terminal. Return
459 the location of QUOTE_CHAR, or NULL if not found. */
462 skip_quote_char (const char *string
, char quote_char
)
464 const char *p
, *last
;
466 p
= last
= find_toplevel_char (string
, quote_char
);
467 while (p
&& *p
!= '\0' && *p
!= ':')
469 p
= find_toplevel_char (p
, quote_char
);
477 /* Make a writable copy of the string given in TOKEN, trimming
478 any trailing whitespace. */
481 copy_token_string (linespec_token token
)
485 if (token
.type
== LSTOKEN_KEYWORD
)
486 return xstrdup (LS_TOKEN_KEYWORD (token
));
488 str
= savestring (LS_TOKEN_STOKEN (token
).ptr
,
489 LS_TOKEN_STOKEN (token
).length
);
490 s
= remove_trailing_whitespace (str
, str
+ LS_TOKEN_STOKEN (token
).length
);
496 /* Does P represent the end of a quote-enclosed linespec? */
499 is_closing_quote_enclosed (const char *p
)
501 if (strchr (linespec_quote_characters
, *p
))
503 p
= skip_spaces ((char *) p
);
504 return (*p
== '\0' || linespec_lexer_lex_keyword (p
));
507 /* Find the end of the parameter list that starts with *INPUT.
508 This helper function assists with lexing string segments
509 which might contain valid (non-terminating) commas. */
512 find_parameter_list_end (const char *input
)
514 char end_char
, start_char
;
519 if (start_char
== '(')
521 else if (start_char
== '<')
530 if (*p
== start_char
)
532 else if (*p
== end_char
)
547 /* Lex a string from the input in PARSER. */
549 static linespec_token
550 linespec_lexer_lex_string (linespec_parser
*parser
)
552 linespec_token token
;
553 const char *start
= PARSER_STREAM (parser
);
555 token
.type
= LSTOKEN_STRING
;
557 /* If the input stream starts with a quote character, skip to the next
558 quote character, regardless of the content. */
559 if (strchr (linespec_quote_characters
, *PARSER_STREAM (parser
)))
562 char quote_char
= *PARSER_STREAM (parser
);
564 /* Special case: Ada operators. */
565 if (PARSER_STATE (parser
)->language
->la_language
== language_ada
566 && quote_char
== '\"')
568 int len
= is_ada_operator (PARSER_STREAM (parser
));
572 /* The input is an Ada operator. Return the quoted string
574 LS_TOKEN_STOKEN (token
).ptr
= PARSER_STREAM (parser
);
575 LS_TOKEN_STOKEN (token
).length
= len
;
576 PARSER_STREAM (parser
) += len
;
580 /* The input does not represent an Ada operator -- fall through
581 to normal quoted string handling. */
584 /* Skip past the beginning quote. */
585 ++(PARSER_STREAM (parser
));
587 /* Mark the start of the string. */
588 LS_TOKEN_STOKEN (token
).ptr
= PARSER_STREAM (parser
);
590 /* Skip to the ending quote. */
591 end
= skip_quote_char (PARSER_STREAM (parser
), quote_char
);
593 /* Error if the input did not terminate properly. */
595 error (_("unmatched quote"));
597 /* Skip over the ending quote and mark the length of the string. */
598 PARSER_STREAM (parser
) = (char *) ++end
;
599 LS_TOKEN_STOKEN (token
).length
= PARSER_STREAM (parser
) - 2 - start
;
605 /* Otherwise, only identifier characters are permitted.
606 Spaces are the exception. In general, we keep spaces,
607 but only if the next characters in the input do not resolve
608 to one of the keywords.
610 This allows users to forgo quoting CV-qualifiers, template arguments,
611 and similar common language constructs. */
615 if (isspace (*PARSER_STREAM (parser
)))
617 p
= skip_spaces_const (PARSER_STREAM (parser
));
618 /* When we get here we know we've found something followed by
619 a space (we skip over parens and templates below).
620 So if we find a keyword now, we know it is a keyword and not,
621 say, a function name. */
622 if (linespec_lexer_lex_keyword (p
) != NULL
)
624 LS_TOKEN_STOKEN (token
).ptr
= start
;
625 LS_TOKEN_STOKEN (token
).length
626 = PARSER_STREAM (parser
) - start
;
630 /* Advance past the whitespace. */
631 PARSER_STREAM (parser
) = p
;
634 /* If the next character is EOI or (single) ':', the
635 string is complete; return the token. */
636 if (*PARSER_STREAM (parser
) == 0)
638 LS_TOKEN_STOKEN (token
).ptr
= start
;
639 LS_TOKEN_STOKEN (token
).length
= PARSER_STREAM (parser
) - start
;
642 else if (PARSER_STREAM (parser
)[0] == ':')
644 /* Do not tokenize the C++ scope operator. */
645 if (PARSER_STREAM (parser
)[1] == ':')
646 ++(PARSER_STREAM (parser
));
648 /* Do not tokenify if the input length so far is one
649 (i.e, a single-letter drive name) and the next character
650 is a directory separator. This allows Windows-style
651 paths to be recognized as filenames without quoting it. */
652 else if ((PARSER_STREAM (parser
) - start
) != 1
653 || !IS_DIR_SEPARATOR (PARSER_STREAM (parser
)[1]))
655 LS_TOKEN_STOKEN (token
).ptr
= start
;
656 LS_TOKEN_STOKEN (token
).length
657 = PARSER_STREAM (parser
) - start
;
661 /* Special case: permit quote-enclosed linespecs. */
662 else if (parser
->is_quote_enclosed
663 && strchr (linespec_quote_characters
,
664 *PARSER_STREAM (parser
))
665 && is_closing_quote_enclosed (PARSER_STREAM (parser
)))
667 LS_TOKEN_STOKEN (token
).ptr
= start
;
668 LS_TOKEN_STOKEN (token
).length
= PARSER_STREAM (parser
) - start
;
671 /* Because commas may terminate a linespec and appear in
672 the middle of valid string input, special cases for
673 '<' and '(' are necessary. */
674 else if (*PARSER_STREAM (parser
) == '<'
675 || *PARSER_STREAM (parser
) == '(')
677 /* Don't interpret 'operator<' / 'operator<<' as a
678 template parameter list though. */
679 if (*PARSER_STREAM (parser
) == '<'
680 && (PARSER_STATE (parser
)->language
->la_language
682 && (PARSER_STREAM (parser
) - start
) >= CP_OPERATOR_LEN
)
684 const char *p
= PARSER_STREAM (parser
);
686 while (p
> start
&& isspace (p
[-1]))
688 if (p
- start
>= CP_OPERATOR_LEN
)
690 p
-= CP_OPERATOR_LEN
;
691 if (strncmp (p
, CP_OPERATOR_STR
, CP_OPERATOR_LEN
) == 0
693 || !(isalnum (p
[-1]) || p
[-1] == '_')))
695 /* This is an operator name. Keep going. */
696 ++(PARSER_STREAM (parser
));
697 if (*PARSER_STREAM (parser
) == '<')
698 ++(PARSER_STREAM (parser
));
704 const char *p
= find_parameter_list_end (PARSER_STREAM (parser
));
705 PARSER_STREAM (parser
) = p
;
707 /* Don't loop around to the normal \0 case above because
708 we don't want to misinterpret a potential keyword at
709 the end of the token when the string isn't
710 "()<>"-balanced. This handles "b
711 function(thread<tab>" in completion mode. */
714 LS_TOKEN_STOKEN (token
).ptr
= start
;
715 LS_TOKEN_STOKEN (token
).length
716 = PARSER_STREAM (parser
) - start
;
722 /* Commas are terminators, but not if they are part of an
724 else if (*PARSER_STREAM (parser
) == ',')
726 if ((PARSER_STATE (parser
)->language
->la_language
728 && (PARSER_STREAM (parser
) - start
) > CP_OPERATOR_LEN
)
730 const char *p
= strstr (start
, CP_OPERATOR_STR
);
732 if (p
!= NULL
&& is_operator_name (p
))
734 /* This is an operator name. Keep going. */
735 ++(PARSER_STREAM (parser
));
740 /* Comma terminates the string. */
741 LS_TOKEN_STOKEN (token
).ptr
= start
;
742 LS_TOKEN_STOKEN (token
).length
= PARSER_STREAM (parser
) - start
;
746 /* Advance the stream. */
747 ++(PARSER_STREAM (parser
));
754 /* Lex a single linespec token from PARSER. */
756 static linespec_token
757 linespec_lexer_lex_one (linespec_parser
*parser
)
761 if (parser
->lexer
.current
.type
== LSTOKEN_CONSUMED
)
763 /* Skip any whitespace. */
764 PARSER_STREAM (parser
) = skip_spaces_const (PARSER_STREAM (parser
));
766 /* Check for a keyword, they end the linespec. */
767 keyword
= linespec_lexer_lex_keyword (PARSER_STREAM (parser
));
770 parser
->lexer
.current
.type
= LSTOKEN_KEYWORD
;
771 LS_TOKEN_KEYWORD (parser
->lexer
.current
) = keyword
;
772 /* We do not advance the stream here intentionally:
773 we would like lexing to stop when a keyword is seen.
775 PARSER_STREAM (parser) += strlen (keyword); */
777 return parser
->lexer
.current
;
780 /* Handle other tokens. */
781 switch (*PARSER_STREAM (parser
))
784 parser
->lexer
.current
.type
= LSTOKEN_EOI
;
788 case '0': case '1': case '2': case '3': case '4':
789 case '5': case '6': case '7': case '8': case '9':
790 if (!linespec_lexer_lex_number (parser
, &(parser
->lexer
.current
)))
791 parser
->lexer
.current
= linespec_lexer_lex_string (parser
);
795 /* If we have a scope operator, lex the input as a string.
796 Otherwise, return LSTOKEN_COLON. */
797 if (PARSER_STREAM (parser
)[1] == ':')
798 parser
->lexer
.current
= linespec_lexer_lex_string (parser
);
801 parser
->lexer
.current
.type
= LSTOKEN_COLON
;
802 ++(PARSER_STREAM (parser
));
806 case '\'': case '\"':
807 /* Special case: permit quote-enclosed linespecs. */
808 if (parser
->is_quote_enclosed
809 && is_closing_quote_enclosed (PARSER_STREAM (parser
)))
811 ++(PARSER_STREAM (parser
));
812 parser
->lexer
.current
.type
= LSTOKEN_EOI
;
815 parser
->lexer
.current
= linespec_lexer_lex_string (parser
);
819 parser
->lexer
.current
.type
= LSTOKEN_COMMA
;
820 LS_TOKEN_STOKEN (parser
->lexer
.current
).ptr
821 = PARSER_STREAM (parser
);
822 LS_TOKEN_STOKEN (parser
->lexer
.current
).length
= 1;
823 ++(PARSER_STREAM (parser
));
827 /* If the input is not a number, it must be a string.
828 [Keywords were already considered above.] */
829 parser
->lexer
.current
= linespec_lexer_lex_string (parser
);
834 return parser
->lexer
.current
;
837 /* Consume the current token and return the next token in PARSER's
840 static linespec_token
841 linespec_lexer_consume_token (linespec_parser
*parser
)
843 parser
->lexer
.current
.type
= LSTOKEN_CONSUMED
;
844 return linespec_lexer_lex_one (parser
);
847 /* Return the next token without consuming the current token. */
849 static linespec_token
850 linespec_lexer_peek_token (linespec_parser
*parser
)
853 const char *saved_stream
= PARSER_STREAM (parser
);
854 linespec_token saved_token
= parser
->lexer
.current
;
856 next
= linespec_lexer_consume_token (parser
);
857 PARSER_STREAM (parser
) = saved_stream
;
858 parser
->lexer
.current
= saved_token
;
862 /* Helper functions. */
864 /* Add SAL to SALS. */
867 add_sal_to_sals_basic (struct symtabs_and_lines
*sals
,
868 struct symtab_and_line
*sal
)
871 sals
->sals
= XRESIZEVEC (struct symtab_and_line
, sals
->sals
, sals
->nelts
);
872 sals
->sals
[sals
->nelts
- 1] = *sal
;
875 /* Add SAL to SALS, and also update SELF->CANONICAL_NAMES to reflect
876 the new sal, if needed. If not NULL, SYMNAME is the name of the
877 symbol to use when constructing the new canonical name.
879 If LITERAL_CANONICAL is non-zero, SYMNAME will be used as the
880 canonical name for the SAL. */
883 add_sal_to_sals (struct linespec_state
*self
,
884 struct symtabs_and_lines
*sals
,
885 struct symtab_and_line
*sal
,
886 const char *symname
, int literal_canonical
)
888 add_sal_to_sals_basic (sals
, sal
);
892 struct linespec_canonical_name
*canonical
;
894 self
->canonical_names
= XRESIZEVEC (struct linespec_canonical_name
,
895 self
->canonical_names
, sals
->nelts
);
896 canonical
= &self
->canonical_names
[sals
->nelts
- 1];
897 if (!literal_canonical
&& sal
->symtab
)
899 symtab_to_fullname (sal
->symtab
);
901 /* Note that the filter doesn't have to be a valid linespec
902 input. We only apply the ":LINE" treatment to Ada for
904 if (symname
!= NULL
&& sal
->line
!= 0
905 && self
->language
->la_language
== language_ada
)
906 canonical
->suffix
= xstrprintf ("%s:%d", symname
, sal
->line
);
907 else if (symname
!= NULL
)
908 canonical
->suffix
= xstrdup (symname
);
910 canonical
->suffix
= xstrprintf ("%d", sal
->line
);
911 canonical
->symtab
= sal
->symtab
;
916 canonical
->suffix
= xstrdup (symname
);
918 canonical
->suffix
= xstrdup ("<unknown>");
919 canonical
->symtab
= NULL
;
924 /* A hash function for address_entry. */
927 hash_address_entry (const void *p
)
929 const struct address_entry
*aep
= (const struct address_entry
*) p
;
932 hash
= iterative_hash_object (aep
->pspace
, 0);
933 return iterative_hash_object (aep
->addr
, hash
);
936 /* An equality function for address_entry. */
939 eq_address_entry (const void *a
, const void *b
)
941 const struct address_entry
*aea
= (const struct address_entry
*) a
;
942 const struct address_entry
*aeb
= (const struct address_entry
*) b
;
944 return aea
->pspace
== aeb
->pspace
&& aea
->addr
== aeb
->addr
;
947 /* Check whether the address, represented by PSPACE and ADDR, is
948 already in the set. If so, return 0. Otherwise, add it and return
952 maybe_add_address (htab_t set
, struct program_space
*pspace
, CORE_ADDR addr
)
954 struct address_entry e
, *p
;
959 slot
= htab_find_slot (set
, &e
, INSERT
);
963 p
= XNEW (struct address_entry
);
964 memcpy (p
, &e
, sizeof (struct address_entry
));
970 /* A helper that walks over all matching symtabs in all objfiles and
971 calls CALLBACK for each symbol matching NAME. If SEARCH_PSPACE is
972 not NULL, then the search is restricted to just that program
973 space. If INCLUDE_INLINE is true then symbols representing
974 inlined instances of functions will be included in the result. */
977 iterate_over_all_matching_symtabs
978 (struct linespec_state
*state
, const char *name
, const domain_enum domain
,
979 struct program_space
*search_pspace
, bool include_inline
,
980 gdb::function_view
<symbol_found_callback_ftype
> callback
)
982 struct objfile
*objfile
;
983 struct program_space
*pspace
;
985 /* The routine to be used for comparison. */
986 symbol_name_cmp_ftype symbol_name_cmp
987 = (state
->language
->la_get_symbol_name_cmp
!= NULL
988 ? state
->language
->la_get_symbol_name_cmp (name
)
993 if (search_pspace
!= NULL
&& search_pspace
!= pspace
)
995 if (pspace
->executing_startup
)
998 set_current_program_space (pspace
);
1000 ALL_OBJFILES (objfile
)
1002 struct compunit_symtab
*cu
;
1005 objfile
->sf
->qf
->expand_symtabs_matching
1008 [&] (const char *symbol_name
)
1010 return symbol_name_cmp (symbol_name
, name
) == 0;
1015 ALL_OBJFILE_COMPUNITS (objfile
, cu
)
1017 struct symtab
*symtab
= COMPUNIT_FILETABS (cu
);
1019 iterate_over_file_blocks (symtab
, name
, domain
, callback
);
1023 struct block
*block
;
1026 for (i
= FIRST_LOCAL_BLOCK
;
1027 i
< BLOCKVECTOR_NBLOCKS (SYMTAB_BLOCKVECTOR (symtab
));
1030 block
= BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab
), i
);
1031 state
->language
->la_iterate_over_symbols
1032 (block
, name
, domain
, [&] (symbol
*sym
)
1034 /* Restrict calls to CALLBACK to symbols
1035 representing inline symbols only. */
1036 if (SYMBOL_INLINED (sym
))
1037 return callback (sym
);
1047 /* Returns the block to be used for symbol searches from
1048 the current location. */
1050 static const struct block
*
1051 get_current_search_block (void)
1053 const struct block
*block
;
1054 enum language save_language
;
1056 /* get_selected_block can change the current language when there is
1057 no selected frame yet. */
1058 save_language
= current_language
->la_language
;
1059 block
= get_selected_block (0);
1060 set_language (save_language
);
1065 /* Iterate over static and global blocks. */
1068 iterate_over_file_blocks
1069 (struct symtab
*symtab
, const char *name
, domain_enum domain
,
1070 gdb::function_view
<symbol_found_callback_ftype
> callback
)
1072 struct block
*block
;
1074 for (block
= BLOCKVECTOR_BLOCK (SYMTAB_BLOCKVECTOR (symtab
), STATIC_BLOCK
);
1076 block
= BLOCK_SUPERBLOCK (block
))
1077 LA_ITERATE_OVER_SYMBOLS (block
, name
, domain
, callback
);
1080 /* A helper for find_method. This finds all methods in type T which
1081 match NAME. It adds matching symbol names to RESULT_NAMES, and
1082 adds T's direct superclasses to SUPERCLASSES. */
1085 find_methods (struct type
*t
, const char *name
,
1086 VEC (const_char_ptr
) **result_names
,
1087 VEC (typep
) **superclasses
)
1090 const char *class_name
= type_name_no_tag (t
);
1092 /* Ignore this class if it doesn't have a name. This is ugly, but
1093 unless we figure out how to get the physname without the name of
1094 the class, then the loop can't do any good. */
1099 t
= check_typedef (t
);
1101 /* Loop over each method name. At this level, all overloads of a name
1102 are counted as a single name. There is an inner loop which loops over
1105 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
1106 method_counter
>= 0;
1109 const char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
1110 char dem_opname
[64];
1112 if (startswith (method_name
, "__") ||
1113 startswith (method_name
, "op") ||
1114 startswith (method_name
, "type"))
1116 if (cplus_demangle_opname (method_name
, dem_opname
, DMGL_ANSI
))
1117 method_name
= dem_opname
;
1118 else if (cplus_demangle_opname (method_name
, dem_opname
, 0))
1119 method_name
= dem_opname
;
1122 if (strcmp_iw (method_name
, name
) == 0)
1126 for (field_counter
= (TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
)
1132 const char *phys_name
;
1134 f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
1135 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
1137 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
1138 VEC_safe_push (const_char_ptr
, *result_names
, phys_name
);
1144 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
1145 VEC_safe_push (typep
, *superclasses
, TYPE_BASECLASS (t
, ibase
));
1148 /* Find an instance of the character C in the string S that is outside
1149 of all parenthesis pairs, single-quoted strings, and double-quoted
1150 strings. Also, ignore the char within a template name, like a ','
1151 within foo<int, int>, while considering C++ operator</operator<<. */
1154 find_toplevel_char (const char *s
, char c
)
1156 int quoted
= 0; /* zero if we're not in quotes;
1157 '"' if we're in a double-quoted string;
1158 '\'' if we're in a single-quoted string. */
1159 int depth
= 0; /* Number of unclosed parens we've seen. */
1162 for (scan
= s
; *scan
; scan
++)
1166 if (*scan
== quoted
)
1168 else if (*scan
== '\\' && *(scan
+ 1))
1171 else if (*scan
== c
&& ! quoted
&& depth
== 0)
1173 else if (*scan
== '"' || *scan
== '\'')
1175 else if (*scan
== '(' || *scan
== '<')
1177 else if ((*scan
== ')' || *scan
== '>') && depth
> 0)
1179 else if (*scan
== 'o' && !quoted
&& depth
== 0)
1181 /* Handle C++ operator names. */
1182 if (strncmp (scan
, CP_OPERATOR_STR
, CP_OPERATOR_LEN
) == 0)
1184 scan
+= CP_OPERATOR_LEN
;
1187 while (isspace (*scan
))
1198 /* Skip over one less than the appropriate number of
1199 characters: the for loop will skip over the last
1225 /* The string equivalent of find_toplevel_char. Returns a pointer
1226 to the location of NEEDLE in HAYSTACK, ignoring any occurrences
1227 inside "()" and "<>". Returns NULL if NEEDLE was not found. */
1230 find_toplevel_string (const char *haystack
, const char *needle
)
1232 const char *s
= haystack
;
1236 s
= find_toplevel_char (s
, *needle
);
1240 /* Found first char in HAYSTACK; check rest of string. */
1241 if (startswith (s
, needle
))
1244 /* Didn't find it; loop over HAYSTACK, looking for the next
1245 instance of the first character of NEEDLE. */
1249 while (s
!= NULL
&& *s
!= '\0');
1251 /* NEEDLE was not found in HAYSTACK. */
1255 /* Convert CANONICAL to its string representation using
1256 symtab_to_fullname for SYMTAB. The caller must xfree the result. */
1259 canonical_to_fullform (const struct linespec_canonical_name
*canonical
)
1261 if (canonical
->symtab
== NULL
)
1262 return xstrdup (canonical
->suffix
);
1264 return xstrprintf ("%s:%s", symtab_to_fullname (canonical
->symtab
),
1268 /* Given FILTERS, a list of canonical names, filter the sals in RESULT
1269 and store the result in SELF->CANONICAL. */
1272 filter_results (struct linespec_state
*self
,
1273 struct symtabs_and_lines
*result
,
1274 VEC (const_char_ptr
) *filters
)
1279 for (i
= 0; VEC_iterate (const_char_ptr
, filters
, i
, name
); ++i
)
1281 struct linespec_sals lsal
;
1284 memset (&lsal
, 0, sizeof (lsal
));
1286 for (j
= 0; j
< result
->nelts
; ++j
)
1288 const struct linespec_canonical_name
*canonical
;
1290 struct cleanup
*cleanup
;
1292 canonical
= &self
->canonical_names
[j
];
1293 fullform
= canonical_to_fullform (canonical
);
1294 cleanup
= make_cleanup (xfree
, fullform
);
1296 if (strcmp (name
, fullform
) == 0)
1297 add_sal_to_sals_basic (&lsal
.sals
, &result
->sals
[j
]);
1299 do_cleanups (cleanup
);
1302 if (lsal
.sals
.nelts
> 0)
1304 lsal
.canonical
= xstrdup (name
);
1305 VEC_safe_push (linespec_sals
, self
->canonical
->sals
, &lsal
);
1309 self
->canonical
->pre_expanded
= 0;
1312 /* Store RESULT into SELF->CANONICAL. */
1315 convert_results_to_lsals (struct linespec_state
*self
,
1316 struct symtabs_and_lines
*result
)
1318 struct linespec_sals lsal
;
1320 lsal
.canonical
= NULL
;
1321 lsal
.sals
= *result
;
1322 VEC_safe_push (linespec_sals
, self
->canonical
->sals
, &lsal
);
1325 /* A structure that contains two string representations of a struct
1326 linespec_canonical_name:
1327 - one where the the symtab's fullname is used;
1328 - one where the filename followed the "set filename-display"
1331 struct decode_line_2_item
1333 /* The form using symtab_to_fullname.
1334 It must be xfree'ed after use. */
1337 /* The form using symtab_to_filename_for_display.
1338 It must be xfree'ed after use. */
1341 /* Field is initialized to zero and it is set to one if the user
1342 requested breakpoint for this entry. */
1343 unsigned int selected
: 1;
1346 /* Helper for qsort to sort decode_line_2_item entries by DISPLAYFORM and
1347 secondarily by FULLFORM. */
1350 decode_line_2_compare_items (const void *ap
, const void *bp
)
1352 const struct decode_line_2_item
*a
= (const struct decode_line_2_item
*) ap
;
1353 const struct decode_line_2_item
*b
= (const struct decode_line_2_item
*) bp
;
1356 retval
= strcmp (a
->displayform
, b
->displayform
);
1360 return strcmp (a
->fullform
, b
->fullform
);
1363 /* Handle multiple results in RESULT depending on SELECT_MODE. This
1364 will either return normally, throw an exception on multiple
1365 results, or present a menu to the user. On return, the SALS vector
1366 in SELF->CANONICAL is set up properly. */
1369 decode_line_2 (struct linespec_state
*self
,
1370 struct symtabs_and_lines
*result
,
1371 const char *select_mode
)
1376 struct cleanup
*old_chain
;
1377 VEC (const_char_ptr
) *filters
= NULL
;
1378 struct decode_line_2_item
*items
;
1381 gdb_assert (select_mode
!= multiple_symbols_all
);
1382 gdb_assert (self
->canonical
!= NULL
);
1383 gdb_assert (result
->nelts
>= 1);
1385 old_chain
= make_cleanup (VEC_cleanup (const_char_ptr
), &filters
);
1387 /* Prepare ITEMS array. */
1388 items_count
= result
->nelts
;
1389 items
= XNEWVEC (struct decode_line_2_item
, items_count
);
1390 make_cleanup (xfree
, items
);
1391 for (i
= 0; i
< items_count
; ++i
)
1393 const struct linespec_canonical_name
*canonical
;
1394 struct decode_line_2_item
*item
;
1396 canonical
= &self
->canonical_names
[i
];
1397 gdb_assert (canonical
->suffix
!= NULL
);
1400 item
->fullform
= canonical_to_fullform (canonical
);
1401 make_cleanup (xfree
, item
->fullform
);
1403 if (canonical
->symtab
== NULL
)
1404 item
->displayform
= canonical
->suffix
;
1407 const char *fn_for_display
;
1409 fn_for_display
= symtab_to_filename_for_display (canonical
->symtab
);
1410 item
->displayform
= xstrprintf ("%s:%s", fn_for_display
,
1412 make_cleanup (xfree
, item
->displayform
);
1418 /* Sort the list of method names. */
1419 qsort (items
, items_count
, sizeof (*items
), decode_line_2_compare_items
);
1421 /* Remove entries with the same FULLFORM. */
1422 if (items_count
>= 2)
1424 struct decode_line_2_item
*dst
, *src
;
1427 for (src
= &items
[1]; src
< &items
[items_count
]; src
++)
1428 if (strcmp (src
->fullform
, dst
->fullform
) != 0)
1430 items_count
= dst
+ 1 - items
;
1433 if (select_mode
== multiple_symbols_cancel
&& items_count
> 1)
1434 error (_("canceled because the command is ambiguous\n"
1435 "See set/show multiple-symbol."));
1437 if (select_mode
== multiple_symbols_all
|| items_count
== 1)
1439 do_cleanups (old_chain
);
1440 convert_results_to_lsals (self
, result
);
1444 printf_unfiltered (_("[0] cancel\n[1] all\n"));
1445 for (i
= 0; i
< items_count
; i
++)
1446 printf_unfiltered ("[%d] %s\n", i
+ 2, items
[i
].displayform
);
1448 prompt
= getenv ("PS2");
1453 args
= command_line_input (prompt
, 0, "overload-choice");
1455 if (args
== 0 || *args
== 0)
1456 error_no_arg (_("one or more choice numbers"));
1458 number_or_range_parser
parser (args
);
1459 while (!parser
.finished ())
1461 int num
= parser
.get_number ();
1464 error (_("canceled"));
1467 /* We intentionally make this result in a single breakpoint,
1468 contrary to what older versions of gdb did. The
1469 rationale is that this lets a user get the
1470 multiple_symbols_all behavior even with the 'ask'
1471 setting; and he can get separate breakpoints by entering
1472 "2-57" at the query. */
1473 do_cleanups (old_chain
);
1474 convert_results_to_lsals (self
, result
);
1479 if (num
>= items_count
)
1480 printf_unfiltered (_("No choice number %d.\n"), num
);
1483 struct decode_line_2_item
*item
= &items
[num
];
1485 if (!item
->selected
)
1487 VEC_safe_push (const_char_ptr
, filters
, item
->fullform
);
1492 printf_unfiltered (_("duplicate request for %d ignored.\n"),
1498 filter_results (self
, result
, filters
);
1499 do_cleanups (old_chain
);
1504 /* The parser of linespec itself. */
1506 /* Throw an appropriate error when SYMBOL is not found (optionally in
1509 static void ATTRIBUTE_NORETURN
1510 symbol_not_found_error (const char *symbol
, const char *filename
)
1515 if (!have_full_symbols ()
1516 && !have_partial_symbols ()
1517 && !have_minimal_symbols ())
1518 throw_error (NOT_FOUND_ERROR
,
1519 _("No symbol table is loaded. Use the \"file\" command."));
1521 /* If SYMBOL starts with '$', the user attempted to either lookup
1522 a function/variable in his code starting with '$' or an internal
1523 variable of that name. Since we do not know which, be concise and
1524 explain both possibilities. */
1528 throw_error (NOT_FOUND_ERROR
,
1529 _("Undefined convenience variable or function \"%s\" "
1530 "not defined in \"%s\"."), symbol
, filename
);
1532 throw_error (NOT_FOUND_ERROR
,
1533 _("Undefined convenience variable or function \"%s\" "
1534 "not defined."), symbol
);
1539 throw_error (NOT_FOUND_ERROR
,
1540 _("Function \"%s\" not defined in \"%s\"."),
1543 throw_error (NOT_FOUND_ERROR
,
1544 _("Function \"%s\" not defined."), symbol
);
1548 /* Throw an appropriate error when an unexpected token is encountered
1551 static void ATTRIBUTE_NORETURN
1552 unexpected_linespec_error (linespec_parser
*parser
)
1554 linespec_token token
;
1555 static const char * token_type_strings
[]
1556 = {"keyword", "colon", "string", "number", "comma", "end of input"};
1558 /* Get the token that generated the error. */
1559 token
= linespec_lexer_lex_one (parser
);
1561 /* Finally, throw the error. */
1562 if (token
.type
== LSTOKEN_STRING
|| token
.type
== LSTOKEN_NUMBER
1563 || token
.type
== LSTOKEN_KEYWORD
)
1567 string
= copy_token_string (token
);
1568 make_cleanup (xfree
, string
);
1569 throw_error (GENERIC_ERROR
,
1570 _("malformed linespec error: unexpected %s, \"%s\""),
1571 token_type_strings
[token
.type
], string
);
1574 throw_error (GENERIC_ERROR
,
1575 _("malformed linespec error: unexpected %s"),
1576 token_type_strings
[token
.type
]);
1579 /* Throw an undefined label error. */
1581 static void ATTRIBUTE_NORETURN
1582 undefined_label_error (const char *function
, const char *label
)
1584 if (function
!= NULL
)
1585 throw_error (NOT_FOUND_ERROR
,
1586 _("No label \"%s\" defined in function \"%s\"."),
1589 throw_error (NOT_FOUND_ERROR
,
1590 _("No label \"%s\" defined in current function."),
1594 /* Throw a source file not found error. */
1596 static void ATTRIBUTE_NORETURN
1597 source_file_not_found_error (const char *name
)
1599 throw_error (NOT_FOUND_ERROR
, _("No source file named %s."), name
);
1602 /* See description in linespec.h. */
1605 linespec_parse_line_offset (const char *string
)
1607 const char *start
= string
;
1608 struct line_offset line_offset
= {0, LINE_OFFSET_NONE
};
1612 line_offset
.sign
= LINE_OFFSET_PLUS
;
1615 else if (*string
== '-')
1617 line_offset
.sign
= LINE_OFFSET_MINUS
;
1621 if (*string
!= '\0' && !isdigit (*string
))
1622 error (_("malformed line offset: \"%s\""), start
);
1624 /* Right now, we only allow base 10 for offsets. */
1625 line_offset
.offset
= atoi (string
);
1629 /* Parse the basic_spec in PARSER's input. */
1632 linespec_parse_basic (linespec_parser
*parser
)
1635 linespec_token token
;
1636 VEC (symbolp
) *symbols
, *labels
;
1637 VEC (bound_minimal_symbol_d
) *minimal_symbols
;
1638 struct cleanup
*cleanup
;
1640 /* Get the next token. */
1641 token
= linespec_lexer_lex_one (parser
);
1643 /* If it is EOI or KEYWORD, issue an error. */
1644 if (token
.type
== LSTOKEN_KEYWORD
|| token
.type
== LSTOKEN_EOI
)
1645 unexpected_linespec_error (parser
);
1646 /* If it is a LSTOKEN_NUMBER, we have an offset. */
1647 else if (token
.type
== LSTOKEN_NUMBER
)
1649 /* Record the line offset and get the next token. */
1650 name
= copy_token_string (token
);
1651 cleanup
= make_cleanup (xfree
, name
);
1652 PARSER_EXPLICIT (parser
)->line_offset
= linespec_parse_line_offset (name
);
1653 do_cleanups (cleanup
);
1655 /* Get the next token. */
1656 token
= linespec_lexer_consume_token (parser
);
1658 /* If the next token is a comma, stop parsing and return. */
1659 if (token
.type
== LSTOKEN_COMMA
)
1662 /* If the next token is anything but EOI or KEYWORD, issue
1664 if (token
.type
!= LSTOKEN_KEYWORD
&& token
.type
!= LSTOKEN_EOI
)
1665 unexpected_linespec_error (parser
);
1668 if (token
.type
== LSTOKEN_KEYWORD
|| token
.type
== LSTOKEN_EOI
)
1671 /* Next token must be LSTOKEN_STRING. */
1672 if (token
.type
!= LSTOKEN_STRING
)
1673 unexpected_linespec_error (parser
);
1675 /* The current token will contain the name of a function, method,
1677 name
= copy_token_string (token
);
1678 cleanup
= make_cleanup (xfree
, name
);
1680 /* Try looking it up as a function/method. */
1681 find_linespec_symbols (PARSER_STATE (parser
),
1682 PARSER_RESULT (parser
)->file_symtabs
, name
,
1683 &symbols
, &minimal_symbols
);
1685 if (symbols
!= NULL
|| minimal_symbols
!= NULL
)
1687 PARSER_RESULT (parser
)->function_symbols
= symbols
;
1688 PARSER_RESULT (parser
)->minimal_symbols
= minimal_symbols
;
1689 PARSER_EXPLICIT (parser
)->function_name
= name
;
1691 discard_cleanups (cleanup
);
1695 /* NAME was not a function or a method. So it must be a label
1696 name or user specified variable like "break foo.c:$zippo". */
1697 labels
= find_label_symbols (PARSER_STATE (parser
), NULL
,
1701 PARSER_RESULT (parser
)->labels
.label_symbols
= labels
;
1702 PARSER_RESULT (parser
)->labels
.function_symbols
= symbols
;
1703 PARSER_EXPLICIT (parser
)->label_name
= name
;
1705 discard_cleanups (cleanup
);
1707 else if (token
.type
== LSTOKEN_STRING
1708 && *LS_TOKEN_STOKEN (token
).ptr
== '$')
1710 /* User specified a convenience variable or history value. */
1711 PARSER_EXPLICIT (parser
)->line_offset
1712 = linespec_parse_variable (PARSER_STATE (parser
), name
);
1714 if (PARSER_EXPLICIT (parser
)->line_offset
.sign
== LINE_OFFSET_UNKNOWN
)
1716 /* The user-specified variable was not valid. Do not
1717 throw an error here. parse_linespec will do it for us. */
1718 PARSER_EXPLICIT (parser
)->function_name
= name
;
1719 discard_cleanups (cleanup
);
1723 /* The convenience variable/history value parsed correctly.
1724 NAME is no longer needed. */
1725 do_cleanups (cleanup
);
1729 /* The name is also not a label. Abort parsing. Do not throw
1730 an error here. parse_linespec will do it for us. */
1732 /* Save a copy of the name we were trying to lookup. */
1733 PARSER_EXPLICIT (parser
)->function_name
= name
;
1734 discard_cleanups (cleanup
);
1739 /* Get the next token. */
1740 token
= linespec_lexer_consume_token (parser
);
1742 if (token
.type
== LSTOKEN_COLON
)
1744 /* User specified a label or a lineno. */
1745 token
= linespec_lexer_consume_token (parser
);
1747 if (token
.type
== LSTOKEN_NUMBER
)
1749 /* User specified an offset. Record the line offset and
1750 get the next token. */
1751 name
= copy_token_string (token
);
1752 cleanup
= make_cleanup (xfree
, name
);
1753 PARSER_EXPLICIT (parser
)->line_offset
1754 = linespec_parse_line_offset (name
);
1755 do_cleanups (cleanup
);
1757 /* Ge the next token. */
1758 token
= linespec_lexer_consume_token (parser
);
1760 else if (token
.type
== LSTOKEN_STRING
)
1762 /* Grab a copy of the label's name and look it up. */
1763 name
= copy_token_string (token
);
1764 cleanup
= make_cleanup (xfree
, name
);
1765 labels
= find_label_symbols (PARSER_STATE (parser
),
1766 PARSER_RESULT (parser
)->function_symbols
,
1771 PARSER_RESULT (parser
)->labels
.label_symbols
= labels
;
1772 PARSER_RESULT (parser
)->labels
.function_symbols
= symbols
;
1773 PARSER_EXPLICIT (parser
)->label_name
= name
;
1775 discard_cleanups (cleanup
);
1779 /* We don't know what it was, but it isn't a label. */
1780 undefined_label_error (PARSER_EXPLICIT (parser
)->function_name
,
1784 /* Check for a line offset. */
1785 token
= linespec_lexer_consume_token (parser
);
1786 if (token
.type
== LSTOKEN_COLON
)
1788 /* Get the next token. */
1789 token
= linespec_lexer_consume_token (parser
);
1791 /* It must be a line offset. */
1792 if (token
.type
!= LSTOKEN_NUMBER
)
1793 unexpected_linespec_error (parser
);
1795 /* Record the line offset and get the next token. */
1796 name
= copy_token_string (token
);
1797 cleanup
= make_cleanup (xfree
, name
);
1799 PARSER_EXPLICIT (parser
)->line_offset
1800 = linespec_parse_line_offset (name
);
1801 do_cleanups (cleanup
);
1803 /* Get the next token. */
1804 token
= linespec_lexer_consume_token (parser
);
1809 /* Trailing ':' in the input. Issue an error. */
1810 unexpected_linespec_error (parser
);
1815 /* Canonicalize the linespec contained in LS. The result is saved into
1816 STATE->canonical. This function handles both linespec and explicit
1820 canonicalize_linespec (struct linespec_state
*state
, const linespec_p ls
)
1822 struct event_location
*canon
;
1823 struct explicit_location
*explicit_loc
;
1825 /* If canonicalization was not requested, no need to do anything. */
1826 if (!state
->canonical
)
1829 /* Save everything as an explicit location. */
1830 state
->canonical
->location
1831 = new_explicit_location (&ls
->explicit_loc
);
1832 canon
= state
->canonical
->location
.get ();
1833 explicit_loc
= get_explicit_location (canon
);
1835 if (explicit_loc
->label_name
!= NULL
)
1837 state
->canonical
->special_display
= 1;
1839 if (explicit_loc
->function_name
== NULL
)
1843 /* No function was specified, so add the symbol name. */
1844 gdb_assert (ls
->labels
.function_symbols
!= NULL
1845 && (VEC_length (symbolp
, ls
->labels
.function_symbols
)
1847 s
= VEC_index (symbolp
, ls
->labels
.function_symbols
, 0);
1848 explicit_loc
->function_name
= xstrdup (SYMBOL_NATURAL_NAME (s
));
1852 /* If this location originally came from a linespec, save a string
1853 representation of it for display and saving to file. */
1854 if (state
->is_linespec
)
1856 char *linespec
= explicit_location_to_linespec (explicit_loc
);
1858 set_event_location_string (canon
, linespec
);
1863 /* Given a line offset in LS, construct the relevant SALs. */
1865 static struct symtabs_and_lines
1866 create_sals_line_offset (struct linespec_state
*self
,
1869 struct symtabs_and_lines values
;
1870 struct symtab_and_line val
;
1871 int use_default
= 0;
1877 /* This is where we need to make sure we have good defaults.
1878 We must guarantee that this section of code is never executed
1879 when we are called with just a function name, since
1880 set_default_source_symtab_and_line uses
1881 select_source_symtab that calls us with such an argument. */
1883 if (VEC_length (symtab_ptr
, ls
->file_symtabs
) == 1
1884 && VEC_index (symtab_ptr
, ls
->file_symtabs
, 0) == NULL
)
1886 const char *fullname
;
1888 set_current_program_space (self
->program_space
);
1890 /* Make sure we have at least a default source line. */
1891 set_default_source_symtab_and_line ();
1892 initialize_defaults (&self
->default_symtab
, &self
->default_line
);
1893 fullname
= symtab_to_fullname (self
->default_symtab
);
1894 VEC_pop (symtab_ptr
, ls
->file_symtabs
);
1895 VEC_free (symtab_ptr
, ls
->file_symtabs
);
1896 ls
->file_symtabs
= collect_symtabs_from_filename (fullname
,
1897 self
->search_pspace
);
1901 val
.line
= ls
->explicit_loc
.line_offset
.offset
;
1902 switch (ls
->explicit_loc
.line_offset
.sign
)
1904 case LINE_OFFSET_PLUS
:
1905 if (ls
->explicit_loc
.line_offset
.offset
== 0)
1908 val
.line
= self
->default_line
+ val
.line
;
1911 case LINE_OFFSET_MINUS
:
1912 if (ls
->explicit_loc
.line_offset
.offset
== 0)
1915 val
.line
= self
->default_line
- val
.line
;
1917 val
.line
= -val
.line
;
1920 case LINE_OFFSET_NONE
:
1921 break; /* No need to adjust val.line. */
1924 if (self
->list_mode
)
1925 decode_digits_list_mode (self
, ls
, &values
, val
);
1928 struct linetable_entry
*best_entry
= NULL
;
1930 const struct block
**blocks
;
1931 struct cleanup
*cleanup
;
1932 struct symtabs_and_lines intermediate_results
;
1935 intermediate_results
.sals
= NULL
;
1936 intermediate_results
.nelts
= 0;
1938 decode_digits_ordinary (self
, ls
, val
.line
, &intermediate_results
,
1940 if (intermediate_results
.nelts
== 0 && best_entry
!= NULL
)
1941 decode_digits_ordinary (self
, ls
, best_entry
->line
,
1942 &intermediate_results
, &best_entry
);
1944 cleanup
= make_cleanup (xfree
, intermediate_results
.sals
);
1946 /* For optimized code, the compiler can scatter one source line
1947 across disjoint ranges of PC values, even when no duplicate
1948 functions or inline functions are involved. For example,
1949 'for (;;)' inside a non-template, non-inline, and non-ctor-or-dtor
1950 function can result in two PC ranges. In this case, we don't
1951 want to set a breakpoint on the first PC of each range. To filter
1952 such cases, we use containing blocks -- for each PC found
1953 above, we see if there are other PCs that are in the same
1954 block. If yes, the other PCs are filtered out. */
1956 filter
= XNEWVEC (int, intermediate_results
.nelts
);
1957 make_cleanup (xfree
, filter
);
1958 blocks
= XNEWVEC (const struct block
*, intermediate_results
.nelts
);
1959 make_cleanup (xfree
, blocks
);
1961 for (i
= 0; i
< intermediate_results
.nelts
; ++i
)
1963 set_current_program_space (intermediate_results
.sals
[i
].pspace
);
1966 blocks
[i
] = block_for_pc_sect (intermediate_results
.sals
[i
].pc
,
1967 intermediate_results
.sals
[i
].section
);
1970 for (i
= 0; i
< intermediate_results
.nelts
; ++i
)
1972 if (blocks
[i
] != NULL
)
1973 for (j
= i
+ 1; j
< intermediate_results
.nelts
; ++j
)
1975 if (blocks
[j
] == blocks
[i
])
1983 for (i
= 0; i
< intermediate_results
.nelts
; ++i
)
1986 struct symbol
*sym
= (blocks
[i
]
1987 ? block_containing_function (blocks
[i
])
1990 if (self
->funfirstline
)
1991 skip_prologue_sal (&intermediate_results
.sals
[i
]);
1992 /* Make sure the line matches the request, not what was
1994 intermediate_results
.sals
[i
].line
= val
.line
;
1995 add_sal_to_sals (self
, &values
, &intermediate_results
.sals
[i
],
1996 sym
? SYMBOL_NATURAL_NAME (sym
) : NULL
, 0);
1999 do_cleanups (cleanup
);
2002 if (values
.nelts
== 0)
2004 if (ls
->explicit_loc
.source_filename
)
2005 throw_error (NOT_FOUND_ERROR
, _("No line %d in file \"%s\"."),
2006 val
.line
, ls
->explicit_loc
.source_filename
);
2008 throw_error (NOT_FOUND_ERROR
, _("No line %d in the current file."),
2015 /* Convert the given ADDRESS into SaLs. */
2017 static struct symtabs_and_lines
2018 convert_address_location_to_sals (struct linespec_state
*self
,
2021 struct symtab_and_line sal
;
2022 struct symtabs_and_lines sals
= {NULL
, 0};
2024 sal
= find_pc_line (address
, 0);
2026 sal
.section
= find_pc_overlay (address
);
2027 sal
.explicit_pc
= 1;
2028 add_sal_to_sals (self
, &sals
, &sal
, core_addr_to_string (address
), 1);
2033 /* Create and return SALs from the linespec LS. */
2035 static struct symtabs_and_lines
2036 convert_linespec_to_sals (struct linespec_state
*state
, linespec_p ls
)
2038 struct symtabs_and_lines sals
= {NULL
, 0};
2040 if (ls
->labels
.label_symbols
!= NULL
)
2042 /* We have just a bunch of functions/methods or labels. */
2044 struct symtab_and_line sal
;
2047 for (i
= 0; VEC_iterate (symbolp
, ls
->labels
.label_symbols
, i
, sym
); ++i
)
2049 struct program_space
*pspace
= SYMTAB_PSPACE (symbol_symtab (sym
));
2051 if (symbol_to_sal (&sal
, state
->funfirstline
, sym
)
2052 && maybe_add_address (state
->addr_set
, pspace
, sal
.pc
))
2053 add_sal_to_sals (state
, &sals
, &sal
,
2054 SYMBOL_NATURAL_NAME (sym
), 0);
2057 else if (ls
->function_symbols
!= NULL
|| ls
->minimal_symbols
!= NULL
)
2059 /* We have just a bunch of functions and/or methods. */
2061 struct symtab_and_line sal
;
2063 bound_minimal_symbol_d
*elem
;
2064 struct program_space
*pspace
;
2066 if (ls
->function_symbols
!= NULL
)
2068 /* Sort symbols so that symbols with the same program space are next
2070 qsort (VEC_address (symbolp
, ls
->function_symbols
),
2071 VEC_length (symbolp
, ls
->function_symbols
),
2072 sizeof (symbolp
), compare_symbols
);
2074 for (i
= 0; VEC_iterate (symbolp
, ls
->function_symbols
, i
, sym
); ++i
)
2076 pspace
= SYMTAB_PSPACE (symbol_symtab (sym
));
2077 set_current_program_space (pspace
);
2078 if (symbol_to_sal (&sal
, state
->funfirstline
, sym
)
2079 && maybe_add_address (state
->addr_set
, pspace
, sal
.pc
))
2080 add_sal_to_sals (state
, &sals
, &sal
,
2081 SYMBOL_NATURAL_NAME (sym
), 0);
2085 if (ls
->minimal_symbols
!= NULL
)
2087 /* Sort minimal symbols by program space, too. */
2088 qsort (VEC_address (bound_minimal_symbol_d
, ls
->minimal_symbols
),
2089 VEC_length (bound_minimal_symbol_d
, ls
->minimal_symbols
),
2090 sizeof (bound_minimal_symbol_d
), compare_msymbols
);
2093 VEC_iterate (bound_minimal_symbol_d
, ls
->minimal_symbols
,
2097 pspace
= elem
->objfile
->pspace
;
2098 set_current_program_space (pspace
);
2099 minsym_found (state
, elem
->objfile
, elem
->minsym
, &sals
);
2103 else if (ls
->explicit_loc
.line_offset
.sign
!= LINE_OFFSET_UNKNOWN
)
2105 /* Only an offset was specified. */
2106 sals
= create_sals_line_offset (state
, ls
);
2108 /* Make sure we have a filename for canonicalization. */
2109 if (ls
->explicit_loc
.source_filename
== NULL
)
2111 const char *fullname
= symtab_to_fullname (state
->default_symtab
);
2113 /* It may be more appropriate to keep DEFAULT_SYMTAB in its symtab
2114 form so that displaying SOURCE_FILENAME can follow the current
2115 FILENAME_DISPLAY_STRING setting. But as it is used only rarely
2116 it has been kept for code simplicity only in absolute form. */
2117 ls
->explicit_loc
.source_filename
= xstrdup (fullname
);
2122 /* We haven't found any results... */
2126 canonicalize_linespec (state
, ls
);
2128 if (sals
.nelts
> 0 && state
->canonical
!= NULL
)
2129 state
->canonical
->pre_expanded
= 1;
2134 /* Build RESULT from the explicit location components SOURCE_FILENAME,
2135 FUNCTION_NAME, LABEL_NAME and LINE_OFFSET. */
2138 convert_explicit_location_to_linespec (struct linespec_state
*self
,
2140 const char *source_filename
,
2141 const char *function_name
,
2142 const char *label_name
,
2143 struct line_offset line_offset
)
2145 VEC (symbolp
) *symbols
, *labels
;
2146 VEC (bound_minimal_symbol_d
) *minimal_symbols
;
2148 if (source_filename
!= NULL
)
2152 result
->file_symtabs
2153 = symtabs_from_filename (source_filename
, self
->search_pspace
);
2155 CATCH (except
, RETURN_MASK_ERROR
)
2157 source_file_not_found_error (source_filename
);
2160 result
->explicit_loc
.source_filename
= xstrdup (source_filename
);
2164 /* A NULL entry means to use the default symtab. */
2165 VEC_safe_push (symtab_ptr
, result
->file_symtabs
, NULL
);
2168 if (function_name
!= NULL
)
2170 find_linespec_symbols (self
, result
->file_symtabs
,
2171 function_name
, &symbols
,
2174 if (symbols
== NULL
&& minimal_symbols
== NULL
)
2175 symbol_not_found_error (function_name
,
2176 result
->explicit_loc
.source_filename
);
2178 result
->explicit_loc
.function_name
= xstrdup (function_name
);
2179 result
->function_symbols
= symbols
;
2180 result
->minimal_symbols
= minimal_symbols
;
2183 if (label_name
!= NULL
)
2186 labels
= find_label_symbols (self
, result
->function_symbols
,
2187 &symbols
, label_name
);
2190 undefined_label_error (result
->explicit_loc
.function_name
,
2193 result
->explicit_loc
.label_name
= xstrdup (label_name
);
2194 result
->labels
.label_symbols
= labels
;
2195 result
->labels
.function_symbols
= symbols
;
2198 if (line_offset
.sign
!= LINE_OFFSET_UNKNOWN
)
2199 result
->explicit_loc
.line_offset
= line_offset
;
2202 /* Convert the explicit location EXPLICIT_LOC into SaLs. */
2204 static struct symtabs_and_lines
2205 convert_explicit_location_to_sals (struct linespec_state
*self
,
2207 const struct explicit_location
*explicit_loc
)
2209 convert_explicit_location_to_linespec (self
, result
,
2210 explicit_loc
->source_filename
,
2211 explicit_loc
->function_name
,
2212 explicit_loc
->label_name
,
2213 explicit_loc
->line_offset
);
2214 return convert_linespec_to_sals (self
, result
);
2217 /* Parse a string that specifies a linespec.
2219 The basic grammar of linespecs:
2221 linespec -> var_spec | basic_spec
2222 var_spec -> '$' (STRING | NUMBER)
2224 basic_spec -> file_offset_spec | function_spec | label_spec
2225 file_offset_spec -> opt_file_spec offset_spec
2226 function_spec -> opt_file_spec function_name_spec opt_label_spec
2227 label_spec -> label_name_spec
2229 opt_file_spec -> "" | file_name_spec ':'
2230 opt_label_spec -> "" | ':' label_name_spec
2232 file_name_spec -> STRING
2233 function_name_spec -> STRING
2234 label_name_spec -> STRING
2235 function_name_spec -> STRING
2236 offset_spec -> NUMBER
2240 This may all be followed by several keywords such as "if EXPR",
2243 A comma will terminate parsing.
2245 The function may be an undebuggable function found in minimal symbol table.
2247 If the argument FUNFIRSTLINE is nonzero, we want the first line
2248 of real code inside a function when a function is specified, and it is
2249 not OK to specify a variable or type to get its line number.
2251 DEFAULT_SYMTAB specifies the file to use if none is specified.
2252 It defaults to current_source_symtab.
2253 DEFAULT_LINE specifies the line number to use for relative
2254 line numbers (that start with signs). Defaults to current_source_line.
2255 If CANONICAL is non-NULL, store an array of strings containing the canonical
2256 line specs there if necessary. Currently overloaded member functions and
2257 line numbers or static functions without a filename yield a canonical
2258 line spec. The array and the line spec strings are allocated on the heap,
2259 it is the callers responsibility to free them.
2261 Note that it is possible to return zero for the symtab
2262 if no file is validly specified. Callers must check that.
2263 Also, the line number returned may be invalid. */
2265 /* Parse the linespec in ARG. */
2267 static struct symtabs_and_lines
2268 parse_linespec (linespec_parser
*parser
, const char *arg
)
2270 linespec_token token
;
2271 struct symtabs_and_lines values
;
2272 struct gdb_exception file_exception
= exception_none
;
2273 struct cleanup
*cleanup
;
2275 /* A special case to start. It has become quite popular for
2276 IDEs to work around bugs in the previous parser by quoting
2277 the entire linespec, so we attempt to deal with this nicely. */
2278 parser
->is_quote_enclosed
= 0;
2279 if (!is_ada_operator (arg
)
2280 && strchr (linespec_quote_characters
, *arg
) != NULL
)
2284 end
= skip_quote_char (arg
+ 1, *arg
);
2285 if (end
!= NULL
&& is_closing_quote_enclosed (end
))
2287 /* Here's the special case. Skip ARG past the initial
2290 parser
->is_quote_enclosed
= 1;
2294 parser
->lexer
.saved_arg
= arg
;
2295 parser
->lexer
.stream
= arg
;
2297 /* Initialize the default symtab and line offset. */
2298 initialize_defaults (&PARSER_STATE (parser
)->default_symtab
,
2299 &PARSER_STATE (parser
)->default_line
);
2301 /* Objective-C shortcut. */
2302 values
= decode_objc (PARSER_STATE (parser
), PARSER_RESULT (parser
), arg
);
2303 if (values
.sals
!= NULL
)
2306 /* Start parsing. */
2308 /* Get the first token. */
2309 token
= linespec_lexer_lex_one (parser
);
2311 /* It must be either LSTOKEN_STRING or LSTOKEN_NUMBER. */
2312 if (token
.type
== LSTOKEN_STRING
&& *LS_TOKEN_STOKEN (token
).ptr
== '$')
2316 /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB. */
2317 VEC_safe_push (symtab_ptr
, PARSER_RESULT (parser
)->file_symtabs
, NULL
);
2319 /* User specified a convenience variable or history value. */
2320 var
= copy_token_string (token
);
2321 cleanup
= make_cleanup (xfree
, var
);
2322 PARSER_EXPLICIT (parser
)->line_offset
2323 = linespec_parse_variable (PARSER_STATE (parser
), var
);
2324 do_cleanups (cleanup
);
2326 /* If a line_offset wasn't found (VAR is the name of a user
2327 variable/function), then skip to normal symbol processing. */
2328 if (PARSER_EXPLICIT (parser
)->line_offset
.sign
!= LINE_OFFSET_UNKNOWN
)
2330 /* Consume this token. */
2331 linespec_lexer_consume_token (parser
);
2333 goto convert_to_sals
;
2336 else if (token
.type
!= LSTOKEN_STRING
&& token
.type
!= LSTOKEN_NUMBER
)
2337 unexpected_linespec_error (parser
);
2339 /* Shortcut: If the next token is not LSTOKEN_COLON, we know that
2340 this token cannot represent a filename. */
2341 token
= linespec_lexer_peek_token (parser
);
2343 if (token
.type
== LSTOKEN_COLON
)
2345 char *user_filename
;
2347 /* Get the current token again and extract the filename. */
2348 token
= linespec_lexer_lex_one (parser
);
2349 user_filename
= copy_token_string (token
);
2351 /* Check if the input is a filename. */
2354 PARSER_RESULT (parser
)->file_symtabs
2355 = symtabs_from_filename (user_filename
,
2356 PARSER_STATE (parser
)->search_pspace
);
2358 CATCH (ex
, RETURN_MASK_ERROR
)
2360 file_exception
= ex
;
2364 if (file_exception
.reason
>= 0)
2366 /* Symtabs were found for the file. Record the filename. */
2367 PARSER_EXPLICIT (parser
)->source_filename
= user_filename
;
2369 /* Get the next token. */
2370 token
= linespec_lexer_consume_token (parser
);
2372 /* This is LSTOKEN_COLON; consume it. */
2373 linespec_lexer_consume_token (parser
);
2377 /* No symtabs found -- discard user_filename. */
2378 xfree (user_filename
);
2380 /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB. */
2381 VEC_safe_push (symtab_ptr
, PARSER_RESULT (parser
)->file_symtabs
, NULL
);
2384 /* If the next token is not EOI, KEYWORD, or COMMA, issue an error. */
2385 else if (token
.type
!= LSTOKEN_EOI
&& token
.type
!= LSTOKEN_KEYWORD
2386 && token
.type
!= LSTOKEN_COMMA
)
2388 /* TOKEN is the _next_ token, not the one currently in the parser.
2389 Consuming the token will give the correct error message. */
2390 linespec_lexer_consume_token (parser
);
2391 unexpected_linespec_error (parser
);
2395 /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB. */
2396 VEC_safe_push (symtab_ptr
, PARSER_RESULT (parser
)->file_symtabs
, NULL
);
2399 /* Parse the rest of the linespec. */
2400 linespec_parse_basic (parser
);
2402 if (PARSER_RESULT (parser
)->function_symbols
== NULL
2403 && PARSER_RESULT (parser
)->labels
.label_symbols
== NULL
2404 && PARSER_EXPLICIT (parser
)->line_offset
.sign
== LINE_OFFSET_UNKNOWN
2405 && PARSER_RESULT (parser
)->minimal_symbols
== NULL
)
2407 /* The linespec didn't parse. Re-throw the file exception if
2409 if (file_exception
.reason
< 0)
2410 throw_exception (file_exception
);
2412 /* Otherwise, the symbol is not found. */
2413 symbol_not_found_error (PARSER_EXPLICIT (parser
)->function_name
,
2414 PARSER_EXPLICIT (parser
)->source_filename
);
2419 /* Get the last token and record how much of the input was parsed,
2421 token
= linespec_lexer_lex_one (parser
);
2422 if (token
.type
!= LSTOKEN_EOI
&& token
.type
!= LSTOKEN_KEYWORD
)
2423 PARSER_STREAM (parser
) = LS_TOKEN_STOKEN (token
).ptr
;
2425 /* Convert the data in PARSER_RESULT to SALs. */
2426 values
= convert_linespec_to_sals (PARSER_STATE (parser
),
2427 PARSER_RESULT (parser
));
2433 /* A constructor for linespec_state. */
2436 linespec_state_constructor (struct linespec_state
*self
,
2437 int flags
, const struct language_defn
*language
,
2438 struct program_space
*search_pspace
,
2439 struct symtab
*default_symtab
,
2441 struct linespec_result
*canonical
)
2443 memset (self
, 0, sizeof (*self
));
2444 self
->language
= language
;
2445 self
->funfirstline
= (flags
& DECODE_LINE_FUNFIRSTLINE
) ? 1 : 0;
2446 self
->list_mode
= (flags
& DECODE_LINE_LIST_MODE
) ? 1 : 0;
2447 self
->search_pspace
= search_pspace
;
2448 self
->default_symtab
= default_symtab
;
2449 self
->default_line
= default_line
;
2450 self
->canonical
= canonical
;
2451 self
->program_space
= current_program_space
;
2452 self
->addr_set
= htab_create_alloc (10, hash_address_entry
, eq_address_entry
,
2453 xfree
, xcalloc
, xfree
);
2454 self
->is_linespec
= 0;
2457 /* Initialize a new linespec parser. */
2460 linespec_parser_new (linespec_parser
*parser
,
2461 int flags
, const struct language_defn
*language
,
2462 struct program_space
*search_pspace
,
2463 struct symtab
*default_symtab
,
2465 struct linespec_result
*canonical
)
2467 memset (parser
, 0, sizeof (linespec_parser
));
2468 parser
->lexer
.current
.type
= LSTOKEN_CONSUMED
;
2469 memset (PARSER_RESULT (parser
), 0, sizeof (struct linespec
));
2470 PARSER_EXPLICIT (parser
)->line_offset
.sign
= LINE_OFFSET_UNKNOWN
;
2471 linespec_state_constructor (PARSER_STATE (parser
), flags
, language
,
2473 default_symtab
, default_line
, canonical
);
2476 /* A destructor for linespec_state. */
2479 linespec_state_destructor (struct linespec_state
*self
)
2481 htab_delete (self
->addr_set
);
2484 /* Delete a linespec parser. */
2487 linespec_parser_delete (void *arg
)
2489 linespec_parser
*parser
= (linespec_parser
*) arg
;
2491 xfree (PARSER_EXPLICIT (parser
)->source_filename
);
2492 xfree (PARSER_EXPLICIT (parser
)->label_name
);
2493 xfree (PARSER_EXPLICIT (parser
)->function_name
);
2495 if (PARSER_RESULT (parser
)->file_symtabs
!= NULL
)
2496 VEC_free (symtab_ptr
, PARSER_RESULT (parser
)->file_symtabs
);
2498 if (PARSER_RESULT (parser
)->function_symbols
!= NULL
)
2499 VEC_free (symbolp
, PARSER_RESULT (parser
)->function_symbols
);
2501 if (PARSER_RESULT (parser
)->minimal_symbols
!= NULL
)
2502 VEC_free (bound_minimal_symbol_d
, PARSER_RESULT (parser
)->minimal_symbols
);
2504 if (PARSER_RESULT (parser
)->labels
.label_symbols
!= NULL
)
2505 VEC_free (symbolp
, PARSER_RESULT (parser
)->labels
.label_symbols
);
2507 if (PARSER_RESULT (parser
)->labels
.function_symbols
!= NULL
)
2508 VEC_free (symbolp
, PARSER_RESULT (parser
)->labels
.function_symbols
);
2510 linespec_state_destructor (PARSER_STATE (parser
));
2513 /* See description in linespec.h. */
2516 linespec_lex_to_end (char **stringp
)
2518 linespec_parser parser
;
2519 struct cleanup
*cleanup
;
2520 linespec_token token
;
2523 if (stringp
== NULL
|| *stringp
== NULL
)
2526 linespec_parser_new (&parser
, 0, current_language
, NULL
, NULL
, 0, NULL
);
2527 cleanup
= make_cleanup (linespec_parser_delete
, &parser
);
2528 parser
.lexer
.saved_arg
= *stringp
;
2529 PARSER_STREAM (&parser
) = orig
= *stringp
;
2533 /* Stop before any comma tokens; we need it to keep it
2534 as the next token in the string. */
2535 token
= linespec_lexer_peek_token (&parser
);
2536 if (token
.type
== LSTOKEN_COMMA
)
2538 token
= linespec_lexer_consume_token (&parser
);
2540 while (token
.type
!= LSTOKEN_EOI
&& token
.type
!= LSTOKEN_KEYWORD
);
2542 *stringp
+= PARSER_STREAM (&parser
) - orig
;
2543 do_cleanups (cleanup
);
2546 /* See linespec.h. */
2549 linespec_complete_function (completion_tracker
&tracker
,
2550 const char *function
,
2551 const char *source_filename
)
2553 complete_symbol_mode mode
= complete_symbol_mode::LINESPEC
;
2555 if (source_filename
!= NULL
)
2557 collect_file_symbol_completion_matches (tracker
, mode
,
2562 collect_symbol_completion_matches (tracker
, mode
, function
, function
);
2565 /* Helper for linespec_complete_label. Find labels that match
2566 LABEL_NAME in the function symbols listed in the PARSER, and add
2567 them to the tracker. */
2570 complete_label (completion_tracker
&tracker
,
2571 linespec_parser
*parser
,
2572 const char *label_name
)
2574 VEC (symbolp
) *label_function_symbols
= NULL
;
2575 VEC (symbolp
) *labels
2576 = find_label_symbols (PARSER_STATE (parser
),
2577 PARSER_RESULT (parser
)->function_symbols
,
2578 &label_function_symbols
,
2583 VEC_iterate (symbolp
, labels
, ix
, label
); ++ix
)
2585 char *match
= xstrdup (SYMBOL_SEARCH_NAME (label
));
2586 tracker
.add_completion (gdb::unique_xmalloc_ptr
<char> (match
));
2588 VEC_free (symbolp
, labels
);
2591 /* See linespec.h. */
2594 linespec_complete_label (completion_tracker
&tracker
,
2595 const struct language_defn
*language
,
2596 const char *source_filename
,
2597 const char *function_name
,
2598 const char *label_name
)
2600 linespec_parser parser
;
2601 struct cleanup
*cleanup
;
2603 linespec_parser_new (&parser
, 0, language
, NULL
, NULL
, 0, NULL
);
2604 cleanup
= make_cleanup (linespec_parser_delete
, &parser
);
2606 line_offset unknown_offset
= { 0, LINE_OFFSET_UNKNOWN
};
2610 convert_explicit_location_to_linespec (PARSER_STATE (&parser
),
2611 PARSER_RESULT (&parser
),
2614 NULL
, unknown_offset
);
2616 CATCH (ex
, RETURN_MASK_ERROR
)
2618 do_cleanups (cleanup
);
2623 complete_label (tracker
, &parser
, label_name
);
2625 do_cleanups (cleanup
);
2628 /* A helper function for decode_line_full and decode_line_1 to
2629 turn LOCATION into symtabs_and_lines. */
2631 static struct symtabs_and_lines
2632 event_location_to_sals (linespec_parser
*parser
,
2633 const struct event_location
*location
)
2635 struct symtabs_and_lines result
= {NULL
, 0};
2637 switch (event_location_type (location
))
2639 case LINESPEC_LOCATION
:
2641 PARSER_STATE (parser
)->is_linespec
= 1;
2644 result
= parse_linespec (parser
, get_linespec_location (location
));
2646 CATCH (except
, RETURN_MASK_ERROR
)
2648 throw_exception (except
);
2654 case ADDRESS_LOCATION
:
2656 const char *addr_string
= get_address_string_location (location
);
2657 CORE_ADDR addr
= get_address_location (location
);
2659 if (addr_string
!= NULL
)
2661 char *expr
= xstrdup (addr_string
);
2662 const char *const_expr
= expr
;
2663 struct cleanup
*cleanup
= make_cleanup (xfree
, expr
);
2665 addr
= linespec_expression_to_pc (&const_expr
);
2666 if (PARSER_STATE (parser
)->canonical
!= NULL
)
2667 PARSER_STATE (parser
)->canonical
->location
2668 = copy_event_location (location
);
2670 do_cleanups (cleanup
);
2673 result
= convert_address_location_to_sals (PARSER_STATE (parser
),
2678 case EXPLICIT_LOCATION
:
2680 const struct explicit_location
*explicit_loc
;
2682 explicit_loc
= get_explicit_location_const (location
);
2683 result
= convert_explicit_location_to_sals (PARSER_STATE (parser
),
2684 PARSER_RESULT (parser
),
2689 case PROBE_LOCATION
:
2690 /* Probes are handled by their own decoders. */
2691 gdb_assert_not_reached ("attempt to decode probe location");
2695 gdb_assert_not_reached ("unhandled event location type");
2701 /* See linespec.h. */
2704 decode_line_full (const struct event_location
*location
, int flags
,
2705 struct program_space
*search_pspace
,
2706 struct symtab
*default_symtab
,
2707 int default_line
, struct linespec_result
*canonical
,
2708 const char *select_mode
,
2711 struct symtabs_and_lines result
;
2712 struct cleanup
*cleanups
;
2713 VEC (const_char_ptr
) *filters
= NULL
;
2714 linespec_parser parser
;
2715 struct linespec_state
*state
;
2717 gdb_assert (canonical
!= NULL
);
2718 /* The filter only makes sense for 'all'. */
2719 gdb_assert (filter
== NULL
|| select_mode
== multiple_symbols_all
);
2720 gdb_assert (select_mode
== NULL
2721 || select_mode
== multiple_symbols_all
2722 || select_mode
== multiple_symbols_ask
2723 || select_mode
== multiple_symbols_cancel
);
2724 gdb_assert ((flags
& DECODE_LINE_LIST_MODE
) == 0);
2726 linespec_parser_new (&parser
, flags
, current_language
,
2727 search_pspace
, default_symtab
,
2728 default_line
, canonical
);
2729 cleanups
= make_cleanup (linespec_parser_delete
, &parser
);
2731 scoped_restore_current_program_space restore_pspace
;
2733 result
= event_location_to_sals (&parser
, location
);
2734 state
= PARSER_STATE (&parser
);
2736 gdb_assert (result
.nelts
== 1 || canonical
->pre_expanded
);
2737 canonical
->pre_expanded
= 1;
2739 /* Arrange for allocated canonical names to be freed. */
2740 if (result
.nelts
> 0)
2744 make_cleanup (xfree
, state
->canonical_names
);
2745 for (i
= 0; i
< result
.nelts
; ++i
)
2747 gdb_assert (state
->canonical_names
[i
].suffix
!= NULL
);
2748 make_cleanup (xfree
, state
->canonical_names
[i
].suffix
);
2752 if (select_mode
== NULL
)
2754 if (interp_ui_out (top_level_interpreter ())->is_mi_like_p ())
2755 select_mode
= multiple_symbols_all
;
2757 select_mode
= multiple_symbols_select_mode ();
2760 if (select_mode
== multiple_symbols_all
)
2764 make_cleanup (VEC_cleanup (const_char_ptr
), &filters
);
2765 VEC_safe_push (const_char_ptr
, filters
, filter
);
2766 filter_results (state
, &result
, filters
);
2769 convert_results_to_lsals (state
, &result
);
2772 decode_line_2 (state
, &result
, select_mode
);
2774 do_cleanups (cleanups
);
2777 /* See linespec.h. */
2779 struct symtabs_and_lines
2780 decode_line_1 (const struct event_location
*location
, int flags
,
2781 struct program_space
*search_pspace
,
2782 struct symtab
*default_symtab
,
2785 struct symtabs_and_lines result
;
2786 linespec_parser parser
;
2787 struct cleanup
*cleanups
;
2789 linespec_parser_new (&parser
, flags
, current_language
,
2790 search_pspace
, default_symtab
,
2791 default_line
, NULL
);
2792 cleanups
= make_cleanup (linespec_parser_delete
, &parser
);
2794 scoped_restore_current_program_space restore_pspace
;
2796 result
= event_location_to_sals (&parser
, location
);
2798 do_cleanups (cleanups
);
2802 /* See linespec.h. */
2804 struct symtabs_and_lines
2805 decode_line_with_current_source (char *string
, int flags
)
2807 struct symtabs_and_lines sals
;
2808 struct symtab_and_line cursal
;
2811 error (_("Empty line specification."));
2813 /* We use whatever is set as the current source line. We do not try
2814 and get a default source symtab+line or it will recursively call us! */
2815 cursal
= get_current_source_symtab_and_line ();
2817 event_location_up location
= string_to_event_location (&string
,
2819 sals
= decode_line_1 (location
.get (), flags
, NULL
,
2820 cursal
.symtab
, cursal
.line
);
2823 error (_("Junk at end of line specification: %s"), string
);
2828 /* See linespec.h. */
2830 struct symtabs_and_lines
2831 decode_line_with_last_displayed (char *string
, int flags
)
2833 struct symtabs_and_lines sals
;
2836 error (_("Empty line specification."));
2838 event_location_up location
= string_to_event_location (&string
,
2840 if (last_displayed_sal_is_valid ())
2841 sals
= decode_line_1 (location
.get (), flags
, NULL
,
2842 get_last_displayed_symtab (),
2843 get_last_displayed_line ());
2845 sals
= decode_line_1 (location
.get (), flags
, NULL
,
2846 (struct symtab
*) NULL
, 0);
2849 error (_("Junk at end of line specification: %s"), string
);
2856 /* First, some functions to initialize stuff at the beggining of the
2860 initialize_defaults (struct symtab
**default_symtab
, int *default_line
)
2862 if (*default_symtab
== 0)
2864 /* Use whatever we have for the default source line. We don't use
2865 get_current_or_default_symtab_and_line as it can recurse and call
2867 struct symtab_and_line cursal
=
2868 get_current_source_symtab_and_line ();
2870 *default_symtab
= cursal
.symtab
;
2871 *default_line
= cursal
.line
;
2877 /* Evaluate the expression pointed to by EXP_PTR into a CORE_ADDR,
2878 advancing EXP_PTR past any parsed text. */
2881 linespec_expression_to_pc (const char **exp_ptr
)
2883 if (current_program_space
->executing_startup
)
2884 /* The error message doesn't really matter, because this case
2885 should only hit during breakpoint reset. */
2886 throw_error (NOT_FOUND_ERROR
, _("cannot evaluate expressions while "
2887 "program space is in startup"));
2890 return value_as_address (parse_to_comma_and_eval (exp_ptr
));
2895 /* Here's where we recognise an Objective-C Selector. An Objective C
2896 selector may be implemented by more than one class, therefore it
2897 may represent more than one method/function. This gives us a
2898 situation somewhat analogous to C++ overloading. If there's more
2899 than one method that could represent the selector, then use some of
2900 the existing C++ code to let the user choose one. */
2902 static struct symtabs_and_lines
2903 decode_objc (struct linespec_state
*self
, linespec_p ls
, const char *arg
)
2905 struct collect_info info
;
2906 VEC (const_char_ptr
) *symbol_names
= NULL
;
2907 struct symtabs_and_lines values
;
2908 const char *new_argptr
;
2909 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (const_char_ptr
),
2913 info
.file_symtabs
= NULL
;
2914 VEC_safe_push (symtab_ptr
, info
.file_symtabs
, NULL
);
2915 make_cleanup (VEC_cleanup (symtab_ptr
), &info
.file_symtabs
);
2916 info
.result
.symbols
= NULL
;
2917 info
.result
.minimal_symbols
= NULL
;
2921 new_argptr
= find_imps (arg
, &symbol_names
);
2922 if (VEC_empty (const_char_ptr
, symbol_names
))
2924 do_cleanups (cleanup
);
2928 add_all_symbol_names_from_pspace (&info
, NULL
, symbol_names
);
2930 if (!VEC_empty (symbolp
, info
.result
.symbols
)
2931 || !VEC_empty (bound_minimal_symbol_d
, info
.result
.minimal_symbols
))
2935 saved_arg
= (char *) alloca (new_argptr
- arg
+ 1);
2936 memcpy (saved_arg
, arg
, new_argptr
- arg
);
2937 saved_arg
[new_argptr
- arg
] = '\0';
2939 ls
->explicit_loc
.function_name
= xstrdup (saved_arg
);
2940 ls
->function_symbols
= info
.result
.symbols
;
2941 ls
->minimal_symbols
= info
.result
.minimal_symbols
;
2942 values
= convert_linespec_to_sals (self
, ls
);
2944 if (self
->canonical
)
2948 self
->canonical
->pre_expanded
= 1;
2950 if (ls
->explicit_loc
.source_filename
)
2952 str
= xstrprintf ("%s:%s",
2953 ls
->explicit_loc
.source_filename
, saved_arg
);
2956 str
= xstrdup (saved_arg
);
2958 make_cleanup (xfree
, str
);
2959 self
->canonical
->location
= new_linespec_location (&str
);
2963 do_cleanups (cleanup
);
2970 /* A function object that serves as symbol_found_callback_ftype
2971 callback for iterate_over_symbols. This is used by
2972 lookup_prefix_sym to collect type symbols. */
2973 class decode_compound_collector
2976 decode_compound_collector ()
2979 m_unique_syms
= htab_create_alloc (1, htab_hash_pointer
,
2980 htab_eq_pointer
, NULL
,
2984 ~decode_compound_collector ()
2986 if (m_unique_syms
!= NULL
)
2987 htab_delete (m_unique_syms
);
2990 /* Releases ownership of the collected symbols and returns them. */
2991 VEC (symbolp
) *release_symbols ()
2993 VEC (symbolp
) *res
= m_symbols
;
2998 /* Callable as a symbol_found_callback_ftype callback. */
2999 bool operator () (symbol
*sym
);
3002 /* A hash table of all symbols we found. We use this to avoid
3003 adding any symbol more than once. */
3004 htab_t m_unique_syms
;
3006 /* The result vector. */
3007 VEC (symbolp
) *m_symbols
;
3011 decode_compound_collector::operator () (symbol
*sym
)
3016 if (SYMBOL_CLASS (sym
) != LOC_TYPEDEF
)
3017 return true; /* Continue iterating. */
3019 t
= SYMBOL_TYPE (sym
);
3020 t
= check_typedef (t
);
3021 if (TYPE_CODE (t
) != TYPE_CODE_STRUCT
3022 && TYPE_CODE (t
) != TYPE_CODE_UNION
3023 && TYPE_CODE (t
) != TYPE_CODE_NAMESPACE
)
3024 return true; /* Continue iterating. */
3026 slot
= htab_find_slot (m_unique_syms
, sym
, INSERT
);
3030 VEC_safe_push (symbolp
, m_symbols
, sym
);
3033 return true; /* Continue iterating. */
3038 /* Return any symbols corresponding to CLASS_NAME in FILE_SYMTABS. */
3040 static VEC (symbolp
) *
3041 lookup_prefix_sym (struct linespec_state
*state
, VEC (symtab_ptr
) *file_symtabs
,
3042 const char *class_name
)
3046 decode_compound_collector collector
;
3048 for (ix
= 0; VEC_iterate (symtab_ptr
, file_symtabs
, ix
, elt
); ++ix
)
3052 iterate_over_all_matching_symtabs (state
, class_name
, STRUCT_DOMAIN
,
3053 NULL
, false, collector
);
3054 iterate_over_all_matching_symtabs (state
, class_name
, VAR_DOMAIN
,
3055 NULL
, false, collector
);
3059 /* Program spaces that are executing startup should have
3060 been filtered out earlier. */
3061 gdb_assert (!SYMTAB_PSPACE (elt
)->executing_startup
);
3062 set_current_program_space (SYMTAB_PSPACE (elt
));
3063 iterate_over_file_blocks (elt
, class_name
, STRUCT_DOMAIN
, collector
);
3064 iterate_over_file_blocks (elt
, class_name
, VAR_DOMAIN
, collector
);
3068 return collector
.release_symbols ();
3071 /* A qsort comparison function for symbols. The resulting order does
3072 not actually matter; we just need to be able to sort them so that
3073 symbols with the same program space end up next to each other. */
3076 compare_symbols (const void *a
, const void *b
)
3078 struct symbol
* const *sa
= (struct symbol
* const*) a
;
3079 struct symbol
* const *sb
= (struct symbol
* const*) b
;
3082 uia
= (uintptr_t) SYMTAB_PSPACE (symbol_symtab (*sa
));
3083 uib
= (uintptr_t) SYMTAB_PSPACE (symbol_symtab (*sb
));
3090 uia
= (uintptr_t) *sa
;
3091 uib
= (uintptr_t) *sb
;
3101 /* Like compare_symbols but for minimal symbols. */
3104 compare_msymbols (const void *a
, const void *b
)
3106 const struct bound_minimal_symbol
*sa
3107 = (const struct bound_minimal_symbol
*) a
;
3108 const struct bound_minimal_symbol
*sb
3109 = (const struct bound_minimal_symbol
*) b
;
3112 uia
= (uintptr_t) sa
->objfile
->pspace
;
3113 uib
= (uintptr_t) sa
->objfile
->pspace
;
3120 uia
= (uintptr_t) sa
->minsym
;
3121 uib
= (uintptr_t) sb
->minsym
;
3131 /* Look for all the matching instances of each symbol in NAMES. Only
3132 instances from PSPACE are considered; other program spaces are
3133 handled by our caller. If PSPACE is NULL, then all program spaces
3134 are considered. Results are stored into INFO. */
3137 add_all_symbol_names_from_pspace (struct collect_info
*info
,
3138 struct program_space
*pspace
,
3139 VEC (const_char_ptr
) *names
)
3144 for (ix
= 0; VEC_iterate (const_char_ptr
, names
, ix
, iter
); ++ix
)
3145 add_matching_symbols_to_info (iter
, info
, pspace
);
3149 find_superclass_methods (VEC (typep
) *superclasses
,
3151 VEC (const_char_ptr
) **result_names
)
3153 int old_len
= VEC_length (const_char_ptr
, *result_names
);
3154 VEC (typep
) *iter_classes
;
3155 struct cleanup
*cleanup
= make_cleanup (null_cleanup
, NULL
);
3157 iter_classes
= superclasses
;
3160 VEC (typep
) *new_supers
= NULL
;
3164 make_cleanup (VEC_cleanup (typep
), &new_supers
);
3165 for (ix
= 0; VEC_iterate (typep
, iter_classes
, ix
, t
); ++ix
)
3166 find_methods (t
, name
, result_names
, &new_supers
);
3168 if (VEC_length (const_char_ptr
, *result_names
) != old_len
3169 || VEC_empty (typep
, new_supers
))
3172 iter_classes
= new_supers
;
3175 do_cleanups (cleanup
);
3178 /* This finds the method METHOD_NAME in the class CLASS_NAME whose type is
3179 given by one of the symbols in SYM_CLASSES. Matches are returned
3180 in SYMBOLS (for debug symbols) and MINSYMS (for minimal symbols). */
3183 find_method (struct linespec_state
*self
, VEC (symtab_ptr
) *file_symtabs
,
3184 const char *class_name
, const char *method_name
,
3185 VEC (symbolp
) *sym_classes
, VEC (symbolp
) **symbols
,
3186 VEC (bound_minimal_symbol_d
) **minsyms
)
3189 struct cleanup
*cleanup
= make_cleanup (null_cleanup
, NULL
);
3191 int last_result_len
;
3192 VEC (typep
) *superclass_vec
;
3193 VEC (const_char_ptr
) *result_names
;
3194 struct collect_info info
;
3196 /* Sort symbols so that symbols with the same program space are next
3198 qsort (VEC_address (symbolp
, sym_classes
),
3199 VEC_length (symbolp
, sym_classes
),
3204 info
.file_symtabs
= file_symtabs
;
3205 info
.result
.symbols
= NULL
;
3206 info
.result
.minimal_symbols
= NULL
;
3208 /* Iterate over all the types, looking for the names of existing
3209 methods matching METHOD_NAME. If we cannot find a direct method in a
3210 given program space, then we consider inherited methods; this is
3211 not ideal (ideal would be to respect C++ hiding rules), but it
3212 seems good enough and is what GDB has historically done. We only
3213 need to collect the names because later we find all symbols with
3214 those names. This loop is written in a somewhat funny way
3215 because we collect data across the program space before deciding
3217 superclass_vec
= NULL
;
3218 make_cleanup (VEC_cleanup (typep
), &superclass_vec
);
3219 result_names
= NULL
;
3220 make_cleanup (VEC_cleanup (const_char_ptr
), &result_names
);
3221 last_result_len
= 0;
3222 for (ix
= 0; VEC_iterate (symbolp
, sym_classes
, ix
, sym
); ++ix
)
3225 struct program_space
*pspace
;
3227 /* Program spaces that are executing startup should have
3228 been filtered out earlier. */
3229 pspace
= SYMTAB_PSPACE (symbol_symtab (sym
));
3230 gdb_assert (!pspace
->executing_startup
);
3231 set_current_program_space (pspace
);
3232 t
= check_typedef (SYMBOL_TYPE (sym
));
3233 find_methods (t
, method_name
, &result_names
, &superclass_vec
);
3235 /* Handle all items from a single program space at once; and be
3236 sure not to miss the last batch. */
3237 if (ix
== VEC_length (symbolp
, sym_classes
) - 1
3239 != SYMTAB_PSPACE (symbol_symtab (VEC_index (symbolp
, sym_classes
,
3242 /* If we did not find a direct implementation anywhere in
3243 this program space, consider superclasses. */
3244 if (VEC_length (const_char_ptr
, result_names
) == last_result_len
)
3245 find_superclass_methods (superclass_vec
, method_name
,
3248 /* We have a list of candidate symbol names, so now we
3249 iterate over the symbol tables looking for all
3250 matches in this pspace. */
3251 add_all_symbol_names_from_pspace (&info
, pspace
, result_names
);
3253 VEC_truncate (typep
, superclass_vec
, 0);
3254 last_result_len
= VEC_length (const_char_ptr
, result_names
);
3258 if (!VEC_empty (symbolp
, info
.result
.symbols
)
3259 || !VEC_empty (bound_minimal_symbol_d
, info
.result
.minimal_symbols
))
3261 *symbols
= info
.result
.symbols
;
3262 *minsyms
= info
.result
.minimal_symbols
;
3263 do_cleanups (cleanup
);
3267 /* Throw an NOT_FOUND_ERROR. This will be caught by the caller
3268 and other attempts to locate the symbol will be made. */
3269 throw_error (NOT_FOUND_ERROR
, _("see caller, this text doesn't matter"));
3276 /* This function object is a callback for iterate_over_symtabs, used
3277 when collecting all matching symtabs. */
3279 class symtab_collector
3285 m_symtab_table
= htab_create (1, htab_hash_pointer
, htab_eq_pointer
,
3289 ~symtab_collector ()
3291 if (m_symtab_table
!= NULL
)
3292 htab_delete (m_symtab_table
);
3295 /* Callable as a symbol_found_callback_ftype callback. */
3296 bool operator () (symtab
*sym
);
3298 /* Releases ownership of the collected symtabs and returns them. */
3299 VEC (symtab_ptr
) *release_symtabs ()
3301 VEC (symtab_ptr
) *res
= m_symtabs
;
3307 /* The result vector of symtabs. */
3308 VEC (symtab_ptr
) *m_symtabs
;
3310 /* This is used to ensure the symtabs are unique. */
3311 htab_t m_symtab_table
;
3315 symtab_collector::operator () (struct symtab
*symtab
)
3319 slot
= htab_find_slot (m_symtab_table
, symtab
, INSERT
);
3323 VEC_safe_push (symtab_ptr
, m_symtabs
, symtab
);
3331 /* Given a file name, return a VEC of all matching symtabs. If
3332 SEARCH_PSPACE is not NULL, the search is restricted to just that
3335 static VEC (symtab_ptr
) *
3336 collect_symtabs_from_filename (const char *file
,
3337 struct program_space
*search_pspace
)
3339 symtab_collector collector
;
3341 /* Find that file's data. */
3342 if (search_pspace
== NULL
)
3344 struct program_space
*pspace
;
3346 ALL_PSPACES (pspace
)
3348 if (pspace
->executing_startup
)
3351 set_current_program_space (pspace
);
3352 iterate_over_symtabs (file
, collector
);
3357 set_current_program_space (search_pspace
);
3358 iterate_over_symtabs (file
, collector
);
3361 return collector
.release_symtabs ();
3364 /* Return all the symtabs associated to the FILENAME. If SEARCH_PSPACE is
3365 not NULL, the search is restricted to just that program space. */
3367 static VEC (symtab_ptr
) *
3368 symtabs_from_filename (const char *filename
,
3369 struct program_space
*search_pspace
)
3371 VEC (symtab_ptr
) *result
;
3373 result
= collect_symtabs_from_filename (filename
, search_pspace
);
3375 if (VEC_empty (symtab_ptr
, result
))
3377 if (!have_full_symbols () && !have_partial_symbols ())
3378 throw_error (NOT_FOUND_ERROR
,
3379 _("No symbol table is loaded. "
3380 "Use the \"file\" command."));
3381 source_file_not_found_error (filename
);
3387 /* Look up a function symbol named NAME in symtabs FILE_SYMTABS. Matching
3388 debug symbols are returned in SYMBOLS. Matching minimal symbols are
3389 returned in MINSYMS. */
3392 find_function_symbols (struct linespec_state
*state
,
3393 VEC (symtab_ptr
) *file_symtabs
, const char *name
,
3394 VEC (symbolp
) **symbols
,
3395 VEC (bound_minimal_symbol_d
) **minsyms
)
3397 struct collect_info info
;
3398 VEC (const_char_ptr
) *symbol_names
= NULL
;
3399 struct cleanup
*cleanup
= make_cleanup (VEC_cleanup (const_char_ptr
),
3403 info
.result
.symbols
= NULL
;
3404 info
.result
.minimal_symbols
= NULL
;
3405 info
.file_symtabs
= file_symtabs
;
3407 /* Try NAME as an Objective-C selector. */
3408 find_imps (name
, &symbol_names
);
3409 if (!VEC_empty (const_char_ptr
, symbol_names
))
3410 add_all_symbol_names_from_pspace (&info
, state
->search_pspace
,
3413 add_matching_symbols_to_info (name
, &info
, state
->search_pspace
);
3415 do_cleanups (cleanup
);
3417 if (VEC_empty (symbolp
, info
.result
.symbols
))
3419 VEC_free (symbolp
, info
.result
.symbols
);
3423 *symbols
= info
.result
.symbols
;
3425 if (VEC_empty (bound_minimal_symbol_d
, info
.result
.minimal_symbols
))
3427 VEC_free (bound_minimal_symbol_d
, info
.result
.minimal_symbols
);
3431 *minsyms
= info
.result
.minimal_symbols
;
3434 /* Find all symbols named NAME in FILE_SYMTABS, returning debug symbols
3435 in SYMBOLS and minimal symbols in MINSYMS. */
3438 find_linespec_symbols (struct linespec_state
*state
,
3439 VEC (symtab_ptr
) *file_symtabs
,
3441 VEC (symbolp
) **symbols
,
3442 VEC (bound_minimal_symbol_d
) **minsyms
)
3444 demangle_result_storage demangle_storage
;
3445 std::string ada_lookup_storage
;
3446 const char *lookup_name
;
3448 if (state
->language
->la_language
== language_ada
)
3450 /* In Ada, the symbol lookups are performed using the encoded
3451 name rather than the demangled name. */
3452 ada_lookup_storage
= ada_name_for_lookup (name
);
3453 lookup_name
= ada_lookup_storage
.c_str ();
3457 lookup_name
= demangle_for_lookup (name
,
3458 state
->language
->la_language
,
3462 std::string canon
= cp_canonicalize_string_no_typedefs (lookup_name
);
3463 if (!canon
.empty ())
3464 lookup_name
= canon
.c_str ();
3466 /* It's important to not call expand_symtabs_matching unnecessarily
3467 as it can really slow things down (by unnecessarily expanding
3468 potentially 1000s of symtabs, which when debugging some apps can
3469 cost 100s of seconds). Avoid this to some extent by *first* calling
3470 find_function_symbols, and only if that doesn't find anything
3471 *then* call find_method. This handles two important cases:
3472 1) break (anonymous namespace)::foo
3473 2) break class::method where method is in class (and not a baseclass) */
3475 find_function_symbols (state
, file_symtabs
, lookup_name
,
3478 /* If we were unable to locate a symbol of the same name, try dividing
3479 the name into class and method names and searching the class and its
3481 if (VEC_empty (symbolp
, *symbols
)
3482 && VEC_empty (bound_minimal_symbol_d
, *minsyms
))
3484 std::string klass
, method
;
3485 const char *last
, *p
, *scope_op
;
3486 VEC (symbolp
) *classes
;
3488 /* See if we can find a scope operator and break this symbol
3489 name into namespaces${SCOPE_OPERATOR}class_name and method_name. */
3491 p
= find_toplevel_string (lookup_name
, scope_op
);
3497 p
= find_toplevel_string (p
+ strlen (scope_op
), scope_op
);
3500 /* If no scope operator was found, there is nothing more we can do;
3501 we already attempted to lookup the entire name as a symbol
3506 /* LOOKUP_NAME points to the class name.
3507 LAST points to the method name. */
3508 klass
= std::string (lookup_name
, last
- lookup_name
);
3510 /* Skip past the scope operator. */
3511 last
+= strlen (scope_op
);
3514 /* Find a list of classes named KLASS. */
3515 classes
= lookup_prefix_sym (state
, file_symtabs
, klass
.c_str ());
3516 struct cleanup
*old_chain
3517 = make_cleanup (VEC_cleanup (symbolp
), &classes
);
3519 if (!VEC_empty (symbolp
, classes
))
3521 /* Now locate a list of suitable methods named METHOD. */
3524 find_method (state
, file_symtabs
,
3525 klass
.c_str (), method
.c_str (),
3526 classes
, symbols
, minsyms
);
3529 /* If successful, we're done. If NOT_FOUND_ERROR
3530 was not thrown, rethrow the exception that we did get. */
3531 CATCH (except
, RETURN_MASK_ERROR
)
3533 if (except
.error
!= NOT_FOUND_ERROR
)
3534 throw_exception (except
);
3539 do_cleanups (old_chain
);
3543 /* Helper for find_label_symbols. Find all labels that match name
3544 NAME in BLOCK. Return all labels that match in FUNCTION_SYMBOLS.
3545 Return the actual function symbol in which the label was found in
3546 LABEL_FUNC_RET. If COMPLETION_MODE is true, then NAME is
3547 interpreted as a label name prefix. Otherwise, only a label named
3548 exactly NAME match. */
3551 find_label_symbols_in_block (const struct block
*block
,
3552 const char *name
, struct symbol
*fn_sym
,
3553 bool completion_mode
,
3554 VEC (symbolp
) **result
,
3555 VEC (symbolp
) **label_funcs_ret
)
3557 if (completion_mode
)
3559 struct block_iterator iter
;
3561 size_t name_len
= strlen (name
);
3563 int (*cmp
) (const char *, const char *, size_t);
3564 cmp
= case_sensitivity
== case_sensitive_on
? strncmp
: strncasecmp
;
3566 ALL_BLOCK_SYMBOLS (block
, iter
, sym
)
3568 if (symbol_matches_domain (SYMBOL_LANGUAGE (sym
),
3569 SYMBOL_DOMAIN (sym
), LABEL_DOMAIN
)
3570 && cmp (SYMBOL_SEARCH_NAME (sym
), name
, name_len
) == 0)
3572 VEC_safe_push (symbolp
, *result
, sym
);
3573 VEC_safe_push (symbolp
, *label_funcs_ret
, fn_sym
);
3579 struct symbol
*sym
= lookup_symbol (name
, block
, LABEL_DOMAIN
, 0).symbol
;
3583 VEC_safe_push (symbolp
, *result
, sym
);
3584 VEC_safe_push (symbolp
, *label_funcs_ret
, fn_sym
);
3589 /* Return all labels that match name NAME in FUNCTION_SYMBOLS. Return
3590 the actual function symbol in which the label was found in
3591 LABEL_FUNC_RET. If COMPLETION_MODE is true, then NAME is
3592 interpreted as a label name prefix. Otherwise, only labels named
3593 exactly NAME match. */
3595 static VEC (symbolp
) *
3596 find_label_symbols (struct linespec_state
*self
,
3597 VEC (symbolp
) *function_symbols
,
3598 VEC (symbolp
) **label_funcs_ret
, const char *name
,
3599 bool completion_mode
)
3602 const struct block
*block
;
3604 struct symbol
*fn_sym
;
3605 VEC (symbolp
) *result
= NULL
;
3607 if (function_symbols
== NULL
)
3609 set_current_program_space (self
->program_space
);
3610 block
= get_current_search_block ();
3613 block
&& !BLOCK_FUNCTION (block
);
3614 block
= BLOCK_SUPERBLOCK (block
))
3618 fn_sym
= BLOCK_FUNCTION (block
);
3620 find_label_symbols_in_block (block
, name
, fn_sym
, completion_mode
,
3621 &result
, label_funcs_ret
);
3626 VEC_iterate (symbolp
, function_symbols
, ix
, fn_sym
); ++ix
)
3628 set_current_program_space (SYMTAB_PSPACE (symbol_symtab (fn_sym
)));
3629 block
= SYMBOL_BLOCK_VALUE (fn_sym
);
3631 find_label_symbols_in_block (block
, name
, fn_sym
, completion_mode
,
3632 &result
, label_funcs_ret
);
3641 /* A helper for create_sals_line_offset that handles the 'list_mode' case. */
3644 decode_digits_list_mode (struct linespec_state
*self
,
3646 struct symtabs_and_lines
*values
,
3647 struct symtab_and_line val
)
3652 gdb_assert (self
->list_mode
);
3654 for (ix
= 0; VEC_iterate (symtab_ptr
, ls
->file_symtabs
, ix
, elt
);
3657 /* The logic above should ensure this. */
3658 gdb_assert (elt
!= NULL
);
3660 set_current_program_space (SYMTAB_PSPACE (elt
));
3662 /* Simplistic search just for the list command. */
3663 val
.symtab
= find_line_symtab (elt
, val
.line
, NULL
, NULL
);
3664 if (val
.symtab
== NULL
)
3666 val
.pspace
= SYMTAB_PSPACE (elt
);
3668 val
.explicit_line
= 1;
3670 add_sal_to_sals (self
, values
, &val
, NULL
, 0);
3674 /* A helper for create_sals_line_offset that iterates over the symtabs,
3675 adding lines to the VEC. */
3678 decode_digits_ordinary (struct linespec_state
*self
,
3681 struct symtabs_and_lines
*sals
,
3682 struct linetable_entry
**best_entry
)
3687 for (ix
= 0; VEC_iterate (symtab_ptr
, ls
->file_symtabs
, ix
, elt
); ++ix
)
3689 std::vector
<CORE_ADDR
> pcs
;
3691 /* The logic above should ensure this. */
3692 gdb_assert (elt
!= NULL
);
3694 set_current_program_space (SYMTAB_PSPACE (elt
));
3696 pcs
= find_pcs_for_symtab_line (elt
, line
, best_entry
);
3697 for (CORE_ADDR pc
: pcs
)
3699 struct symtab_and_line sal
;
3702 sal
.pspace
= SYMTAB_PSPACE (elt
);
3706 add_sal_to_sals_basic (sals
, &sal
);
3713 /* Return the line offset represented by VARIABLE. */
3715 static struct line_offset
3716 linespec_parse_variable (struct linespec_state
*self
, const char *variable
)
3720 struct line_offset offset
= {0, LINE_OFFSET_NONE
};
3722 p
= (variable
[1] == '$') ? variable
+ 2 : variable
+ 1;
3725 while (*p
>= '0' && *p
<= '9')
3727 if (!*p
) /* Reached end of token without hitting non-digit. */
3729 /* We have a value history reference. */
3730 struct value
*val_history
;
3732 sscanf ((variable
[1] == '$') ? variable
+ 2 : variable
+ 1, "%d", &index
);
3734 = access_value_history ((variable
[1] == '$') ? -index
: index
);
3735 if (TYPE_CODE (value_type (val_history
)) != TYPE_CODE_INT
)
3736 error (_("History values used in line "
3737 "specs must have integer values."));
3738 offset
.offset
= value_as_long (val_history
);
3742 /* Not all digits -- may be user variable/function or a
3743 convenience variable. */
3745 struct internalvar
*ivar
;
3747 /* Try it as a convenience variable. If it is not a convenience
3748 variable, return and allow normal symbol lookup to occur. */
3749 ivar
= lookup_only_internalvar (variable
+ 1);
3751 /* No internal variable with that name. Mark the offset
3752 as unknown to allow the name to be looked up as a symbol. */
3753 offset
.sign
= LINE_OFFSET_UNKNOWN
;
3756 /* We found a valid variable name. If it is not an integer,
3758 if (!get_internalvar_integer (ivar
, &valx
))
3759 error (_("Convenience variables used in line "
3760 "specs must have integer values."));
3762 offset
.offset
= valx
;
3770 /* We've found a minimal symbol MSYMBOL in OBJFILE to associate with our
3771 linespec; return the SAL in RESULT. This function should return SALs
3772 matching those from find_function_start_sal, otherwise false
3773 multiple-locations breakpoints could be placed. */
3776 minsym_found (struct linespec_state
*self
, struct objfile
*objfile
,
3777 struct minimal_symbol
*msymbol
,
3778 struct symtabs_and_lines
*result
)
3780 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3782 struct symtab_and_line sal
;
3784 sal
= find_pc_sect_line (MSYMBOL_VALUE_ADDRESS (objfile
, msymbol
),
3785 (struct obj_section
*) 0, 0);
3786 sal
.section
= MSYMBOL_OBJ_SECTION (objfile
, msymbol
);
3788 /* The minimal symbol might point to a function descriptor;
3789 resolve it to the actual code address instead. */
3790 pc
= gdbarch_convert_from_func_ptr_addr (gdbarch
, sal
.pc
, ¤t_target
);
3792 sal
= find_pc_sect_line (pc
, NULL
, 0);
3794 if (self
->funfirstline
)
3796 if (sal
.symtab
!= NULL
3797 && (COMPUNIT_LOCATIONS_VALID (SYMTAB_COMPUNIT (sal
.symtab
))
3798 || SYMTAB_LANGUAGE (sal
.symtab
) == language_asm
))
3800 /* If gdbarch_convert_from_func_ptr_addr does not apply then
3801 sal.SECTION, sal.LINE&co. will stay correct from above.
3802 If gdbarch_convert_from_func_ptr_addr applies then
3803 sal.SECTION is cleared from above and sal.LINE&co. will
3804 stay correct from the last find_pc_sect_line above. */
3805 sal
.pc
= MSYMBOL_VALUE_ADDRESS (objfile
, msymbol
);
3806 sal
.pc
= gdbarch_convert_from_func_ptr_addr (gdbarch
, sal
.pc
,
3808 if (gdbarch_skip_entrypoint_p (gdbarch
))
3809 sal
.pc
= gdbarch_skip_entrypoint (gdbarch
, sal
.pc
);
3812 skip_prologue_sal (&sal
);
3815 if (maybe_add_address (self
->addr_set
, objfile
->pspace
, sal
.pc
))
3816 add_sal_to_sals (self
, result
, &sal
, MSYMBOL_NATURAL_NAME (msymbol
), 0);
3819 /* A helper struct to pass some data through
3820 iterate_over_minimal_symbols. */
3822 struct collect_minsyms
3824 /* The objfile we're examining. */
3825 struct objfile
*objfile
;
3827 /* Only search the given symtab, or NULL to search for all symbols. */
3828 struct symtab
*symtab
;
3830 /* The funfirstline setting from the initial call. */
3833 /* The list_mode setting from the initial call. */
3836 /* The resulting symbols. */
3837 VEC (bound_minimal_symbol_d
) *msyms
;
3840 /* A helper function to classify a minimal_symbol_type according to
3844 classify_mtype (enum minimal_symbol_type t
)
3851 /* Intermediate priority. */
3854 case mst_solib_trampoline
:
3855 /* Lowest priority. */
3859 /* Highest priority. */
3864 /* Callback for qsort that sorts symbols by priority. */
3867 compare_msyms (const void *a
, const void *b
)
3869 const bound_minimal_symbol_d
*moa
= (const bound_minimal_symbol_d
*) a
;
3870 const bound_minimal_symbol_d
*mob
= (const bound_minimal_symbol_d
*) b
;
3871 enum minimal_symbol_type ta
= MSYMBOL_TYPE (moa
->minsym
);
3872 enum minimal_symbol_type tb
= MSYMBOL_TYPE (mob
->minsym
);
3874 return classify_mtype (ta
) - classify_mtype (tb
);
3877 /* Callback for iterate_over_minimal_symbols that adds the symbol to
3881 add_minsym (struct minimal_symbol
*minsym
, void *d
)
3883 struct collect_minsyms
*info
= (struct collect_minsyms
*) d
;
3884 bound_minimal_symbol_d mo
;
3887 mo
.objfile
= info
->objfile
;
3889 if (info
->symtab
!= NULL
)
3892 struct symtab_and_line sal
;
3893 struct gdbarch
*gdbarch
= get_objfile_arch (info
->objfile
);
3895 sal
= find_pc_sect_line (MSYMBOL_VALUE_ADDRESS (info
->objfile
, minsym
),
3897 sal
.section
= MSYMBOL_OBJ_SECTION (info
->objfile
, minsym
);
3899 = gdbarch_convert_from_func_ptr_addr (gdbarch
, sal
.pc
, ¤t_target
);
3901 sal
= find_pc_sect_line (pc
, NULL
, 0);
3903 if (info
->symtab
!= sal
.symtab
)
3907 /* Exclude data symbols when looking for breakpoint locations. */
3908 if (!info
->list_mode
)
3909 switch (minsym
->type
)
3911 case mst_slot_got_plt
:
3918 /* Make sure this minsym is not a function descriptor
3919 before we decide to discard it. */
3920 struct gdbarch
*gdbarch
= get_objfile_arch (info
->objfile
);
3921 CORE_ADDR addr
= gdbarch_convert_from_func_ptr_addr
3922 (gdbarch
, BMSYMBOL_VALUE_ADDRESS (mo
),
3925 if (addr
== BMSYMBOL_VALUE_ADDRESS (mo
))
3930 VEC_safe_push (bound_minimal_symbol_d
, info
->msyms
, &mo
);
3933 /* Search for minimal symbols called NAME. If SEARCH_PSPACE
3934 is not NULL, the search is restricted to just that program
3937 If SYMTAB is NULL, search all objfiles, otherwise
3938 restrict results to the given SYMTAB. */
3941 search_minsyms_for_name (struct collect_info
*info
, const char *name
,
3942 struct program_space
*search_pspace
,
3943 struct symtab
*symtab
)
3945 struct collect_minsyms local
;
3946 struct cleanup
*cleanup
;
3948 memset (&local
, 0, sizeof (local
));
3949 local
.funfirstline
= info
->state
->funfirstline
;
3950 local
.list_mode
= info
->state
->list_mode
;
3951 local
.symtab
= symtab
;
3953 cleanup
= make_cleanup (VEC_cleanup (bound_minimal_symbol_d
), &local
.msyms
);
3957 struct program_space
*pspace
;
3959 ALL_PSPACES (pspace
)
3961 struct objfile
*objfile
;
3963 if (search_pspace
!= NULL
&& search_pspace
!= pspace
)
3965 if (pspace
->executing_startup
)
3968 set_current_program_space (pspace
);
3970 ALL_OBJFILES (objfile
)
3972 local
.objfile
= objfile
;
3973 iterate_over_minimal_symbols (objfile
, name
, add_minsym
, &local
);
3979 if (search_pspace
== NULL
|| SYMTAB_PSPACE (symtab
) == search_pspace
)
3981 set_current_program_space (SYMTAB_PSPACE (symtab
));
3982 local
.objfile
= SYMTAB_OBJFILE(symtab
);
3983 iterate_over_minimal_symbols (local
.objfile
, name
, add_minsym
,
3988 if (!VEC_empty (bound_minimal_symbol_d
, local
.msyms
))
3992 bound_minimal_symbol_d
*item
;
3994 qsort (VEC_address (bound_minimal_symbol_d
, local
.msyms
),
3995 VEC_length (bound_minimal_symbol_d
, local
.msyms
),
3996 sizeof (bound_minimal_symbol_d
),
3999 /* Now the minsyms are in classification order. So, we walk
4000 over them and process just the minsyms with the same
4001 classification as the very first minsym in the list. */
4002 item
= VEC_index (bound_minimal_symbol_d
, local
.msyms
, 0);
4003 classification
= classify_mtype (MSYMBOL_TYPE (item
->minsym
));
4006 VEC_iterate (bound_minimal_symbol_d
, local
.msyms
, ix
, item
);
4009 if (classify_mtype (MSYMBOL_TYPE (item
->minsym
)) != classification
)
4012 VEC_safe_push (bound_minimal_symbol_d
,
4013 info
->result
.minimal_symbols
, item
);
4017 do_cleanups (cleanup
);
4020 /* A helper function to add all symbols matching NAME to INFO. If
4021 PSPACE is not NULL, the search is restricted to just that program
4025 add_matching_symbols_to_info (const char *name
,
4026 struct collect_info
*info
,
4027 struct program_space
*pspace
)
4032 for (ix
= 0; VEC_iterate (symtab_ptr
, info
->file_symtabs
, ix
, elt
); ++ix
)
4036 iterate_over_all_matching_symtabs (info
->state
, name
, VAR_DOMAIN
,
4037 pspace
, true, [&] (symbol
*sym
)
4038 { return info
->add_symbol (sym
); });
4039 search_minsyms_for_name (info
, name
, pspace
, NULL
);
4041 else if (pspace
== NULL
|| pspace
== SYMTAB_PSPACE (elt
))
4043 int prev_len
= VEC_length (symbolp
, info
->result
.symbols
);
4045 /* Program spaces that are executing startup should have
4046 been filtered out earlier. */
4047 gdb_assert (!SYMTAB_PSPACE (elt
)->executing_startup
);
4048 set_current_program_space (SYMTAB_PSPACE (elt
));
4049 iterate_over_file_blocks (elt
, name
, VAR_DOMAIN
, [&] (symbol
*sym
)
4050 { return info
->add_symbol (sym
); });
4052 /* If no new symbols were found in this iteration and this symtab
4053 is in assembler, we might actually be looking for a label for
4054 which we don't have debug info. Check for a minimal symbol in
4056 if (prev_len
== VEC_length (symbolp
, info
->result
.symbols
)
4057 && elt
->language
== language_asm
)
4058 search_minsyms_for_name (info
, name
, pspace
, elt
);
4065 /* Now come some functions that are called from multiple places within
4069 symbol_to_sal (struct symtab_and_line
*result
,
4070 int funfirstline
, struct symbol
*sym
)
4072 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
4074 *result
= find_function_start_sal (sym
, funfirstline
);
4079 if (SYMBOL_CLASS (sym
) == LOC_LABEL
&& SYMBOL_VALUE_ADDRESS (sym
) != 0)
4082 result
->symtab
= symbol_symtab (sym
);
4083 result
->line
= SYMBOL_LINE (sym
);
4084 result
->pc
= SYMBOL_VALUE_ADDRESS (sym
);
4085 result
->pspace
= SYMTAB_PSPACE (result
->symtab
);
4086 result
->explicit_pc
= 1;
4089 else if (funfirstline
)
4093 else if (SYMBOL_LINE (sym
) != 0)
4095 /* We know its line number. */
4097 result
->symtab
= symbol_symtab (sym
);
4098 result
->line
= SYMBOL_LINE (sym
);
4099 result
->pspace
= SYMTAB_PSPACE (result
->symtab
);
4107 linespec_result::~linespec_result ()
4110 struct linespec_sals
*lsal
;
4112 for (i
= 0; VEC_iterate (linespec_sals
, sals
, i
, lsal
); ++i
)
4114 xfree (lsal
->canonical
);
4115 xfree (lsal
->sals
.sals
);
4117 VEC_free (linespec_sals
, sals
);
4120 /* Return the quote characters permitted by the linespec parser. */
4123 get_gdb_linespec_parser_quote_characters (void)
4125 return linespec_quote_characters
;