xref: /dflybsd-src/contrib/gdb-7/gdb/linespec.c (revision de8e141f24382815c10a4012d209bbbf7abf1112)
15796c8dcSSimon Schubert /* Parser for linespec for the GNU debugger, GDB.
25796c8dcSSimon Schubert 
3*ef5ccd6cSJohn Marino    Copyright (C) 1986-2013 Free Software Foundation, Inc.
45796c8dcSSimon Schubert 
55796c8dcSSimon Schubert    This file is part of GDB.
65796c8dcSSimon Schubert 
75796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
85796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
95796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
105796c8dcSSimon Schubert    (at your option) any later version.
115796c8dcSSimon Schubert 
125796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
135796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
145796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
155796c8dcSSimon Schubert    GNU General Public License for more details.
165796c8dcSSimon Schubert 
175796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
185796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
195796c8dcSSimon Schubert 
205796c8dcSSimon Schubert #include "defs.h"
215796c8dcSSimon Schubert #include "symtab.h"
225796c8dcSSimon Schubert #include "frame.h"
235796c8dcSSimon Schubert #include "command.h"
245796c8dcSSimon Schubert #include "symfile.h"
255796c8dcSSimon Schubert #include "objfiles.h"
265796c8dcSSimon Schubert #include "source.h"
275796c8dcSSimon Schubert #include "demangle.h"
285796c8dcSSimon Schubert #include "value.h"
295796c8dcSSimon Schubert #include "completer.h"
305796c8dcSSimon Schubert #include "cp-abi.h"
31cf7f2e2dSJohn Marino #include "cp-support.h"
325796c8dcSSimon Schubert #include "parser-defs.h"
335796c8dcSSimon Schubert #include "block.h"
345796c8dcSSimon Schubert #include "objc-lang.h"
355796c8dcSSimon Schubert #include "linespec.h"
365796c8dcSSimon Schubert #include "exceptions.h"
375796c8dcSSimon Schubert #include "language.h"
385796c8dcSSimon Schubert #include "interps.h"
395796c8dcSSimon Schubert #include "mi/mi-cmds.h"
405796c8dcSSimon Schubert #include "target.h"
41cf7f2e2dSJohn Marino #include "arch-utils.h"
42c50c785cSJohn Marino #include <ctype.h>
43c50c785cSJohn Marino #include "cli/cli-utils.h"
44a45ae5f8SJohn Marino #include "filenames.h"
45a45ae5f8SJohn Marino #include "ada-lang.h"
46*ef5ccd6cSJohn Marino #include "stack.h"
475796c8dcSSimon Schubert 
48a45ae5f8SJohn Marino typedef struct symtab *symtab_p;
49a45ae5f8SJohn Marino DEF_VEC_P (symtab_p);
505796c8dcSSimon Schubert 
51a45ae5f8SJohn Marino typedef struct symbol *symbolp;
52a45ae5f8SJohn Marino DEF_VEC_P (symbolp);
53a45ae5f8SJohn Marino 
54a45ae5f8SJohn Marino typedef struct type *typep;
55a45ae5f8SJohn Marino DEF_VEC_P (typep);
56a45ae5f8SJohn Marino 
57a45ae5f8SJohn Marino /* An address entry is used to ensure that any given location is only
58a45ae5f8SJohn Marino    added to the result a single time.  It holds an address and the
59a45ae5f8SJohn Marino    program space from which the address came.  */
60a45ae5f8SJohn Marino 
61a45ae5f8SJohn Marino struct address_entry
62a45ae5f8SJohn Marino {
63a45ae5f8SJohn Marino   struct program_space *pspace;
64a45ae5f8SJohn Marino   CORE_ADDR addr;
65a45ae5f8SJohn Marino };
66a45ae5f8SJohn Marino 
67*ef5ccd6cSJohn Marino /* A helper struct which just holds a minimal symbol and the object
68*ef5ccd6cSJohn Marino    file from which it came.  */
69*ef5ccd6cSJohn Marino 
70*ef5ccd6cSJohn Marino typedef struct minsym_and_objfile
71*ef5ccd6cSJohn Marino {
72*ef5ccd6cSJohn Marino   struct minimal_symbol *minsym;
73*ef5ccd6cSJohn Marino   struct objfile *objfile;
74*ef5ccd6cSJohn Marino } minsym_and_objfile_d;
75*ef5ccd6cSJohn Marino 
76*ef5ccd6cSJohn Marino DEF_VEC_O (minsym_and_objfile_d);
77*ef5ccd6cSJohn Marino 
78*ef5ccd6cSJohn Marino /* An enumeration of possible signs for a line offset.  */
79*ef5ccd6cSJohn Marino enum offset_relative_sign
80*ef5ccd6cSJohn Marino {
81*ef5ccd6cSJohn Marino   /* No sign  */
82*ef5ccd6cSJohn Marino   LINE_OFFSET_NONE,
83*ef5ccd6cSJohn Marino 
84*ef5ccd6cSJohn Marino   /* A plus sign ("+")  */
85*ef5ccd6cSJohn Marino   LINE_OFFSET_PLUS,
86*ef5ccd6cSJohn Marino 
87*ef5ccd6cSJohn Marino   /* A minus sign ("-")  */
88*ef5ccd6cSJohn Marino   LINE_OFFSET_MINUS,
89*ef5ccd6cSJohn Marino 
90*ef5ccd6cSJohn Marino   /* A special "sign" for unspecified offset.  */
91*ef5ccd6cSJohn Marino   LINE_OFFSET_UNKNOWN
92*ef5ccd6cSJohn Marino };
93*ef5ccd6cSJohn Marino 
94*ef5ccd6cSJohn Marino /* A line offset in a linespec.  */
95*ef5ccd6cSJohn Marino 
96*ef5ccd6cSJohn Marino struct line_offset
97*ef5ccd6cSJohn Marino {
98*ef5ccd6cSJohn Marino   /* Line offset and any specified sign.  */
99*ef5ccd6cSJohn Marino   int offset;
100*ef5ccd6cSJohn Marino   enum offset_relative_sign sign;
101*ef5ccd6cSJohn Marino };
102*ef5ccd6cSJohn Marino 
103*ef5ccd6cSJohn Marino /* A linespec.  Elements of this structure are filled in by a parser
104*ef5ccd6cSJohn Marino    (either parse_linespec or some other function).  The structure is
105*ef5ccd6cSJohn Marino    then converted into SALs by convert_linespec_to_sals.  */
106*ef5ccd6cSJohn Marino 
107*ef5ccd6cSJohn Marino struct linespec
108*ef5ccd6cSJohn Marino {
109*ef5ccd6cSJohn Marino   /* An expression and the resulting PC.  Specifying an expression
110*ef5ccd6cSJohn Marino      currently precludes the use of other members.  */
111*ef5ccd6cSJohn Marino 
112*ef5ccd6cSJohn Marino   /* The expression entered by the user.  */
113*ef5ccd6cSJohn Marino   const char *expression;
114*ef5ccd6cSJohn Marino 
115*ef5ccd6cSJohn Marino   /* The resulting PC expression derived from evaluating EXPRESSION.  */
116*ef5ccd6cSJohn Marino   CORE_ADDR expr_pc;
117*ef5ccd6cSJohn Marino 
118*ef5ccd6cSJohn Marino   /* Any specified file symtabs.  */
119*ef5ccd6cSJohn Marino 
120*ef5ccd6cSJohn Marino   /* The user-supplied source filename or NULL if none was specified.  */
121*ef5ccd6cSJohn Marino   const char *source_filename;
122*ef5ccd6cSJohn Marino 
123*ef5ccd6cSJohn Marino   /* The list of symtabs to search to which to limit the search.  May not
124*ef5ccd6cSJohn Marino      be NULL.  If SOURCE_FILENAME is NULL (no user-specified filename),
125*ef5ccd6cSJohn Marino      FILE_SYMTABS should contain one single NULL member.  This will
126*ef5ccd6cSJohn Marino      cause the code to use the default symtab.  */
127*ef5ccd6cSJohn Marino   VEC (symtab_p) *file_symtabs;
128*ef5ccd6cSJohn Marino 
129*ef5ccd6cSJohn Marino   /* The name of a function or method and any matching symbols.  */
130*ef5ccd6cSJohn Marino 
131*ef5ccd6cSJohn Marino   /* The user-specified function name.  If no function name was
132*ef5ccd6cSJohn Marino      supplied, this may be NULL.  */
133*ef5ccd6cSJohn Marino   const char *function_name;
134*ef5ccd6cSJohn Marino 
135*ef5ccd6cSJohn Marino   /* A list of matching function symbols and minimal symbols.  Both lists
136*ef5ccd6cSJohn Marino      may be NULL if no matching symbols were found.  */
137*ef5ccd6cSJohn Marino   VEC (symbolp) *function_symbols;
138*ef5ccd6cSJohn Marino   VEC (minsym_and_objfile_d) *minimal_symbols;
139*ef5ccd6cSJohn Marino 
140*ef5ccd6cSJohn Marino   /* The name of a label and matching symbols.  */
141*ef5ccd6cSJohn Marino 
142*ef5ccd6cSJohn Marino   /* The user-specified label name.  */
143*ef5ccd6cSJohn Marino   const char *label_name;
144*ef5ccd6cSJohn Marino 
145*ef5ccd6cSJohn Marino   /* A structure of matching label symbols and the corresponding
146*ef5ccd6cSJohn Marino      function symbol in which the label was found.  Both may be NULL
147*ef5ccd6cSJohn Marino      or both must be non-NULL.  */
148*ef5ccd6cSJohn Marino   struct
149*ef5ccd6cSJohn Marino   {
150*ef5ccd6cSJohn Marino     VEC (symbolp) *label_symbols;
151*ef5ccd6cSJohn Marino     VEC (symbolp) *function_symbols;
152*ef5ccd6cSJohn Marino   } labels;
153*ef5ccd6cSJohn Marino 
154*ef5ccd6cSJohn Marino   /* Line offset.  It may be LINE_OFFSET_UNKNOWN, meaning that no
155*ef5ccd6cSJohn Marino    offset was specified.  */
156*ef5ccd6cSJohn Marino   struct line_offset line_offset;
157*ef5ccd6cSJohn Marino };
158*ef5ccd6cSJohn Marino typedef struct linespec *linespec_p;
159*ef5ccd6cSJohn Marino 
160*ef5ccd6cSJohn Marino /* A canonical linespec represented as a symtab-related string.
161*ef5ccd6cSJohn Marino 
162*ef5ccd6cSJohn Marino    Each entry represents the "SYMTAB:SUFFIX" linespec string.
163*ef5ccd6cSJohn Marino    SYMTAB can be converted for example by symtab_to_fullname or
164*ef5ccd6cSJohn Marino    symtab_to_filename_for_display as needed.  */
165*ef5ccd6cSJohn Marino 
166*ef5ccd6cSJohn Marino struct linespec_canonical_name
167*ef5ccd6cSJohn Marino {
168*ef5ccd6cSJohn Marino   /* Remaining text part of the linespec string.  */
169*ef5ccd6cSJohn Marino   char *suffix;
170*ef5ccd6cSJohn Marino 
171*ef5ccd6cSJohn Marino   /* If NULL then SUFFIX is the whole linespec string.  */
172*ef5ccd6cSJohn Marino   struct symtab *symtab;
173*ef5ccd6cSJohn Marino };
174*ef5ccd6cSJohn Marino 
175a45ae5f8SJohn Marino /* An instance of this is used to keep all state while linespec
176a45ae5f8SJohn Marino    operates.  This instance is passed around as a 'this' pointer to
177a45ae5f8SJohn Marino    the various implementation methods.  */
178a45ae5f8SJohn Marino 
179a45ae5f8SJohn Marino struct linespec_state
180a45ae5f8SJohn Marino {
181*ef5ccd6cSJohn Marino   /* The language in use during linespec processing.  */
182*ef5ccd6cSJohn Marino   const struct language_defn *language;
183*ef5ccd6cSJohn Marino 
184a45ae5f8SJohn Marino   /* The program space as seen when the module was entered.  */
185a45ae5f8SJohn Marino   struct program_space *program_space;
186a45ae5f8SJohn Marino 
187a45ae5f8SJohn Marino   /* The default symtab to use, if no other symtab is specified.  */
188a45ae5f8SJohn Marino   struct symtab *default_symtab;
189a45ae5f8SJohn Marino 
190a45ae5f8SJohn Marino   /* The default line to use.  */
191a45ae5f8SJohn Marino   int default_line;
192a45ae5f8SJohn Marino 
193a45ae5f8SJohn Marino   /* The 'funfirstline' value that was passed in to decode_line_1 or
194a45ae5f8SJohn Marino      decode_line_full.  */
195a45ae5f8SJohn Marino   int funfirstline;
196a45ae5f8SJohn Marino 
197a45ae5f8SJohn Marino   /* Nonzero if we are running in 'list' mode; see decode_line_list.  */
198a45ae5f8SJohn Marino   int list_mode;
199a45ae5f8SJohn Marino 
200a45ae5f8SJohn Marino   /* The 'canonical' value passed to decode_line_full, or NULL.  */
201a45ae5f8SJohn Marino   struct linespec_result *canonical;
202a45ae5f8SJohn Marino 
203a45ae5f8SJohn Marino   /* Canonical strings that mirror the symtabs_and_lines result.  */
204*ef5ccd6cSJohn Marino   struct linespec_canonical_name *canonical_names;
205a45ae5f8SJohn Marino 
206a45ae5f8SJohn Marino   /* This is a set of address_entry objects which is used to prevent
207a45ae5f8SJohn Marino      duplicate symbols from being entered into the result.  */
208a45ae5f8SJohn Marino   htab_t addr_set;
209a45ae5f8SJohn Marino };
210a45ae5f8SJohn Marino 
211a45ae5f8SJohn Marino /* This is a helper object that is used when collecting symbols into a
212a45ae5f8SJohn Marino    result.  */
213a45ae5f8SJohn Marino 
214a45ae5f8SJohn Marino struct collect_info
215a45ae5f8SJohn Marino {
216a45ae5f8SJohn Marino   /* The linespec object in use.  */
217a45ae5f8SJohn Marino   struct linespec_state *state;
218a45ae5f8SJohn Marino 
219*ef5ccd6cSJohn Marino   /* A list of symtabs to which to restrict matches.  */
220*ef5ccd6cSJohn Marino   VEC (symtab_p) *file_symtabs;
221*ef5ccd6cSJohn Marino 
222a45ae5f8SJohn Marino   /* The result being accumulated.  */
223*ef5ccd6cSJohn Marino   struct
224*ef5ccd6cSJohn Marino   {
225*ef5ccd6cSJohn Marino     VEC (symbolp) *symbols;
226*ef5ccd6cSJohn Marino     VEC (minsym_and_objfile_d) *minimal_symbols;
227*ef5ccd6cSJohn Marino   } result;
228a45ae5f8SJohn Marino };
2295796c8dcSSimon Schubert 
230*ef5ccd6cSJohn Marino /* Token types  */
231*ef5ccd6cSJohn Marino 
232*ef5ccd6cSJohn Marino enum ls_token_type
233*ef5ccd6cSJohn Marino {
234*ef5ccd6cSJohn Marino   /* A keyword  */
235*ef5ccd6cSJohn Marino   LSTOKEN_KEYWORD = 0,
236*ef5ccd6cSJohn Marino 
237*ef5ccd6cSJohn Marino   /* A colon "separator"  */
238*ef5ccd6cSJohn Marino   LSTOKEN_COLON,
239*ef5ccd6cSJohn Marino 
240*ef5ccd6cSJohn Marino   /* A string  */
241*ef5ccd6cSJohn Marino   LSTOKEN_STRING,
242*ef5ccd6cSJohn Marino 
243*ef5ccd6cSJohn Marino   /* A number  */
244*ef5ccd6cSJohn Marino   LSTOKEN_NUMBER,
245*ef5ccd6cSJohn Marino 
246*ef5ccd6cSJohn Marino   /* A comma  */
247*ef5ccd6cSJohn Marino   LSTOKEN_COMMA,
248*ef5ccd6cSJohn Marino 
249*ef5ccd6cSJohn Marino   /* EOI (end of input)  */
250*ef5ccd6cSJohn Marino   LSTOKEN_EOI,
251*ef5ccd6cSJohn Marino 
252*ef5ccd6cSJohn Marino   /* Consumed token  */
253*ef5ccd6cSJohn Marino   LSTOKEN_CONSUMED
254*ef5ccd6cSJohn Marino };
255*ef5ccd6cSJohn Marino typedef enum ls_token_type linespec_token_type;
256*ef5ccd6cSJohn Marino 
257*ef5ccd6cSJohn Marino /* List of keywords  */
258*ef5ccd6cSJohn Marino 
259*ef5ccd6cSJohn Marino static const char * const linespec_keywords[] = { "if", "thread", "task" };
260*ef5ccd6cSJohn Marino 
261*ef5ccd6cSJohn Marino /* A token of the linespec lexer  */
262*ef5ccd6cSJohn Marino 
263*ef5ccd6cSJohn Marino struct ls_token
264*ef5ccd6cSJohn Marino {
265*ef5ccd6cSJohn Marino   /* The type of the token  */
266*ef5ccd6cSJohn Marino   linespec_token_type type;
267*ef5ccd6cSJohn Marino 
268*ef5ccd6cSJohn Marino   /* Data for the token  */
269*ef5ccd6cSJohn Marino   union
270*ef5ccd6cSJohn Marino   {
271*ef5ccd6cSJohn Marino     /* A string, given as a stoken  */
272*ef5ccd6cSJohn Marino     struct stoken string;
273*ef5ccd6cSJohn Marino 
274*ef5ccd6cSJohn Marino     /* A keyword  */
275*ef5ccd6cSJohn Marino     const char *keyword;
276*ef5ccd6cSJohn Marino   } data;
277*ef5ccd6cSJohn Marino };
278*ef5ccd6cSJohn Marino typedef struct ls_token linespec_token;
279*ef5ccd6cSJohn Marino 
280*ef5ccd6cSJohn Marino #define LS_TOKEN_STOKEN(TOK) (TOK).data.string
281*ef5ccd6cSJohn Marino #define LS_TOKEN_KEYWORD(TOK) (TOK).data.keyword
282*ef5ccd6cSJohn Marino 
283*ef5ccd6cSJohn Marino /* An instance of the linespec parser.  */
284*ef5ccd6cSJohn Marino 
285*ef5ccd6cSJohn Marino struct ls_parser
286*ef5ccd6cSJohn Marino {
287*ef5ccd6cSJohn Marino   /* Lexer internal data  */
288*ef5ccd6cSJohn Marino   struct
289*ef5ccd6cSJohn Marino   {
290*ef5ccd6cSJohn Marino     /* Save head of input stream.  */
291*ef5ccd6cSJohn Marino     char *saved_arg;
292*ef5ccd6cSJohn Marino 
293*ef5ccd6cSJohn Marino     /* Head of the input stream.  */
294*ef5ccd6cSJohn Marino     char **stream;
295*ef5ccd6cSJohn Marino #define PARSER_STREAM(P) (*(P)->lexer.stream)
296*ef5ccd6cSJohn Marino 
297*ef5ccd6cSJohn Marino     /* The current token.  */
298*ef5ccd6cSJohn Marino     linespec_token current;
299*ef5ccd6cSJohn Marino   } lexer;
300*ef5ccd6cSJohn Marino 
301*ef5ccd6cSJohn Marino   /* Is the entire linespec quote-enclosed?  */
302*ef5ccd6cSJohn Marino   int is_quote_enclosed;
303*ef5ccd6cSJohn Marino 
304*ef5ccd6cSJohn Marino   /* Is a keyword syntactically valid at this point?
305*ef5ccd6cSJohn Marino      In, e.g., "break thread thread 1", the leading "keyword" must not
306*ef5ccd6cSJohn Marino      be interpreted as such.  */
307*ef5ccd6cSJohn Marino   int keyword_ok;
308*ef5ccd6cSJohn Marino 
309*ef5ccd6cSJohn Marino   /* The state of the parse.  */
310*ef5ccd6cSJohn Marino   struct linespec_state state;
311*ef5ccd6cSJohn Marino #define PARSER_STATE(PPTR) (&(PPTR)->state)
312*ef5ccd6cSJohn Marino 
313*ef5ccd6cSJohn Marino   /* The result of the parse.  */
314*ef5ccd6cSJohn Marino   struct linespec result;
315*ef5ccd6cSJohn Marino #define PARSER_RESULT(PPTR) (&(PPTR)->result)
316*ef5ccd6cSJohn Marino };
317*ef5ccd6cSJohn Marino typedef struct ls_parser linespec_parser;
318*ef5ccd6cSJohn Marino 
319c50c785cSJohn Marino /* Prototypes for local functions.  */
3205796c8dcSSimon Schubert 
321*ef5ccd6cSJohn Marino static void iterate_over_file_blocks (struct symtab *symtab,
322*ef5ccd6cSJohn Marino 				      const char *name, domain_enum domain,
323*ef5ccd6cSJohn Marino 				      symbol_found_callback_ftype *callback,
324*ef5ccd6cSJohn Marino 				      void *data);
325*ef5ccd6cSJohn Marino 
3265796c8dcSSimon Schubert static void initialize_defaults (struct symtab **default_symtab,
3275796c8dcSSimon Schubert 				 int *default_line);
3285796c8dcSSimon Schubert 
329*ef5ccd6cSJohn Marino static CORE_ADDR linespec_expression_to_pc (const char **exp_ptr);
3305796c8dcSSimon Schubert 
331a45ae5f8SJohn Marino static struct symtabs_and_lines decode_objc (struct linespec_state *self,
332*ef5ccd6cSJohn Marino 					     linespec_p ls,
333a45ae5f8SJohn Marino 					     char **argptr);
3345796c8dcSSimon Schubert 
335*ef5ccd6cSJohn Marino static VEC (symtab_p) *symtabs_from_filename (const char *);
3365796c8dcSSimon Schubert 
337*ef5ccd6cSJohn Marino static VEC (symbolp) *find_label_symbols (struct linespec_state *self,
338a45ae5f8SJohn Marino 					  VEC (symbolp) *function_symbols,
339*ef5ccd6cSJohn Marino 					  VEC (symbolp) **label_funcs_ret,
340*ef5ccd6cSJohn Marino 					  const char *name);
341c50c785cSJohn Marino 
342*ef5ccd6cSJohn Marino static void find_linespec_symbols (struct linespec_state *self,
343*ef5ccd6cSJohn Marino 				   VEC (symtab_p) *file_symtabs,
344*ef5ccd6cSJohn Marino 				   const char *name,
345*ef5ccd6cSJohn Marino 				   VEC (symbolp) **symbols,
346*ef5ccd6cSJohn Marino 				   VEC (minsym_and_objfile_d) **minsyms);
347*ef5ccd6cSJohn Marino 
348*ef5ccd6cSJohn Marino static struct line_offset
349*ef5ccd6cSJohn Marino      linespec_parse_variable (struct linespec_state *self,
350*ef5ccd6cSJohn Marino 			      const char *variable);
3515796c8dcSSimon Schubert 
352a45ae5f8SJohn Marino static int symbol_to_sal (struct symtab_and_line *result,
353a45ae5f8SJohn Marino 			  int funfirstline, struct symbol *sym);
3545796c8dcSSimon Schubert 
355a45ae5f8SJohn Marino static void add_matching_symbols_to_info (const char *name,
356a45ae5f8SJohn Marino 					  struct collect_info *info,
357a45ae5f8SJohn Marino 					  struct program_space *pspace);
358a45ae5f8SJohn Marino 
359a45ae5f8SJohn Marino static void add_all_symbol_names_from_pspace (struct collect_info *info,
360a45ae5f8SJohn Marino 					      struct program_space *pspace,
361a45ae5f8SJohn Marino 					      VEC (const_char_ptr) *names);
3625796c8dcSSimon Schubert 
363*ef5ccd6cSJohn Marino static VEC (symtab_p) *collect_symtabs_from_filename (const char *file);
364*ef5ccd6cSJohn Marino 
365*ef5ccd6cSJohn Marino static void decode_digits_ordinary (struct linespec_state *self,
366*ef5ccd6cSJohn Marino 				    linespec_p ls,
367*ef5ccd6cSJohn Marino 				    int line,
368*ef5ccd6cSJohn Marino 				    struct symtabs_and_lines *sals,
369*ef5ccd6cSJohn Marino 				    struct linetable_entry **best_entry);
370*ef5ccd6cSJohn Marino 
371*ef5ccd6cSJohn Marino static void decode_digits_list_mode (struct linespec_state *self,
372*ef5ccd6cSJohn Marino 				     linespec_p ls,
373*ef5ccd6cSJohn Marino 				     struct symtabs_and_lines *values,
374*ef5ccd6cSJohn Marino 				     struct symtab_and_line val);
375*ef5ccd6cSJohn Marino 
376*ef5ccd6cSJohn Marino static void minsym_found (struct linespec_state *self, struct objfile *objfile,
377*ef5ccd6cSJohn Marino 			  struct minimal_symbol *msymbol,
378*ef5ccd6cSJohn Marino 			  struct symtabs_and_lines *result);
379*ef5ccd6cSJohn Marino 
380*ef5ccd6cSJohn Marino static int compare_symbols (const void *a, const void *b);
381*ef5ccd6cSJohn Marino 
382*ef5ccd6cSJohn Marino static int compare_msymbols (const void *a, const void *b);
383*ef5ccd6cSJohn Marino 
384*ef5ccd6cSJohn Marino static const char *find_toplevel_char (const char *s, char c);
385*ef5ccd6cSJohn Marino 
386*ef5ccd6cSJohn Marino /* Permitted quote characters for the parser.  This is different from the
387*ef5ccd6cSJohn Marino    completer's quote characters to allow backward compatibility with the
388*ef5ccd6cSJohn Marino    previous parser.  */
389*ef5ccd6cSJohn Marino static const char *const linespec_quote_characters = "\"\'";
390*ef5ccd6cSJohn Marino 
391*ef5ccd6cSJohn Marino /* Lexer functions.  */
392*ef5ccd6cSJohn Marino 
393*ef5ccd6cSJohn Marino /* Lex a number from the input in PARSER.  This only supports
394*ef5ccd6cSJohn Marino    decimal numbers.
395*ef5ccd6cSJohn Marino 
396*ef5ccd6cSJohn Marino    Return true if input is decimal numbers.  Return false if not.  */
397*ef5ccd6cSJohn Marino 
398*ef5ccd6cSJohn Marino static int
linespec_lexer_lex_number(linespec_parser * parser,linespec_token * tokenp)399*ef5ccd6cSJohn Marino linespec_lexer_lex_number (linespec_parser *parser, linespec_token *tokenp)
400*ef5ccd6cSJohn Marino {
401*ef5ccd6cSJohn Marino   tokenp->type = LSTOKEN_NUMBER;
402*ef5ccd6cSJohn Marino   LS_TOKEN_STOKEN (*tokenp).length = 0;
403*ef5ccd6cSJohn Marino   LS_TOKEN_STOKEN (*tokenp).ptr = PARSER_STREAM (parser);
404*ef5ccd6cSJohn Marino 
405*ef5ccd6cSJohn Marino   /* Keep any sign at the start of the stream.  */
406*ef5ccd6cSJohn Marino   if (*PARSER_STREAM (parser) == '+' || *PARSER_STREAM (parser) == '-')
407*ef5ccd6cSJohn Marino     {
408*ef5ccd6cSJohn Marino       ++LS_TOKEN_STOKEN (*tokenp).length;
409*ef5ccd6cSJohn Marino       ++(PARSER_STREAM (parser));
410*ef5ccd6cSJohn Marino     }
411*ef5ccd6cSJohn Marino 
412*ef5ccd6cSJohn Marino   while (isdigit (*PARSER_STREAM (parser)))
413*ef5ccd6cSJohn Marino     {
414*ef5ccd6cSJohn Marino       ++LS_TOKEN_STOKEN (*tokenp).length;
415*ef5ccd6cSJohn Marino       ++(PARSER_STREAM (parser));
416*ef5ccd6cSJohn Marino     }
417*ef5ccd6cSJohn Marino 
418*ef5ccd6cSJohn Marino   /* If the next character in the input buffer is not a space, comma,
419*ef5ccd6cSJohn Marino      quote, or colon, this input does not represent a number.  */
420*ef5ccd6cSJohn Marino   if (*PARSER_STREAM (parser) != '\0'
421*ef5ccd6cSJohn Marino       && !isspace (*PARSER_STREAM (parser)) && *PARSER_STREAM (parser) != ','
422*ef5ccd6cSJohn Marino       && *PARSER_STREAM (parser) != ':'
423*ef5ccd6cSJohn Marino       && !strchr (linespec_quote_characters, *PARSER_STREAM (parser)))
424*ef5ccd6cSJohn Marino     {
425*ef5ccd6cSJohn Marino       PARSER_STREAM (parser) = LS_TOKEN_STOKEN (*tokenp).ptr;
426*ef5ccd6cSJohn Marino       return 0;
427*ef5ccd6cSJohn Marino     }
428*ef5ccd6cSJohn Marino 
429*ef5ccd6cSJohn Marino   return 1;
430*ef5ccd6cSJohn Marino }
431*ef5ccd6cSJohn Marino 
432*ef5ccd6cSJohn Marino /* Does P represent one of the keywords?  If so, return
433*ef5ccd6cSJohn Marino    the keyword.  If not, return NULL.  */
434*ef5ccd6cSJohn Marino 
435*ef5ccd6cSJohn Marino static const char *
linespec_lexer_lex_keyword(const char * p)436*ef5ccd6cSJohn Marino linespec_lexer_lex_keyword (const char *p)
437*ef5ccd6cSJohn Marino {
438*ef5ccd6cSJohn Marino   int i;
439*ef5ccd6cSJohn Marino 
440*ef5ccd6cSJohn Marino   if (p != NULL)
441*ef5ccd6cSJohn Marino     {
442*ef5ccd6cSJohn Marino       for (i = 0; i < ARRAY_SIZE (linespec_keywords); ++i)
443*ef5ccd6cSJohn Marino 	{
444*ef5ccd6cSJohn Marino 	  int len = strlen (linespec_keywords[i]);
445*ef5ccd6cSJohn Marino 
446*ef5ccd6cSJohn Marino 	  /* If P begins with one of the keywords and the next
447*ef5ccd6cSJohn Marino 	     character is not a valid identifier character,
448*ef5ccd6cSJohn Marino 	     we have found a keyword.  */
449*ef5ccd6cSJohn Marino 	  if (strncmp (p, linespec_keywords[i], len) == 0
450*ef5ccd6cSJohn Marino 	      && !(isalnum (p[len]) || p[len] == '_'))
451*ef5ccd6cSJohn Marino 	    return linespec_keywords[i];
452*ef5ccd6cSJohn Marino 	}
453*ef5ccd6cSJohn Marino     }
454*ef5ccd6cSJohn Marino 
455*ef5ccd6cSJohn Marino   return NULL;
456*ef5ccd6cSJohn Marino }
457*ef5ccd6cSJohn Marino 
458*ef5ccd6cSJohn Marino /* Does STRING represent an Ada operator?  If so, return the length
459*ef5ccd6cSJohn Marino    of the decoded operator name.  If not, return 0.  */
460*ef5ccd6cSJohn Marino 
461*ef5ccd6cSJohn Marino static int
is_ada_operator(const char * string)462*ef5ccd6cSJohn Marino is_ada_operator (const char *string)
463*ef5ccd6cSJohn Marino {
464*ef5ccd6cSJohn Marino   const struct ada_opname_map *mapping;
465*ef5ccd6cSJohn Marino 
466*ef5ccd6cSJohn Marino   for (mapping = ada_opname_table;
467*ef5ccd6cSJohn Marino        mapping->encoded != NULL
468*ef5ccd6cSJohn Marino 	 && strncmp (mapping->decoded, string,
469*ef5ccd6cSJohn Marino 		     strlen (mapping->decoded)) != 0; ++mapping)
470*ef5ccd6cSJohn Marino     ;
471*ef5ccd6cSJohn Marino 
472*ef5ccd6cSJohn Marino   return mapping->decoded == NULL ? 0 : strlen (mapping->decoded);
473*ef5ccd6cSJohn Marino }
474*ef5ccd6cSJohn Marino 
475*ef5ccd6cSJohn Marino /* Find QUOTE_CHAR in STRING, accounting for the ':' terminal.  Return
476*ef5ccd6cSJohn Marino    the location of QUOTE_CHAR, or NULL if not found.  */
477*ef5ccd6cSJohn Marino 
478*ef5ccd6cSJohn Marino static const char *
skip_quote_char(const char * string,char quote_char)479*ef5ccd6cSJohn Marino skip_quote_char (const char *string, char quote_char)
480*ef5ccd6cSJohn Marino {
481*ef5ccd6cSJohn Marino   const char *p, *last;
482*ef5ccd6cSJohn Marino 
483*ef5ccd6cSJohn Marino   p = last = find_toplevel_char (string, quote_char);
484*ef5ccd6cSJohn Marino   while (p && *p != '\0' && *p != ':')
485*ef5ccd6cSJohn Marino     {
486*ef5ccd6cSJohn Marino       p = find_toplevel_char (p, quote_char);
487*ef5ccd6cSJohn Marino       if (p != NULL)
488*ef5ccd6cSJohn Marino 	last = p++;
489*ef5ccd6cSJohn Marino     }
490*ef5ccd6cSJohn Marino 
491*ef5ccd6cSJohn Marino   return last;
492*ef5ccd6cSJohn Marino }
493*ef5ccd6cSJohn Marino 
494*ef5ccd6cSJohn Marino /* Make a writable copy of the string given in TOKEN, trimming
495*ef5ccd6cSJohn Marino    any trailing whitespace.  */
496*ef5ccd6cSJohn Marino 
497*ef5ccd6cSJohn Marino static char *
copy_token_string(linespec_token token)498*ef5ccd6cSJohn Marino copy_token_string (linespec_token token)
499*ef5ccd6cSJohn Marino {
500*ef5ccd6cSJohn Marino   char *str, *s;
501*ef5ccd6cSJohn Marino 
502*ef5ccd6cSJohn Marino   if (token.type == LSTOKEN_KEYWORD)
503*ef5ccd6cSJohn Marino     return xstrdup (LS_TOKEN_KEYWORD (token));
504*ef5ccd6cSJohn Marino 
505*ef5ccd6cSJohn Marino   str = savestring (LS_TOKEN_STOKEN (token).ptr,
506*ef5ccd6cSJohn Marino 		    LS_TOKEN_STOKEN (token).length);
507*ef5ccd6cSJohn Marino   s = remove_trailing_whitespace (str, str + LS_TOKEN_STOKEN (token).length);
508*ef5ccd6cSJohn Marino   *s = '\0';
509*ef5ccd6cSJohn Marino 
510*ef5ccd6cSJohn Marino   return str;
511*ef5ccd6cSJohn Marino }
512*ef5ccd6cSJohn Marino 
513*ef5ccd6cSJohn Marino /* Does P represent the end of a quote-enclosed linespec?  */
514*ef5ccd6cSJohn Marino 
515*ef5ccd6cSJohn Marino static int
is_closing_quote_enclosed(const char * p)516*ef5ccd6cSJohn Marino is_closing_quote_enclosed (const char *p)
517*ef5ccd6cSJohn Marino {
518*ef5ccd6cSJohn Marino   if (strchr (linespec_quote_characters, *p))
519*ef5ccd6cSJohn Marino     ++p;
520*ef5ccd6cSJohn Marino   p = skip_spaces ((char *) p);
521*ef5ccd6cSJohn Marino   return (*p == '\0' || linespec_lexer_lex_keyword (p));
522*ef5ccd6cSJohn Marino }
523*ef5ccd6cSJohn Marino 
524*ef5ccd6cSJohn Marino /* Find the end of the parameter list that starts with *INPUT.
525*ef5ccd6cSJohn Marino    This helper function assists with lexing string segments
526*ef5ccd6cSJohn Marino    which might contain valid (non-terminating) commas.  */
527*ef5ccd6cSJohn Marino 
528*ef5ccd6cSJohn Marino static char *
find_parameter_list_end(char * input)529*ef5ccd6cSJohn Marino find_parameter_list_end (char *input)
530*ef5ccd6cSJohn Marino {
531*ef5ccd6cSJohn Marino   char end_char, start_char;
532*ef5ccd6cSJohn Marino   int depth;
533*ef5ccd6cSJohn Marino   char *p;
534*ef5ccd6cSJohn Marino 
535*ef5ccd6cSJohn Marino   start_char = *input;
536*ef5ccd6cSJohn Marino   if (start_char == '(')
537*ef5ccd6cSJohn Marino     end_char = ')';
538*ef5ccd6cSJohn Marino   else if (start_char == '<')
539*ef5ccd6cSJohn Marino     end_char = '>';
540*ef5ccd6cSJohn Marino   else
541*ef5ccd6cSJohn Marino     return NULL;
542*ef5ccd6cSJohn Marino 
543*ef5ccd6cSJohn Marino   p = input;
544*ef5ccd6cSJohn Marino   depth = 0;
545*ef5ccd6cSJohn Marino   while (*p)
546*ef5ccd6cSJohn Marino     {
547*ef5ccd6cSJohn Marino       if (*p == start_char)
548*ef5ccd6cSJohn Marino 	++depth;
549*ef5ccd6cSJohn Marino       else if (*p == end_char)
550*ef5ccd6cSJohn Marino 	{
551*ef5ccd6cSJohn Marino 	  if (--depth == 0)
552*ef5ccd6cSJohn Marino 	    {
553*ef5ccd6cSJohn Marino 	      ++p;
554*ef5ccd6cSJohn Marino 	      break;
555*ef5ccd6cSJohn Marino 	    }
556*ef5ccd6cSJohn Marino 	}
557*ef5ccd6cSJohn Marino       ++p;
558*ef5ccd6cSJohn Marino     }
559*ef5ccd6cSJohn Marino 
560*ef5ccd6cSJohn Marino   return p;
561*ef5ccd6cSJohn Marino }
562*ef5ccd6cSJohn Marino 
563*ef5ccd6cSJohn Marino 
564*ef5ccd6cSJohn Marino /* Lex a string from the input in PARSER.  */
565*ef5ccd6cSJohn Marino 
566*ef5ccd6cSJohn Marino static linespec_token
linespec_lexer_lex_string(linespec_parser * parser)567*ef5ccd6cSJohn Marino linespec_lexer_lex_string (linespec_parser *parser)
568*ef5ccd6cSJohn Marino {
569*ef5ccd6cSJohn Marino   linespec_token token;
570*ef5ccd6cSJohn Marino   char *start = PARSER_STREAM (parser);
571*ef5ccd6cSJohn Marino 
572*ef5ccd6cSJohn Marino   token.type = LSTOKEN_STRING;
573*ef5ccd6cSJohn Marino 
574*ef5ccd6cSJohn Marino   /* If the input stream starts with a quote character, skip to the next
575*ef5ccd6cSJohn Marino      quote character, regardless of the content.  */
576*ef5ccd6cSJohn Marino   if (strchr (linespec_quote_characters, *PARSER_STREAM (parser)))
577*ef5ccd6cSJohn Marino     {
578*ef5ccd6cSJohn Marino       const char *end;
579*ef5ccd6cSJohn Marino       char quote_char = *PARSER_STREAM (parser);
580*ef5ccd6cSJohn Marino 
581*ef5ccd6cSJohn Marino       /* Special case: Ada operators.  */
582*ef5ccd6cSJohn Marino       if (PARSER_STATE (parser)->language->la_language == language_ada
583*ef5ccd6cSJohn Marino 	  && quote_char == '\"')
584*ef5ccd6cSJohn Marino 	{
585*ef5ccd6cSJohn Marino 	  int len = is_ada_operator (PARSER_STREAM (parser));
586*ef5ccd6cSJohn Marino 
587*ef5ccd6cSJohn Marino 	  if (len != 0)
588*ef5ccd6cSJohn Marino 	    {
589*ef5ccd6cSJohn Marino 	      /* The input is an Ada operator.  Return the quoted string
590*ef5ccd6cSJohn Marino 		 as-is.  */
591*ef5ccd6cSJohn Marino 	      LS_TOKEN_STOKEN (token).ptr = PARSER_STREAM (parser);
592*ef5ccd6cSJohn Marino 	      LS_TOKEN_STOKEN (token).length = len;
593*ef5ccd6cSJohn Marino 	      PARSER_STREAM (parser) += len;
594*ef5ccd6cSJohn Marino 	      return token;
595*ef5ccd6cSJohn Marino 	    }
596*ef5ccd6cSJohn Marino 
597*ef5ccd6cSJohn Marino 	  /* The input does not represent an Ada operator -- fall through
598*ef5ccd6cSJohn Marino 	     to normal quoted string handling.  */
599*ef5ccd6cSJohn Marino 	}
600*ef5ccd6cSJohn Marino 
601*ef5ccd6cSJohn Marino       /* Skip past the beginning quote.  */
602*ef5ccd6cSJohn Marino       ++(PARSER_STREAM (parser));
603*ef5ccd6cSJohn Marino 
604*ef5ccd6cSJohn Marino       /* Mark the start of the string.  */
605*ef5ccd6cSJohn Marino       LS_TOKEN_STOKEN (token).ptr = PARSER_STREAM (parser);
606*ef5ccd6cSJohn Marino 
607*ef5ccd6cSJohn Marino       /* Skip to the ending quote.  */
608*ef5ccd6cSJohn Marino       end = skip_quote_char (PARSER_STREAM (parser), quote_char);
609*ef5ccd6cSJohn Marino 
610*ef5ccd6cSJohn Marino       /* Error if the input did not terminate properly.  */
611*ef5ccd6cSJohn Marino       if (end == NULL)
612*ef5ccd6cSJohn Marino 	error (_("unmatched quote"));
613*ef5ccd6cSJohn Marino 
614*ef5ccd6cSJohn Marino       /* Skip over the ending quote and mark the length of the string.  */
615*ef5ccd6cSJohn Marino       PARSER_STREAM (parser) = (char *) ++end;
616*ef5ccd6cSJohn Marino       LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - 2 - start;
617*ef5ccd6cSJohn Marino     }
618*ef5ccd6cSJohn Marino   else
619*ef5ccd6cSJohn Marino     {
620*ef5ccd6cSJohn Marino       char *p;
621*ef5ccd6cSJohn Marino 
622*ef5ccd6cSJohn Marino       /* Otherwise, only identifier characters are permitted.
623*ef5ccd6cSJohn Marino 	 Spaces are the exception.  In general, we keep spaces,
624*ef5ccd6cSJohn Marino 	 but only if the next characters in the input do not resolve
625*ef5ccd6cSJohn Marino 	 to one of the keywords.
626*ef5ccd6cSJohn Marino 
627*ef5ccd6cSJohn Marino 	 This allows users to forgo quoting CV-qualifiers, template arguments,
628*ef5ccd6cSJohn Marino 	 and similar common language constructs.  */
629*ef5ccd6cSJohn Marino 
630*ef5ccd6cSJohn Marino       while (1)
631*ef5ccd6cSJohn Marino 	{
632*ef5ccd6cSJohn Marino 	  if (isspace (*PARSER_STREAM (parser)))
633*ef5ccd6cSJohn Marino 	    {
634*ef5ccd6cSJohn Marino 	      p = skip_spaces (PARSER_STREAM (parser));
635*ef5ccd6cSJohn Marino 	      /* When we get here we know we've found something followed by
636*ef5ccd6cSJohn Marino 		 a space (we skip over parens and templates below).
637*ef5ccd6cSJohn Marino 		 So if we find a keyword now, we know it is a keyword and not,
638*ef5ccd6cSJohn Marino 		 say, a function name.  */
639*ef5ccd6cSJohn Marino 	      if (linespec_lexer_lex_keyword (p) != NULL)
640*ef5ccd6cSJohn Marino 		{
641*ef5ccd6cSJohn Marino 		  LS_TOKEN_STOKEN (token).ptr = start;
642*ef5ccd6cSJohn Marino 		  LS_TOKEN_STOKEN (token).length
643*ef5ccd6cSJohn Marino 		    = PARSER_STREAM (parser) - start;
644*ef5ccd6cSJohn Marino 		  return token;
645*ef5ccd6cSJohn Marino 		}
646*ef5ccd6cSJohn Marino 
647*ef5ccd6cSJohn Marino 	      /* Advance past the whitespace.  */
648*ef5ccd6cSJohn Marino 	      PARSER_STREAM (parser) = p;
649*ef5ccd6cSJohn Marino 	    }
650*ef5ccd6cSJohn Marino 
651*ef5ccd6cSJohn Marino 	  /* If the next character is EOI or (single) ':', the
652*ef5ccd6cSJohn Marino 	     string is complete;  return the token.  */
653*ef5ccd6cSJohn Marino 	  if (*PARSER_STREAM (parser) == 0)
654*ef5ccd6cSJohn Marino 	    {
655*ef5ccd6cSJohn Marino 	      LS_TOKEN_STOKEN (token).ptr = start;
656*ef5ccd6cSJohn Marino 	      LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - start;
657*ef5ccd6cSJohn Marino 	      return token;
658*ef5ccd6cSJohn Marino 	    }
659*ef5ccd6cSJohn Marino 	  else if (PARSER_STREAM (parser)[0] == ':')
660*ef5ccd6cSJohn Marino 	    {
661*ef5ccd6cSJohn Marino 	      /* Do not tokenize the C++ scope operator. */
662*ef5ccd6cSJohn Marino 	      if (PARSER_STREAM (parser)[1] == ':')
663*ef5ccd6cSJohn Marino 		++(PARSER_STREAM (parser));
664*ef5ccd6cSJohn Marino 
665*ef5ccd6cSJohn Marino 	      /* Do not tokenify if the input length so far is one
666*ef5ccd6cSJohn Marino 		 (i.e, a single-letter drive name) and the next character
667*ef5ccd6cSJohn Marino 		 is a directory separator.  This allows Windows-style
668*ef5ccd6cSJohn Marino 		 paths to be recognized as filenames without quoting it.  */
669*ef5ccd6cSJohn Marino 	      else if ((PARSER_STREAM (parser) - start) != 1
670*ef5ccd6cSJohn Marino 		       || !IS_DIR_SEPARATOR (PARSER_STREAM (parser)[1]))
671*ef5ccd6cSJohn Marino 		{
672*ef5ccd6cSJohn Marino 		  LS_TOKEN_STOKEN (token).ptr = start;
673*ef5ccd6cSJohn Marino 		  LS_TOKEN_STOKEN (token).length
674*ef5ccd6cSJohn Marino 		    = PARSER_STREAM (parser) - start;
675*ef5ccd6cSJohn Marino 		  return token;
676*ef5ccd6cSJohn Marino 		}
677*ef5ccd6cSJohn Marino 	    }
678*ef5ccd6cSJohn Marino 	  /* Special case: permit quote-enclosed linespecs.  */
679*ef5ccd6cSJohn Marino 	  else if (parser->is_quote_enclosed
680*ef5ccd6cSJohn Marino 		   && strchr (linespec_quote_characters,
681*ef5ccd6cSJohn Marino 			      *PARSER_STREAM (parser))
682*ef5ccd6cSJohn Marino 		   && is_closing_quote_enclosed (PARSER_STREAM (parser)))
683*ef5ccd6cSJohn Marino 	    {
684*ef5ccd6cSJohn Marino 	      LS_TOKEN_STOKEN (token).ptr = start;
685*ef5ccd6cSJohn Marino 	      LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - start;
686*ef5ccd6cSJohn Marino 	      return token;
687*ef5ccd6cSJohn Marino 	    }
688*ef5ccd6cSJohn Marino 	  /* Because commas may terminate a linespec and appear in
689*ef5ccd6cSJohn Marino 	     the middle of valid string input, special cases for
690*ef5ccd6cSJohn Marino 	     '<' and '(' are necessary.  */
691*ef5ccd6cSJohn Marino 	  else if (*PARSER_STREAM (parser) == '<'
692*ef5ccd6cSJohn Marino 		   || *PARSER_STREAM (parser) == '(')
693*ef5ccd6cSJohn Marino 	    {
694*ef5ccd6cSJohn Marino 	      char *p;
695*ef5ccd6cSJohn Marino 
696*ef5ccd6cSJohn Marino 	      p = find_parameter_list_end (PARSER_STREAM (parser));
697*ef5ccd6cSJohn Marino 	      if (p != NULL)
698*ef5ccd6cSJohn Marino 		{
699*ef5ccd6cSJohn Marino 		  PARSER_STREAM (parser) = p;
700*ef5ccd6cSJohn Marino 		  continue;
701*ef5ccd6cSJohn Marino 		}
702*ef5ccd6cSJohn Marino 	    }
703*ef5ccd6cSJohn Marino 	  /* Commas are terminators, but not if they are part of an
704*ef5ccd6cSJohn Marino 	     operator name.  */
705*ef5ccd6cSJohn Marino 	  else if (*PARSER_STREAM (parser) == ',')
706*ef5ccd6cSJohn Marino 	    {
707*ef5ccd6cSJohn Marino 	      if ((PARSER_STATE (parser)->language->la_language
708*ef5ccd6cSJohn Marino 		   == language_cplus)
709*ef5ccd6cSJohn Marino 		  && (PARSER_STREAM (parser) - start) > 8
710*ef5ccd6cSJohn Marino 		  /* strlen ("operator") */)
711*ef5ccd6cSJohn Marino 		{
712*ef5ccd6cSJohn Marino 		  char *p = strstr (start, "operator");
713*ef5ccd6cSJohn Marino 
714*ef5ccd6cSJohn Marino 		  if (p != NULL && is_operator_name (p))
715*ef5ccd6cSJohn Marino 		    {
716*ef5ccd6cSJohn Marino 		      /* This is an operator name.  Keep going.  */
717*ef5ccd6cSJohn Marino 		      ++(PARSER_STREAM (parser));
718*ef5ccd6cSJohn Marino 		      continue;
719*ef5ccd6cSJohn Marino 		    }
720*ef5ccd6cSJohn Marino 		}
721*ef5ccd6cSJohn Marino 
722*ef5ccd6cSJohn Marino 	      /* Comma terminates the string.  */
723*ef5ccd6cSJohn Marino 	      LS_TOKEN_STOKEN (token).ptr = start;
724*ef5ccd6cSJohn Marino 	      LS_TOKEN_STOKEN (token).length = PARSER_STREAM (parser) - start;
725*ef5ccd6cSJohn Marino 	      return token;
726*ef5ccd6cSJohn Marino 	    }
727*ef5ccd6cSJohn Marino 
728*ef5ccd6cSJohn Marino 	  /* Advance the stream.  */
729*ef5ccd6cSJohn Marino 	  ++(PARSER_STREAM (parser));
730*ef5ccd6cSJohn Marino 	}
731*ef5ccd6cSJohn Marino     }
732*ef5ccd6cSJohn Marino 
733*ef5ccd6cSJohn Marino   return token;
734*ef5ccd6cSJohn Marino }
735*ef5ccd6cSJohn Marino 
736*ef5ccd6cSJohn Marino /* Lex a single linespec token from PARSER.  */
737*ef5ccd6cSJohn Marino 
738*ef5ccd6cSJohn Marino static linespec_token
linespec_lexer_lex_one(linespec_parser * parser)739*ef5ccd6cSJohn Marino linespec_lexer_lex_one (linespec_parser *parser)
740*ef5ccd6cSJohn Marino {
741*ef5ccd6cSJohn Marino   const char *keyword;
742*ef5ccd6cSJohn Marino 
743*ef5ccd6cSJohn Marino   if (parser->lexer.current.type == LSTOKEN_CONSUMED)
744*ef5ccd6cSJohn Marino     {
745*ef5ccd6cSJohn Marino       /* Skip any whitespace.  */
746*ef5ccd6cSJohn Marino       PARSER_STREAM (parser) = skip_spaces (PARSER_STREAM (parser));
747*ef5ccd6cSJohn Marino 
748*ef5ccd6cSJohn Marino       /* Check for a keyword, they end the linespec.  */
749*ef5ccd6cSJohn Marino       keyword = NULL;
750*ef5ccd6cSJohn Marino       if (parser->keyword_ok)
751*ef5ccd6cSJohn Marino 	keyword = linespec_lexer_lex_keyword (PARSER_STREAM (parser));
752*ef5ccd6cSJohn Marino       if (keyword != NULL)
753*ef5ccd6cSJohn Marino 	{
754*ef5ccd6cSJohn Marino 	  parser->lexer.current.type = LSTOKEN_KEYWORD;
755*ef5ccd6cSJohn Marino 	  LS_TOKEN_KEYWORD (parser->lexer.current) = keyword;
756*ef5ccd6cSJohn Marino 	  return parser->lexer.current;
757*ef5ccd6cSJohn Marino 	}
758*ef5ccd6cSJohn Marino 
759*ef5ccd6cSJohn Marino       /* Handle other tokens.  */
760*ef5ccd6cSJohn Marino       switch (*PARSER_STREAM (parser))
761*ef5ccd6cSJohn Marino 	{
762*ef5ccd6cSJohn Marino 	case 0:
763*ef5ccd6cSJohn Marino 	  parser->lexer.current.type = LSTOKEN_EOI;
764*ef5ccd6cSJohn Marino 	  break;
765*ef5ccd6cSJohn Marino 
766*ef5ccd6cSJohn Marino 	case '+': case '-':
767*ef5ccd6cSJohn Marino 	case '0': case '1': case '2': case '3': case '4':
768*ef5ccd6cSJohn Marino         case '5': case '6': case '7': case '8': case '9':
769*ef5ccd6cSJohn Marino            if (!linespec_lexer_lex_number (parser, &(parser->lexer.current)))
770*ef5ccd6cSJohn Marino 	     parser->lexer.current = linespec_lexer_lex_string (parser);
771*ef5ccd6cSJohn Marino           break;
772*ef5ccd6cSJohn Marino 
773*ef5ccd6cSJohn Marino 	case ':':
774*ef5ccd6cSJohn Marino 	  /* If we have a scope operator, lex the input as a string.
775*ef5ccd6cSJohn Marino 	     Otherwise, return LSTOKEN_COLON.  */
776*ef5ccd6cSJohn Marino 	  if (PARSER_STREAM (parser)[1] == ':')
777*ef5ccd6cSJohn Marino 	    parser->lexer.current = linespec_lexer_lex_string (parser);
778*ef5ccd6cSJohn Marino 	  else
779*ef5ccd6cSJohn Marino 	    {
780*ef5ccd6cSJohn Marino 	      parser->lexer.current.type = LSTOKEN_COLON;
781*ef5ccd6cSJohn Marino 	      ++(PARSER_STREAM (parser));
782*ef5ccd6cSJohn Marino 	    }
783*ef5ccd6cSJohn Marino 	  break;
784*ef5ccd6cSJohn Marino 
785*ef5ccd6cSJohn Marino 	case '\'': case '\"':
786*ef5ccd6cSJohn Marino 	  /* Special case: permit quote-enclosed linespecs.  */
787*ef5ccd6cSJohn Marino 	  if (parser->is_quote_enclosed
788*ef5ccd6cSJohn Marino 	      && is_closing_quote_enclosed (PARSER_STREAM (parser)))
789*ef5ccd6cSJohn Marino 	    {
790*ef5ccd6cSJohn Marino 	      ++(PARSER_STREAM (parser));
791*ef5ccd6cSJohn Marino 	      parser->lexer.current.type = LSTOKEN_EOI;
792*ef5ccd6cSJohn Marino 	    }
793*ef5ccd6cSJohn Marino 	  else
794*ef5ccd6cSJohn Marino 	    parser->lexer.current = linespec_lexer_lex_string (parser);
795*ef5ccd6cSJohn Marino 	  break;
796*ef5ccd6cSJohn Marino 
797*ef5ccd6cSJohn Marino 	case ',':
798*ef5ccd6cSJohn Marino 	  parser->lexer.current.type = LSTOKEN_COMMA;
799*ef5ccd6cSJohn Marino 	  LS_TOKEN_STOKEN (parser->lexer.current).ptr
800*ef5ccd6cSJohn Marino 	    = PARSER_STREAM (parser);
801*ef5ccd6cSJohn Marino 	  LS_TOKEN_STOKEN (parser->lexer.current).length = 1;
802*ef5ccd6cSJohn Marino 	  ++(PARSER_STREAM (parser));
803*ef5ccd6cSJohn Marino 	  break;
804*ef5ccd6cSJohn Marino 
805*ef5ccd6cSJohn Marino 	default:
806*ef5ccd6cSJohn Marino 	  /* If the input is not a number, it must be a string.
807*ef5ccd6cSJohn Marino 	     [Keywords were already considered above.]  */
808*ef5ccd6cSJohn Marino 	  parser->lexer.current = linespec_lexer_lex_string (parser);
809*ef5ccd6cSJohn Marino 	  break;
810*ef5ccd6cSJohn Marino 	}
811*ef5ccd6cSJohn Marino     }
812*ef5ccd6cSJohn Marino 
813*ef5ccd6cSJohn Marino   return parser->lexer.current;
814*ef5ccd6cSJohn Marino }
815*ef5ccd6cSJohn Marino 
816*ef5ccd6cSJohn Marino /* Consume the current token and return the next token in PARSER's
817*ef5ccd6cSJohn Marino    input stream.  */
818*ef5ccd6cSJohn Marino 
819*ef5ccd6cSJohn Marino static linespec_token
linespec_lexer_consume_token(linespec_parser * parser)820*ef5ccd6cSJohn Marino linespec_lexer_consume_token (linespec_parser *parser)
821*ef5ccd6cSJohn Marino {
822*ef5ccd6cSJohn Marino   parser->lexer.current.type = LSTOKEN_CONSUMED;
823*ef5ccd6cSJohn Marino   return linespec_lexer_lex_one (parser);
824*ef5ccd6cSJohn Marino }
825*ef5ccd6cSJohn Marino 
826*ef5ccd6cSJohn Marino /* Return the next token without consuming the current token.  */
827*ef5ccd6cSJohn Marino 
828*ef5ccd6cSJohn Marino static linespec_token
linespec_lexer_peek_token(linespec_parser * parser)829*ef5ccd6cSJohn Marino linespec_lexer_peek_token (linespec_parser *parser)
830*ef5ccd6cSJohn Marino {
831*ef5ccd6cSJohn Marino   linespec_token next;
832*ef5ccd6cSJohn Marino   char *saved_stream = PARSER_STREAM (parser);
833*ef5ccd6cSJohn Marino   linespec_token saved_token = parser->lexer.current;
834*ef5ccd6cSJohn Marino 
835*ef5ccd6cSJohn Marino   next = linespec_lexer_consume_token (parser);
836*ef5ccd6cSJohn Marino   PARSER_STREAM (parser) = saved_stream;
837*ef5ccd6cSJohn Marino   parser->lexer.current = saved_token;
838*ef5ccd6cSJohn Marino   return next;
839*ef5ccd6cSJohn Marino }
840*ef5ccd6cSJohn Marino 
8415796c8dcSSimon Schubert /* Helper functions.  */
8425796c8dcSSimon Schubert 
843a45ae5f8SJohn Marino /* Add SAL to SALS.  */
844a45ae5f8SJohn Marino 
845a45ae5f8SJohn Marino static void
add_sal_to_sals_basic(struct symtabs_and_lines * sals,struct symtab_and_line * sal)846a45ae5f8SJohn Marino add_sal_to_sals_basic (struct symtabs_and_lines *sals,
847a45ae5f8SJohn Marino 		       struct symtab_and_line *sal)
848a45ae5f8SJohn Marino {
849a45ae5f8SJohn Marino   ++sals->nelts;
850a45ae5f8SJohn Marino   sals->sals = xrealloc (sals->sals, sals->nelts * sizeof (sals->sals[0]));
851a45ae5f8SJohn Marino   sals->sals[sals->nelts - 1] = *sal;
852a45ae5f8SJohn Marino }
853a45ae5f8SJohn Marino 
854a45ae5f8SJohn Marino /* Add SAL to SALS, and also update SELF->CANONICAL_NAMES to reflect
855a45ae5f8SJohn Marino    the new sal, if needed.  If not NULL, SYMNAME is the name of the
856*ef5ccd6cSJohn Marino    symbol to use when constructing the new canonical name.
857*ef5ccd6cSJohn Marino 
858*ef5ccd6cSJohn Marino    If LITERAL_CANONICAL is non-zero, SYMNAME will be used as the
859*ef5ccd6cSJohn Marino    canonical name for the SAL.  */
860a45ae5f8SJohn Marino 
861a45ae5f8SJohn Marino static void
add_sal_to_sals(struct linespec_state * self,struct symtabs_and_lines * sals,struct symtab_and_line * sal,const char * symname,int literal_canonical)862a45ae5f8SJohn Marino add_sal_to_sals (struct linespec_state *self,
863a45ae5f8SJohn Marino 		 struct symtabs_and_lines *sals,
864a45ae5f8SJohn Marino 		 struct symtab_and_line *sal,
865*ef5ccd6cSJohn Marino 		 const char *symname, int literal_canonical)
866a45ae5f8SJohn Marino {
867a45ae5f8SJohn Marino   add_sal_to_sals_basic (sals, sal);
868a45ae5f8SJohn Marino 
869a45ae5f8SJohn Marino   if (self->canonical)
870a45ae5f8SJohn Marino     {
871*ef5ccd6cSJohn Marino       struct linespec_canonical_name *canonical;
872a45ae5f8SJohn Marino 
873a45ae5f8SJohn Marino       self->canonical_names = xrealloc (self->canonical_names,
874*ef5ccd6cSJohn Marino 					(sals->nelts
875*ef5ccd6cSJohn Marino 					 * sizeof (*self->canonical_names)));
876*ef5ccd6cSJohn Marino       canonical = &self->canonical_names[sals->nelts - 1];
877*ef5ccd6cSJohn Marino       if (!literal_canonical && sal->symtab)
878a45ae5f8SJohn Marino 	{
879*ef5ccd6cSJohn Marino 	  const char *fullname = symtab_to_fullname (sal->symtab);
880a45ae5f8SJohn Marino 
881a45ae5f8SJohn Marino 	  /* Note that the filter doesn't have to be a valid linespec
882a45ae5f8SJohn Marino 	     input.  We only apply the ":LINE" treatment to Ada for
883a45ae5f8SJohn Marino 	     the time being.  */
884a45ae5f8SJohn Marino 	  if (symname != NULL && sal->line != 0
885*ef5ccd6cSJohn Marino 	      && self->language->la_language == language_ada)
886*ef5ccd6cSJohn Marino 	    canonical->suffix = xstrprintf ("%s:%d", symname, sal->line);
887a45ae5f8SJohn Marino 	  else if (symname != NULL)
888*ef5ccd6cSJohn Marino 	    canonical->suffix = xstrdup (symname);
889a45ae5f8SJohn Marino 	  else
890*ef5ccd6cSJohn Marino 	    canonical->suffix = xstrprintf ("%d", sal->line);
891*ef5ccd6cSJohn Marino 	  canonical->symtab = sal->symtab;
892a45ae5f8SJohn Marino 	}
893*ef5ccd6cSJohn Marino       else
894*ef5ccd6cSJohn Marino 	{
895*ef5ccd6cSJohn Marino 	  if (symname != NULL)
896*ef5ccd6cSJohn Marino 	    canonical->suffix = xstrdup (symname);
897*ef5ccd6cSJohn Marino 	  else
898*ef5ccd6cSJohn Marino 	    canonical->suffix = NULL;
899*ef5ccd6cSJohn Marino 	  canonical->symtab = NULL;
900*ef5ccd6cSJohn Marino 	}
901a45ae5f8SJohn Marino     }
902a45ae5f8SJohn Marino }
903a45ae5f8SJohn Marino 
904a45ae5f8SJohn Marino /* A hash function for address_entry.  */
905a45ae5f8SJohn Marino 
906a45ae5f8SJohn Marino static hashval_t
hash_address_entry(const void * p)907a45ae5f8SJohn Marino hash_address_entry (const void *p)
908a45ae5f8SJohn Marino {
909a45ae5f8SJohn Marino   const struct address_entry *aep = p;
910a45ae5f8SJohn Marino   hashval_t hash;
911a45ae5f8SJohn Marino 
912a45ae5f8SJohn Marino   hash = iterative_hash_object (aep->pspace, 0);
913a45ae5f8SJohn Marino   return iterative_hash_object (aep->addr, hash);
914a45ae5f8SJohn Marino }
915a45ae5f8SJohn Marino 
916a45ae5f8SJohn Marino /* An equality function for address_entry.  */
917a45ae5f8SJohn Marino 
918a45ae5f8SJohn Marino static int
eq_address_entry(const void * a,const void * b)919a45ae5f8SJohn Marino eq_address_entry (const void *a, const void *b)
920a45ae5f8SJohn Marino {
921a45ae5f8SJohn Marino   const struct address_entry *aea = a;
922a45ae5f8SJohn Marino   const struct address_entry *aeb = b;
923a45ae5f8SJohn Marino 
924a45ae5f8SJohn Marino   return aea->pspace == aeb->pspace && aea->addr == aeb->addr;
925a45ae5f8SJohn Marino }
926a45ae5f8SJohn Marino 
927a45ae5f8SJohn Marino /* Check whether the address, represented by PSPACE and ADDR, is
928a45ae5f8SJohn Marino    already in the set.  If so, return 0.  Otherwise, add it and return
929a45ae5f8SJohn Marino    1.  */
930a45ae5f8SJohn Marino 
931a45ae5f8SJohn Marino static int
maybe_add_address(htab_t set,struct program_space * pspace,CORE_ADDR addr)932a45ae5f8SJohn Marino maybe_add_address (htab_t set, struct program_space *pspace, CORE_ADDR addr)
933a45ae5f8SJohn Marino {
934a45ae5f8SJohn Marino   struct address_entry e, *p;
935a45ae5f8SJohn Marino   void **slot;
936a45ae5f8SJohn Marino 
937a45ae5f8SJohn Marino   e.pspace = pspace;
938a45ae5f8SJohn Marino   e.addr = addr;
939a45ae5f8SJohn Marino   slot = htab_find_slot (set, &e, INSERT);
940a45ae5f8SJohn Marino   if (*slot)
941a45ae5f8SJohn Marino     return 0;
942a45ae5f8SJohn Marino 
943a45ae5f8SJohn Marino   p = XNEW (struct address_entry);
944a45ae5f8SJohn Marino   memcpy (p, &e, sizeof (struct address_entry));
945a45ae5f8SJohn Marino   *slot = p;
946a45ae5f8SJohn Marino 
947a45ae5f8SJohn Marino   return 1;
948a45ae5f8SJohn Marino }
949a45ae5f8SJohn Marino 
950*ef5ccd6cSJohn Marino /* A callback function and the additional data to call it with.  */
9515796c8dcSSimon Schubert 
952*ef5ccd6cSJohn Marino struct symbol_and_data_callback
9535796c8dcSSimon Schubert {
954*ef5ccd6cSJohn Marino   /* The callback to use.  */
955*ef5ccd6cSJohn Marino   symbol_found_callback_ftype *callback;
956cf7f2e2dSJohn Marino 
957*ef5ccd6cSJohn Marino   /* Data to be passed to the callback.  */
958*ef5ccd6cSJohn Marino   void *data;
959*ef5ccd6cSJohn Marino };
9605796c8dcSSimon Schubert 
961*ef5ccd6cSJohn Marino /* A helper for iterate_over_all_matching_symtabs that is used to
962*ef5ccd6cSJohn Marino    restrict calls to another callback to symbols representing inline
963*ef5ccd6cSJohn Marino    symbols only.  */
964*ef5ccd6cSJohn Marino 
965*ef5ccd6cSJohn Marino static int
iterate_inline_only(struct symbol * sym,void * d)966*ef5ccd6cSJohn Marino iterate_inline_only (struct symbol *sym, void *d)
9675796c8dcSSimon Schubert {
968*ef5ccd6cSJohn Marino   if (SYMBOL_INLINED (sym))
969*ef5ccd6cSJohn Marino     {
970*ef5ccd6cSJohn Marino       struct symbol_and_data_callback *cad = d;
971cf7f2e2dSJohn Marino 
972*ef5ccd6cSJohn Marino       return cad->callback (sym, cad->data);
973*ef5ccd6cSJohn Marino     }
974*ef5ccd6cSJohn Marino   return 1; /* Continue iterating.  */
9755796c8dcSSimon Schubert }
9765796c8dcSSimon Schubert 
977*ef5ccd6cSJohn Marino /* Some data for the expand_symtabs_matching callback.  */
9785796c8dcSSimon Schubert 
979*ef5ccd6cSJohn Marino struct symbol_matcher_data
980*ef5ccd6cSJohn Marino {
981*ef5ccd6cSJohn Marino   /* The lookup name against which symbol name should be compared.  */
982*ef5ccd6cSJohn Marino   const char *lookup_name;
983*ef5ccd6cSJohn Marino 
984*ef5ccd6cSJohn Marino   /* The routine to be used for comparison.  */
985*ef5ccd6cSJohn Marino   symbol_name_cmp_ftype symbol_name_cmp;
986*ef5ccd6cSJohn Marino };
9875796c8dcSSimon Schubert 
988a45ae5f8SJohn Marino /* A helper for iterate_over_all_matching_symtabs that is passed as a
989a45ae5f8SJohn Marino    callback to the expand_symtabs_matching method.  */
9905796c8dcSSimon Schubert 
9915796c8dcSSimon Schubert static int
iterate_name_matcher(const char * name,void * d)992*ef5ccd6cSJohn Marino iterate_name_matcher (const char *name, void *d)
9935796c8dcSSimon Schubert {
994*ef5ccd6cSJohn Marino   const struct symbol_matcher_data *data = d;
9955796c8dcSSimon Schubert 
996*ef5ccd6cSJohn Marino   if (data->symbol_name_cmp (name, data->lookup_name) == 0)
997*ef5ccd6cSJohn Marino     return 1; /* Expand this symbol's symbol table.  */
998*ef5ccd6cSJohn Marino   return 0; /* Skip this symbol.  */
999a45ae5f8SJohn Marino }
10005796c8dcSSimon Schubert 
1001a45ae5f8SJohn Marino /* A helper that walks over all matching symtabs in all objfiles and
1002a45ae5f8SJohn Marino    calls CALLBACK for each symbol matching NAME.  If SEARCH_PSPACE is
1003a45ae5f8SJohn Marino    not NULL, then the search is restricted to just that program
1004*ef5ccd6cSJohn Marino    space.  If INCLUDE_INLINE is nonzero then symbols representing
1005*ef5ccd6cSJohn Marino    inlined instances of functions will be included in the result.  */
10065796c8dcSSimon Schubert 
1007a45ae5f8SJohn Marino static void
iterate_over_all_matching_symtabs(struct linespec_state * state,const char * name,const domain_enum domain,symbol_found_callback_ftype * callback,void * data,struct program_space * search_pspace,int include_inline)1008*ef5ccd6cSJohn Marino iterate_over_all_matching_symtabs (struct linespec_state *state,
1009*ef5ccd6cSJohn Marino 				   const char *name,
1010a45ae5f8SJohn Marino 				   const domain_enum domain,
1011*ef5ccd6cSJohn Marino 				   symbol_found_callback_ftype *callback,
1012a45ae5f8SJohn Marino 				   void *data,
1013*ef5ccd6cSJohn Marino 				   struct program_space *search_pspace,
1014*ef5ccd6cSJohn Marino 				   int include_inline)
1015a45ae5f8SJohn Marino {
1016a45ae5f8SJohn Marino   struct objfile *objfile;
1017a45ae5f8SJohn Marino   struct program_space *pspace;
1018*ef5ccd6cSJohn Marino   struct symbol_matcher_data matcher_data;
1019*ef5ccd6cSJohn Marino 
1020*ef5ccd6cSJohn Marino   matcher_data.lookup_name = name;
1021*ef5ccd6cSJohn Marino   matcher_data.symbol_name_cmp =
1022*ef5ccd6cSJohn Marino     state->language->la_get_symbol_name_cmp != NULL
1023*ef5ccd6cSJohn Marino     ? state->language->la_get_symbol_name_cmp (name)
1024*ef5ccd6cSJohn Marino     : strcmp_iw;
1025a45ae5f8SJohn Marino 
1026a45ae5f8SJohn Marino   ALL_PSPACES (pspace)
1027a45ae5f8SJohn Marino   {
1028a45ae5f8SJohn Marino     if (search_pspace != NULL && search_pspace != pspace)
1029a45ae5f8SJohn Marino       continue;
1030a45ae5f8SJohn Marino     if (pspace->executing_startup)
1031a45ae5f8SJohn Marino       continue;
1032a45ae5f8SJohn Marino 
1033a45ae5f8SJohn Marino     set_current_program_space (pspace);
1034a45ae5f8SJohn Marino 
1035a45ae5f8SJohn Marino     ALL_OBJFILES (objfile)
1036a45ae5f8SJohn Marino     {
1037a45ae5f8SJohn Marino       struct symtab *symtab;
1038a45ae5f8SJohn Marino 
1039a45ae5f8SJohn Marino       if (objfile->sf)
1040a45ae5f8SJohn Marino 	objfile->sf->qf->expand_symtabs_matching (objfile, NULL,
1041a45ae5f8SJohn Marino 						  iterate_name_matcher,
1042a45ae5f8SJohn Marino 						  ALL_DOMAIN,
1043*ef5ccd6cSJohn Marino 						  &matcher_data);
1044a45ae5f8SJohn Marino 
1045*ef5ccd6cSJohn Marino       ALL_OBJFILE_PRIMARY_SYMTABS (objfile, symtab)
1046a45ae5f8SJohn Marino 	{
1047*ef5ccd6cSJohn Marino 	  iterate_over_file_blocks (symtab, name, domain, callback, data);
1048*ef5ccd6cSJohn Marino 
1049*ef5ccd6cSJohn Marino 	  if (include_inline)
1050a45ae5f8SJohn Marino 	    {
1051*ef5ccd6cSJohn Marino 	      struct symbol_and_data_callback cad = { callback, data };
1052a45ae5f8SJohn Marino 	      struct block *block;
1053*ef5ccd6cSJohn Marino 	      int i;
1054a45ae5f8SJohn Marino 
1055*ef5ccd6cSJohn Marino 	      for (i = FIRST_LOCAL_BLOCK;
1056*ef5ccd6cSJohn Marino 		   i < BLOCKVECTOR_NBLOCKS (BLOCKVECTOR (symtab)); i++)
1057*ef5ccd6cSJohn Marino 		{
1058*ef5ccd6cSJohn Marino 		  block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), i);
1059*ef5ccd6cSJohn Marino 		  state->language->la_iterate_over_symbols
1060*ef5ccd6cSJohn Marino 		    (block, name, domain, iterate_inline_only, &cad);
1061*ef5ccd6cSJohn Marino 		}
1062a45ae5f8SJohn Marino 	    }
1063a45ae5f8SJohn Marino 	}
1064a45ae5f8SJohn Marino     }
1065a45ae5f8SJohn Marino   }
10665796c8dcSSimon Schubert }
10675796c8dcSSimon Schubert 
1068*ef5ccd6cSJohn Marino /* Returns the block to be used for symbol searches from
1069*ef5ccd6cSJohn Marino    the current location.  */
1070c50c785cSJohn Marino 
1071c50c785cSJohn Marino static struct block *
get_current_search_block(void)1072*ef5ccd6cSJohn Marino get_current_search_block (void)
1073c50c785cSJohn Marino {
1074c50c785cSJohn Marino   struct block *block;
1075c50c785cSJohn Marino   enum language save_language;
1076c50c785cSJohn Marino 
1077c50c785cSJohn Marino   /* get_selected_block can change the current language when there is
1078c50c785cSJohn Marino      no selected frame yet.  */
1079c50c785cSJohn Marino   save_language = current_language->la_language;
1080c50c785cSJohn Marino   block = get_selected_block (0);
1081c50c785cSJohn Marino   set_language (save_language);
1082c50c785cSJohn Marino 
1083c50c785cSJohn Marino   return block;
1084c50c785cSJohn Marino }
1085c50c785cSJohn Marino 
1086*ef5ccd6cSJohn Marino /* Iterate over static and global blocks.  */
1087*ef5ccd6cSJohn Marino 
1088*ef5ccd6cSJohn Marino static void
iterate_over_file_blocks(struct symtab * symtab,const char * name,domain_enum domain,symbol_found_callback_ftype * callback,void * data)1089*ef5ccd6cSJohn Marino iterate_over_file_blocks (struct symtab *symtab,
1090*ef5ccd6cSJohn Marino 			  const char *name, domain_enum domain,
1091*ef5ccd6cSJohn Marino 			  symbol_found_callback_ftype *callback, void *data)
1092*ef5ccd6cSJohn Marino {
1093*ef5ccd6cSJohn Marino   struct block *block;
1094*ef5ccd6cSJohn Marino 
1095*ef5ccd6cSJohn Marino   for (block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab), STATIC_BLOCK);
1096*ef5ccd6cSJohn Marino        block != NULL;
1097*ef5ccd6cSJohn Marino        block = BLOCK_SUPERBLOCK (block))
1098*ef5ccd6cSJohn Marino     LA_ITERATE_OVER_SYMBOLS (block, name, domain, callback, data);
1099*ef5ccd6cSJohn Marino }
1100*ef5ccd6cSJohn Marino 
1101a45ae5f8SJohn Marino /* A helper for find_method.  This finds all methods in type T which
1102*ef5ccd6cSJohn Marino    match NAME.  It adds matching symbol names to RESULT_NAMES, and
1103a45ae5f8SJohn Marino    adds T's direct superclasses to SUPERCLASSES.  */
11045796c8dcSSimon Schubert 
1105a45ae5f8SJohn Marino static void
find_methods(struct type * t,const char * name,VEC (const_char_ptr)** result_names,VEC (typep)** superclasses)1106a45ae5f8SJohn Marino find_methods (struct type *t, const char *name,
1107a45ae5f8SJohn Marino 	      VEC (const_char_ptr) **result_names,
1108a45ae5f8SJohn Marino 	      VEC (typep) **superclasses)
11095796c8dcSSimon Schubert {
11105796c8dcSSimon Schubert   int ibase;
1111*ef5ccd6cSJohn Marino   const char *class_name = type_name_no_tag (t);
1112c50c785cSJohn Marino 
11135796c8dcSSimon Schubert   /* Ignore this class if it doesn't have a name.  This is ugly, but
11145796c8dcSSimon Schubert      unless we figure out how to get the physname without the name of
11155796c8dcSSimon Schubert      the class, then the loop can't do any good.  */
1116a45ae5f8SJohn Marino   if (class_name)
11175796c8dcSSimon Schubert     {
11185796c8dcSSimon Schubert       int method_counter;
11195796c8dcSSimon Schubert 
11205796c8dcSSimon Schubert       CHECK_TYPEDEF (t);
11215796c8dcSSimon Schubert 
11225796c8dcSSimon Schubert       /* Loop over each method name.  At this level, all overloads of a name
11235796c8dcSSimon Schubert          are counted as a single name.  There is an inner loop which loops over
11245796c8dcSSimon Schubert          each overload.  */
11255796c8dcSSimon Schubert 
11265796c8dcSSimon Schubert       for (method_counter = TYPE_NFN_FIELDS (t) - 1;
11275796c8dcSSimon Schubert 	   method_counter >= 0;
11285796c8dcSSimon Schubert 	   --method_counter)
11295796c8dcSSimon Schubert 	{
1130*ef5ccd6cSJohn Marino 	  const char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
11315796c8dcSSimon Schubert 	  char dem_opname[64];
11325796c8dcSSimon Schubert 
11335796c8dcSSimon Schubert 	  if (strncmp (method_name, "__", 2) == 0 ||
11345796c8dcSSimon Schubert 	      strncmp (method_name, "op", 2) == 0 ||
11355796c8dcSSimon Schubert 	      strncmp (method_name, "type", 4) == 0)
11365796c8dcSSimon Schubert 	    {
11375796c8dcSSimon Schubert 	      if (cplus_demangle_opname (method_name, dem_opname, DMGL_ANSI))
11385796c8dcSSimon Schubert 		method_name = dem_opname;
11395796c8dcSSimon Schubert 	      else if (cplus_demangle_opname (method_name, dem_opname, 0))
11405796c8dcSSimon Schubert 		method_name = dem_opname;
11415796c8dcSSimon Schubert 	    }
11425796c8dcSSimon Schubert 
1143a45ae5f8SJohn Marino 	  if (strcmp_iw (method_name, name) == 0)
1144a45ae5f8SJohn Marino 	    {
1145a45ae5f8SJohn Marino 	      int field_counter;
1146a45ae5f8SJohn Marino 
1147a45ae5f8SJohn Marino 	      for (field_counter = (TYPE_FN_FIELDLIST_LENGTH (t, method_counter)
1148a45ae5f8SJohn Marino 				    - 1);
1149a45ae5f8SJohn Marino 		   field_counter >= 0;
1150a45ae5f8SJohn Marino 		   --field_counter)
1151a45ae5f8SJohn Marino 		{
1152a45ae5f8SJohn Marino 		  struct fn_field *f;
1153a45ae5f8SJohn Marino 		  const char *phys_name;
1154a45ae5f8SJohn Marino 
1155a45ae5f8SJohn Marino 		  f = TYPE_FN_FIELDLIST1 (t, method_counter);
1156a45ae5f8SJohn Marino 		  if (TYPE_FN_FIELD_STUB (f, field_counter))
1157a45ae5f8SJohn Marino 		    continue;
1158a45ae5f8SJohn Marino 		  phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
1159a45ae5f8SJohn Marino 		  VEC_safe_push (const_char_ptr, *result_names, phys_name);
1160a45ae5f8SJohn Marino 		}
1161a45ae5f8SJohn Marino 	    }
11625796c8dcSSimon Schubert 	}
11635796c8dcSSimon Schubert     }
11645796c8dcSSimon Schubert 
11655796c8dcSSimon Schubert   for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
1166a45ae5f8SJohn Marino     VEC_safe_push (typep, *superclasses, TYPE_BASECLASS (t, ibase));
11675796c8dcSSimon Schubert }
11685796c8dcSSimon Schubert 
11695796c8dcSSimon Schubert /* Find an instance of the character C in the string S that is outside
11705796c8dcSSimon Schubert    of all parenthesis pairs, single-quoted strings, and double-quoted
11715796c8dcSSimon Schubert    strings.  Also, ignore the char within a template name, like a ','
11725796c8dcSSimon Schubert    within foo<int, int>.  */
11735796c8dcSSimon Schubert 
1174*ef5ccd6cSJohn Marino static const char *
find_toplevel_char(const char * s,char c)1175*ef5ccd6cSJohn Marino find_toplevel_char (const char *s, char c)
11765796c8dcSSimon Schubert {
11775796c8dcSSimon Schubert   int quoted = 0;		/* zero if we're not in quotes;
11785796c8dcSSimon Schubert 				   '"' if we're in a double-quoted string;
11795796c8dcSSimon Schubert 				   '\'' if we're in a single-quoted string.  */
11805796c8dcSSimon Schubert   int depth = 0;		/* Number of unclosed parens we've seen.  */
1181*ef5ccd6cSJohn Marino   const char *scan;
11825796c8dcSSimon Schubert 
11835796c8dcSSimon Schubert   for (scan = s; *scan; scan++)
11845796c8dcSSimon Schubert     {
11855796c8dcSSimon Schubert       if (quoted)
11865796c8dcSSimon Schubert 	{
11875796c8dcSSimon Schubert 	  if (*scan == quoted)
11885796c8dcSSimon Schubert 	    quoted = 0;
11895796c8dcSSimon Schubert 	  else if (*scan == '\\' && *(scan + 1))
11905796c8dcSSimon Schubert 	    scan++;
11915796c8dcSSimon Schubert 	}
11925796c8dcSSimon Schubert       else if (*scan == c && ! quoted && depth == 0)
11935796c8dcSSimon Schubert 	return scan;
11945796c8dcSSimon Schubert       else if (*scan == '"' || *scan == '\'')
11955796c8dcSSimon Schubert 	quoted = *scan;
11965796c8dcSSimon Schubert       else if (*scan == '(' || *scan == '<')
11975796c8dcSSimon Schubert 	depth++;
11985796c8dcSSimon Schubert       else if ((*scan == ')' || *scan == '>') && depth > 0)
11995796c8dcSSimon Schubert 	depth--;
12005796c8dcSSimon Schubert     }
12015796c8dcSSimon Schubert 
12025796c8dcSSimon Schubert   return 0;
12035796c8dcSSimon Schubert }
12045796c8dcSSimon Schubert 
1205*ef5ccd6cSJohn Marino /* The string equivalent of find_toplevel_char.  Returns a pointer
1206*ef5ccd6cSJohn Marino    to the location of NEEDLE in HAYSTACK, ignoring any occurrences
1207*ef5ccd6cSJohn Marino    inside "()" and "<>".  Returns NULL if NEEDLE was not found.  */
12085796c8dcSSimon Schubert 
1209*ef5ccd6cSJohn Marino static const char *
find_toplevel_string(const char * haystack,const char * needle)1210*ef5ccd6cSJohn Marino find_toplevel_string (const char *haystack, const char *needle)
12115796c8dcSSimon Schubert {
1212*ef5ccd6cSJohn Marino   const char *s = haystack;
1213*ef5ccd6cSJohn Marino 
1214*ef5ccd6cSJohn Marino   do
1215*ef5ccd6cSJohn Marino     {
1216*ef5ccd6cSJohn Marino       s = find_toplevel_char (s, *needle);
1217*ef5ccd6cSJohn Marino 
1218*ef5ccd6cSJohn Marino       if (s != NULL)
1219*ef5ccd6cSJohn Marino 	{
1220*ef5ccd6cSJohn Marino 	  /* Found first char in HAYSTACK;  check rest of string.  */
1221*ef5ccd6cSJohn Marino 	  if (strncmp (s, needle, strlen (needle)) == 0)
1222*ef5ccd6cSJohn Marino 	    return s;
1223*ef5ccd6cSJohn Marino 
1224*ef5ccd6cSJohn Marino 	  /* Didn't find it; loop over HAYSTACK, looking for the next
1225*ef5ccd6cSJohn Marino 	     instance of the first character of NEEDLE.  */
1226*ef5ccd6cSJohn Marino 	  ++s;
1227*ef5ccd6cSJohn Marino 	}
1228*ef5ccd6cSJohn Marino     }
1229*ef5ccd6cSJohn Marino   while (s != NULL && *s != '\0');
1230*ef5ccd6cSJohn Marino 
1231*ef5ccd6cSJohn Marino   /* NEEDLE was not found in HAYSTACK.  */
1232*ef5ccd6cSJohn Marino   return NULL;
1233*ef5ccd6cSJohn Marino }
1234*ef5ccd6cSJohn Marino 
1235*ef5ccd6cSJohn Marino /* Convert CANONICAL to its string representation using
1236*ef5ccd6cSJohn Marino    symtab_to_fullname for SYMTAB.  The caller must xfree the result.  */
1237*ef5ccd6cSJohn Marino 
1238*ef5ccd6cSJohn Marino static char *
canonical_to_fullform(const struct linespec_canonical_name * canonical)1239*ef5ccd6cSJohn Marino canonical_to_fullform (const struct linespec_canonical_name *canonical)
1240*ef5ccd6cSJohn Marino {
1241*ef5ccd6cSJohn Marino   if (canonical->symtab == NULL)
1242*ef5ccd6cSJohn Marino     return xstrdup (canonical->suffix);
1243*ef5ccd6cSJohn Marino   else
1244*ef5ccd6cSJohn Marino     return xstrprintf ("%s:%s", symtab_to_fullname (canonical->symtab),
1245*ef5ccd6cSJohn Marino 		       canonical->suffix);
12465796c8dcSSimon Schubert }
12475796c8dcSSimon Schubert 
1248a45ae5f8SJohn Marino /* Given FILTERS, a list of canonical names, filter the sals in RESULT
1249a45ae5f8SJohn Marino    and store the result in SELF->CANONICAL.  */
12505796c8dcSSimon Schubert 
1251a45ae5f8SJohn Marino static void
filter_results(struct linespec_state * self,struct symtabs_and_lines * result,VEC (const_char_ptr)* filters)1252a45ae5f8SJohn Marino filter_results (struct linespec_state *self,
1253a45ae5f8SJohn Marino 		struct symtabs_and_lines *result,
1254a45ae5f8SJohn Marino 		VEC (const_char_ptr) *filters)
12555796c8dcSSimon Schubert {
12565796c8dcSSimon Schubert   int i;
1257a45ae5f8SJohn Marino   const char *name;
12585796c8dcSSimon Schubert 
1259a45ae5f8SJohn Marino   for (i = 0; VEC_iterate (const_char_ptr, filters, i, name); ++i)
1260a45ae5f8SJohn Marino     {
1261a45ae5f8SJohn Marino       struct linespec_sals lsal;
1262a45ae5f8SJohn Marino       int j;
1263a45ae5f8SJohn Marino 
1264a45ae5f8SJohn Marino       memset (&lsal, 0, sizeof (lsal));
1265a45ae5f8SJohn Marino 
1266a45ae5f8SJohn Marino       for (j = 0; j < result->nelts; ++j)
1267a45ae5f8SJohn Marino 	{
1268*ef5ccd6cSJohn Marino 	  const struct linespec_canonical_name *canonical;
1269*ef5ccd6cSJohn Marino 	  char *fullform;
1270*ef5ccd6cSJohn Marino 	  struct cleanup *cleanup;
1271*ef5ccd6cSJohn Marino 
1272*ef5ccd6cSJohn Marino 	  canonical = &self->canonical_names[j];
1273*ef5ccd6cSJohn Marino 	  fullform = canonical_to_fullform (canonical);
1274*ef5ccd6cSJohn Marino 	  cleanup = make_cleanup (xfree, fullform);
1275*ef5ccd6cSJohn Marino 
1276*ef5ccd6cSJohn Marino 	  if (strcmp (name, fullform) == 0)
1277a45ae5f8SJohn Marino 	    add_sal_to_sals_basic (&lsal.sals, &result->sals[j]);
1278*ef5ccd6cSJohn Marino 
1279*ef5ccd6cSJohn Marino 	  do_cleanups (cleanup);
1280a45ae5f8SJohn Marino 	}
1281a45ae5f8SJohn Marino 
1282a45ae5f8SJohn Marino       if (lsal.sals.nelts > 0)
1283a45ae5f8SJohn Marino 	{
1284a45ae5f8SJohn Marino 	  lsal.canonical = xstrdup (name);
1285a45ae5f8SJohn Marino 	  VEC_safe_push (linespec_sals, self->canonical->sals, &lsal);
1286a45ae5f8SJohn Marino 	}
1287a45ae5f8SJohn Marino     }
1288a45ae5f8SJohn Marino 
1289a45ae5f8SJohn Marino   self->canonical->pre_expanded = 0;
1290a45ae5f8SJohn Marino }
1291a45ae5f8SJohn Marino 
1292a45ae5f8SJohn Marino /* Store RESULT into SELF->CANONICAL.  */
1293a45ae5f8SJohn Marino 
1294a45ae5f8SJohn Marino static void
convert_results_to_lsals(struct linespec_state * self,struct symtabs_and_lines * result)1295a45ae5f8SJohn Marino convert_results_to_lsals (struct linespec_state *self,
1296a45ae5f8SJohn Marino 			  struct symtabs_and_lines *result)
1297a45ae5f8SJohn Marino {
1298a45ae5f8SJohn Marino   struct linespec_sals lsal;
1299a45ae5f8SJohn Marino 
1300a45ae5f8SJohn Marino   lsal.canonical = NULL;
1301a45ae5f8SJohn Marino   lsal.sals = *result;
1302a45ae5f8SJohn Marino   VEC_safe_push (linespec_sals, self->canonical->sals, &lsal);
1303a45ae5f8SJohn Marino }
1304a45ae5f8SJohn Marino 
1305*ef5ccd6cSJohn Marino /* A structure that contains two string representations of a struct
1306*ef5ccd6cSJohn Marino    linespec_canonical_name:
1307*ef5ccd6cSJohn Marino      - one where the the symtab's fullname is used;
1308*ef5ccd6cSJohn Marino      - one where the filename followed the "set filename-display"
1309*ef5ccd6cSJohn Marino        setting.  */
1310*ef5ccd6cSJohn Marino 
1311*ef5ccd6cSJohn Marino struct decode_line_2_item
1312*ef5ccd6cSJohn Marino {
1313*ef5ccd6cSJohn Marino   /* The form using symtab_to_fullname.
1314*ef5ccd6cSJohn Marino      It must be xfree'ed after use.  */
1315*ef5ccd6cSJohn Marino   char *fullform;
1316*ef5ccd6cSJohn Marino 
1317*ef5ccd6cSJohn Marino   /* The form using symtab_to_filename_for_display.
1318*ef5ccd6cSJohn Marino      It must be xfree'ed after use.  */
1319*ef5ccd6cSJohn Marino   char *displayform;
1320*ef5ccd6cSJohn Marino 
1321*ef5ccd6cSJohn Marino   /* Field is initialized to zero and it is set to one if the user
1322*ef5ccd6cSJohn Marino      requested breakpoint for this entry.  */
1323*ef5ccd6cSJohn Marino   unsigned int selected : 1;
1324*ef5ccd6cSJohn Marino };
1325*ef5ccd6cSJohn Marino 
1326*ef5ccd6cSJohn Marino /* Helper for qsort to sort decode_line_2_item entries by DISPLAYFORM and
1327*ef5ccd6cSJohn Marino    secondarily by FULLFORM.  */
1328*ef5ccd6cSJohn Marino 
1329*ef5ccd6cSJohn Marino static int
decode_line_2_compare_items(const void * ap,const void * bp)1330*ef5ccd6cSJohn Marino decode_line_2_compare_items (const void *ap, const void *bp)
1331*ef5ccd6cSJohn Marino {
1332*ef5ccd6cSJohn Marino   const struct decode_line_2_item *a = ap;
1333*ef5ccd6cSJohn Marino   const struct decode_line_2_item *b = bp;
1334*ef5ccd6cSJohn Marino   int retval;
1335*ef5ccd6cSJohn Marino 
1336*ef5ccd6cSJohn Marino   retval = strcmp (a->displayform, b->displayform);
1337*ef5ccd6cSJohn Marino   if (retval != 0)
1338*ef5ccd6cSJohn Marino     return retval;
1339*ef5ccd6cSJohn Marino 
1340*ef5ccd6cSJohn Marino   return strcmp (a->fullform, b->fullform);
1341*ef5ccd6cSJohn Marino }
1342*ef5ccd6cSJohn Marino 
1343a45ae5f8SJohn Marino /* Handle multiple results in RESULT depending on SELECT_MODE.  This
1344a45ae5f8SJohn Marino    will either return normally, throw an exception on multiple
1345a45ae5f8SJohn Marino    results, or present a menu to the user.  On return, the SALS vector
1346a45ae5f8SJohn Marino    in SELF->CANONICAL is set up properly.  */
1347a45ae5f8SJohn Marino 
1348a45ae5f8SJohn Marino static void
decode_line_2(struct linespec_state * self,struct symtabs_and_lines * result,const char * select_mode)1349a45ae5f8SJohn Marino decode_line_2 (struct linespec_state *self,
1350a45ae5f8SJohn Marino 	       struct symtabs_and_lines *result,
1351a45ae5f8SJohn Marino 	       const char *select_mode)
1352a45ae5f8SJohn Marino {
1353a45ae5f8SJohn Marino   char *args, *prompt;
1354a45ae5f8SJohn Marino   int i;
1355a45ae5f8SJohn Marino   struct cleanup *old_chain;
1356*ef5ccd6cSJohn Marino   VEC (const_char_ptr) *filters = NULL;
1357a45ae5f8SJohn Marino   struct get_number_or_range_state state;
1358*ef5ccd6cSJohn Marino   struct decode_line_2_item *items;
1359*ef5ccd6cSJohn Marino   int items_count;
1360a45ae5f8SJohn Marino 
1361a45ae5f8SJohn Marino   gdb_assert (select_mode != multiple_symbols_all);
1362a45ae5f8SJohn Marino   gdb_assert (self->canonical != NULL);
1363*ef5ccd6cSJohn Marino   gdb_assert (result->nelts >= 1);
1364a45ae5f8SJohn Marino 
1365*ef5ccd6cSJohn Marino   old_chain = make_cleanup (VEC_cleanup (const_char_ptr), &filters);
1366a45ae5f8SJohn Marino 
1367*ef5ccd6cSJohn Marino   /* Prepare ITEMS array.  */
1368*ef5ccd6cSJohn Marino   items_count = result->nelts;
1369*ef5ccd6cSJohn Marino   items = xmalloc (sizeof (*items) * items_count);
1370*ef5ccd6cSJohn Marino   make_cleanup (xfree, items);
1371*ef5ccd6cSJohn Marino   for (i = 0; i < items_count; ++i)
1372a45ae5f8SJohn Marino     {
1373*ef5ccd6cSJohn Marino       const struct linespec_canonical_name *canonical;
1374*ef5ccd6cSJohn Marino       struct decode_line_2_item *item;
1375*ef5ccd6cSJohn Marino 
1376*ef5ccd6cSJohn Marino       canonical = &self->canonical_names[i];
1377*ef5ccd6cSJohn Marino       gdb_assert (canonical->suffix != NULL);
1378*ef5ccd6cSJohn Marino       item = &items[i];
1379*ef5ccd6cSJohn Marino 
1380*ef5ccd6cSJohn Marino       item->fullform = canonical_to_fullform (canonical);
1381*ef5ccd6cSJohn Marino       make_cleanup (xfree, item->fullform);
1382*ef5ccd6cSJohn Marino 
1383*ef5ccd6cSJohn Marino       if (canonical->symtab == NULL)
1384*ef5ccd6cSJohn Marino 	item->displayform = canonical->suffix;
1385*ef5ccd6cSJohn Marino       else
1386a45ae5f8SJohn Marino 	{
1387*ef5ccd6cSJohn Marino 	  const char *fn_for_display;
1388*ef5ccd6cSJohn Marino 
1389*ef5ccd6cSJohn Marino 	  fn_for_display = symtab_to_filename_for_display (canonical->symtab);
1390*ef5ccd6cSJohn Marino 	  item->displayform = xstrprintf ("%s:%s", fn_for_display,
1391*ef5ccd6cSJohn Marino 					  canonical->suffix);
1392*ef5ccd6cSJohn Marino 	  make_cleanup (xfree, item->displayform);
1393a45ae5f8SJohn Marino 	}
1394a45ae5f8SJohn Marino 
1395*ef5ccd6cSJohn Marino       item->selected = 0;
1396a45ae5f8SJohn Marino     }
1397a45ae5f8SJohn Marino 
1398*ef5ccd6cSJohn Marino   /* Sort the list of method names.  */
1399*ef5ccd6cSJohn Marino   qsort (items, items_count, sizeof (*items), decode_line_2_compare_items);
1400*ef5ccd6cSJohn Marino 
1401*ef5ccd6cSJohn Marino   /* Remove entries with the same FULLFORM.  */
1402*ef5ccd6cSJohn Marino   if (items_count >= 2)
1403*ef5ccd6cSJohn Marino     {
1404*ef5ccd6cSJohn Marino       struct decode_line_2_item *dst, *src;
1405*ef5ccd6cSJohn Marino 
1406*ef5ccd6cSJohn Marino       dst = items;
1407*ef5ccd6cSJohn Marino       for (src = &items[1]; src < &items[items_count]; src++)
1408*ef5ccd6cSJohn Marino 	if (strcmp (src->fullform, dst->fullform) != 0)
1409*ef5ccd6cSJohn Marino 	  *++dst = *src;
1410*ef5ccd6cSJohn Marino       items_count = dst + 1 - items;
1411*ef5ccd6cSJohn Marino     }
1412*ef5ccd6cSJohn Marino 
1413*ef5ccd6cSJohn Marino   if (select_mode == multiple_symbols_cancel && items_count > 1)
1414c50c785cSJohn Marino     error (_("canceled because the command is ambiguous\n"
1415c50c785cSJohn Marino 	     "See set/show multiple-symbol."));
14165796c8dcSSimon Schubert 
1417*ef5ccd6cSJohn Marino   if (select_mode == multiple_symbols_all || items_count == 1)
14185796c8dcSSimon Schubert     {
1419a45ae5f8SJohn Marino       do_cleanups (old_chain);
1420a45ae5f8SJohn Marino       convert_results_to_lsals (self, result);
1421a45ae5f8SJohn Marino       return;
1422a45ae5f8SJohn Marino     }
14235796c8dcSSimon Schubert 
1424a45ae5f8SJohn Marino   printf_unfiltered (_("[0] cancel\n[1] all\n"));
1425*ef5ccd6cSJohn Marino   for (i = 0; i < items_count; i++)
1426*ef5ccd6cSJohn Marino     printf_unfiltered ("[%d] %s\n", i + 2, items[i].displayform);
14275796c8dcSSimon Schubert 
14285796c8dcSSimon Schubert   prompt = getenv ("PS2");
14295796c8dcSSimon Schubert   if (prompt == NULL)
14305796c8dcSSimon Schubert     {
14315796c8dcSSimon Schubert       prompt = "> ";
14325796c8dcSSimon Schubert     }
14335796c8dcSSimon Schubert   args = command_line_input (prompt, 0, "overload-choice");
14345796c8dcSSimon Schubert 
14355796c8dcSSimon Schubert   if (args == 0 || *args == 0)
14365796c8dcSSimon Schubert     error_no_arg (_("one or more choice numbers"));
14375796c8dcSSimon Schubert 
1438a45ae5f8SJohn Marino   init_number_or_range (&state, args);
1439a45ae5f8SJohn Marino   while (!state.finished)
14405796c8dcSSimon Schubert     {
14415796c8dcSSimon Schubert       int num;
14425796c8dcSSimon Schubert 
1443a45ae5f8SJohn Marino       num = get_number_or_range (&state);
14445796c8dcSSimon Schubert 
14455796c8dcSSimon Schubert       if (num == 0)
14465796c8dcSSimon Schubert 	error (_("canceled"));
14475796c8dcSSimon Schubert       else if (num == 1)
14485796c8dcSSimon Schubert 	{
1449a45ae5f8SJohn Marino 	  /* We intentionally make this result in a single breakpoint,
1450a45ae5f8SJohn Marino 	     contrary to what older versions of gdb did.  The
1451a45ae5f8SJohn Marino 	     rationale is that this lets a user get the
1452a45ae5f8SJohn Marino 	     multiple_symbols_all behavior even with the 'ask'
1453a45ae5f8SJohn Marino 	     setting; and he can get separate breakpoints by entering
1454a45ae5f8SJohn Marino 	     "2-57" at the query.  */
1455a45ae5f8SJohn Marino 	  do_cleanups (old_chain);
1456a45ae5f8SJohn Marino 	  convert_results_to_lsals (self, result);
1457a45ae5f8SJohn Marino 	  return;
14585796c8dcSSimon Schubert 	}
14595796c8dcSSimon Schubert 
1460a45ae5f8SJohn Marino       num -= 2;
1461*ef5ccd6cSJohn Marino       if (num >= items_count)
14625796c8dcSSimon Schubert 	printf_unfiltered (_("No choice number %d.\n"), num);
14635796c8dcSSimon Schubert       else
14645796c8dcSSimon Schubert 	{
1465*ef5ccd6cSJohn Marino 	  struct decode_line_2_item *item = &items[num];
1466a45ae5f8SJohn Marino 
1467*ef5ccd6cSJohn Marino 	  if (!item->selected)
14685796c8dcSSimon Schubert 	    {
1469*ef5ccd6cSJohn Marino 	      VEC_safe_push (const_char_ptr, filters, item->fullform);
1470*ef5ccd6cSJohn Marino 	      item->selected = 1;
14715796c8dcSSimon Schubert 	    }
14725796c8dcSSimon Schubert 	  else
14735796c8dcSSimon Schubert 	    {
1474c50c785cSJohn Marino 	      printf_unfiltered (_("duplicate request for %d ignored.\n"),
1475*ef5ccd6cSJohn Marino 				 num + 2);
14765796c8dcSSimon Schubert 	    }
14775796c8dcSSimon Schubert 	}
14785796c8dcSSimon Schubert     }
1479a45ae5f8SJohn Marino 
1480a45ae5f8SJohn Marino   filter_results (self, result, filters);
1481a45ae5f8SJohn Marino   do_cleanups (old_chain);
14825796c8dcSSimon Schubert }
1483cf7f2e2dSJohn Marino 
14845796c8dcSSimon Schubert 
1485*ef5ccd6cSJohn Marino 
14865796c8dcSSimon Schubert /* The parser of linespec itself.  */
14875796c8dcSSimon Schubert 
1488*ef5ccd6cSJohn Marino /* Throw an appropriate error when SYMBOL is not found (optionally in
1489*ef5ccd6cSJohn Marino    FILENAME).  */
1490*ef5ccd6cSJohn Marino 
1491*ef5ccd6cSJohn Marino static void ATTRIBUTE_NORETURN
symbol_not_found_error(const char * symbol,const char * filename)1492*ef5ccd6cSJohn Marino symbol_not_found_error (const char *symbol, const char *filename)
1493*ef5ccd6cSJohn Marino {
1494*ef5ccd6cSJohn Marino   if (symbol == NULL)
1495*ef5ccd6cSJohn Marino     symbol = "";
1496*ef5ccd6cSJohn Marino 
1497*ef5ccd6cSJohn Marino   if (!have_full_symbols ()
1498*ef5ccd6cSJohn Marino       && !have_partial_symbols ()
1499*ef5ccd6cSJohn Marino       && !have_minimal_symbols ())
1500*ef5ccd6cSJohn Marino     throw_error (NOT_FOUND_ERROR,
1501*ef5ccd6cSJohn Marino 		 _("No symbol table is loaded.  Use the \"file\" command."));
1502*ef5ccd6cSJohn Marino 
1503*ef5ccd6cSJohn Marino   /* If SYMBOL starts with '$', the user attempted to either lookup
1504*ef5ccd6cSJohn Marino      a function/variable in his code starting with '$' or an internal
1505*ef5ccd6cSJohn Marino      variable of that name.  Since we do not know which, be concise and
1506*ef5ccd6cSJohn Marino      explain both possibilities.  */
1507*ef5ccd6cSJohn Marino   if (*symbol == '$')
1508*ef5ccd6cSJohn Marino     {
1509*ef5ccd6cSJohn Marino       if (filename)
1510*ef5ccd6cSJohn Marino 	throw_error (NOT_FOUND_ERROR,
1511*ef5ccd6cSJohn Marino 		     _("Undefined convenience variable or function \"%s\" "
1512*ef5ccd6cSJohn Marino 		       "not defined in \"%s\"."), symbol, filename);
1513*ef5ccd6cSJohn Marino       else
1514*ef5ccd6cSJohn Marino 	throw_error (NOT_FOUND_ERROR,
1515*ef5ccd6cSJohn Marino 		     _("Undefined convenience variable or function \"%s\" "
1516*ef5ccd6cSJohn Marino 		       "not defined."), symbol);
1517*ef5ccd6cSJohn Marino     }
1518*ef5ccd6cSJohn Marino   else
1519*ef5ccd6cSJohn Marino     {
1520*ef5ccd6cSJohn Marino       if (filename)
1521*ef5ccd6cSJohn Marino 	throw_error (NOT_FOUND_ERROR,
1522*ef5ccd6cSJohn Marino 		     _("Function \"%s\" not defined in \"%s\"."),
1523*ef5ccd6cSJohn Marino 		     symbol, filename);
1524*ef5ccd6cSJohn Marino       else
1525*ef5ccd6cSJohn Marino 	throw_error (NOT_FOUND_ERROR,
1526*ef5ccd6cSJohn Marino 		     _("Function \"%s\" not defined."), symbol);
1527*ef5ccd6cSJohn Marino     }
1528*ef5ccd6cSJohn Marino }
1529*ef5ccd6cSJohn Marino 
1530*ef5ccd6cSJohn Marino /* Throw an appropriate error when an unexpected token is encountered
1531*ef5ccd6cSJohn Marino    in the input.  */
1532*ef5ccd6cSJohn Marino 
1533*ef5ccd6cSJohn Marino static void ATTRIBUTE_NORETURN
unexpected_linespec_error(linespec_parser * parser)1534*ef5ccd6cSJohn Marino unexpected_linespec_error (linespec_parser *parser)
1535*ef5ccd6cSJohn Marino {
1536*ef5ccd6cSJohn Marino   linespec_token token;
1537*ef5ccd6cSJohn Marino   static const char * token_type_strings[]
1538*ef5ccd6cSJohn Marino     = {"keyword", "colon", "string", "number", "comma", "end of input"};
1539*ef5ccd6cSJohn Marino 
1540*ef5ccd6cSJohn Marino   /* Get the token that generated the error.  */
1541*ef5ccd6cSJohn Marino   token = linespec_lexer_lex_one (parser);
1542*ef5ccd6cSJohn Marino 
1543*ef5ccd6cSJohn Marino   /* Finally, throw the error.  */
1544*ef5ccd6cSJohn Marino   if (token.type == LSTOKEN_STRING || token.type == LSTOKEN_NUMBER
1545*ef5ccd6cSJohn Marino       || token.type == LSTOKEN_KEYWORD)
1546*ef5ccd6cSJohn Marino     {
1547*ef5ccd6cSJohn Marino       char *string;
1548*ef5ccd6cSJohn Marino       struct cleanup *cleanup;
1549*ef5ccd6cSJohn Marino 
1550*ef5ccd6cSJohn Marino       string = copy_token_string (token);
1551*ef5ccd6cSJohn Marino       cleanup = make_cleanup (xfree, string);
1552*ef5ccd6cSJohn Marino       throw_error (GENERIC_ERROR,
1553*ef5ccd6cSJohn Marino 		   _("malformed linespec error: unexpected %s, \"%s\""),
1554*ef5ccd6cSJohn Marino 		   token_type_strings[token.type], string);
1555*ef5ccd6cSJohn Marino     }
1556*ef5ccd6cSJohn Marino   else
1557*ef5ccd6cSJohn Marino     throw_error (GENERIC_ERROR,
1558*ef5ccd6cSJohn Marino 		 _("malformed linespec error: unexpected %s"),
1559*ef5ccd6cSJohn Marino 		 token_type_strings[token.type]);
1560*ef5ccd6cSJohn Marino }
1561*ef5ccd6cSJohn Marino 
1562*ef5ccd6cSJohn Marino /* Parse and return a line offset in STRING.  */
1563*ef5ccd6cSJohn Marino 
1564*ef5ccd6cSJohn Marino static struct line_offset
linespec_parse_line_offset(const char * string)1565*ef5ccd6cSJohn Marino linespec_parse_line_offset (const char *string)
1566*ef5ccd6cSJohn Marino {
1567*ef5ccd6cSJohn Marino   struct line_offset line_offset = {0, LINE_OFFSET_NONE};
1568*ef5ccd6cSJohn Marino 
1569*ef5ccd6cSJohn Marino   if (*string == '+')
1570*ef5ccd6cSJohn Marino     {
1571*ef5ccd6cSJohn Marino       line_offset.sign = LINE_OFFSET_PLUS;
1572*ef5ccd6cSJohn Marino       ++string;
1573*ef5ccd6cSJohn Marino     }
1574*ef5ccd6cSJohn Marino   else if (*string == '-')
1575*ef5ccd6cSJohn Marino     {
1576*ef5ccd6cSJohn Marino       line_offset.sign = LINE_OFFSET_MINUS;
1577*ef5ccd6cSJohn Marino       ++string;
1578*ef5ccd6cSJohn Marino     }
1579*ef5ccd6cSJohn Marino 
1580*ef5ccd6cSJohn Marino   /* Right now, we only allow base 10 for offsets.  */
1581*ef5ccd6cSJohn Marino   line_offset.offset = atoi (string);
1582*ef5ccd6cSJohn Marino   return line_offset;
1583*ef5ccd6cSJohn Marino }
1584*ef5ccd6cSJohn Marino 
1585*ef5ccd6cSJohn Marino /* Parse the basic_spec in PARSER's input.  */
1586*ef5ccd6cSJohn Marino 
1587*ef5ccd6cSJohn Marino static void
linespec_parse_basic(linespec_parser * parser)1588*ef5ccd6cSJohn Marino linespec_parse_basic (linespec_parser *parser)
1589*ef5ccd6cSJohn Marino {
1590*ef5ccd6cSJohn Marino   char *name;
1591*ef5ccd6cSJohn Marino   linespec_token token;
1592*ef5ccd6cSJohn Marino   VEC (symbolp) *symbols, *labels;
1593*ef5ccd6cSJohn Marino   VEC (minsym_and_objfile_d) *minimal_symbols;
1594*ef5ccd6cSJohn Marino   struct cleanup *cleanup;
1595*ef5ccd6cSJohn Marino 
1596*ef5ccd6cSJohn Marino   /* Get the next token.  */
1597*ef5ccd6cSJohn Marino   token = linespec_lexer_lex_one (parser);
1598*ef5ccd6cSJohn Marino 
1599*ef5ccd6cSJohn Marino   /* If it is EOI or KEYWORD, issue an error.  */
1600*ef5ccd6cSJohn Marino   if (token.type == LSTOKEN_KEYWORD || token.type == LSTOKEN_EOI)
1601*ef5ccd6cSJohn Marino     unexpected_linespec_error (parser);
1602*ef5ccd6cSJohn Marino   /* If it is a LSTOKEN_NUMBER, we have an offset.  */
1603*ef5ccd6cSJohn Marino   else if (token.type == LSTOKEN_NUMBER)
1604*ef5ccd6cSJohn Marino     {
1605*ef5ccd6cSJohn Marino       /* Record the line offset and get the next token.  */
1606*ef5ccd6cSJohn Marino       name = copy_token_string (token);
1607*ef5ccd6cSJohn Marino       cleanup = make_cleanup (xfree, name);
1608*ef5ccd6cSJohn Marino       PARSER_RESULT (parser)->line_offset = linespec_parse_line_offset (name);
1609*ef5ccd6cSJohn Marino       do_cleanups (cleanup);
1610*ef5ccd6cSJohn Marino 
1611*ef5ccd6cSJohn Marino       /* Get the next token.  */
1612*ef5ccd6cSJohn Marino       token = linespec_lexer_consume_token (parser);
1613*ef5ccd6cSJohn Marino 
1614*ef5ccd6cSJohn Marino       /* If the next token is a comma, stop parsing and return.  */
1615*ef5ccd6cSJohn Marino       if (token.type == LSTOKEN_COMMA)
1616*ef5ccd6cSJohn Marino 	return;
1617*ef5ccd6cSJohn Marino 
1618*ef5ccd6cSJohn Marino       /* If the next token is anything but EOI or KEYWORD, issue
1619*ef5ccd6cSJohn Marino 	 an error.  */
1620*ef5ccd6cSJohn Marino       if (token.type != LSTOKEN_KEYWORD && token.type != LSTOKEN_EOI)
1621*ef5ccd6cSJohn Marino 	unexpected_linespec_error (parser);
1622*ef5ccd6cSJohn Marino     }
1623*ef5ccd6cSJohn Marino 
1624*ef5ccd6cSJohn Marino   if (token.type == LSTOKEN_KEYWORD || token.type == LSTOKEN_EOI)
1625*ef5ccd6cSJohn Marino     return;
1626*ef5ccd6cSJohn Marino 
1627*ef5ccd6cSJohn Marino   /* Next token must be LSTOKEN_STRING.  */
1628*ef5ccd6cSJohn Marino   if (token.type != LSTOKEN_STRING)
1629*ef5ccd6cSJohn Marino     unexpected_linespec_error (parser);
1630*ef5ccd6cSJohn Marino 
1631*ef5ccd6cSJohn Marino   /* The current token will contain the name of a function, method,
1632*ef5ccd6cSJohn Marino      or label.  */
1633*ef5ccd6cSJohn Marino   name  = copy_token_string (token);
1634*ef5ccd6cSJohn Marino   cleanup = make_cleanup (xfree, name);
1635*ef5ccd6cSJohn Marino 
1636*ef5ccd6cSJohn Marino   /* Try looking it up as a function/method.  */
1637*ef5ccd6cSJohn Marino   find_linespec_symbols (PARSER_STATE (parser),
1638*ef5ccd6cSJohn Marino 			 PARSER_RESULT (parser)->file_symtabs, name,
1639*ef5ccd6cSJohn Marino 			 &symbols, &minimal_symbols);
1640*ef5ccd6cSJohn Marino 
1641*ef5ccd6cSJohn Marino   if (symbols != NULL || minimal_symbols != NULL)
1642*ef5ccd6cSJohn Marino     {
1643*ef5ccd6cSJohn Marino       PARSER_RESULT (parser)->function_symbols = symbols;
1644*ef5ccd6cSJohn Marino       PARSER_RESULT (parser)->minimal_symbols = minimal_symbols;
1645*ef5ccd6cSJohn Marino       PARSER_RESULT (parser)->function_name = name;
1646*ef5ccd6cSJohn Marino       symbols = NULL;
1647*ef5ccd6cSJohn Marino       discard_cleanups (cleanup);
1648*ef5ccd6cSJohn Marino     }
1649*ef5ccd6cSJohn Marino   else
1650*ef5ccd6cSJohn Marino     {
1651*ef5ccd6cSJohn Marino       /* NAME was not a function or a method.  So it must be a label
1652*ef5ccd6cSJohn Marino 	 name.  */
1653*ef5ccd6cSJohn Marino       labels = find_label_symbols (PARSER_STATE (parser), NULL,
1654*ef5ccd6cSJohn Marino 				   &symbols, name);
1655*ef5ccd6cSJohn Marino       if (labels != NULL)
1656*ef5ccd6cSJohn Marino 	{
1657*ef5ccd6cSJohn Marino 	  PARSER_RESULT (parser)->labels.label_symbols = labels;
1658*ef5ccd6cSJohn Marino 	  PARSER_RESULT (parser)->labels.function_symbols = symbols;
1659*ef5ccd6cSJohn Marino 	  PARSER_RESULT (parser)->label_name = name;
1660*ef5ccd6cSJohn Marino 	  symbols = NULL;
1661*ef5ccd6cSJohn Marino 	  discard_cleanups (cleanup);
1662*ef5ccd6cSJohn Marino 	}
1663*ef5ccd6cSJohn Marino       else
1664*ef5ccd6cSJohn Marino 	{
1665*ef5ccd6cSJohn Marino 	  /* The name is also not a label.  Abort parsing.  Do not throw
1666*ef5ccd6cSJohn Marino 	     an error here.  parse_linespec will do it for us.  */
1667*ef5ccd6cSJohn Marino 
1668*ef5ccd6cSJohn Marino 	  /* Save a copy of the name we were trying to lookup.  */
1669*ef5ccd6cSJohn Marino 	  PARSER_RESULT (parser)->function_name = name;
1670*ef5ccd6cSJohn Marino 	  discard_cleanups (cleanup);
1671*ef5ccd6cSJohn Marino 	  return;
1672*ef5ccd6cSJohn Marino 	}
1673*ef5ccd6cSJohn Marino     }
1674*ef5ccd6cSJohn Marino 
1675*ef5ccd6cSJohn Marino   /* Get the next token.  */
1676*ef5ccd6cSJohn Marino   token = linespec_lexer_consume_token (parser);
1677*ef5ccd6cSJohn Marino 
1678*ef5ccd6cSJohn Marino   if (token.type == LSTOKEN_COLON)
1679*ef5ccd6cSJohn Marino     {
1680*ef5ccd6cSJohn Marino       /* User specified a label or a lineno.  */
1681*ef5ccd6cSJohn Marino       token = linespec_lexer_consume_token (parser);
1682*ef5ccd6cSJohn Marino 
1683*ef5ccd6cSJohn Marino       if (token.type == LSTOKEN_NUMBER)
1684*ef5ccd6cSJohn Marino 	{
1685*ef5ccd6cSJohn Marino 	  /* User specified an offset.  Record the line offset and
1686*ef5ccd6cSJohn Marino 	     get the next token.  */
1687*ef5ccd6cSJohn Marino 	  name = copy_token_string (token);
1688*ef5ccd6cSJohn Marino 	  cleanup = make_cleanup (xfree, name);
1689*ef5ccd6cSJohn Marino 	  PARSER_RESULT (parser)->line_offset
1690*ef5ccd6cSJohn Marino 	    = linespec_parse_line_offset (name);
1691*ef5ccd6cSJohn Marino 	  do_cleanups (cleanup);
1692*ef5ccd6cSJohn Marino 
1693*ef5ccd6cSJohn Marino 	  /* Ge the next token.  */
1694*ef5ccd6cSJohn Marino 	  token = linespec_lexer_consume_token (parser);
1695*ef5ccd6cSJohn Marino 	}
1696*ef5ccd6cSJohn Marino       else if (token.type == LSTOKEN_STRING)
1697*ef5ccd6cSJohn Marino 	{
1698*ef5ccd6cSJohn Marino 	  /* Grab a copy of the label's name and look it up.  */
1699*ef5ccd6cSJohn Marino 	  name = copy_token_string (token);
1700*ef5ccd6cSJohn Marino 	  cleanup = make_cleanup (xfree, name);
1701*ef5ccd6cSJohn Marino 	  labels = find_label_symbols (PARSER_STATE (parser),
1702*ef5ccd6cSJohn Marino 				       PARSER_RESULT (parser)->function_symbols,
1703*ef5ccd6cSJohn Marino 				       &symbols, name);
1704*ef5ccd6cSJohn Marino 
1705*ef5ccd6cSJohn Marino 	  if (labels != NULL)
1706*ef5ccd6cSJohn Marino 	    {
1707*ef5ccd6cSJohn Marino 	      PARSER_RESULT (parser)->labels.label_symbols = labels;
1708*ef5ccd6cSJohn Marino 	      PARSER_RESULT (parser)->labels.function_symbols = symbols;
1709*ef5ccd6cSJohn Marino 	      PARSER_RESULT (parser)->label_name = name;
1710*ef5ccd6cSJohn Marino 	      symbols = NULL;
1711*ef5ccd6cSJohn Marino 	      discard_cleanups (cleanup);
1712*ef5ccd6cSJohn Marino 	    }
1713*ef5ccd6cSJohn Marino 	  else
1714*ef5ccd6cSJohn Marino 	    {
1715*ef5ccd6cSJohn Marino 	      /* We don't know what it was, but it isn't a label.  */
1716*ef5ccd6cSJohn Marino 	      throw_error (NOT_FOUND_ERROR,
1717*ef5ccd6cSJohn Marino 			   _("No label \"%s\" defined in function \"%s\"."),
1718*ef5ccd6cSJohn Marino 			   name, PARSER_RESULT (parser)->function_name);
1719*ef5ccd6cSJohn Marino 	    }
1720*ef5ccd6cSJohn Marino 
1721*ef5ccd6cSJohn Marino 	  /* Check for a line offset.  */
1722*ef5ccd6cSJohn Marino 	  token = linespec_lexer_consume_token (parser);
1723*ef5ccd6cSJohn Marino 	  if (token.type == LSTOKEN_COLON)
1724*ef5ccd6cSJohn Marino 	    {
1725*ef5ccd6cSJohn Marino 	      /* Get the next token.  */
1726*ef5ccd6cSJohn Marino 	      token = linespec_lexer_consume_token (parser);
1727*ef5ccd6cSJohn Marino 
1728*ef5ccd6cSJohn Marino 	      /* It must be a line offset.  */
1729*ef5ccd6cSJohn Marino 	      if (token.type != LSTOKEN_NUMBER)
1730*ef5ccd6cSJohn Marino 		unexpected_linespec_error (parser);
1731*ef5ccd6cSJohn Marino 
1732*ef5ccd6cSJohn Marino 	      /* Record the lione offset and get the next token.  */
1733*ef5ccd6cSJohn Marino 	      name = copy_token_string (token);
1734*ef5ccd6cSJohn Marino 	      cleanup = make_cleanup (xfree, name);
1735*ef5ccd6cSJohn Marino 
1736*ef5ccd6cSJohn Marino 	      PARSER_RESULT (parser)->line_offset
1737*ef5ccd6cSJohn Marino 		= linespec_parse_line_offset (name);
1738*ef5ccd6cSJohn Marino 	      do_cleanups (cleanup);
1739*ef5ccd6cSJohn Marino 
1740*ef5ccd6cSJohn Marino 	      /* Get the next token.  */
1741*ef5ccd6cSJohn Marino 	      token = linespec_lexer_consume_token (parser);
1742*ef5ccd6cSJohn Marino 	    }
1743*ef5ccd6cSJohn Marino 	}
1744*ef5ccd6cSJohn Marino       else
1745*ef5ccd6cSJohn Marino 	{
1746*ef5ccd6cSJohn Marino 	  /* Trailing ':' in the input. Issue an error.  */
1747*ef5ccd6cSJohn Marino 	  unexpected_linespec_error (parser);
1748*ef5ccd6cSJohn Marino 	}
1749*ef5ccd6cSJohn Marino     }
1750*ef5ccd6cSJohn Marino }
1751*ef5ccd6cSJohn Marino 
1752*ef5ccd6cSJohn Marino /* Canonicalize the linespec contained in LS.  The result is saved into
1753*ef5ccd6cSJohn Marino    STATE->canonical.  */
1754*ef5ccd6cSJohn Marino 
1755*ef5ccd6cSJohn Marino static void
canonicalize_linespec(struct linespec_state * state,linespec_p ls)1756*ef5ccd6cSJohn Marino canonicalize_linespec (struct linespec_state *state, linespec_p ls)
1757*ef5ccd6cSJohn Marino {
1758*ef5ccd6cSJohn Marino   /* If canonicalization was not requested, no need to do anything.  */
1759*ef5ccd6cSJohn Marino   if (!state->canonical)
1760*ef5ccd6cSJohn Marino     return;
1761*ef5ccd6cSJohn Marino 
1762*ef5ccd6cSJohn Marino   /* Shortcut expressions, which can only appear by themselves.  */
1763*ef5ccd6cSJohn Marino   if (ls->expression != NULL)
1764*ef5ccd6cSJohn Marino     state->canonical->addr_string = xstrdup (ls->expression);
1765*ef5ccd6cSJohn Marino   else
1766*ef5ccd6cSJohn Marino     {
1767*ef5ccd6cSJohn Marino       struct ui_file *buf;
1768*ef5ccd6cSJohn Marino       int need_colon = 0;
1769*ef5ccd6cSJohn Marino 
1770*ef5ccd6cSJohn Marino       buf = mem_fileopen ();
1771*ef5ccd6cSJohn Marino       if (ls->source_filename)
1772*ef5ccd6cSJohn Marino 	{
1773*ef5ccd6cSJohn Marino 	  fputs_unfiltered (ls->source_filename, buf);
1774*ef5ccd6cSJohn Marino 	  need_colon = 1;
1775*ef5ccd6cSJohn Marino 	}
1776*ef5ccd6cSJohn Marino 
1777*ef5ccd6cSJohn Marino       if (ls->function_name)
1778*ef5ccd6cSJohn Marino 	{
1779*ef5ccd6cSJohn Marino 	  if (need_colon)
1780*ef5ccd6cSJohn Marino 	    fputc_unfiltered (':', buf);
1781*ef5ccd6cSJohn Marino 	  fputs_unfiltered (ls->function_name, buf);
1782*ef5ccd6cSJohn Marino 	  need_colon = 1;
1783*ef5ccd6cSJohn Marino 	}
1784*ef5ccd6cSJohn Marino 
1785*ef5ccd6cSJohn Marino       if (ls->label_name)
1786*ef5ccd6cSJohn Marino 	{
1787*ef5ccd6cSJohn Marino 	  if (need_colon)
1788*ef5ccd6cSJohn Marino 	    fputc_unfiltered (':', buf);
1789*ef5ccd6cSJohn Marino 
1790*ef5ccd6cSJohn Marino 	  if (ls->function_name == NULL)
1791*ef5ccd6cSJohn Marino 	    {
1792*ef5ccd6cSJohn Marino 	      struct symbol *s;
1793*ef5ccd6cSJohn Marino 
1794*ef5ccd6cSJohn Marino 	      /* No function was specified, so add the symbol name.  */
1795*ef5ccd6cSJohn Marino 	      gdb_assert (ls->labels.function_symbols != NULL
1796*ef5ccd6cSJohn Marino 			  && (VEC_length (symbolp, ls->labels.function_symbols)
1797*ef5ccd6cSJohn Marino 			      == 1));
1798*ef5ccd6cSJohn Marino 	      s = VEC_index (symbolp, ls->labels.function_symbols, 0);
1799*ef5ccd6cSJohn Marino 	      fputs_unfiltered (SYMBOL_NATURAL_NAME (s), buf);
1800*ef5ccd6cSJohn Marino 	      fputc_unfiltered (':', buf);
1801*ef5ccd6cSJohn Marino 	    }
1802*ef5ccd6cSJohn Marino 
1803*ef5ccd6cSJohn Marino 	  fputs_unfiltered (ls->label_name, buf);
1804*ef5ccd6cSJohn Marino 	  need_colon = 1;
1805*ef5ccd6cSJohn Marino 	  state->canonical->special_display = 1;
1806*ef5ccd6cSJohn Marino 	}
1807*ef5ccd6cSJohn Marino 
1808*ef5ccd6cSJohn Marino       if (ls->line_offset.sign != LINE_OFFSET_UNKNOWN)
1809*ef5ccd6cSJohn Marino 	{
1810*ef5ccd6cSJohn Marino 	  if (need_colon)
1811*ef5ccd6cSJohn Marino 	    fputc_unfiltered (':', buf);
1812*ef5ccd6cSJohn Marino 	  fprintf_filtered (buf, "%s%d",
1813*ef5ccd6cSJohn Marino 			    (ls->line_offset.sign == LINE_OFFSET_NONE ? ""
1814*ef5ccd6cSJohn Marino 			     : (ls->line_offset.sign
1815*ef5ccd6cSJohn Marino 				== LINE_OFFSET_PLUS ? "+" : "-")),
1816*ef5ccd6cSJohn Marino 			    ls->line_offset.offset);
1817*ef5ccd6cSJohn Marino 	}
1818*ef5ccd6cSJohn Marino 
1819*ef5ccd6cSJohn Marino       state->canonical->addr_string = ui_file_xstrdup (buf, NULL);
1820*ef5ccd6cSJohn Marino       ui_file_delete (buf);
1821*ef5ccd6cSJohn Marino     }
1822*ef5ccd6cSJohn Marino }
1823*ef5ccd6cSJohn Marino 
1824*ef5ccd6cSJohn Marino /* Given a line offset in LS, construct the relevant SALs.  */
1825*ef5ccd6cSJohn Marino 
1826*ef5ccd6cSJohn Marino static struct symtabs_and_lines
create_sals_line_offset(struct linespec_state * self,linespec_p ls)1827*ef5ccd6cSJohn Marino create_sals_line_offset (struct linespec_state *self,
1828*ef5ccd6cSJohn Marino 			 linespec_p ls)
1829*ef5ccd6cSJohn Marino {
1830*ef5ccd6cSJohn Marino   struct symtabs_and_lines values;
1831*ef5ccd6cSJohn Marino   struct symtab_and_line val;
1832*ef5ccd6cSJohn Marino   int use_default = 0;
1833*ef5ccd6cSJohn Marino 
1834*ef5ccd6cSJohn Marino   init_sal (&val);
1835*ef5ccd6cSJohn Marino   values.sals = NULL;
1836*ef5ccd6cSJohn Marino   values.nelts = 0;
1837*ef5ccd6cSJohn Marino 
1838*ef5ccd6cSJohn Marino   /* This is where we need to make sure we have good defaults.
1839*ef5ccd6cSJohn Marino      We must guarantee that this section of code is never executed
1840*ef5ccd6cSJohn Marino      when we are called with just a function name, since
1841*ef5ccd6cSJohn Marino      set_default_source_symtab_and_line uses
1842*ef5ccd6cSJohn Marino      select_source_symtab that calls us with such an argument.  */
1843*ef5ccd6cSJohn Marino 
1844*ef5ccd6cSJohn Marino   if (VEC_length (symtab_p, ls->file_symtabs) == 1
1845*ef5ccd6cSJohn Marino       && VEC_index (symtab_p, ls->file_symtabs, 0) == NULL)
1846*ef5ccd6cSJohn Marino     {
1847*ef5ccd6cSJohn Marino       const char *fullname;
1848*ef5ccd6cSJohn Marino 
1849*ef5ccd6cSJohn Marino       set_current_program_space (self->program_space);
1850*ef5ccd6cSJohn Marino 
1851*ef5ccd6cSJohn Marino       /* Make sure we have at least a default source line.  */
1852*ef5ccd6cSJohn Marino       set_default_source_symtab_and_line ();
1853*ef5ccd6cSJohn Marino       initialize_defaults (&self->default_symtab, &self->default_line);
1854*ef5ccd6cSJohn Marino       fullname = symtab_to_fullname (self->default_symtab);
1855*ef5ccd6cSJohn Marino       VEC_pop (symtab_p, ls->file_symtabs);
1856*ef5ccd6cSJohn Marino       VEC_free (symtab_p, ls->file_symtabs);
1857*ef5ccd6cSJohn Marino       ls->file_symtabs = collect_symtabs_from_filename (fullname);
1858*ef5ccd6cSJohn Marino       use_default = 1;
1859*ef5ccd6cSJohn Marino     }
1860*ef5ccd6cSJohn Marino 
1861*ef5ccd6cSJohn Marino   val.line = ls->line_offset.offset;
1862*ef5ccd6cSJohn Marino   switch (ls->line_offset.sign)
1863*ef5ccd6cSJohn Marino     {
1864*ef5ccd6cSJohn Marino     case LINE_OFFSET_PLUS:
1865*ef5ccd6cSJohn Marino       if (ls->line_offset.offset == 0)
1866*ef5ccd6cSJohn Marino 	val.line = 5;
1867*ef5ccd6cSJohn Marino       if (use_default)
1868*ef5ccd6cSJohn Marino 	val.line = self->default_line + val.line;
1869*ef5ccd6cSJohn Marino       break;
1870*ef5ccd6cSJohn Marino 
1871*ef5ccd6cSJohn Marino     case LINE_OFFSET_MINUS:
1872*ef5ccd6cSJohn Marino       if (ls->line_offset.offset == 0)
1873*ef5ccd6cSJohn Marino 	val.line = 15;
1874*ef5ccd6cSJohn Marino       if (use_default)
1875*ef5ccd6cSJohn Marino 	val.line = self->default_line - val.line;
1876*ef5ccd6cSJohn Marino       else
1877*ef5ccd6cSJohn Marino 	val.line = -val.line;
1878*ef5ccd6cSJohn Marino       break;
1879*ef5ccd6cSJohn Marino 
1880*ef5ccd6cSJohn Marino     case LINE_OFFSET_NONE:
1881*ef5ccd6cSJohn Marino       break;			/* No need to adjust val.line.  */
1882*ef5ccd6cSJohn Marino     }
1883*ef5ccd6cSJohn Marino 
1884*ef5ccd6cSJohn Marino   if (self->list_mode)
1885*ef5ccd6cSJohn Marino     decode_digits_list_mode (self, ls, &values, val);
1886*ef5ccd6cSJohn Marino   else
1887*ef5ccd6cSJohn Marino     {
1888*ef5ccd6cSJohn Marino       struct linetable_entry *best_entry = NULL;
1889*ef5ccd6cSJohn Marino       int *filter;
1890*ef5ccd6cSJohn Marino       struct block **blocks;
1891*ef5ccd6cSJohn Marino       struct cleanup *cleanup;
1892*ef5ccd6cSJohn Marino       struct symtabs_and_lines intermediate_results;
1893*ef5ccd6cSJohn Marino       int i, j;
1894*ef5ccd6cSJohn Marino 
1895*ef5ccd6cSJohn Marino       intermediate_results.sals = NULL;
1896*ef5ccd6cSJohn Marino       intermediate_results.nelts = 0;
1897*ef5ccd6cSJohn Marino 
1898*ef5ccd6cSJohn Marino       decode_digits_ordinary (self, ls, val.line, &intermediate_results,
1899*ef5ccd6cSJohn Marino 			      &best_entry);
1900*ef5ccd6cSJohn Marino       if (intermediate_results.nelts == 0 && best_entry != NULL)
1901*ef5ccd6cSJohn Marino 	decode_digits_ordinary (self, ls, best_entry->line,
1902*ef5ccd6cSJohn Marino 				&intermediate_results, &best_entry);
1903*ef5ccd6cSJohn Marino 
1904*ef5ccd6cSJohn Marino       cleanup = make_cleanup (xfree, intermediate_results.sals);
1905*ef5ccd6cSJohn Marino 
1906*ef5ccd6cSJohn Marino       /* For optimized code, the compiler can scatter one source line
1907*ef5ccd6cSJohn Marino 	 across disjoint ranges of PC values, even when no duplicate
1908*ef5ccd6cSJohn Marino 	 functions or inline functions are involved.  For example,
1909*ef5ccd6cSJohn Marino 	 'for (;;)' inside a non-template, non-inline, and non-ctor-or-dtor
1910*ef5ccd6cSJohn Marino 	 function can result in two PC ranges.  In this case, we don't
1911*ef5ccd6cSJohn Marino 	 want to set a breakpoint on the first PC of each range.  To filter
1912*ef5ccd6cSJohn Marino 	 such cases, we use containing blocks -- for each PC found
1913*ef5ccd6cSJohn Marino 	 above, we see if there are other PCs that are in the same
1914*ef5ccd6cSJohn Marino 	 block.  If yes, the other PCs are filtered out.  */
1915*ef5ccd6cSJohn Marino 
1916*ef5ccd6cSJohn Marino       filter = XNEWVEC (int, intermediate_results.nelts);
1917*ef5ccd6cSJohn Marino       make_cleanup (xfree, filter);
1918*ef5ccd6cSJohn Marino       blocks = XNEWVEC (struct block *, intermediate_results.nelts);
1919*ef5ccd6cSJohn Marino       make_cleanup (xfree, blocks);
1920*ef5ccd6cSJohn Marino 
1921*ef5ccd6cSJohn Marino       for (i = 0; i < intermediate_results.nelts; ++i)
1922*ef5ccd6cSJohn Marino 	{
1923*ef5ccd6cSJohn Marino 	  set_current_program_space (intermediate_results.sals[i].pspace);
1924*ef5ccd6cSJohn Marino 
1925*ef5ccd6cSJohn Marino 	  filter[i] = 1;
1926*ef5ccd6cSJohn Marino 	  blocks[i] = block_for_pc_sect (intermediate_results.sals[i].pc,
1927*ef5ccd6cSJohn Marino 					 intermediate_results.sals[i].section);
1928*ef5ccd6cSJohn Marino 	}
1929*ef5ccd6cSJohn Marino 
1930*ef5ccd6cSJohn Marino       for (i = 0; i < intermediate_results.nelts; ++i)
1931*ef5ccd6cSJohn Marino 	{
1932*ef5ccd6cSJohn Marino 	  if (blocks[i] != NULL)
1933*ef5ccd6cSJohn Marino 	    for (j = i + 1; j < intermediate_results.nelts; ++j)
1934*ef5ccd6cSJohn Marino 	      {
1935*ef5ccd6cSJohn Marino 		if (blocks[j] == blocks[i])
1936*ef5ccd6cSJohn Marino 		  {
1937*ef5ccd6cSJohn Marino 		    filter[j] = 0;
1938*ef5ccd6cSJohn Marino 		    break;
1939*ef5ccd6cSJohn Marino 		  }
1940*ef5ccd6cSJohn Marino 	      }
1941*ef5ccd6cSJohn Marino 	}
1942*ef5ccd6cSJohn Marino 
1943*ef5ccd6cSJohn Marino       for (i = 0; i < intermediate_results.nelts; ++i)
1944*ef5ccd6cSJohn Marino 	if (filter[i])
1945*ef5ccd6cSJohn Marino 	  {
1946*ef5ccd6cSJohn Marino 	    struct symbol *sym = (blocks[i]
1947*ef5ccd6cSJohn Marino 				  ? block_containing_function (blocks[i])
1948*ef5ccd6cSJohn Marino 				  : NULL);
1949*ef5ccd6cSJohn Marino 
1950*ef5ccd6cSJohn Marino 	    if (self->funfirstline)
1951*ef5ccd6cSJohn Marino 	      skip_prologue_sal (&intermediate_results.sals[i]);
1952*ef5ccd6cSJohn Marino 	    /* Make sure the line matches the request, not what was
1953*ef5ccd6cSJohn Marino 	       found.  */
1954*ef5ccd6cSJohn Marino 	    intermediate_results.sals[i].line = val.line;
1955*ef5ccd6cSJohn Marino 	    add_sal_to_sals (self, &values, &intermediate_results.sals[i],
1956*ef5ccd6cSJohn Marino 			     sym ? SYMBOL_NATURAL_NAME (sym) : NULL, 0);
1957*ef5ccd6cSJohn Marino 	  }
1958*ef5ccd6cSJohn Marino 
1959*ef5ccd6cSJohn Marino       do_cleanups (cleanup);
1960*ef5ccd6cSJohn Marino     }
1961*ef5ccd6cSJohn Marino 
1962*ef5ccd6cSJohn Marino   if (values.nelts == 0)
1963*ef5ccd6cSJohn Marino     {
1964*ef5ccd6cSJohn Marino       if (ls->source_filename)
1965*ef5ccd6cSJohn Marino 	throw_error (NOT_FOUND_ERROR, _("No line %d in file \"%s\"."),
1966*ef5ccd6cSJohn Marino 		     val.line, ls->source_filename);
1967*ef5ccd6cSJohn Marino       else
1968*ef5ccd6cSJohn Marino 	throw_error (NOT_FOUND_ERROR, _("No line %d in the current file."),
1969*ef5ccd6cSJohn Marino 		     val.line);
1970*ef5ccd6cSJohn Marino     }
1971*ef5ccd6cSJohn Marino 
1972*ef5ccd6cSJohn Marino   return values;
1973*ef5ccd6cSJohn Marino }
1974*ef5ccd6cSJohn Marino 
1975*ef5ccd6cSJohn Marino /* Create and return SALs from the linespec LS.  */
1976*ef5ccd6cSJohn Marino 
1977*ef5ccd6cSJohn Marino static struct symtabs_and_lines
convert_linespec_to_sals(struct linespec_state * state,linespec_p ls)1978*ef5ccd6cSJohn Marino convert_linespec_to_sals (struct linespec_state *state, linespec_p ls)
1979*ef5ccd6cSJohn Marino {
1980*ef5ccd6cSJohn Marino   struct symtabs_and_lines sals = {NULL, 0};
1981*ef5ccd6cSJohn Marino 
1982*ef5ccd6cSJohn Marino   if (ls->expression != NULL)
1983*ef5ccd6cSJohn Marino     {
1984*ef5ccd6cSJohn Marino       struct symtab_and_line sal;
1985*ef5ccd6cSJohn Marino 
1986*ef5ccd6cSJohn Marino       /* We have an expression.  No other attribute is allowed.  */
1987*ef5ccd6cSJohn Marino       sal = find_pc_line (ls->expr_pc, 0);
1988*ef5ccd6cSJohn Marino       sal.pc = ls->expr_pc;
1989*ef5ccd6cSJohn Marino       sal.section = find_pc_overlay (ls->expr_pc);
1990*ef5ccd6cSJohn Marino       sal.explicit_pc = 1;
1991*ef5ccd6cSJohn Marino       add_sal_to_sals (state, &sals, &sal, ls->expression, 1);
1992*ef5ccd6cSJohn Marino     }
1993*ef5ccd6cSJohn Marino   else if (ls->labels.label_symbols != NULL)
1994*ef5ccd6cSJohn Marino     {
1995*ef5ccd6cSJohn Marino       /* We have just a bunch of functions/methods or labels.  */
1996*ef5ccd6cSJohn Marino       int i;
1997*ef5ccd6cSJohn Marino       struct symtab_and_line sal;
1998*ef5ccd6cSJohn Marino       struct symbol *sym;
1999*ef5ccd6cSJohn Marino 
2000*ef5ccd6cSJohn Marino       for (i = 0; VEC_iterate (symbolp, ls->labels.label_symbols, i, sym); ++i)
2001*ef5ccd6cSJohn Marino 	{
2002*ef5ccd6cSJohn Marino 	  if (symbol_to_sal (&sal, state->funfirstline, sym))
2003*ef5ccd6cSJohn Marino 	    add_sal_to_sals (state, &sals, &sal,
2004*ef5ccd6cSJohn Marino 			     SYMBOL_NATURAL_NAME (sym), 0);
2005*ef5ccd6cSJohn Marino 	}
2006*ef5ccd6cSJohn Marino     }
2007*ef5ccd6cSJohn Marino   else if (ls->function_symbols != NULL || ls->minimal_symbols != NULL)
2008*ef5ccd6cSJohn Marino     {
2009*ef5ccd6cSJohn Marino       /* We have just a bunch of functions and/or methods.  */
2010*ef5ccd6cSJohn Marino       int i;
2011*ef5ccd6cSJohn Marino       struct symtab_and_line sal;
2012*ef5ccd6cSJohn Marino       struct symbol *sym;
2013*ef5ccd6cSJohn Marino       minsym_and_objfile_d *elem;
2014*ef5ccd6cSJohn Marino       struct program_space *pspace;
2015*ef5ccd6cSJohn Marino 
2016*ef5ccd6cSJohn Marino       if (ls->function_symbols != NULL)
2017*ef5ccd6cSJohn Marino 	{
2018*ef5ccd6cSJohn Marino 	  /* Sort symbols so that symbols with the same program space are next
2019*ef5ccd6cSJohn Marino 	     to each other.  */
2020*ef5ccd6cSJohn Marino 	  qsort (VEC_address (symbolp, ls->function_symbols),
2021*ef5ccd6cSJohn Marino 		 VEC_length (symbolp, ls->function_symbols),
2022*ef5ccd6cSJohn Marino 		 sizeof (symbolp), compare_symbols);
2023*ef5ccd6cSJohn Marino 
2024*ef5ccd6cSJohn Marino 	  for (i = 0; VEC_iterate (symbolp, ls->function_symbols, i, sym); ++i)
2025*ef5ccd6cSJohn Marino 	    {
2026*ef5ccd6cSJohn Marino 	      pspace = SYMTAB_PSPACE (SYMBOL_SYMTAB (sym));
2027*ef5ccd6cSJohn Marino 	      set_current_program_space (pspace);
2028*ef5ccd6cSJohn Marino 	      if (symbol_to_sal (&sal, state->funfirstline, sym)
2029*ef5ccd6cSJohn Marino 		  && maybe_add_address (state->addr_set, pspace, sal.pc))
2030*ef5ccd6cSJohn Marino 		add_sal_to_sals (state, &sals, &sal,
2031*ef5ccd6cSJohn Marino 				 SYMBOL_NATURAL_NAME (sym), 0);
2032*ef5ccd6cSJohn Marino 	    }
2033*ef5ccd6cSJohn Marino 	}
2034*ef5ccd6cSJohn Marino 
2035*ef5ccd6cSJohn Marino       if (ls->minimal_symbols != NULL)
2036*ef5ccd6cSJohn Marino 	{
2037*ef5ccd6cSJohn Marino 	  /* Sort minimal symbols by program space, too.  */
2038*ef5ccd6cSJohn Marino 	  qsort (VEC_address (minsym_and_objfile_d, ls->minimal_symbols),
2039*ef5ccd6cSJohn Marino 		 VEC_length (minsym_and_objfile_d, ls->minimal_symbols),
2040*ef5ccd6cSJohn Marino 		 sizeof (minsym_and_objfile_d), compare_msymbols);
2041*ef5ccd6cSJohn Marino 
2042*ef5ccd6cSJohn Marino 	  for (i = 0;
2043*ef5ccd6cSJohn Marino 	       VEC_iterate (minsym_and_objfile_d, ls->minimal_symbols, i, elem);
2044*ef5ccd6cSJohn Marino 	       ++i)
2045*ef5ccd6cSJohn Marino 	    {
2046*ef5ccd6cSJohn Marino 	      pspace = elem->objfile->pspace;
2047*ef5ccd6cSJohn Marino 	      set_current_program_space (pspace);
2048*ef5ccd6cSJohn Marino 	      minsym_found (state, elem->objfile, elem->minsym, &sals);
2049*ef5ccd6cSJohn Marino 	    }
2050*ef5ccd6cSJohn Marino 	}
2051*ef5ccd6cSJohn Marino     }
2052*ef5ccd6cSJohn Marino   else if (ls->line_offset.sign != LINE_OFFSET_UNKNOWN)
2053*ef5ccd6cSJohn Marino     {
2054*ef5ccd6cSJohn Marino       /* Only an offset was specified.  */
2055*ef5ccd6cSJohn Marino 	sals = create_sals_line_offset (state, ls);
2056*ef5ccd6cSJohn Marino 
2057*ef5ccd6cSJohn Marino 	/* Make sure we have a filename for canonicalization.  */
2058*ef5ccd6cSJohn Marino 	if (ls->source_filename == NULL)
2059*ef5ccd6cSJohn Marino 	  {
2060*ef5ccd6cSJohn Marino 	    const char *fullname = symtab_to_fullname (state->default_symtab);
2061*ef5ccd6cSJohn Marino 
2062*ef5ccd6cSJohn Marino 	    ls->source_filename = xstrdup (fullname);
2063*ef5ccd6cSJohn Marino 	  }
2064*ef5ccd6cSJohn Marino     }
2065*ef5ccd6cSJohn Marino   else
2066*ef5ccd6cSJohn Marino     {
2067*ef5ccd6cSJohn Marino       /* We haven't found any results...  */
2068*ef5ccd6cSJohn Marino       return sals;
2069*ef5ccd6cSJohn Marino     }
2070*ef5ccd6cSJohn Marino 
2071*ef5ccd6cSJohn Marino   canonicalize_linespec (state, ls);
2072*ef5ccd6cSJohn Marino 
2073*ef5ccd6cSJohn Marino   if (sals.nelts > 0 && state->canonical != NULL)
2074*ef5ccd6cSJohn Marino     state->canonical->pre_expanded = 1;
2075*ef5ccd6cSJohn Marino 
2076*ef5ccd6cSJohn Marino   return sals;
2077*ef5ccd6cSJohn Marino }
2078*ef5ccd6cSJohn Marino 
2079*ef5ccd6cSJohn Marino /* Parse a string that specifies a linespec.
20805796c8dcSSimon Schubert    Pass the address of a char * variable; that variable will be
20815796c8dcSSimon Schubert    advanced over the characters actually parsed.
20825796c8dcSSimon Schubert 
2083*ef5ccd6cSJohn Marino    The basic grammar of linespecs:
20845796c8dcSSimon Schubert 
2085*ef5ccd6cSJohn Marino    linespec -> expr_spec | var_spec | basic_spec
2086*ef5ccd6cSJohn Marino    expr_spec -> '*' STRING
2087*ef5ccd6cSJohn Marino    var_spec -> '$' (STRING | NUMBER)
20885796c8dcSSimon Schubert 
2089*ef5ccd6cSJohn Marino    basic_spec -> file_offset_spec | function_spec | label_spec
2090*ef5ccd6cSJohn Marino    file_offset_spec -> opt_file_spec offset_spec
2091*ef5ccd6cSJohn Marino    function_spec -> opt_file_spec function_name_spec opt_label_spec
2092*ef5ccd6cSJohn Marino    label_spec -> label_name_spec
20935796c8dcSSimon Schubert 
2094*ef5ccd6cSJohn Marino    opt_file_spec -> "" | file_name_spec ':'
2095*ef5ccd6cSJohn Marino    opt_label_spec -> "" | ':' label_name_spec
2096*ef5ccd6cSJohn Marino 
2097*ef5ccd6cSJohn Marino    file_name_spec -> STRING
2098*ef5ccd6cSJohn Marino    function_name_spec -> STRING
2099*ef5ccd6cSJohn Marino    label_name_spec -> STRING
2100*ef5ccd6cSJohn Marino    function_name_spec -> STRING
2101*ef5ccd6cSJohn Marino    offset_spec -> NUMBER
2102*ef5ccd6cSJohn Marino                -> '+' NUMBER
2103*ef5ccd6cSJohn Marino 	       -> '-' NUMBER
2104*ef5ccd6cSJohn Marino 
2105*ef5ccd6cSJohn Marino    This may all be followed by several keywords such as "if EXPR",
2106*ef5ccd6cSJohn Marino    which we ignore.
2107*ef5ccd6cSJohn Marino 
2108*ef5ccd6cSJohn Marino    A comma will terminate parsing.
2109*ef5ccd6cSJohn Marino 
2110*ef5ccd6cSJohn Marino    The function may be an undebuggable function found in minimal symbol table.
21115796c8dcSSimon Schubert 
21125796c8dcSSimon Schubert    If the argument FUNFIRSTLINE is nonzero, we want the first line
21135796c8dcSSimon Schubert    of real code inside a function when a function is specified, and it is
21145796c8dcSSimon Schubert    not OK to specify a variable or type to get its line number.
21155796c8dcSSimon Schubert 
21165796c8dcSSimon Schubert    DEFAULT_SYMTAB specifies the file to use if none is specified.
21175796c8dcSSimon Schubert    It defaults to current_source_symtab.
21185796c8dcSSimon Schubert    DEFAULT_LINE specifies the line number to use for relative
21195796c8dcSSimon Schubert    line numbers (that start with signs).  Defaults to current_source_line.
21205796c8dcSSimon Schubert    If CANONICAL is non-NULL, store an array of strings containing the canonical
21215796c8dcSSimon Schubert    line specs there if necessary.  Currently overloaded member functions and
21225796c8dcSSimon Schubert    line numbers or static functions without a filename yield a canonical
21235796c8dcSSimon Schubert    line spec.  The array and the line spec strings are allocated on the heap,
21245796c8dcSSimon Schubert    it is the callers responsibility to free them.
21255796c8dcSSimon Schubert 
21265796c8dcSSimon Schubert    Note that it is possible to return zero for the symtab
21275796c8dcSSimon Schubert    if no file is validly specified.  Callers must check that.
2128c50c785cSJohn Marino    Also, the line number returned may be invalid.  */
21295796c8dcSSimon Schubert 
2130*ef5ccd6cSJohn Marino /* Parse the linespec in ARGPTR.  */
21315796c8dcSSimon Schubert 
2132*ef5ccd6cSJohn Marino static struct symtabs_and_lines
parse_linespec(linespec_parser * parser,char ** argptr)2133*ef5ccd6cSJohn Marino parse_linespec (linespec_parser *parser, char **argptr)
21345796c8dcSSimon Schubert {
2135*ef5ccd6cSJohn Marino   linespec_token token;
2136*ef5ccd6cSJohn Marino   struct symtabs_and_lines values;
2137c50c785cSJohn Marino   volatile struct gdb_exception file_exception;
2138*ef5ccd6cSJohn Marino   struct cleanup *cleanup;
21395796c8dcSSimon Schubert 
2140*ef5ccd6cSJohn Marino   /* A special case to start.  It has become quite popular for
2141*ef5ccd6cSJohn Marino      IDEs to work around bugs in the previous parser by quoting
2142*ef5ccd6cSJohn Marino      the entire linespec, so we attempt to deal with this nicely.  */
2143*ef5ccd6cSJohn Marino   parser->is_quote_enclosed = 0;
2144*ef5ccd6cSJohn Marino   if (!is_ada_operator (*argptr)
2145*ef5ccd6cSJohn Marino       && strchr (linespec_quote_characters, **argptr) != NULL)
2146a45ae5f8SJohn Marino     {
2147*ef5ccd6cSJohn Marino       const char *end;
2148*ef5ccd6cSJohn Marino 
2149*ef5ccd6cSJohn Marino       end = skip_quote_char (*argptr + 1, **argptr);
2150*ef5ccd6cSJohn Marino       if (end != NULL && is_closing_quote_enclosed (end))
2151*ef5ccd6cSJohn Marino 	{
2152*ef5ccd6cSJohn Marino 	  /* Here's the special case.  Skip ARGPTR past the initial
2153*ef5ccd6cSJohn Marino 	     quote.  */
2154*ef5ccd6cSJohn Marino 	  ++(*argptr);
2155*ef5ccd6cSJohn Marino 	  parser->is_quote_enclosed = 1;
2156*ef5ccd6cSJohn Marino 	}
2157*ef5ccd6cSJohn Marino     }
2158*ef5ccd6cSJohn Marino 
2159*ef5ccd6cSJohn Marino   /* A keyword at the start cannot be interpreted as such.
2160*ef5ccd6cSJohn Marino      Consider "b thread thread 42".  */
2161*ef5ccd6cSJohn Marino   parser->keyword_ok = 0;
2162*ef5ccd6cSJohn Marino 
2163*ef5ccd6cSJohn Marino   parser->lexer.saved_arg = *argptr;
2164*ef5ccd6cSJohn Marino   parser->lexer.stream = argptr;
2165*ef5ccd6cSJohn Marino   file_exception.reason = 0;
2166*ef5ccd6cSJohn Marino 
2167*ef5ccd6cSJohn Marino   /* Initialize the default symtab and line offset.  */
2168*ef5ccd6cSJohn Marino   initialize_defaults (&PARSER_STATE (parser)->default_symtab,
2169*ef5ccd6cSJohn Marino 		       &PARSER_STATE (parser)->default_line);
2170*ef5ccd6cSJohn Marino 
2171*ef5ccd6cSJohn Marino   /* Objective-C shortcut.  */
2172*ef5ccd6cSJohn Marino   values = decode_objc (PARSER_STATE (parser), PARSER_RESULT (parser), argptr);
2173*ef5ccd6cSJohn Marino   if (values.sals != NULL)
2174*ef5ccd6cSJohn Marino     return values;
2175*ef5ccd6cSJohn Marino 
2176*ef5ccd6cSJohn Marino   /* Start parsing.  */
2177*ef5ccd6cSJohn Marino 
2178*ef5ccd6cSJohn Marino   /* Get the first token.  */
2179*ef5ccd6cSJohn Marino   token = linespec_lexer_lex_one (parser);
2180*ef5ccd6cSJohn Marino 
2181*ef5ccd6cSJohn Marino   /* It must be either LSTOKEN_STRING or LSTOKEN_NUMBER.  */
2182*ef5ccd6cSJohn Marino   if (token.type == LSTOKEN_STRING && *LS_TOKEN_STOKEN (token).ptr == '*')
2183*ef5ccd6cSJohn Marino     {
2184*ef5ccd6cSJohn Marino       char *expr;
2185*ef5ccd6cSJohn Marino       const char *copy;
2186*ef5ccd6cSJohn Marino 
2187*ef5ccd6cSJohn Marino       /* User specified an expression, *EXPR.  */
2188*ef5ccd6cSJohn Marino       copy = expr = copy_token_string (token);
2189*ef5ccd6cSJohn Marino       cleanup = make_cleanup (xfree, expr);
2190*ef5ccd6cSJohn Marino       PARSER_RESULT (parser)->expr_pc = linespec_expression_to_pc (&copy);
2191*ef5ccd6cSJohn Marino       discard_cleanups (cleanup);
2192*ef5ccd6cSJohn Marino       PARSER_RESULT (parser)->expression = expr;
2193*ef5ccd6cSJohn Marino 
2194*ef5ccd6cSJohn Marino       /* This is a little hacky/tricky.  If linespec_expression_to_pc
2195*ef5ccd6cSJohn Marino 	 did not evaluate the entire token, then we must find the
2196*ef5ccd6cSJohn Marino 	 string COPY inside the original token buffer.  */
2197*ef5ccd6cSJohn Marino       if (*copy != '\0')
2198*ef5ccd6cSJohn Marino 	{
2199*ef5ccd6cSJohn Marino 	  PARSER_STREAM (parser) = strstr (parser->lexer.saved_arg, copy);
2200*ef5ccd6cSJohn Marino 	  gdb_assert (PARSER_STREAM (parser) != NULL);
2201*ef5ccd6cSJohn Marino 	}
2202*ef5ccd6cSJohn Marino 
2203*ef5ccd6cSJohn Marino       /* Consume the token.  */
2204*ef5ccd6cSJohn Marino       linespec_lexer_consume_token (parser);
2205*ef5ccd6cSJohn Marino 
2206*ef5ccd6cSJohn Marino       goto convert_to_sals;
2207*ef5ccd6cSJohn Marino     }
2208*ef5ccd6cSJohn Marino   else if (token.type == LSTOKEN_STRING && *LS_TOKEN_STOKEN (token).ptr == '$')
2209*ef5ccd6cSJohn Marino     {
2210*ef5ccd6cSJohn Marino       char *var;
2211*ef5ccd6cSJohn Marino 
2212*ef5ccd6cSJohn Marino       /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB.  */
2213*ef5ccd6cSJohn Marino       VEC_safe_push (symtab_p, PARSER_RESULT (parser)->file_symtabs, NULL);
2214*ef5ccd6cSJohn Marino 
2215*ef5ccd6cSJohn Marino       /* User specified a convenience variable or history value.  */
2216*ef5ccd6cSJohn Marino       var = copy_token_string (token);
2217*ef5ccd6cSJohn Marino       cleanup = make_cleanup (xfree, var);
2218*ef5ccd6cSJohn Marino       PARSER_RESULT (parser)->line_offset
2219*ef5ccd6cSJohn Marino 	= linespec_parse_variable (PARSER_STATE (parser), var);
2220a45ae5f8SJohn Marino       do_cleanups (cleanup);
22215796c8dcSSimon Schubert 
2222*ef5ccd6cSJohn Marino       /* If a line_offset wasn't found (VAR is the name of a user
2223*ef5ccd6cSJohn Marino 	 variable/function), then skip to normal symbol processing.  */
2224*ef5ccd6cSJohn Marino       if (PARSER_RESULT (parser)->line_offset.sign != LINE_OFFSET_UNKNOWN)
2225c50c785cSJohn Marino 	{
2226*ef5ccd6cSJohn Marino 	  /* Consume this token.  */
2227*ef5ccd6cSJohn Marino 	  linespec_lexer_consume_token (parser);
2228*ef5ccd6cSJohn Marino 
2229*ef5ccd6cSJohn Marino 	  goto convert_to_sals;
2230c50c785cSJohn Marino 	}
2231*ef5ccd6cSJohn Marino     }
2232*ef5ccd6cSJohn Marino   else if (token.type != LSTOKEN_STRING && token.type != LSTOKEN_NUMBER)
2233*ef5ccd6cSJohn Marino     unexpected_linespec_error (parser);
22345796c8dcSSimon Schubert 
2235*ef5ccd6cSJohn Marino   /* Now we can recognize keywords.  */
2236*ef5ccd6cSJohn Marino   parser->keyword_ok = 1;
22375796c8dcSSimon Schubert 
2238*ef5ccd6cSJohn Marino   /* Shortcut: If the next token is not LSTOKEN_COLON, we know that
2239*ef5ccd6cSJohn Marino      this token cannot represent a filename.  */
2240*ef5ccd6cSJohn Marino   token = linespec_lexer_peek_token (parser);
22415796c8dcSSimon Schubert 
2242*ef5ccd6cSJohn Marino   if (token.type == LSTOKEN_COLON)
2243*ef5ccd6cSJohn Marino     {
2244*ef5ccd6cSJohn Marino       char *user_filename;
22455796c8dcSSimon Schubert 
2246*ef5ccd6cSJohn Marino       /* Get the current token again and extract the filename.  */
2247*ef5ccd6cSJohn Marino       token = linespec_lexer_lex_one (parser);
2248*ef5ccd6cSJohn Marino       user_filename = copy_token_string (token);
2249*ef5ccd6cSJohn Marino 
2250*ef5ccd6cSJohn Marino       /* Check if the input is a filename.  */
2251c50c785cSJohn Marino       TRY_CATCH (file_exception, RETURN_MASK_ERROR)
2252c50c785cSJohn Marino 	{
2253*ef5ccd6cSJohn Marino 	  PARSER_RESULT (parser)->file_symtabs
2254*ef5ccd6cSJohn Marino 	    = symtabs_from_filename (user_filename);
2255c50c785cSJohn Marino 	}
2256c50c785cSJohn Marino 
2257c50c785cSJohn Marino       if (file_exception.reason >= 0)
2258c50c785cSJohn Marino 	{
2259*ef5ccd6cSJohn Marino 	  /* Symtabs were found for the file.  Record the filename.  */
2260*ef5ccd6cSJohn Marino 	  PARSER_RESULT (parser)->source_filename = user_filename;
2261c50c785cSJohn Marino 
2262*ef5ccd6cSJohn Marino 	  /* Get the next token.  */
2263*ef5ccd6cSJohn Marino 	  token = linespec_lexer_consume_token (parser);
2264c50c785cSJohn Marino 
2265*ef5ccd6cSJohn Marino 	  /* This is LSTOKEN_COLON; consume it.  */
2266*ef5ccd6cSJohn Marino 	  linespec_lexer_consume_token (parser);
2267c50c785cSJohn Marino 	}
2268c50c785cSJohn Marino       else
2269c50c785cSJohn Marino 	{
2270*ef5ccd6cSJohn Marino 	  /* No symtabs found -- discard user_filename.  */
2271*ef5ccd6cSJohn Marino 	  xfree (user_filename);
2272*ef5ccd6cSJohn Marino 
2273*ef5ccd6cSJohn Marino 	  /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB.  */
2274*ef5ccd6cSJohn Marino 	  VEC_safe_push (symtab_p, PARSER_RESULT (parser)->file_symtabs, NULL);
2275*ef5ccd6cSJohn Marino 	}
2276*ef5ccd6cSJohn Marino     }
2277*ef5ccd6cSJohn Marino   /* If the next token is not EOI, KEYWORD, or COMMA, issue an error.  */
2278*ef5ccd6cSJohn Marino   else if (token.type != LSTOKEN_EOI && token.type != LSTOKEN_KEYWORD
2279*ef5ccd6cSJohn Marino 	   && token.type != LSTOKEN_COMMA)
2280*ef5ccd6cSJohn Marino     {
2281*ef5ccd6cSJohn Marino       /* TOKEN is the _next_ token, not the one currently in the parser.
2282*ef5ccd6cSJohn Marino 	 Consuming the token will give the correct error message.  */
2283*ef5ccd6cSJohn Marino       linespec_lexer_consume_token (parser);
2284*ef5ccd6cSJohn Marino       unexpected_linespec_error (parser);
2285*ef5ccd6cSJohn Marino     }
2286*ef5ccd6cSJohn Marino   else
2287*ef5ccd6cSJohn Marino     {
2288*ef5ccd6cSJohn Marino       /* A NULL entry means to use GLOBAL_DEFAULT_SYMTAB.  */
2289*ef5ccd6cSJohn Marino       VEC_safe_push (symtab_p, PARSER_RESULT (parser)->file_symtabs, NULL);
2290*ef5ccd6cSJohn Marino     }
2291*ef5ccd6cSJohn Marino 
2292*ef5ccd6cSJohn Marino   /* Parse the rest of the linespec.  */
2293*ef5ccd6cSJohn Marino   linespec_parse_basic (parser);
2294*ef5ccd6cSJohn Marino 
2295*ef5ccd6cSJohn Marino   if (PARSER_RESULT (parser)->function_symbols == NULL
2296*ef5ccd6cSJohn Marino       && PARSER_RESULT (parser)->labels.label_symbols == NULL
2297*ef5ccd6cSJohn Marino       && PARSER_RESULT (parser)->line_offset.sign == LINE_OFFSET_UNKNOWN
2298*ef5ccd6cSJohn Marino       && PARSER_RESULT (parser)->minimal_symbols == NULL)
2299*ef5ccd6cSJohn Marino     {
2300*ef5ccd6cSJohn Marino       /* The linespec didn't parse.  Re-throw the file exception if
2301*ef5ccd6cSJohn Marino 	 there was one.  */
2302c50c785cSJohn Marino       if (file_exception.reason < 0)
2303c50c785cSJohn Marino 	throw_exception (file_exception);
2304a45ae5f8SJohn Marino 
2305*ef5ccd6cSJohn Marino       /* Otherwise, the symbol is not found.  */
2306*ef5ccd6cSJohn Marino       symbol_not_found_error (PARSER_RESULT (parser)->function_name,
2307*ef5ccd6cSJohn Marino 			      PARSER_RESULT (parser)->source_filename);
2308c50c785cSJohn Marino     }
23095796c8dcSSimon Schubert 
2310*ef5ccd6cSJohn Marino  convert_to_sals:
23115796c8dcSSimon Schubert 
2312*ef5ccd6cSJohn Marino   /* Get the last token and record how much of the input was parsed,
2313*ef5ccd6cSJohn Marino      if necessary.  */
2314*ef5ccd6cSJohn Marino   token = linespec_lexer_lex_one (parser);
2315*ef5ccd6cSJohn Marino   if (token.type != LSTOKEN_EOI && token.type != LSTOKEN_KEYWORD)
2316*ef5ccd6cSJohn Marino     PARSER_STREAM (parser) = LS_TOKEN_STOKEN (token).ptr;
23175796c8dcSSimon Schubert 
2318*ef5ccd6cSJohn Marino   /* Convert the data in PARSER_RESULT to SALs.  */
2319*ef5ccd6cSJohn Marino   values = convert_linespec_to_sals (PARSER_STATE (parser),
2320*ef5ccd6cSJohn Marino 				     PARSER_RESULT (parser));
2321cf7f2e2dSJohn Marino 
2322a45ae5f8SJohn Marino   return values;
2323a45ae5f8SJohn Marino }
23245796c8dcSSimon Schubert 
2325a45ae5f8SJohn Marino 
2326a45ae5f8SJohn Marino /* A constructor for linespec_state.  */
2327a45ae5f8SJohn Marino 
2328a45ae5f8SJohn Marino static void
linespec_state_constructor(struct linespec_state * self,int flags,const struct language_defn * language,struct symtab * default_symtab,int default_line,struct linespec_result * canonical)2329a45ae5f8SJohn Marino linespec_state_constructor (struct linespec_state *self,
2330*ef5ccd6cSJohn Marino 			    int flags, const struct language_defn *language,
2331a45ae5f8SJohn Marino 			    struct symtab *default_symtab,
2332a45ae5f8SJohn Marino 			    int default_line,
2333a45ae5f8SJohn Marino 			    struct linespec_result *canonical)
2334a45ae5f8SJohn Marino {
2335a45ae5f8SJohn Marino   memset (self, 0, sizeof (*self));
2336*ef5ccd6cSJohn Marino   self->language = language;
2337a45ae5f8SJohn Marino   self->funfirstline = (flags & DECODE_LINE_FUNFIRSTLINE) ? 1 : 0;
2338a45ae5f8SJohn Marino   self->list_mode = (flags & DECODE_LINE_LIST_MODE) ? 1 : 0;
2339a45ae5f8SJohn Marino   self->default_symtab = default_symtab;
2340a45ae5f8SJohn Marino   self->default_line = default_line;
2341a45ae5f8SJohn Marino   self->canonical = canonical;
2342a45ae5f8SJohn Marino   self->program_space = current_program_space;
2343a45ae5f8SJohn Marino   self->addr_set = htab_create_alloc (10, hash_address_entry, eq_address_entry,
2344a45ae5f8SJohn Marino 				      xfree, xcalloc, xfree);
2345a45ae5f8SJohn Marino }
2346a45ae5f8SJohn Marino 
2347*ef5ccd6cSJohn Marino /* Initialize a new linespec parser.  */
2348*ef5ccd6cSJohn Marino 
2349*ef5ccd6cSJohn Marino static void
linespec_parser_new(linespec_parser * parser,int flags,const struct language_defn * language,struct symtab * default_symtab,int default_line,struct linespec_result * canonical)2350*ef5ccd6cSJohn Marino linespec_parser_new (linespec_parser *parser,
2351*ef5ccd6cSJohn Marino 		     int flags, const struct language_defn *language,
2352*ef5ccd6cSJohn Marino 		     struct symtab *default_symtab,
2353*ef5ccd6cSJohn Marino 		     int default_line,
2354*ef5ccd6cSJohn Marino 		     struct linespec_result *canonical)
2355*ef5ccd6cSJohn Marino {
2356*ef5ccd6cSJohn Marino   parser->lexer.current.type = LSTOKEN_CONSUMED;
2357*ef5ccd6cSJohn Marino   memset (PARSER_RESULT (parser), 0, sizeof (struct linespec));
2358*ef5ccd6cSJohn Marino   PARSER_RESULT (parser)->line_offset.sign = LINE_OFFSET_UNKNOWN;
2359*ef5ccd6cSJohn Marino   linespec_state_constructor (PARSER_STATE (parser), flags, language,
2360*ef5ccd6cSJohn Marino 			      default_symtab, default_line, canonical);
2361*ef5ccd6cSJohn Marino }
2362*ef5ccd6cSJohn Marino 
2363a45ae5f8SJohn Marino /* A destructor for linespec_state.  */
2364a45ae5f8SJohn Marino 
2365a45ae5f8SJohn Marino static void
linespec_state_destructor(struct linespec_state * self)2366*ef5ccd6cSJohn Marino linespec_state_destructor (struct linespec_state *self)
2367a45ae5f8SJohn Marino {
2368a45ae5f8SJohn Marino   htab_delete (self->addr_set);
2369a45ae5f8SJohn Marino }
2370a45ae5f8SJohn Marino 
2371*ef5ccd6cSJohn Marino /* Delete a linespec parser.  */
2372*ef5ccd6cSJohn Marino 
2373*ef5ccd6cSJohn Marino static void
linespec_parser_delete(void * arg)2374*ef5ccd6cSJohn Marino linespec_parser_delete (void *arg)
2375*ef5ccd6cSJohn Marino {
2376*ef5ccd6cSJohn Marino   linespec_parser *parser = (linespec_parser *) arg;
2377*ef5ccd6cSJohn Marino 
2378*ef5ccd6cSJohn Marino   xfree ((char *) PARSER_RESULT (parser)->expression);
2379*ef5ccd6cSJohn Marino   xfree ((char *) PARSER_RESULT (parser)->source_filename);
2380*ef5ccd6cSJohn Marino   xfree ((char *) PARSER_RESULT (parser)->label_name);
2381*ef5ccd6cSJohn Marino   xfree ((char *) PARSER_RESULT (parser)->function_name);
2382*ef5ccd6cSJohn Marino 
2383*ef5ccd6cSJohn Marino   if (PARSER_RESULT (parser)->file_symtabs != NULL)
2384*ef5ccd6cSJohn Marino     VEC_free (symtab_p, PARSER_RESULT (parser)->file_symtabs);
2385*ef5ccd6cSJohn Marino 
2386*ef5ccd6cSJohn Marino   if (PARSER_RESULT (parser)->function_symbols != NULL)
2387*ef5ccd6cSJohn Marino     VEC_free (symbolp, PARSER_RESULT (parser)->function_symbols);
2388*ef5ccd6cSJohn Marino 
2389*ef5ccd6cSJohn Marino   if (PARSER_RESULT (parser)->minimal_symbols != NULL)
2390*ef5ccd6cSJohn Marino     VEC_free (minsym_and_objfile_d, PARSER_RESULT (parser)->minimal_symbols);
2391*ef5ccd6cSJohn Marino 
2392*ef5ccd6cSJohn Marino   if (PARSER_RESULT (parser)->labels.label_symbols != NULL)
2393*ef5ccd6cSJohn Marino     VEC_free (symbolp, PARSER_RESULT (parser)->labels.label_symbols);
2394*ef5ccd6cSJohn Marino 
2395*ef5ccd6cSJohn Marino   if (PARSER_RESULT (parser)->labels.function_symbols != NULL)
2396*ef5ccd6cSJohn Marino     VEC_free (symbolp, PARSER_RESULT (parser)->labels.function_symbols);
2397*ef5ccd6cSJohn Marino 
2398*ef5ccd6cSJohn Marino   linespec_state_destructor (PARSER_STATE (parser));
2399*ef5ccd6cSJohn Marino }
2400*ef5ccd6cSJohn Marino 
2401a45ae5f8SJohn Marino /* See linespec.h.  */
2402a45ae5f8SJohn Marino 
2403a45ae5f8SJohn Marino void
decode_line_full(char ** argptr,int flags,struct symtab * default_symtab,int default_line,struct linespec_result * canonical,const char * select_mode,const char * filter)2404a45ae5f8SJohn Marino decode_line_full (char **argptr, int flags,
2405a45ae5f8SJohn Marino 		  struct symtab *default_symtab,
2406a45ae5f8SJohn Marino 		  int default_line, struct linespec_result *canonical,
2407a45ae5f8SJohn Marino 		  const char *select_mode,
2408a45ae5f8SJohn Marino 		  const char *filter)
2409a45ae5f8SJohn Marino {
2410a45ae5f8SJohn Marino   struct symtabs_and_lines result;
2411a45ae5f8SJohn Marino   struct cleanup *cleanups;
2412a45ae5f8SJohn Marino   VEC (const_char_ptr) *filters = NULL;
2413*ef5ccd6cSJohn Marino   linespec_parser parser;
2414*ef5ccd6cSJohn Marino   struct linespec_state *state;
2415a45ae5f8SJohn Marino 
2416a45ae5f8SJohn Marino   gdb_assert (canonical != NULL);
2417a45ae5f8SJohn Marino   /* The filter only makes sense for 'all'.  */
2418a45ae5f8SJohn Marino   gdb_assert (filter == NULL || select_mode == multiple_symbols_all);
2419a45ae5f8SJohn Marino   gdb_assert (select_mode == NULL
2420a45ae5f8SJohn Marino 	      || select_mode == multiple_symbols_all
2421a45ae5f8SJohn Marino 	      || select_mode == multiple_symbols_ask
2422a45ae5f8SJohn Marino 	      || select_mode == multiple_symbols_cancel);
2423a45ae5f8SJohn Marino   gdb_assert ((flags & DECODE_LINE_LIST_MODE) == 0);
2424a45ae5f8SJohn Marino 
2425*ef5ccd6cSJohn Marino   linespec_parser_new (&parser, flags, current_language, default_symtab,
2426*ef5ccd6cSJohn Marino 		       default_line, canonical);
2427*ef5ccd6cSJohn Marino   cleanups = make_cleanup (linespec_parser_delete, &parser);
2428a45ae5f8SJohn Marino   save_current_program_space ();
2429a45ae5f8SJohn Marino 
2430*ef5ccd6cSJohn Marino   result = parse_linespec (&parser, argptr);
2431*ef5ccd6cSJohn Marino   state = PARSER_STATE (&parser);
2432a45ae5f8SJohn Marino 
2433a45ae5f8SJohn Marino   gdb_assert (result.nelts == 1 || canonical->pre_expanded);
2434a45ae5f8SJohn Marino   gdb_assert (canonical->addr_string != NULL);
2435a45ae5f8SJohn Marino   canonical->pre_expanded = 1;
2436a45ae5f8SJohn Marino 
2437*ef5ccd6cSJohn Marino   /* Arrange for allocated canonical names to be freed.  */
2438a45ae5f8SJohn Marino   if (result.nelts > 0)
2439a45ae5f8SJohn Marino     {
2440a45ae5f8SJohn Marino       int i;
2441a45ae5f8SJohn Marino 
2442*ef5ccd6cSJohn Marino       make_cleanup (xfree, state->canonical_names);
2443a45ae5f8SJohn Marino       for (i = 0; i < result.nelts; ++i)
2444a45ae5f8SJohn Marino 	{
2445*ef5ccd6cSJohn Marino 	  gdb_assert (state->canonical_names[i].suffix != NULL);
2446*ef5ccd6cSJohn Marino 	  make_cleanup (xfree, state->canonical_names[i].suffix);
2447a45ae5f8SJohn Marino 	}
2448a45ae5f8SJohn Marino     }
2449a45ae5f8SJohn Marino 
2450a45ae5f8SJohn Marino   if (select_mode == NULL)
2451a45ae5f8SJohn Marino     {
2452a45ae5f8SJohn Marino       if (ui_out_is_mi_like_p (interp_ui_out (top_level_interpreter ())))
2453a45ae5f8SJohn Marino 	select_mode = multiple_symbols_all;
2454a45ae5f8SJohn Marino       else
2455a45ae5f8SJohn Marino 	select_mode = multiple_symbols_select_mode ();
2456a45ae5f8SJohn Marino     }
2457a45ae5f8SJohn Marino 
2458a45ae5f8SJohn Marino   if (select_mode == multiple_symbols_all)
2459a45ae5f8SJohn Marino     {
2460a45ae5f8SJohn Marino       if (filter != NULL)
2461a45ae5f8SJohn Marino 	{
2462a45ae5f8SJohn Marino 	  make_cleanup (VEC_cleanup (const_char_ptr), &filters);
2463a45ae5f8SJohn Marino 	  VEC_safe_push (const_char_ptr, filters, filter);
2464*ef5ccd6cSJohn Marino 	  filter_results (state, &result, filters);
2465a45ae5f8SJohn Marino 	}
2466a45ae5f8SJohn Marino       else
2467*ef5ccd6cSJohn Marino 	convert_results_to_lsals (state, &result);
2468a45ae5f8SJohn Marino     }
2469a45ae5f8SJohn Marino   else
2470*ef5ccd6cSJohn Marino     decode_line_2 (state, &result, select_mode);
2471a45ae5f8SJohn Marino 
2472a45ae5f8SJohn Marino   do_cleanups (cleanups);
2473a45ae5f8SJohn Marino }
2474a45ae5f8SJohn Marino 
2475*ef5ccd6cSJohn Marino /* See linespec.h.  */
2476*ef5ccd6cSJohn Marino 
2477a45ae5f8SJohn Marino struct symtabs_and_lines
decode_line_1(char ** argptr,int flags,struct symtab * default_symtab,int default_line)2478a45ae5f8SJohn Marino decode_line_1 (char **argptr, int flags,
2479a45ae5f8SJohn Marino 	       struct symtab *default_symtab,
2480a45ae5f8SJohn Marino 	       int default_line)
2481a45ae5f8SJohn Marino {
2482a45ae5f8SJohn Marino   struct symtabs_and_lines result;
2483*ef5ccd6cSJohn Marino   linespec_parser parser;
2484a45ae5f8SJohn Marino   struct cleanup *cleanups;
2485a45ae5f8SJohn Marino 
2486*ef5ccd6cSJohn Marino   linespec_parser_new (&parser, flags, current_language, default_symtab,
2487*ef5ccd6cSJohn Marino 		       default_line, NULL);
2488*ef5ccd6cSJohn Marino   cleanups = make_cleanup (linespec_parser_delete, &parser);
2489a45ae5f8SJohn Marino   save_current_program_space ();
2490a45ae5f8SJohn Marino 
2491*ef5ccd6cSJohn Marino   result = parse_linespec (&parser, argptr);
2492*ef5ccd6cSJohn Marino 
2493a45ae5f8SJohn Marino   do_cleanups (cleanups);
2494a45ae5f8SJohn Marino   return result;
24955796c8dcSSimon Schubert }
24965796c8dcSSimon Schubert 
2497*ef5ccd6cSJohn Marino /* See linespec.h.  */
2498*ef5ccd6cSJohn Marino 
2499*ef5ccd6cSJohn Marino struct symtabs_and_lines
decode_line_with_current_source(char * string,int flags)2500*ef5ccd6cSJohn Marino decode_line_with_current_source (char *string, int flags)
2501*ef5ccd6cSJohn Marino {
2502*ef5ccd6cSJohn Marino   struct symtabs_and_lines sals;
2503*ef5ccd6cSJohn Marino   struct symtab_and_line cursal;
2504*ef5ccd6cSJohn Marino 
2505*ef5ccd6cSJohn Marino   if (string == 0)
2506*ef5ccd6cSJohn Marino     error (_("Empty line specification."));
2507*ef5ccd6cSJohn Marino 
2508*ef5ccd6cSJohn Marino   /* We use whatever is set as the current source line.  We do not try
2509*ef5ccd6cSJohn Marino      and get a default source symtab+line or it will recursively call us!  */
2510*ef5ccd6cSJohn Marino   cursal = get_current_source_symtab_and_line ();
2511*ef5ccd6cSJohn Marino 
2512*ef5ccd6cSJohn Marino   sals = decode_line_1 (&string, flags,
2513*ef5ccd6cSJohn Marino 			cursal.symtab, cursal.line);
2514*ef5ccd6cSJohn Marino 
2515*ef5ccd6cSJohn Marino   if (*string)
2516*ef5ccd6cSJohn Marino     error (_("Junk at end of line specification: %s"), string);
2517*ef5ccd6cSJohn Marino   return sals;
2518*ef5ccd6cSJohn Marino }
2519*ef5ccd6cSJohn Marino 
2520*ef5ccd6cSJohn Marino /* See linespec.h.  */
2521*ef5ccd6cSJohn Marino 
2522*ef5ccd6cSJohn Marino struct symtabs_and_lines
decode_line_with_last_displayed(char * string,int flags)2523*ef5ccd6cSJohn Marino decode_line_with_last_displayed (char *string, int flags)
2524*ef5ccd6cSJohn Marino {
2525*ef5ccd6cSJohn Marino   struct symtabs_and_lines sals;
2526*ef5ccd6cSJohn Marino 
2527*ef5ccd6cSJohn Marino   if (string == 0)
2528*ef5ccd6cSJohn Marino     error (_("Empty line specification."));
2529*ef5ccd6cSJohn Marino 
2530*ef5ccd6cSJohn Marino   if (last_displayed_sal_is_valid ())
2531*ef5ccd6cSJohn Marino     sals = decode_line_1 (&string, flags,
2532*ef5ccd6cSJohn Marino 			  get_last_displayed_symtab (),
2533*ef5ccd6cSJohn Marino 			  get_last_displayed_line ());
2534*ef5ccd6cSJohn Marino   else
2535*ef5ccd6cSJohn Marino     sals = decode_line_1 (&string, flags, (struct symtab *) NULL, 0);
2536*ef5ccd6cSJohn Marino 
2537*ef5ccd6cSJohn Marino   if (*string)
2538*ef5ccd6cSJohn Marino     error (_("Junk at end of line specification: %s"), string);
2539*ef5ccd6cSJohn Marino   return sals;
2540*ef5ccd6cSJohn Marino }
2541*ef5ccd6cSJohn Marino 
25425796c8dcSSimon Schubert 
25435796c8dcSSimon Schubert 
25445796c8dcSSimon Schubert /* First, some functions to initialize stuff at the beggining of the
25455796c8dcSSimon Schubert    function.  */
25465796c8dcSSimon Schubert 
25475796c8dcSSimon Schubert static void
initialize_defaults(struct symtab ** default_symtab,int * default_line)25485796c8dcSSimon Schubert initialize_defaults (struct symtab **default_symtab, int *default_line)
25495796c8dcSSimon Schubert {
25505796c8dcSSimon Schubert   if (*default_symtab == 0)
25515796c8dcSSimon Schubert     {
25525796c8dcSSimon Schubert       /* Use whatever we have for the default source line.  We don't use
25535796c8dcSSimon Schubert          get_current_or_default_symtab_and_line as it can recurse and call
25545796c8dcSSimon Schubert 	 us back!  */
25555796c8dcSSimon Schubert       struct symtab_and_line cursal =
25565796c8dcSSimon Schubert 	get_current_source_symtab_and_line ();
25575796c8dcSSimon Schubert 
25585796c8dcSSimon Schubert       *default_symtab = cursal.symtab;
25595796c8dcSSimon Schubert       *default_line = cursal.line;
25605796c8dcSSimon Schubert     }
25615796c8dcSSimon Schubert }
25625796c8dcSSimon Schubert 
25635796c8dcSSimon Schubert 
25645796c8dcSSimon Schubert 
2565*ef5ccd6cSJohn Marino /* Evaluate the expression pointed to by EXP_PTR into a CORE_ADDR,
2566*ef5ccd6cSJohn Marino    advancing EXP_PTR past any parsed text.  */
25675796c8dcSSimon Schubert 
2568*ef5ccd6cSJohn Marino static CORE_ADDR
linespec_expression_to_pc(const char ** exp_ptr)2569*ef5ccd6cSJohn Marino linespec_expression_to_pc (const char **exp_ptr)
25705796c8dcSSimon Schubert {
2571a45ae5f8SJohn Marino   if (current_program_space->executing_startup)
2572a45ae5f8SJohn Marino     /* The error message doesn't really matter, because this case
2573a45ae5f8SJohn Marino        should only hit during breakpoint reset.  */
2574a45ae5f8SJohn Marino     throw_error (NOT_FOUND_ERROR, _("cannot evaluate expressions while "
2575a45ae5f8SJohn Marino 				    "program space is in startup"));
25765796c8dcSSimon Schubert 
2577*ef5ccd6cSJohn Marino   (*exp_ptr)++;
2578*ef5ccd6cSJohn Marino   return value_as_address (parse_to_comma_and_eval (exp_ptr));
25795796c8dcSSimon Schubert }
25805796c8dcSSimon Schubert 
25815796c8dcSSimon Schubert 
25825796c8dcSSimon Schubert 
25835796c8dcSSimon Schubert /* Here's where we recognise an Objective-C Selector.  An Objective C
25845796c8dcSSimon Schubert    selector may be implemented by more than one class, therefore it
25855796c8dcSSimon Schubert    may represent more than one method/function.  This gives us a
25865796c8dcSSimon Schubert    situation somewhat analogous to C++ overloading.  If there's more
25875796c8dcSSimon Schubert    than one method that could represent the selector, then use some of
25885796c8dcSSimon Schubert    the existing C++ code to let the user choose one.  */
25895796c8dcSSimon Schubert 
2590a45ae5f8SJohn Marino static struct symtabs_and_lines
decode_objc(struct linespec_state * self,linespec_p ls,char ** argptr)2591*ef5ccd6cSJohn Marino decode_objc (struct linespec_state *self, linespec_p ls, char **argptr)
25925796c8dcSSimon Schubert {
2593a45ae5f8SJohn Marino   struct collect_info info;
2594a45ae5f8SJohn Marino   VEC (const_char_ptr) *symbol_names = NULL;
2595*ef5ccd6cSJohn Marino   struct symtabs_and_lines values;
2596a45ae5f8SJohn Marino   char *new_argptr;
2597a45ae5f8SJohn Marino   struct cleanup *cleanup = make_cleanup (VEC_cleanup (const_char_ptr),
2598a45ae5f8SJohn Marino 					  &symbol_names);
25995796c8dcSSimon Schubert 
2600a45ae5f8SJohn Marino   info.state = self;
2601*ef5ccd6cSJohn Marino   info.file_symtabs = NULL;
2602*ef5ccd6cSJohn Marino   VEC_safe_push (symtab_p, info.file_symtabs, NULL);
2603*ef5ccd6cSJohn Marino   make_cleanup (VEC_cleanup (symtab_p), &info.file_symtabs);
2604*ef5ccd6cSJohn Marino   info.result.symbols = NULL;
2605*ef5ccd6cSJohn Marino   info.result.minimal_symbols = NULL;
2606*ef5ccd6cSJohn Marino   values.nelts = 0;
2607*ef5ccd6cSJohn Marino   values.sals = NULL;
26085796c8dcSSimon Schubert 
2609a45ae5f8SJohn Marino   new_argptr = find_imps (*argptr, &symbol_names);
2610a45ae5f8SJohn Marino   if (VEC_empty (const_char_ptr, symbol_names))
26115796c8dcSSimon Schubert     {
2612a45ae5f8SJohn Marino       do_cleanups (cleanup);
2613*ef5ccd6cSJohn Marino       return values;
26145796c8dcSSimon Schubert     }
26155796c8dcSSimon Schubert 
2616a45ae5f8SJohn Marino   add_all_symbol_names_from_pspace (&info, NULL, symbol_names);
26175796c8dcSSimon Schubert 
2618*ef5ccd6cSJohn Marino   if (!VEC_empty (symbolp, info.result.symbols)
2619*ef5ccd6cSJohn Marino       || !VEC_empty (minsym_and_objfile_d, info.result.minimal_symbols))
26205796c8dcSSimon Schubert     {
2621a45ae5f8SJohn Marino       char *saved_arg;
2622a45ae5f8SJohn Marino 
2623a45ae5f8SJohn Marino       saved_arg = alloca (new_argptr - *argptr + 1);
2624a45ae5f8SJohn Marino       memcpy (saved_arg, *argptr, new_argptr - *argptr);
2625a45ae5f8SJohn Marino       saved_arg[new_argptr - *argptr] = '\0';
2626a45ae5f8SJohn Marino 
2627*ef5ccd6cSJohn Marino       ls->function_name = xstrdup (saved_arg);
2628*ef5ccd6cSJohn Marino       ls->function_symbols = info.result.symbols;
2629*ef5ccd6cSJohn Marino       ls->minimal_symbols = info.result.minimal_symbols;
2630*ef5ccd6cSJohn Marino       values = convert_linespec_to_sals (self, ls);
2631*ef5ccd6cSJohn Marino 
2632a45ae5f8SJohn Marino       if (self->canonical)
26335796c8dcSSimon Schubert 	{
2634a45ae5f8SJohn Marino 	  self->canonical->pre_expanded = 1;
2635*ef5ccd6cSJohn Marino 	  if (ls->source_filename)
2636a45ae5f8SJohn Marino 	    self->canonical->addr_string
2637*ef5ccd6cSJohn Marino 	      = xstrprintf ("%s:%s", ls->source_filename, saved_arg);
26385796c8dcSSimon Schubert 	  else
2639a45ae5f8SJohn Marino 	    self->canonical->addr_string = xstrdup (saved_arg);
26405796c8dcSSimon Schubert 	}
26415796c8dcSSimon Schubert     }
26425796c8dcSSimon Schubert 
2643a45ae5f8SJohn Marino   *argptr = new_argptr;
26445796c8dcSSimon Schubert 
2645a45ae5f8SJohn Marino   do_cleanups (cleanup);
26465796c8dcSSimon Schubert 
2647a45ae5f8SJohn Marino   return values;
2648a45ae5f8SJohn Marino }
2649c50c785cSJohn Marino 
2650a45ae5f8SJohn Marino /* An instance of this type is used when collecting prefix symbols for
2651a45ae5f8SJohn Marino    decode_compound.  */
26525796c8dcSSimon Schubert 
2653a45ae5f8SJohn Marino struct decode_compound_collector
2654c50c785cSJohn Marino {
2655a45ae5f8SJohn Marino   /* The result vector.  */
2656a45ae5f8SJohn Marino   VEC (symbolp) *symbols;
26575796c8dcSSimon Schubert 
2658a45ae5f8SJohn Marino   /* A hash table of all symbols we found.  We use this to avoid
2659a45ae5f8SJohn Marino      adding any symbol more than once.  */
2660a45ae5f8SJohn Marino   htab_t unique_syms;
2661a45ae5f8SJohn Marino };
2662a45ae5f8SJohn Marino 
2663a45ae5f8SJohn Marino /* A callback for iterate_over_symbols that is used by
2664a45ae5f8SJohn Marino    lookup_prefix_sym to collect type symbols.  */
2665a45ae5f8SJohn Marino 
2666a45ae5f8SJohn Marino static int
collect_one_symbol(struct symbol * sym,void * d)2667a45ae5f8SJohn Marino collect_one_symbol (struct symbol *sym, void *d)
2668a45ae5f8SJohn Marino {
2669a45ae5f8SJohn Marino   struct decode_compound_collector *collector = d;
2670a45ae5f8SJohn Marino   void **slot;
2671a45ae5f8SJohn Marino   struct type *t;
2672a45ae5f8SJohn Marino 
2673a45ae5f8SJohn Marino   if (SYMBOL_CLASS (sym) != LOC_TYPEDEF)
2674*ef5ccd6cSJohn Marino     return 1; /* Continue iterating.  */
2675a45ae5f8SJohn Marino 
2676a45ae5f8SJohn Marino   t = SYMBOL_TYPE (sym);
2677a45ae5f8SJohn Marino   CHECK_TYPEDEF (t);
2678a45ae5f8SJohn Marino   if (TYPE_CODE (t) != TYPE_CODE_STRUCT
2679a45ae5f8SJohn Marino       && TYPE_CODE (t) != TYPE_CODE_UNION
2680a45ae5f8SJohn Marino       && TYPE_CODE (t) != TYPE_CODE_NAMESPACE)
2681*ef5ccd6cSJohn Marino     return 1; /* Continue iterating.  */
2682a45ae5f8SJohn Marino 
2683a45ae5f8SJohn Marino   slot = htab_find_slot (collector->unique_syms, sym, INSERT);
2684a45ae5f8SJohn Marino   if (!*slot)
2685a45ae5f8SJohn Marino     {
2686a45ae5f8SJohn Marino       *slot = sym;
2687a45ae5f8SJohn Marino       VEC_safe_push (symbolp, collector->symbols, sym);
2688c50c785cSJohn Marino     }
2689c50c785cSJohn Marino 
2690*ef5ccd6cSJohn Marino   return 1; /* Continue iterating.  */
26915796c8dcSSimon Schubert }
26925796c8dcSSimon Schubert 
2693*ef5ccd6cSJohn Marino /* Return any symbols corresponding to CLASS_NAME in FILE_SYMTABS.  */
26945796c8dcSSimon Schubert 
VEC(symbolp)2695a45ae5f8SJohn Marino static VEC (symbolp) *
2696*ef5ccd6cSJohn Marino lookup_prefix_sym (struct linespec_state *state, VEC (symtab_p) *file_symtabs,
2697*ef5ccd6cSJohn Marino 		   const char *class_name)
26985796c8dcSSimon Schubert {
2699a45ae5f8SJohn Marino   int ix;
2700a45ae5f8SJohn Marino   struct symtab *elt;
2701a45ae5f8SJohn Marino   struct decode_compound_collector collector;
2702a45ae5f8SJohn Marino   struct cleanup *outer;
2703a45ae5f8SJohn Marino   struct cleanup *cleanup;
27045796c8dcSSimon Schubert 
2705a45ae5f8SJohn Marino   collector.symbols = NULL;
2706*ef5ccd6cSJohn Marino   outer = make_cleanup (VEC_cleanup (symbolp), &collector.symbols);
2707a45ae5f8SJohn Marino 
2708a45ae5f8SJohn Marino   collector.unique_syms = htab_create_alloc (1, htab_hash_pointer,
2709a45ae5f8SJohn Marino 					     htab_eq_pointer, NULL,
2710a45ae5f8SJohn Marino 					     xcalloc, xfree);
2711a45ae5f8SJohn Marino   cleanup = make_cleanup_htab_delete (collector.unique_syms);
2712a45ae5f8SJohn Marino 
2713a45ae5f8SJohn Marino   for (ix = 0; VEC_iterate (symtab_p, file_symtabs, ix, elt); ++ix)
2714cf7f2e2dSJohn Marino     {
2715a45ae5f8SJohn Marino       if (elt == NULL)
2716cf7f2e2dSJohn Marino 	{
2717*ef5ccd6cSJohn Marino 	  iterate_over_all_matching_symtabs (state, class_name, STRUCT_DOMAIN,
2718a45ae5f8SJohn Marino 					     collect_one_symbol, &collector,
2719*ef5ccd6cSJohn Marino 					     NULL, 0);
2720*ef5ccd6cSJohn Marino 	  iterate_over_all_matching_symtabs (state, class_name, VAR_DOMAIN,
2721a45ae5f8SJohn Marino 					     collect_one_symbol, &collector,
2722*ef5ccd6cSJohn Marino 					     NULL, 0);
2723a45ae5f8SJohn Marino 	}
2724a45ae5f8SJohn Marino       else
2725a45ae5f8SJohn Marino 	{
2726a45ae5f8SJohn Marino 	  /* Program spaces that are executing startup should have
2727a45ae5f8SJohn Marino 	     been filtered out earlier.  */
2728a45ae5f8SJohn Marino 	  gdb_assert (!SYMTAB_PSPACE (elt)->executing_startup);
2729a45ae5f8SJohn Marino 	  set_current_program_space (SYMTAB_PSPACE (elt));
2730*ef5ccd6cSJohn Marino 	  iterate_over_file_blocks (elt, class_name, STRUCT_DOMAIN,
2731a45ae5f8SJohn Marino 				    collect_one_symbol, &collector);
2732*ef5ccd6cSJohn Marino 	  iterate_over_file_blocks (elt, class_name, VAR_DOMAIN,
2733a45ae5f8SJohn Marino 				    collect_one_symbol, &collector);
2734cf7f2e2dSJohn Marino 	}
2735cf7f2e2dSJohn Marino     }
2736cf7f2e2dSJohn Marino 
2737a45ae5f8SJohn Marino   do_cleanups (cleanup);
2738a45ae5f8SJohn Marino   discard_cleanups (outer);
2739a45ae5f8SJohn Marino   return collector.symbols;
27405796c8dcSSimon Schubert }
27415796c8dcSSimon Schubert 
2742a45ae5f8SJohn Marino /* A qsort comparison function for symbols.  The resulting order does
2743a45ae5f8SJohn Marino    not actually matter; we just need to be able to sort them so that
2744a45ae5f8SJohn Marino    symbols with the same program space end up next to each other.  */
2745a45ae5f8SJohn Marino 
2746a45ae5f8SJohn Marino static int
compare_symbols(const void * a,const void * b)2747a45ae5f8SJohn Marino compare_symbols (const void *a, const void *b)
2748a45ae5f8SJohn Marino {
2749a45ae5f8SJohn Marino   struct symbol * const *sa = a;
2750a45ae5f8SJohn Marino   struct symbol * const *sb = b;
2751a45ae5f8SJohn Marino   uintptr_t uia, uib;
2752a45ae5f8SJohn Marino 
2753a45ae5f8SJohn Marino   uia = (uintptr_t) SYMTAB_PSPACE (SYMBOL_SYMTAB (*sa));
2754a45ae5f8SJohn Marino   uib = (uintptr_t) SYMTAB_PSPACE (SYMBOL_SYMTAB (*sb));
2755a45ae5f8SJohn Marino 
2756a45ae5f8SJohn Marino   if (uia < uib)
2757a45ae5f8SJohn Marino     return -1;
2758a45ae5f8SJohn Marino   if (uia > uib)
2759a45ae5f8SJohn Marino     return 1;
2760a45ae5f8SJohn Marino 
2761a45ae5f8SJohn Marino   uia = (uintptr_t) *sa;
2762a45ae5f8SJohn Marino   uib = (uintptr_t) *sb;
2763a45ae5f8SJohn Marino 
2764a45ae5f8SJohn Marino   if (uia < uib)
2765a45ae5f8SJohn Marino     return -1;
2766a45ae5f8SJohn Marino   if (uia > uib)
2767a45ae5f8SJohn Marino     return 1;
2768a45ae5f8SJohn Marino 
2769a45ae5f8SJohn Marino   return 0;
2770a45ae5f8SJohn Marino }
2771a45ae5f8SJohn Marino 
2772*ef5ccd6cSJohn Marino /* Like compare_symbols but for minimal symbols.  */
2773*ef5ccd6cSJohn Marino 
2774*ef5ccd6cSJohn Marino static int
compare_msymbols(const void * a,const void * b)2775*ef5ccd6cSJohn Marino compare_msymbols (const void *a, const void *b)
2776*ef5ccd6cSJohn Marino {
2777*ef5ccd6cSJohn Marino   const struct minsym_and_objfile *sa = a;
2778*ef5ccd6cSJohn Marino   const struct minsym_and_objfile *sb = b;
2779*ef5ccd6cSJohn Marino   uintptr_t uia, uib;
2780*ef5ccd6cSJohn Marino 
2781*ef5ccd6cSJohn Marino   uia = (uintptr_t) sa->objfile->pspace;
2782*ef5ccd6cSJohn Marino   uib = (uintptr_t) sa->objfile->pspace;
2783*ef5ccd6cSJohn Marino 
2784*ef5ccd6cSJohn Marino   if (uia < uib)
2785*ef5ccd6cSJohn Marino     return -1;
2786*ef5ccd6cSJohn Marino   if (uia > uib)
2787*ef5ccd6cSJohn Marino     return 1;
2788*ef5ccd6cSJohn Marino 
2789*ef5ccd6cSJohn Marino   uia = (uintptr_t) sa->minsym;
2790*ef5ccd6cSJohn Marino   uib = (uintptr_t) sb->minsym;
2791*ef5ccd6cSJohn Marino 
2792*ef5ccd6cSJohn Marino   if (uia < uib)
2793*ef5ccd6cSJohn Marino     return -1;
2794*ef5ccd6cSJohn Marino   if (uia > uib)
2795*ef5ccd6cSJohn Marino     return 1;
2796*ef5ccd6cSJohn Marino 
2797*ef5ccd6cSJohn Marino   return 0;
2798*ef5ccd6cSJohn Marino }
2799*ef5ccd6cSJohn Marino 
2800a45ae5f8SJohn Marino /* Look for all the matching instances of each symbol in NAMES.  Only
2801a45ae5f8SJohn Marino    instances from PSPACE are considered; other program spaces are
2802a45ae5f8SJohn Marino    handled by our caller.  If PSPACE is NULL, then all program spaces
2803a45ae5f8SJohn Marino    are considered.  Results are stored into INFO.  */
2804a45ae5f8SJohn Marino 
2805a45ae5f8SJohn Marino static void
add_all_symbol_names_from_pspace(struct collect_info * info,struct program_space * pspace,VEC (const_char_ptr)* names)2806a45ae5f8SJohn Marino add_all_symbol_names_from_pspace (struct collect_info *info,
2807a45ae5f8SJohn Marino 				  struct program_space *pspace,
2808a45ae5f8SJohn Marino 				  VEC (const_char_ptr) *names)
2809a45ae5f8SJohn Marino {
2810a45ae5f8SJohn Marino   int ix;
2811a45ae5f8SJohn Marino   const char *iter;
2812a45ae5f8SJohn Marino 
2813a45ae5f8SJohn Marino   for (ix = 0; VEC_iterate (const_char_ptr, names, ix, iter); ++ix)
2814a45ae5f8SJohn Marino     add_matching_symbols_to_info (iter, info, pspace);
2815a45ae5f8SJohn Marino }
2816a45ae5f8SJohn Marino 
2817a45ae5f8SJohn Marino static void
find_superclass_methods(VEC (typep)* superclasses,const char * name,VEC (const_char_ptr)** result_names)2818a45ae5f8SJohn Marino find_superclass_methods (VEC (typep) *superclasses,
2819a45ae5f8SJohn Marino 			 const char *name,
2820a45ae5f8SJohn Marino 			 VEC (const_char_ptr) **result_names)
2821a45ae5f8SJohn Marino {
2822a45ae5f8SJohn Marino   int old_len = VEC_length (const_char_ptr, *result_names);
2823a45ae5f8SJohn Marino   VEC (typep) *iter_classes;
2824a45ae5f8SJohn Marino   struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
2825a45ae5f8SJohn Marino 
2826a45ae5f8SJohn Marino   iter_classes = superclasses;
2827a45ae5f8SJohn Marino   while (1)
2828a45ae5f8SJohn Marino     {
2829a45ae5f8SJohn Marino       VEC (typep) *new_supers = NULL;
2830a45ae5f8SJohn Marino       int ix;
2831a45ae5f8SJohn Marino       struct type *t;
2832a45ae5f8SJohn Marino 
2833a45ae5f8SJohn Marino       make_cleanup (VEC_cleanup (typep), &new_supers);
2834a45ae5f8SJohn Marino       for (ix = 0; VEC_iterate (typep, iter_classes, ix, t); ++ix)
2835a45ae5f8SJohn Marino 	find_methods (t, name, result_names, &new_supers);
2836a45ae5f8SJohn Marino 
2837a45ae5f8SJohn Marino       if (VEC_length (const_char_ptr, *result_names) != old_len
2838a45ae5f8SJohn Marino 	  || VEC_empty (typep, new_supers))
2839a45ae5f8SJohn Marino 	break;
2840a45ae5f8SJohn Marino 
2841a45ae5f8SJohn Marino       iter_classes = new_supers;
2842a45ae5f8SJohn Marino     }
2843a45ae5f8SJohn Marino 
2844a45ae5f8SJohn Marino   do_cleanups (cleanup);
2845a45ae5f8SJohn Marino }
2846a45ae5f8SJohn Marino 
2847*ef5ccd6cSJohn Marino /* This finds the method METHOD_NAME in the class CLASS_NAME whose type is
2848*ef5ccd6cSJohn Marino    given by one of the symbols in SYM_CLASSES.  Matches are returned
2849*ef5ccd6cSJohn Marino    in SYMBOLS (for debug symbols) and MINSYMS (for minimal symbols).  */
28505796c8dcSSimon Schubert 
2851*ef5ccd6cSJohn Marino static void
find_method(struct linespec_state * self,VEC (symtab_p)* file_symtabs,const char * class_name,const char * method_name,VEC (symbolp)* sym_classes,VEC (symbolp)** symbols,VEC (minsym_and_objfile_d)** minsyms)2852*ef5ccd6cSJohn Marino find_method (struct linespec_state *self, VEC (symtab_p) *file_symtabs,
2853*ef5ccd6cSJohn Marino 	     const char *class_name, const char *method_name,
2854*ef5ccd6cSJohn Marino 	     VEC (symbolp) *sym_classes, VEC (symbolp) **symbols,
2855*ef5ccd6cSJohn Marino 	     VEC (minsym_and_objfile_d) **minsyms)
28565796c8dcSSimon Schubert {
2857a45ae5f8SJohn Marino   struct symbol *sym;
2858a45ae5f8SJohn Marino   struct cleanup *cleanup = make_cleanup (null_cleanup, NULL);
2859a45ae5f8SJohn Marino   int ix;
2860a45ae5f8SJohn Marino   int last_result_len;
2861a45ae5f8SJohn Marino   VEC (typep) *superclass_vec;
2862a45ae5f8SJohn Marino   VEC (const_char_ptr) *result_names;
2863a45ae5f8SJohn Marino   struct collect_info info;
2864cf7f2e2dSJohn Marino 
2865a45ae5f8SJohn Marino   /* Sort symbols so that symbols with the same program space are next
2866a45ae5f8SJohn Marino      to each other.  */
2867a45ae5f8SJohn Marino   qsort (VEC_address (symbolp, sym_classes),
2868a45ae5f8SJohn Marino 	 VEC_length (symbolp, sym_classes),
2869a45ae5f8SJohn Marino 	 sizeof (symbolp),
2870a45ae5f8SJohn Marino 	 compare_symbols);
2871a45ae5f8SJohn Marino 
2872a45ae5f8SJohn Marino   info.state = self;
2873*ef5ccd6cSJohn Marino   info.file_symtabs = file_symtabs;
2874*ef5ccd6cSJohn Marino   info.result.symbols = NULL;
2875*ef5ccd6cSJohn Marino   info.result.minimal_symbols = NULL;
2876a45ae5f8SJohn Marino 
2877a45ae5f8SJohn Marino   /* Iterate over all the types, looking for the names of existing
2878*ef5ccd6cSJohn Marino      methods matching METHOD_NAME.  If we cannot find a direct method in a
2879a45ae5f8SJohn Marino      given program space, then we consider inherited methods; this is
2880a45ae5f8SJohn Marino      not ideal (ideal would be to respect C++ hiding rules), but it
2881a45ae5f8SJohn Marino      seems good enough and is what GDB has historically done.  We only
2882a45ae5f8SJohn Marino      need to collect the names because later we find all symbols with
2883a45ae5f8SJohn Marino      those names.  This loop is written in a somewhat funny way
2884a45ae5f8SJohn Marino      because we collect data across the program space before deciding
2885a45ae5f8SJohn Marino      what to do.  */
2886a45ae5f8SJohn Marino   superclass_vec = NULL;
2887a45ae5f8SJohn Marino   make_cleanup (VEC_cleanup (typep), &superclass_vec);
2888a45ae5f8SJohn Marino   result_names = NULL;
2889a45ae5f8SJohn Marino   make_cleanup (VEC_cleanup (const_char_ptr), &result_names);
2890a45ae5f8SJohn Marino   last_result_len = 0;
2891a45ae5f8SJohn Marino   for (ix = 0; VEC_iterate (symbolp, sym_classes, ix, sym); ++ix)
2892cf7f2e2dSJohn Marino     {
2893a45ae5f8SJohn Marino       struct type *t;
2894a45ae5f8SJohn Marino       struct program_space *pspace;
2895a45ae5f8SJohn Marino 
2896a45ae5f8SJohn Marino       /* Program spaces that are executing startup should have
2897a45ae5f8SJohn Marino 	 been filtered out earlier.  */
2898a45ae5f8SJohn Marino       gdb_assert (!SYMTAB_PSPACE (SYMBOL_SYMTAB (sym))->executing_startup);
2899a45ae5f8SJohn Marino       pspace = SYMTAB_PSPACE (SYMBOL_SYMTAB (sym));
2900a45ae5f8SJohn Marino       set_current_program_space (pspace);
2901a45ae5f8SJohn Marino       t = check_typedef (SYMBOL_TYPE (sym));
2902*ef5ccd6cSJohn Marino       find_methods (t, method_name, &result_names, &superclass_vec);
2903a45ae5f8SJohn Marino 
2904a45ae5f8SJohn Marino       /* Handle all items from a single program space at once; and be
2905a45ae5f8SJohn Marino 	 sure not to miss the last batch.  */
2906a45ae5f8SJohn Marino       if (ix == VEC_length (symbolp, sym_classes) - 1
2907a45ae5f8SJohn Marino 	  || (pspace
2908a45ae5f8SJohn Marino 	      != SYMTAB_PSPACE (SYMBOL_SYMTAB (VEC_index (symbolp, sym_classes,
2909a45ae5f8SJohn Marino 							  ix + 1)))))
2910cf7f2e2dSJohn Marino 	{
2911a45ae5f8SJohn Marino 	  /* If we did not find a direct implementation anywhere in
2912a45ae5f8SJohn Marino 	     this program space, consider superclasses.  */
2913a45ae5f8SJohn Marino 	  if (VEC_length (const_char_ptr, result_names) == last_result_len)
2914*ef5ccd6cSJohn Marino 	    find_superclass_methods (superclass_vec, method_name,
2915*ef5ccd6cSJohn Marino 				     &result_names);
2916a45ae5f8SJohn Marino 
2917a45ae5f8SJohn Marino 	  /* We have a list of candidate symbol names, so now we
2918a45ae5f8SJohn Marino 	     iterate over the symbol tables looking for all
2919a45ae5f8SJohn Marino 	     matches in this pspace.  */
2920a45ae5f8SJohn Marino 	  add_all_symbol_names_from_pspace (&info, pspace, result_names);
2921a45ae5f8SJohn Marino 
2922a45ae5f8SJohn Marino 	  VEC_truncate (typep, superclass_vec, 0);
2923a45ae5f8SJohn Marino 	  last_result_len = VEC_length (const_char_ptr, result_names);
2924cf7f2e2dSJohn Marino 	}
2925cf7f2e2dSJohn Marino     }
2926cf7f2e2dSJohn Marino 
2927*ef5ccd6cSJohn Marino   if (!VEC_empty (symbolp, info.result.symbols)
2928*ef5ccd6cSJohn Marino       || !VEC_empty (minsym_and_objfile_d, info.result.minimal_symbols))
2929a45ae5f8SJohn Marino     {
2930*ef5ccd6cSJohn Marino       *symbols = info.result.symbols;
2931*ef5ccd6cSJohn Marino       *minsyms = info.result.minimal_symbols;
2932a45ae5f8SJohn Marino       do_cleanups (cleanup);
2933*ef5ccd6cSJohn Marino       return;
2934a45ae5f8SJohn Marino     }
2935a45ae5f8SJohn Marino 
2936*ef5ccd6cSJohn Marino   /* Throw an NOT_FOUND_ERROR.  This will be caught by the caller
2937*ef5ccd6cSJohn Marino      and other attempts to locate the symbol will be made.  */
2938*ef5ccd6cSJohn Marino   throw_error (NOT_FOUND_ERROR, _("see caller, this text doesn't matter"));
29395796c8dcSSimon Schubert }
29405796c8dcSSimon Schubert 
29415796c8dcSSimon Schubert 
29425796c8dcSSimon Schubert 
2943a45ae5f8SJohn Marino /* This object is used when collecting all matching symtabs.  */
29445796c8dcSSimon Schubert 
2945a45ae5f8SJohn Marino struct symtab_collector
2946a45ae5f8SJohn Marino {
2947a45ae5f8SJohn Marino   /* The result vector of symtabs.  */
2948a45ae5f8SJohn Marino   VEC (symtab_p) *symtabs;
2949a45ae5f8SJohn Marino 
2950a45ae5f8SJohn Marino   /* This is used to ensure the symtabs are unique.  */
2951a45ae5f8SJohn Marino   htab_t symtab_table;
2952a45ae5f8SJohn Marino };
2953a45ae5f8SJohn Marino 
2954a45ae5f8SJohn Marino /* Callback for iterate_over_symtabs.  */
2955a45ae5f8SJohn Marino 
2956a45ae5f8SJohn Marino static int
add_symtabs_to_list(struct symtab * symtab,void * d)2957a45ae5f8SJohn Marino add_symtabs_to_list (struct symtab *symtab, void *d)
2958a45ae5f8SJohn Marino {
2959a45ae5f8SJohn Marino   struct symtab_collector *data = d;
2960a45ae5f8SJohn Marino   void **slot;
2961a45ae5f8SJohn Marino 
2962a45ae5f8SJohn Marino   slot = htab_find_slot (data->symtab_table, symtab, INSERT);
2963a45ae5f8SJohn Marino   if (!*slot)
2964a45ae5f8SJohn Marino     {
2965a45ae5f8SJohn Marino       *slot = symtab;
2966a45ae5f8SJohn Marino       VEC_safe_push (symtab_p, data->symtabs, symtab);
2967a45ae5f8SJohn Marino     }
2968a45ae5f8SJohn Marino 
2969a45ae5f8SJohn Marino   return 0;
2970a45ae5f8SJohn Marino }
2971a45ae5f8SJohn Marino 
2972a45ae5f8SJohn Marino /* Given a file name, return a VEC of all matching symtabs.  */
2973a45ae5f8SJohn Marino 
VEC(symtab_p)2974a45ae5f8SJohn Marino static VEC (symtab_p) *
2975a45ae5f8SJohn Marino collect_symtabs_from_filename (const char *file)
2976a45ae5f8SJohn Marino {
2977a45ae5f8SJohn Marino   struct symtab_collector collector;
2978a45ae5f8SJohn Marino   struct cleanup *cleanups;
2979a45ae5f8SJohn Marino   struct program_space *pspace;
2980a45ae5f8SJohn Marino 
2981a45ae5f8SJohn Marino   collector.symtabs = NULL;
2982a45ae5f8SJohn Marino   collector.symtab_table = htab_create (1, htab_hash_pointer, htab_eq_pointer,
2983a45ae5f8SJohn Marino 					NULL);
2984a45ae5f8SJohn Marino   cleanups = make_cleanup_htab_delete (collector.symtab_table);
2985a45ae5f8SJohn Marino 
2986a45ae5f8SJohn Marino   /* Find that file's data.  */
2987a45ae5f8SJohn Marino   ALL_PSPACES (pspace)
2988a45ae5f8SJohn Marino   {
2989a45ae5f8SJohn Marino     if (pspace->executing_startup)
2990a45ae5f8SJohn Marino       continue;
2991a45ae5f8SJohn Marino 
2992a45ae5f8SJohn Marino     set_current_program_space (pspace);
2993a45ae5f8SJohn Marino     iterate_over_symtabs (file, add_symtabs_to_list, &collector);
2994a45ae5f8SJohn Marino   }
2995a45ae5f8SJohn Marino 
2996a45ae5f8SJohn Marino   do_cleanups (cleanups);
2997a45ae5f8SJohn Marino   return collector.symtabs;
2998a45ae5f8SJohn Marino }
2999a45ae5f8SJohn Marino 
3000*ef5ccd6cSJohn Marino /* Return all the symtabs associated to the FILENAME.  */
3001a45ae5f8SJohn Marino 
VEC(symtab_p)3002a45ae5f8SJohn Marino static VEC (symtab_p) *
3003*ef5ccd6cSJohn Marino symtabs_from_filename (const char *filename)
30045796c8dcSSimon Schubert {
3005a45ae5f8SJohn Marino   VEC (symtab_p) *result;
30065796c8dcSSimon Schubert 
3007*ef5ccd6cSJohn Marino   result = collect_symtabs_from_filename (filename);
3008a45ae5f8SJohn Marino 
3009a45ae5f8SJohn Marino   if (VEC_empty (symtab_p, result))
30105796c8dcSSimon Schubert     {
30115796c8dcSSimon Schubert       if (!have_full_symbols () && !have_partial_symbols ())
30125796c8dcSSimon Schubert 	throw_error (NOT_FOUND_ERROR,
3013c50c785cSJohn Marino 		     _("No symbol table is loaded.  "
3014c50c785cSJohn Marino 		       "Use the \"file\" command."));
3015*ef5ccd6cSJohn Marino       throw_error (NOT_FOUND_ERROR, _("No source file named %s."), filename);
30165796c8dcSSimon Schubert     }
30175796c8dcSSimon Schubert 
3018a45ae5f8SJohn Marino   return result;
3019a45ae5f8SJohn Marino }
3020a45ae5f8SJohn Marino 
3021*ef5ccd6cSJohn Marino /* Look up a function symbol named NAME in symtabs FILE_SYMTABS.  Matching
3022*ef5ccd6cSJohn Marino    debug symbols are returned in SYMBOLS.  Matching minimal symbols are
3023*ef5ccd6cSJohn Marino    returned in MINSYMS.  */
3024a45ae5f8SJohn Marino 
3025*ef5ccd6cSJohn Marino static void
find_function_symbols(struct linespec_state * state,VEC (symtab_p)* file_symtabs,const char * name,VEC (symbolp)** symbols,VEC (minsym_and_objfile_d)** minsyms)3026*ef5ccd6cSJohn Marino find_function_symbols (struct linespec_state *state,
3027*ef5ccd6cSJohn Marino 		       VEC (symtab_p) *file_symtabs, const char *name,
3028*ef5ccd6cSJohn Marino 		       VEC (symbolp) **symbols,
3029*ef5ccd6cSJohn Marino 		       VEC (minsym_and_objfile_d) **minsyms)
3030a45ae5f8SJohn Marino {
3031*ef5ccd6cSJohn Marino   struct collect_info info;
3032*ef5ccd6cSJohn Marino   VEC (const_char_ptr) *symbol_names = NULL;
3033*ef5ccd6cSJohn Marino   struct cleanup *cleanup = make_cleanup (VEC_cleanup (const_char_ptr),
3034*ef5ccd6cSJohn Marino 					  &symbol_names);
3035a45ae5f8SJohn Marino 
3036*ef5ccd6cSJohn Marino   info.state = state;
3037*ef5ccd6cSJohn Marino   info.result.symbols = NULL;
3038*ef5ccd6cSJohn Marino   info.result.minimal_symbols = NULL;
3039*ef5ccd6cSJohn Marino   info.file_symtabs = file_symtabs;
3040a45ae5f8SJohn Marino 
3041*ef5ccd6cSJohn Marino   /* Try NAME as an Objective-C selector.  */
3042*ef5ccd6cSJohn Marino   find_imps ((char *) name, &symbol_names);
3043*ef5ccd6cSJohn Marino   if (!VEC_empty (const_char_ptr, symbol_names))
3044*ef5ccd6cSJohn Marino     add_all_symbol_names_from_pspace (&info, NULL, symbol_names);
3045*ef5ccd6cSJohn Marino   else
3046*ef5ccd6cSJohn Marino     add_matching_symbols_to_info (name, &info, NULL);
3047*ef5ccd6cSJohn Marino 
3048*ef5ccd6cSJohn Marino   do_cleanups (cleanup);
3049*ef5ccd6cSJohn Marino 
3050*ef5ccd6cSJohn Marino   if (VEC_empty (symbolp, info.result.symbols))
3051*ef5ccd6cSJohn Marino     {
3052*ef5ccd6cSJohn Marino       VEC_free (symbolp, info.result.symbols);
3053*ef5ccd6cSJohn Marino       *symbols = NULL;
3054*ef5ccd6cSJohn Marino     }
3055*ef5ccd6cSJohn Marino   else
3056*ef5ccd6cSJohn Marino     *symbols = info.result.symbols;
3057*ef5ccd6cSJohn Marino 
3058*ef5ccd6cSJohn Marino   if (VEC_empty (minsym_and_objfile_d, info.result.minimal_symbols))
3059*ef5ccd6cSJohn Marino     {
3060*ef5ccd6cSJohn Marino       VEC_free (minsym_and_objfile_d, info.result.minimal_symbols);
3061*ef5ccd6cSJohn Marino       *minsyms = NULL;
3062*ef5ccd6cSJohn Marino     }
3063*ef5ccd6cSJohn Marino   else
3064*ef5ccd6cSJohn Marino     *minsyms = info.result.minimal_symbols;
30655796c8dcSSimon Schubert }
30665796c8dcSSimon Schubert 
3067*ef5ccd6cSJohn Marino /* Find all symbols named NAME in FILE_SYMTABS, returning debug symbols
3068*ef5ccd6cSJohn Marino    in SYMBOLS and minimal symbols in MINSYMS.  */
3069*ef5ccd6cSJohn Marino 
3070*ef5ccd6cSJohn Marino static void
find_linespec_symbols(struct linespec_state * state,VEC (symtab_p)* file_symtabs,const char * name,VEC (symbolp)** symbols,VEC (minsym_and_objfile_d)** minsyms)3071*ef5ccd6cSJohn Marino find_linespec_symbols (struct linespec_state *state,
3072*ef5ccd6cSJohn Marino 		       VEC (symtab_p) *file_symtabs,
3073*ef5ccd6cSJohn Marino 		       const char *name,
3074*ef5ccd6cSJohn Marino 		       VEC (symbolp) **symbols,
3075*ef5ccd6cSJohn Marino 		       VEC (minsym_and_objfile_d) **minsyms)
3076*ef5ccd6cSJohn Marino {
3077*ef5ccd6cSJohn Marino   struct cleanup *cleanup;
3078*ef5ccd6cSJohn Marino   char *canon;
3079*ef5ccd6cSJohn Marino   const char *lookup_name;
3080*ef5ccd6cSJohn Marino   volatile struct gdb_exception except;
3081*ef5ccd6cSJohn Marino 
3082*ef5ccd6cSJohn Marino   cleanup = demangle_for_lookup (name, state->language->la_language,
3083*ef5ccd6cSJohn Marino 				 &lookup_name);
3084*ef5ccd6cSJohn Marino   if (state->language->la_language == language_ada)
3085*ef5ccd6cSJohn Marino     {
3086*ef5ccd6cSJohn Marino       /* In Ada, the symbol lookups are performed using the encoded
3087*ef5ccd6cSJohn Marino          name rather than the demangled name.  */
3088*ef5ccd6cSJohn Marino       lookup_name = ada_name_for_lookup (name);
3089*ef5ccd6cSJohn Marino       make_cleanup (xfree, (void *) lookup_name);
3090*ef5ccd6cSJohn Marino     }
3091*ef5ccd6cSJohn Marino 
3092*ef5ccd6cSJohn Marino   canon = cp_canonicalize_string_no_typedefs (lookup_name);
3093*ef5ccd6cSJohn Marino   if (canon != NULL)
3094*ef5ccd6cSJohn Marino     {
3095*ef5ccd6cSJohn Marino       lookup_name = canon;
3096*ef5ccd6cSJohn Marino       cleanup = make_cleanup (xfree, canon);
3097*ef5ccd6cSJohn Marino     }
3098*ef5ccd6cSJohn Marino 
3099*ef5ccd6cSJohn Marino   /* It's important to not call expand_symtabs_matching unnecessarily
3100*ef5ccd6cSJohn Marino      as it can really slow things down (by unnecessarily expanding
3101*ef5ccd6cSJohn Marino      potentially 1000s of symtabs, which when debugging some apps can
3102*ef5ccd6cSJohn Marino      cost 100s of seconds).  Avoid this to some extent by *first* calling
3103*ef5ccd6cSJohn Marino      find_function_symbols, and only if that doesn't find anything
3104*ef5ccd6cSJohn Marino      *then* call find_method.  This handles two important cases:
3105*ef5ccd6cSJohn Marino      1) break (anonymous namespace)::foo
3106*ef5ccd6cSJohn Marino      2) break class::method where method is in class (and not a baseclass)  */
3107*ef5ccd6cSJohn Marino 
3108*ef5ccd6cSJohn Marino   find_function_symbols (state, file_symtabs, lookup_name,
3109*ef5ccd6cSJohn Marino 			 symbols, minsyms);
3110*ef5ccd6cSJohn Marino 
3111*ef5ccd6cSJohn Marino   /* If we were unable to locate a symbol of the same name, try dividing
3112*ef5ccd6cSJohn Marino      the name into class and method names and searching the class and its
3113*ef5ccd6cSJohn Marino      baseclasses.  */
3114*ef5ccd6cSJohn Marino   if (VEC_empty (symbolp, *symbols)
3115*ef5ccd6cSJohn Marino       && VEC_empty (minsym_and_objfile_d, *minsyms))
3116*ef5ccd6cSJohn Marino     {
3117*ef5ccd6cSJohn Marino       char *klass, *method;
3118*ef5ccd6cSJohn Marino       const char *last, *p, *scope_op;
3119*ef5ccd6cSJohn Marino       VEC (symbolp) *classes;
3120*ef5ccd6cSJohn Marino 
3121*ef5ccd6cSJohn Marino       /* See if we can find a scope operator and break this symbol
3122*ef5ccd6cSJohn Marino 	 name into namespaces${SCOPE_OPERATOR}class_name and method_name.  */
3123*ef5ccd6cSJohn Marino       scope_op = "::";
3124*ef5ccd6cSJohn Marino       p = find_toplevel_string (lookup_name, scope_op);
3125*ef5ccd6cSJohn Marino       if (p == NULL)
3126*ef5ccd6cSJohn Marino 	{
3127*ef5ccd6cSJohn Marino 	  /* No C++ scope operator.  Try Java.  */
3128*ef5ccd6cSJohn Marino 	  scope_op = ".";
3129*ef5ccd6cSJohn Marino 	  p = find_toplevel_string (lookup_name, scope_op);
3130*ef5ccd6cSJohn Marino 	}
3131*ef5ccd6cSJohn Marino 
3132*ef5ccd6cSJohn Marino       last = NULL;
3133*ef5ccd6cSJohn Marino       while (p != NULL)
3134*ef5ccd6cSJohn Marino 	{
3135*ef5ccd6cSJohn Marino 	  last = p;
3136*ef5ccd6cSJohn Marino 	  p = find_toplevel_string (p + strlen (scope_op), scope_op);
3137*ef5ccd6cSJohn Marino 	}
3138*ef5ccd6cSJohn Marino 
3139*ef5ccd6cSJohn Marino       /* If no scope operator was found, there is nothing more we can do;
3140*ef5ccd6cSJohn Marino 	 we already attempted to lookup the entire name as a symbol
3141*ef5ccd6cSJohn Marino 	 and failed.  */
3142*ef5ccd6cSJohn Marino       if (last == NULL)
3143*ef5ccd6cSJohn Marino 	{
3144*ef5ccd6cSJohn Marino 	  do_cleanups (cleanup);
3145*ef5ccd6cSJohn Marino 	  return;
3146*ef5ccd6cSJohn Marino 	}
3147*ef5ccd6cSJohn Marino 
3148*ef5ccd6cSJohn Marino       /* LOOKUP_NAME points to the class name.
3149*ef5ccd6cSJohn Marino 	 LAST points to the method name.  */
3150*ef5ccd6cSJohn Marino       klass = xmalloc ((last - lookup_name + 1) * sizeof (char));
3151*ef5ccd6cSJohn Marino       make_cleanup (xfree, klass);
3152*ef5ccd6cSJohn Marino       strncpy (klass, lookup_name, last - lookup_name);
3153*ef5ccd6cSJohn Marino       klass[last - lookup_name] = '\0';
3154*ef5ccd6cSJohn Marino 
3155*ef5ccd6cSJohn Marino       /* Skip past the scope operator.  */
3156*ef5ccd6cSJohn Marino       last += strlen (scope_op);
3157*ef5ccd6cSJohn Marino       method = xmalloc ((strlen (last) + 1) * sizeof (char));
3158*ef5ccd6cSJohn Marino       make_cleanup (xfree, method);
3159*ef5ccd6cSJohn Marino       strcpy (method, last);
3160*ef5ccd6cSJohn Marino 
3161*ef5ccd6cSJohn Marino       /* Find a list of classes named KLASS.  */
3162*ef5ccd6cSJohn Marino       classes = lookup_prefix_sym (state, file_symtabs, klass);
3163*ef5ccd6cSJohn Marino       make_cleanup (VEC_cleanup (symbolp), &classes);
3164*ef5ccd6cSJohn Marino 
3165*ef5ccd6cSJohn Marino       if (!VEC_empty (symbolp, classes))
3166*ef5ccd6cSJohn Marino 	{
3167*ef5ccd6cSJohn Marino 	  /* Now locate a list of suitable methods named METHOD.  */
3168*ef5ccd6cSJohn Marino 	  TRY_CATCH (except, RETURN_MASK_ERROR)
3169*ef5ccd6cSJohn Marino 	    {
3170*ef5ccd6cSJohn Marino 	      find_method (state, file_symtabs, klass, method, classes,
3171*ef5ccd6cSJohn Marino 			   symbols, minsyms);
3172*ef5ccd6cSJohn Marino 	    }
3173*ef5ccd6cSJohn Marino 
3174*ef5ccd6cSJohn Marino 	  /* If successful, we're done.  If NOT_FOUND_ERROR
3175*ef5ccd6cSJohn Marino 	     was not thrown, rethrow the exception that we did get.  */
3176*ef5ccd6cSJohn Marino 	  if (except.reason < 0 && except.error != NOT_FOUND_ERROR)
3177*ef5ccd6cSJohn Marino 	    throw_exception (except);
3178*ef5ccd6cSJohn Marino 	}
3179*ef5ccd6cSJohn Marino     }
3180*ef5ccd6cSJohn Marino 
3181*ef5ccd6cSJohn Marino   do_cleanups (cleanup);
3182*ef5ccd6cSJohn Marino }
3183*ef5ccd6cSJohn Marino 
3184*ef5ccd6cSJohn Marino /* Return all labels named NAME in FUNCTION_SYMBOLS.  Return the
3185*ef5ccd6cSJohn Marino    actual function symbol in which the label was found in LABEL_FUNC_RET.  */
3186c50c785cSJohn Marino 
VEC(symbolp)3187a45ae5f8SJohn Marino static VEC (symbolp) *
3188*ef5ccd6cSJohn Marino find_label_symbols (struct linespec_state *self,
3189*ef5ccd6cSJohn Marino 		    VEC (symbolp) *function_symbols,
3190*ef5ccd6cSJohn Marino 		    VEC (symbolp) **label_funcs_ret, const char *name)
3191c50c785cSJohn Marino {
3192*ef5ccd6cSJohn Marino   int ix;
3193*ef5ccd6cSJohn Marino   struct block *block;
3194*ef5ccd6cSJohn Marino   struct symbol *sym;
3195*ef5ccd6cSJohn Marino   struct symbol *fn_sym;
3196a45ae5f8SJohn Marino   VEC (symbolp) *result = NULL;
3197c50c785cSJohn Marino 
3198*ef5ccd6cSJohn Marino   if (function_symbols == NULL)
3199*ef5ccd6cSJohn Marino     {
3200*ef5ccd6cSJohn Marino       set_current_program_space (self->program_space);
3201*ef5ccd6cSJohn Marino       block = get_current_search_block ();
3202c50c785cSJohn Marino 
3203*ef5ccd6cSJohn Marino       for (;
3204*ef5ccd6cSJohn Marino 	   block && !BLOCK_FUNCTION (block);
3205*ef5ccd6cSJohn Marino 	   block = BLOCK_SUPERBLOCK (block))
3206*ef5ccd6cSJohn Marino 	;
3207*ef5ccd6cSJohn Marino       if (!block)
3208*ef5ccd6cSJohn Marino 	return NULL;
3209*ef5ccd6cSJohn Marino       fn_sym = BLOCK_FUNCTION (block);
3210c50c785cSJohn Marino 
3211*ef5ccd6cSJohn Marino       sym = lookup_symbol (name, block, LABEL_DOMAIN, 0);
3212*ef5ccd6cSJohn Marino 
3213*ef5ccd6cSJohn Marino       if (sym != NULL)
3214*ef5ccd6cSJohn Marino 	{
3215*ef5ccd6cSJohn Marino 	  VEC_safe_push (symbolp, result, sym);
3216*ef5ccd6cSJohn Marino 	  VEC_safe_push (symbolp, *label_funcs_ret, fn_sym);
3217*ef5ccd6cSJohn Marino 	}
3218*ef5ccd6cSJohn Marino     }
3219a45ae5f8SJohn Marino   else
3220a45ae5f8SJohn Marino     {
3221*ef5ccd6cSJohn Marino       for (ix = 0;
3222*ef5ccd6cSJohn Marino 	   VEC_iterate (symbolp, function_symbols, ix, fn_sym); ++ix)
3223*ef5ccd6cSJohn Marino 	{
3224*ef5ccd6cSJohn Marino 	  set_current_program_space (SYMTAB_PSPACE (SYMBOL_SYMTAB (fn_sym)));
3225*ef5ccd6cSJohn Marino 	  block = SYMBOL_BLOCK_VALUE (fn_sym);
3226*ef5ccd6cSJohn Marino 	  sym = lookup_symbol (name, block, LABEL_DOMAIN, 0);
3227*ef5ccd6cSJohn Marino 
3228*ef5ccd6cSJohn Marino 	  if (sym != NULL)
3229*ef5ccd6cSJohn Marino 	    {
3230*ef5ccd6cSJohn Marino 	      VEC_safe_push (symbolp, result, sym);
3231*ef5ccd6cSJohn Marino 	      VEC_safe_push (symbolp, *label_funcs_ret, fn_sym);
3232*ef5ccd6cSJohn Marino 	    }
3233*ef5ccd6cSJohn Marino 	}
3234a45ae5f8SJohn Marino     }
3235c50c785cSJohn Marino 
3236a45ae5f8SJohn Marino   return result;
3237c50c785cSJohn Marino }
3238c50c785cSJohn Marino 
32395796c8dcSSimon Schubert 
32405796c8dcSSimon Schubert 
3241*ef5ccd6cSJohn Marino /* A helper for create_sals_line_offset that handles the 'list_mode' case.  */
3242a45ae5f8SJohn Marino 
3243a45ae5f8SJohn Marino static void
decode_digits_list_mode(struct linespec_state * self,linespec_p ls,struct symtabs_and_lines * values,struct symtab_and_line val)3244a45ae5f8SJohn Marino decode_digits_list_mode (struct linespec_state *self,
3245*ef5ccd6cSJohn Marino 			 linespec_p ls,
3246a45ae5f8SJohn Marino 			 struct symtabs_and_lines *values,
3247a45ae5f8SJohn Marino 			 struct symtab_and_line val)
3248a45ae5f8SJohn Marino {
3249a45ae5f8SJohn Marino   int ix;
3250a45ae5f8SJohn Marino   struct symtab *elt;
3251a45ae5f8SJohn Marino 
3252a45ae5f8SJohn Marino   gdb_assert (self->list_mode);
3253a45ae5f8SJohn Marino 
3254*ef5ccd6cSJohn Marino   for (ix = 0; VEC_iterate (symtab_p, ls->file_symtabs, ix, elt);
3255*ef5ccd6cSJohn Marino        ++ix)
3256a45ae5f8SJohn Marino     {
3257a45ae5f8SJohn Marino       /* The logic above should ensure this.  */
3258a45ae5f8SJohn Marino       gdb_assert (elt != NULL);
3259a45ae5f8SJohn Marino 
3260a45ae5f8SJohn Marino       set_current_program_space (SYMTAB_PSPACE (elt));
3261a45ae5f8SJohn Marino 
3262a45ae5f8SJohn Marino       /* Simplistic search just for the list command.  */
3263a45ae5f8SJohn Marino       val.symtab = find_line_symtab (elt, val.line, NULL, NULL);
3264a45ae5f8SJohn Marino       if (val.symtab == NULL)
3265a45ae5f8SJohn Marino 	val.symtab = elt;
3266a45ae5f8SJohn Marino       val.pspace = SYMTAB_PSPACE (elt);
3267a45ae5f8SJohn Marino       val.pc = 0;
3268a45ae5f8SJohn Marino       val.explicit_line = 1;
3269a45ae5f8SJohn Marino 
3270*ef5ccd6cSJohn Marino       add_sal_to_sals (self, values, &val, NULL, 0);
3271a45ae5f8SJohn Marino     }
3272a45ae5f8SJohn Marino }
3273a45ae5f8SJohn Marino 
3274*ef5ccd6cSJohn Marino /* A helper for create_sals_line_offset that iterates over the symtabs,
3275a45ae5f8SJohn Marino    adding lines to the VEC.  */
3276a45ae5f8SJohn Marino 
3277a45ae5f8SJohn Marino static void
decode_digits_ordinary(struct linespec_state * self,linespec_p ls,int line,struct symtabs_and_lines * sals,struct linetable_entry ** best_entry)3278a45ae5f8SJohn Marino decode_digits_ordinary (struct linespec_state *self,
3279*ef5ccd6cSJohn Marino 			linespec_p ls,
3280a45ae5f8SJohn Marino 			int line,
3281a45ae5f8SJohn Marino 			struct symtabs_and_lines *sals,
3282a45ae5f8SJohn Marino 			struct linetable_entry **best_entry)
3283a45ae5f8SJohn Marino {
3284a45ae5f8SJohn Marino   int ix;
3285a45ae5f8SJohn Marino   struct symtab *elt;
3286a45ae5f8SJohn Marino 
3287*ef5ccd6cSJohn Marino   for (ix = 0; VEC_iterate (symtab_p, ls->file_symtabs, ix, elt); ++ix)
3288a45ae5f8SJohn Marino     {
3289a45ae5f8SJohn Marino       int i;
3290a45ae5f8SJohn Marino       VEC (CORE_ADDR) *pcs;
3291a45ae5f8SJohn Marino       CORE_ADDR pc;
3292a45ae5f8SJohn Marino 
3293a45ae5f8SJohn Marino       /* The logic above should ensure this.  */
3294a45ae5f8SJohn Marino       gdb_assert (elt != NULL);
3295a45ae5f8SJohn Marino 
3296a45ae5f8SJohn Marino       set_current_program_space (SYMTAB_PSPACE (elt));
3297a45ae5f8SJohn Marino 
3298a45ae5f8SJohn Marino       pcs = find_pcs_for_symtab_line (elt, line, best_entry);
3299a45ae5f8SJohn Marino       for (i = 0; VEC_iterate (CORE_ADDR, pcs, i, pc); ++i)
3300a45ae5f8SJohn Marino 	{
3301a45ae5f8SJohn Marino 	  struct symtab_and_line sal;
3302a45ae5f8SJohn Marino 
3303a45ae5f8SJohn Marino 	  init_sal (&sal);
3304a45ae5f8SJohn Marino 	  sal.pspace = SYMTAB_PSPACE (elt);
3305a45ae5f8SJohn Marino 	  sal.symtab = elt;
3306a45ae5f8SJohn Marino 	  sal.line = line;
3307a45ae5f8SJohn Marino 	  sal.pc = pc;
3308a45ae5f8SJohn Marino 	  add_sal_to_sals_basic (sals, &sal);
3309a45ae5f8SJohn Marino 	}
3310a45ae5f8SJohn Marino 
3311a45ae5f8SJohn Marino       VEC_free (CORE_ADDR, pcs);
3312a45ae5f8SJohn Marino     }
3313a45ae5f8SJohn Marino }
3314a45ae5f8SJohn Marino 
33155796c8dcSSimon Schubert 
33165796c8dcSSimon Schubert 
3317*ef5ccd6cSJohn Marino /* Return the line offset represented by VARIABLE.  */
33185796c8dcSSimon Schubert 
3319*ef5ccd6cSJohn Marino static struct line_offset
linespec_parse_variable(struct linespec_state * self,const char * variable)3320*ef5ccd6cSJohn Marino linespec_parse_variable (struct linespec_state *self, const char *variable)
33215796c8dcSSimon Schubert {
33225796c8dcSSimon Schubert   int index = 0;
3323*ef5ccd6cSJohn Marino   const char *p;
3324*ef5ccd6cSJohn Marino   struct line_offset offset = {0, LINE_OFFSET_NONE};
33255796c8dcSSimon Schubert 
3326*ef5ccd6cSJohn Marino   p = (variable[1] == '$') ? variable + 2 : variable + 1;
3327*ef5ccd6cSJohn Marino   if (*p == '$')
3328*ef5ccd6cSJohn Marino     ++p;
33295796c8dcSSimon Schubert   while (*p >= '0' && *p <= '9')
3330*ef5ccd6cSJohn Marino     ++p;
33315796c8dcSSimon Schubert   if (!*p)		/* Reached end of token without hitting non-digit.  */
33325796c8dcSSimon Schubert     {
33335796c8dcSSimon Schubert       /* We have a value history reference.  */
33345796c8dcSSimon Schubert       struct value *val_history;
3335cf7f2e2dSJohn Marino 
3336*ef5ccd6cSJohn Marino       sscanf ((variable[1] == '$') ? variable + 2 : variable + 1, "%d", &index);
3337*ef5ccd6cSJohn Marino       val_history
3338*ef5ccd6cSJohn Marino 	= access_value_history ((variable[1] == '$') ? -index : index);
33395796c8dcSSimon Schubert       if (TYPE_CODE (value_type (val_history)) != TYPE_CODE_INT)
3340c50c785cSJohn Marino 	error (_("History values used in line "
3341c50c785cSJohn Marino 		 "specs must have integer values."));
3342*ef5ccd6cSJohn Marino       offset.offset = value_as_long (val_history);
33435796c8dcSSimon Schubert     }
33445796c8dcSSimon Schubert   else
33455796c8dcSSimon Schubert     {
33465796c8dcSSimon Schubert       /* Not all digits -- may be user variable/function or a
33475796c8dcSSimon Schubert 	 convenience variable.  */
3348*ef5ccd6cSJohn Marino       LONGEST valx;
3349*ef5ccd6cSJohn Marino       struct internalvar *ivar;
33505796c8dcSSimon Schubert 
3351*ef5ccd6cSJohn Marino       /* Try it as a convenience variable.  If it is not a convenience
3352*ef5ccd6cSJohn Marino 	 variable, return and allow normal symbol lookup to occur.  */
3353*ef5ccd6cSJohn Marino       ivar = lookup_only_internalvar (variable + 1);
3354*ef5ccd6cSJohn Marino       if (ivar == NULL)
3355*ef5ccd6cSJohn Marino 	/* No internal variable with that name.  Mark the offset
3356*ef5ccd6cSJohn Marino 	   as unknown to allow the name to be looked up as a symbol.  */
3357*ef5ccd6cSJohn Marino 	offset.sign = LINE_OFFSET_UNKNOWN;
3358*ef5ccd6cSJohn Marino       else
3359a45ae5f8SJohn Marino 	{
3360*ef5ccd6cSJohn Marino 	  /* We found a valid variable name.  If it is not an integer,
3361*ef5ccd6cSJohn Marino 	     throw an error.  */
3362*ef5ccd6cSJohn Marino 	  if (!get_internalvar_integer (ivar, &valx))
3363c50c785cSJohn Marino 	    error (_("Convenience variables used in line "
3364c50c785cSJohn Marino 		     "specs must have integer values."));
3365a45ae5f8SJohn Marino 	  else
3366*ef5ccd6cSJohn Marino 	    offset.offset = valx;
3367*ef5ccd6cSJohn Marino 	}
3368a45ae5f8SJohn Marino     }
33695796c8dcSSimon Schubert 
3370*ef5ccd6cSJohn Marino   return offset;
3371a45ae5f8SJohn Marino }
33725796c8dcSSimon Schubert 
33735796c8dcSSimon Schubert 
3374a45ae5f8SJohn Marino /* A callback used to possibly add a symbol to the results.  */
3375a45ae5f8SJohn Marino 
3376a45ae5f8SJohn Marino static int
collect_symbols(struct symbol * sym,void * data)3377a45ae5f8SJohn Marino collect_symbols (struct symbol *sym, void *data)
3378a45ae5f8SJohn Marino {
3379a45ae5f8SJohn Marino   struct collect_info *info = data;
3380a45ae5f8SJohn Marino 
3381*ef5ccd6cSJohn Marino   /* In list mode, add all matching symbols, regardless of class.
3382*ef5ccd6cSJohn Marino      This allows the user to type "list a_global_variable".  */
3383*ef5ccd6cSJohn Marino   if (SYMBOL_CLASS (sym) == LOC_BLOCK || info->state->list_mode)
3384*ef5ccd6cSJohn Marino     VEC_safe_push (symbolp, info->result.symbols, sym);
3385*ef5ccd6cSJohn Marino   return 1; /* Continue iterating.  */
3386a45ae5f8SJohn Marino }
3387a45ae5f8SJohn Marino 
3388*ef5ccd6cSJohn Marino /* We've found a minimal symbol MSYMBOL in OBJFILE to associate with our
3389*ef5ccd6cSJohn Marino    linespec; return the SAL in RESULT.  */
3390a45ae5f8SJohn Marino 
3391a45ae5f8SJohn Marino static void
minsym_found(struct linespec_state * self,struct objfile * objfile,struct minimal_symbol * msymbol,struct symtabs_and_lines * result)3392a45ae5f8SJohn Marino minsym_found (struct linespec_state *self, struct objfile *objfile,
3393a45ae5f8SJohn Marino 	      struct minimal_symbol *msymbol,
3394a45ae5f8SJohn Marino 	      struct symtabs_and_lines *result)
3395a45ae5f8SJohn Marino {
3396a45ae5f8SJohn Marino   struct gdbarch *gdbarch = get_objfile_arch (objfile);
3397a45ae5f8SJohn Marino   CORE_ADDR pc;
3398a45ae5f8SJohn Marino   struct symtab_and_line sal;
3399a45ae5f8SJohn Marino 
3400a45ae5f8SJohn Marino   sal = find_pc_sect_line (SYMBOL_VALUE_ADDRESS (msymbol),
3401a45ae5f8SJohn Marino 			   (struct obj_section *) 0, 0);
3402a45ae5f8SJohn Marino   sal.section = SYMBOL_OBJ_SECTION (msymbol);
3403a45ae5f8SJohn Marino 
3404a45ae5f8SJohn Marino   /* The minimal symbol might point to a function descriptor;
3405a45ae5f8SJohn Marino      resolve it to the actual code address instead.  */
3406a45ae5f8SJohn Marino   pc = gdbarch_convert_from_func_ptr_addr (gdbarch, sal.pc, &current_target);
3407a45ae5f8SJohn Marino   if (pc != sal.pc)
3408a45ae5f8SJohn Marino     sal = find_pc_sect_line (pc, NULL, 0);
3409a45ae5f8SJohn Marino 
3410a45ae5f8SJohn Marino   if (self->funfirstline)
3411a45ae5f8SJohn Marino     skip_prologue_sal (&sal);
3412a45ae5f8SJohn Marino 
3413a45ae5f8SJohn Marino   if (maybe_add_address (self->addr_set, objfile->pspace, sal.pc))
3414*ef5ccd6cSJohn Marino     add_sal_to_sals (self, result, &sal, SYMBOL_NATURAL_NAME (msymbol), 0);
3415a45ae5f8SJohn Marino }
3416a45ae5f8SJohn Marino 
3417a45ae5f8SJohn Marino /* A helper struct to pass some data through
3418a45ae5f8SJohn Marino    iterate_over_minimal_symbols.  */
3419a45ae5f8SJohn Marino 
3420a45ae5f8SJohn Marino struct collect_minsyms
3421a45ae5f8SJohn Marino {
3422a45ae5f8SJohn Marino   /* The objfile we're examining.  */
3423a45ae5f8SJohn Marino   struct objfile *objfile;
3424a45ae5f8SJohn Marino 
3425a45ae5f8SJohn Marino   /* The funfirstline setting from the initial call.  */
3426a45ae5f8SJohn Marino   int funfirstline;
3427a45ae5f8SJohn Marino 
3428a45ae5f8SJohn Marino   /* The list_mode setting from the initial call.  */
3429a45ae5f8SJohn Marino   int list_mode;
3430a45ae5f8SJohn Marino 
3431a45ae5f8SJohn Marino   /* The resulting symbols.  */
3432a45ae5f8SJohn Marino   VEC (minsym_and_objfile_d) *msyms;
3433a45ae5f8SJohn Marino };
3434a45ae5f8SJohn Marino 
3435a45ae5f8SJohn Marino /* A helper function to classify a minimal_symbol_type according to
3436a45ae5f8SJohn Marino    priority.  */
3437a45ae5f8SJohn Marino 
3438a45ae5f8SJohn Marino static int
classify_mtype(enum minimal_symbol_type t)3439a45ae5f8SJohn Marino classify_mtype (enum minimal_symbol_type t)
3440a45ae5f8SJohn Marino {
3441a45ae5f8SJohn Marino   switch (t)
3442a45ae5f8SJohn Marino     {
3443a45ae5f8SJohn Marino     case mst_file_text:
3444a45ae5f8SJohn Marino     case mst_file_data:
3445a45ae5f8SJohn Marino     case mst_file_bss:
3446a45ae5f8SJohn Marino       /* Intermediate priority.  */
3447a45ae5f8SJohn Marino       return 1;
3448a45ae5f8SJohn Marino 
3449a45ae5f8SJohn Marino     case mst_solib_trampoline:
3450a45ae5f8SJohn Marino       /* Lowest priority.  */
3451a45ae5f8SJohn Marino       return 2;
3452a45ae5f8SJohn Marino 
3453a45ae5f8SJohn Marino     default:
3454a45ae5f8SJohn Marino       /* Highest priority.  */
3455a45ae5f8SJohn Marino       return 0;
3456a45ae5f8SJohn Marino     }
3457a45ae5f8SJohn Marino }
3458a45ae5f8SJohn Marino 
3459a45ae5f8SJohn Marino /* Callback for qsort that sorts symbols by priority.  */
3460a45ae5f8SJohn Marino 
3461a45ae5f8SJohn Marino static int
compare_msyms(const void * a,const void * b)3462a45ae5f8SJohn Marino compare_msyms (const void *a, const void *b)
3463a45ae5f8SJohn Marino {
3464a45ae5f8SJohn Marino   const minsym_and_objfile_d *moa = a;
3465a45ae5f8SJohn Marino   const minsym_and_objfile_d *mob = b;
3466a45ae5f8SJohn Marino   enum minimal_symbol_type ta = MSYMBOL_TYPE (moa->minsym);
3467a45ae5f8SJohn Marino   enum minimal_symbol_type tb = MSYMBOL_TYPE (mob->minsym);
3468a45ae5f8SJohn Marino 
3469a45ae5f8SJohn Marino   return classify_mtype (ta) - classify_mtype (tb);
3470a45ae5f8SJohn Marino }
3471a45ae5f8SJohn Marino 
3472a45ae5f8SJohn Marino /* Callback for iterate_over_minimal_symbols that adds the symbol to
3473a45ae5f8SJohn Marino    the result.  */
3474a45ae5f8SJohn Marino 
3475a45ae5f8SJohn Marino static void
add_minsym(struct minimal_symbol * minsym,void * d)3476a45ae5f8SJohn Marino add_minsym (struct minimal_symbol *minsym, void *d)
3477a45ae5f8SJohn Marino {
3478a45ae5f8SJohn Marino   struct collect_minsyms *info = d;
3479a45ae5f8SJohn Marino   minsym_and_objfile_d mo;
3480a45ae5f8SJohn Marino 
3481a45ae5f8SJohn Marino   /* Exclude data symbols when looking for breakpoint locations.   */
3482a45ae5f8SJohn Marino   if (!info->list_mode)
3483a45ae5f8SJohn Marino     switch (minsym->type)
3484a45ae5f8SJohn Marino       {
3485a45ae5f8SJohn Marino 	case mst_slot_got_plt:
3486a45ae5f8SJohn Marino 	case mst_data:
3487a45ae5f8SJohn Marino 	case mst_bss:
3488a45ae5f8SJohn Marino 	case mst_abs:
3489a45ae5f8SJohn Marino 	case mst_file_data:
3490a45ae5f8SJohn Marino 	case mst_file_bss:
3491a45ae5f8SJohn Marino 	  {
3492a45ae5f8SJohn Marino 	    /* Make sure this minsym is not a function descriptor
3493a45ae5f8SJohn Marino 	       before we decide to discard it.  */
3494a45ae5f8SJohn Marino 	    struct gdbarch *gdbarch = info->objfile->gdbarch;
3495a45ae5f8SJohn Marino 	    CORE_ADDR addr = gdbarch_convert_from_func_ptr_addr
3496a45ae5f8SJohn Marino 			       (gdbarch, SYMBOL_VALUE_ADDRESS (minsym),
3497a45ae5f8SJohn Marino 				&current_target);
3498a45ae5f8SJohn Marino 
3499a45ae5f8SJohn Marino 	    if (addr == SYMBOL_VALUE_ADDRESS (minsym))
3500a45ae5f8SJohn Marino 	      return;
3501a45ae5f8SJohn Marino 	  }
3502a45ae5f8SJohn Marino       }
3503a45ae5f8SJohn Marino 
3504a45ae5f8SJohn Marino   mo.minsym = minsym;
3505a45ae5f8SJohn Marino   mo.objfile = info->objfile;
3506a45ae5f8SJohn Marino   VEC_safe_push (minsym_and_objfile_d, info->msyms, &mo);
3507a45ae5f8SJohn Marino }
3508a45ae5f8SJohn Marino 
3509a45ae5f8SJohn Marino /* Search minimal symbols in all objfiles for NAME.  If SEARCH_PSPACE
3510a45ae5f8SJohn Marino    is not NULL, the search is restricted to just that program
3511a45ae5f8SJohn Marino    space.  */
3512a45ae5f8SJohn Marino 
3513a45ae5f8SJohn Marino static void
search_minsyms_for_name(struct collect_info * info,const char * name,struct program_space * search_pspace)3514a45ae5f8SJohn Marino search_minsyms_for_name (struct collect_info *info, const char *name,
3515a45ae5f8SJohn Marino 			 struct program_space *search_pspace)
3516a45ae5f8SJohn Marino {
3517a45ae5f8SJohn Marino   struct objfile *objfile;
3518a45ae5f8SJohn Marino   struct program_space *pspace;
3519a45ae5f8SJohn Marino 
3520a45ae5f8SJohn Marino   ALL_PSPACES (pspace)
3521a45ae5f8SJohn Marino   {
3522a45ae5f8SJohn Marino     struct collect_minsyms local;
3523a45ae5f8SJohn Marino     struct cleanup *cleanup;
3524a45ae5f8SJohn Marino 
3525a45ae5f8SJohn Marino     if (search_pspace != NULL && search_pspace != pspace)
3526a45ae5f8SJohn Marino       continue;
3527a45ae5f8SJohn Marino     if (pspace->executing_startup)
3528a45ae5f8SJohn Marino       continue;
3529a45ae5f8SJohn Marino 
3530a45ae5f8SJohn Marino     set_current_program_space (pspace);
3531a45ae5f8SJohn Marino 
3532a45ae5f8SJohn Marino     memset (&local, 0, sizeof (local));
3533a45ae5f8SJohn Marino     local.funfirstline = info->state->funfirstline;
3534a45ae5f8SJohn Marino     local.list_mode = info->state->list_mode;
3535a45ae5f8SJohn Marino 
3536a45ae5f8SJohn Marino     cleanup = make_cleanup (VEC_cleanup (minsym_and_objfile_d),
3537a45ae5f8SJohn Marino 			    &local.msyms);
3538a45ae5f8SJohn Marino 
3539a45ae5f8SJohn Marino     ALL_OBJFILES (objfile)
3540a45ae5f8SJohn Marino     {
3541a45ae5f8SJohn Marino       local.objfile = objfile;
3542a45ae5f8SJohn Marino       iterate_over_minimal_symbols (objfile, name, add_minsym, &local);
3543a45ae5f8SJohn Marino     }
3544a45ae5f8SJohn Marino 
3545a45ae5f8SJohn Marino     if (!VEC_empty (minsym_and_objfile_d, local.msyms))
3546a45ae5f8SJohn Marino       {
3547a45ae5f8SJohn Marino 	int classification;
3548a45ae5f8SJohn Marino 	int ix;
3549a45ae5f8SJohn Marino 	minsym_and_objfile_d *item;
3550a45ae5f8SJohn Marino 
3551a45ae5f8SJohn Marino 	qsort (VEC_address (minsym_and_objfile_d, local.msyms),
3552a45ae5f8SJohn Marino 	       VEC_length (minsym_and_objfile_d, local.msyms),
3553a45ae5f8SJohn Marino 	       sizeof (minsym_and_objfile_d),
3554a45ae5f8SJohn Marino 	       compare_msyms);
3555a45ae5f8SJohn Marino 
3556a45ae5f8SJohn Marino 	/* Now the minsyms are in classification order.  So, we walk
3557a45ae5f8SJohn Marino 	   over them and process just the minsyms with the same
3558a45ae5f8SJohn Marino 	   classification as the very first minsym in the list.  */
3559a45ae5f8SJohn Marino 	item = VEC_index (minsym_and_objfile_d, local.msyms, 0);
3560a45ae5f8SJohn Marino 	classification = classify_mtype (MSYMBOL_TYPE (item->minsym));
3561a45ae5f8SJohn Marino 
3562a45ae5f8SJohn Marino 	for (ix = 0;
3563a45ae5f8SJohn Marino 	     VEC_iterate (minsym_and_objfile_d, local.msyms, ix, item);
3564a45ae5f8SJohn Marino 	     ++ix)
3565a45ae5f8SJohn Marino 	  {
3566a45ae5f8SJohn Marino 	    if (classify_mtype (MSYMBOL_TYPE (item->minsym)) != classification)
3567a45ae5f8SJohn Marino 	      break;
3568a45ae5f8SJohn Marino 
3569*ef5ccd6cSJohn Marino 	    VEC_safe_push (minsym_and_objfile_d,
3570*ef5ccd6cSJohn Marino 			   info->result.minimal_symbols, item);
3571a45ae5f8SJohn Marino 	  }
3572a45ae5f8SJohn Marino       }
3573a45ae5f8SJohn Marino 
3574a45ae5f8SJohn Marino     do_cleanups (cleanup);
3575a45ae5f8SJohn Marino   }
3576a45ae5f8SJohn Marino }
3577a45ae5f8SJohn Marino 
3578a45ae5f8SJohn Marino /* A helper function to add all symbols matching NAME to INFO.  If
3579a45ae5f8SJohn Marino    PSPACE is not NULL, the search is restricted to just that program
3580a45ae5f8SJohn Marino    space.  */
3581a45ae5f8SJohn Marino 
3582a45ae5f8SJohn Marino static void
add_matching_symbols_to_info(const char * name,struct collect_info * info,struct program_space * pspace)3583a45ae5f8SJohn Marino add_matching_symbols_to_info (const char *name,
3584a45ae5f8SJohn Marino 			      struct collect_info *info,
3585a45ae5f8SJohn Marino 			      struct program_space *pspace)
3586a45ae5f8SJohn Marino {
3587a45ae5f8SJohn Marino   int ix;
3588a45ae5f8SJohn Marino   struct symtab *elt;
3589a45ae5f8SJohn Marino 
3590*ef5ccd6cSJohn Marino   for (ix = 0; VEC_iterate (symtab_p, info->file_symtabs, ix, elt); ++ix)
3591a45ae5f8SJohn Marino     {
3592a45ae5f8SJohn Marino       if (elt == NULL)
3593a45ae5f8SJohn Marino 	{
3594*ef5ccd6cSJohn Marino 	  iterate_over_all_matching_symtabs (info->state, name, VAR_DOMAIN,
3595a45ae5f8SJohn Marino 					     collect_symbols, info,
3596*ef5ccd6cSJohn Marino 					     pspace, 1);
3597a45ae5f8SJohn Marino 	  search_minsyms_for_name (info, name, pspace);
3598a45ae5f8SJohn Marino 	}
3599a45ae5f8SJohn Marino       else if (pspace == NULL || pspace == SYMTAB_PSPACE (elt))
3600a45ae5f8SJohn Marino 	{
3601a45ae5f8SJohn Marino 	  /* Program spaces that are executing startup should have
3602a45ae5f8SJohn Marino 	     been filtered out earlier.  */
3603a45ae5f8SJohn Marino 	  gdb_assert (!SYMTAB_PSPACE (elt)->executing_startup);
3604a45ae5f8SJohn Marino 	  set_current_program_space (SYMTAB_PSPACE (elt));
3605*ef5ccd6cSJohn Marino 	  iterate_over_file_blocks (elt, name, VAR_DOMAIN,
3606*ef5ccd6cSJohn Marino 				    collect_symbols, info);
3607a45ae5f8SJohn Marino 	}
3608a45ae5f8SJohn Marino     }
3609c50c785cSJohn Marino }
3610c50c785cSJohn Marino 
36115796c8dcSSimon Schubert 
36125796c8dcSSimon Schubert 
36135796c8dcSSimon Schubert /* Now come some functions that are called from multiple places within
36145796c8dcSSimon Schubert    decode_line_1.  */
36155796c8dcSSimon Schubert 
3616a45ae5f8SJohn Marino static int
symbol_to_sal(struct symtab_and_line * result,int funfirstline,struct symbol * sym)3617a45ae5f8SJohn Marino symbol_to_sal (struct symtab_and_line *result,
3618a45ae5f8SJohn Marino 	       int funfirstline, struct symbol *sym)
36195796c8dcSSimon Schubert {
36205796c8dcSSimon Schubert   if (SYMBOL_CLASS (sym) == LOC_BLOCK)
36215796c8dcSSimon Schubert     {
3622a45ae5f8SJohn Marino       *result = find_function_start_sal (sym, funfirstline);
3623a45ae5f8SJohn Marino       return 1;
36245796c8dcSSimon Schubert     }
36255796c8dcSSimon Schubert   else
36265796c8dcSSimon Schubert     {
3627c50c785cSJohn Marino       if (SYMBOL_CLASS (sym) == LOC_LABEL && SYMBOL_VALUE_ADDRESS (sym) != 0)
3628c50c785cSJohn Marino 	{
3629a45ae5f8SJohn Marino 	  init_sal (result);
3630a45ae5f8SJohn Marino 	  result->symtab = SYMBOL_SYMTAB (sym);
3631a45ae5f8SJohn Marino 	  result->line = SYMBOL_LINE (sym);
3632a45ae5f8SJohn Marino 	  result->pc = SYMBOL_VALUE_ADDRESS (sym);
3633a45ae5f8SJohn Marino 	  result->pspace = SYMTAB_PSPACE (SYMBOL_SYMTAB (sym));
3634a45ae5f8SJohn Marino 	  result->explicit_pc = 1;
3635a45ae5f8SJohn Marino 	  return 1;
3636c50c785cSJohn Marino 	}
3637c50c785cSJohn Marino       else if (funfirstline)
3638c50c785cSJohn Marino 	{
3639a45ae5f8SJohn Marino 	  /* Nothing.  */
3640c50c785cSJohn Marino 	}
36415796c8dcSSimon Schubert       else if (SYMBOL_LINE (sym) != 0)
36425796c8dcSSimon Schubert 	{
36435796c8dcSSimon Schubert 	  /* We know its line number.  */
3644a45ae5f8SJohn Marino 	  init_sal (result);
3645a45ae5f8SJohn Marino 	  result->symtab = SYMBOL_SYMTAB (sym);
3646a45ae5f8SJohn Marino 	  result->line = SYMBOL_LINE (sym);
3647a45ae5f8SJohn Marino 	  result->pspace = SYMTAB_PSPACE (SYMBOL_SYMTAB (sym));
3648a45ae5f8SJohn Marino 	  return 1;
36495796c8dcSSimon Schubert 	}
36505796c8dcSSimon Schubert     }
36515796c8dcSSimon Schubert 
3652a45ae5f8SJohn Marino   return 0;
36535796c8dcSSimon Schubert }
3654c50c785cSJohn Marino 
3655a45ae5f8SJohn Marino /* See the comment in linespec.h.  */
3656a45ae5f8SJohn Marino 
3657c50c785cSJohn Marino void
init_linespec_result(struct linespec_result * lr)3658c50c785cSJohn Marino init_linespec_result (struct linespec_result *lr)
3659c50c785cSJohn Marino {
3660c50c785cSJohn Marino   memset (lr, 0, sizeof (*lr));
3661c50c785cSJohn Marino }
3662a45ae5f8SJohn Marino 
3663a45ae5f8SJohn Marino /* See the comment in linespec.h.  */
3664a45ae5f8SJohn Marino 
3665a45ae5f8SJohn Marino void
destroy_linespec_result(struct linespec_result * ls)3666a45ae5f8SJohn Marino destroy_linespec_result (struct linespec_result *ls)
3667a45ae5f8SJohn Marino {
3668a45ae5f8SJohn Marino   int i;
3669a45ae5f8SJohn Marino   struct linespec_sals *lsal;
3670a45ae5f8SJohn Marino 
3671a45ae5f8SJohn Marino   xfree (ls->addr_string);
3672a45ae5f8SJohn Marino   for (i = 0; VEC_iterate (linespec_sals, ls->sals, i, lsal); ++i)
3673a45ae5f8SJohn Marino     {
3674a45ae5f8SJohn Marino       xfree (lsal->canonical);
3675a45ae5f8SJohn Marino       xfree (lsal->sals.sals);
3676a45ae5f8SJohn Marino     }
3677a45ae5f8SJohn Marino   VEC_free (linespec_sals, ls->sals);
3678a45ae5f8SJohn Marino }
3679a45ae5f8SJohn Marino 
3680a45ae5f8SJohn Marino /* Cleanup function for a linespec_result.  */
3681a45ae5f8SJohn Marino 
3682a45ae5f8SJohn Marino static void
cleanup_linespec_result(void * a)3683a45ae5f8SJohn Marino cleanup_linespec_result (void *a)
3684a45ae5f8SJohn Marino {
3685a45ae5f8SJohn Marino   destroy_linespec_result (a);
3686a45ae5f8SJohn Marino }
3687a45ae5f8SJohn Marino 
3688a45ae5f8SJohn Marino /* See the comment in linespec.h.  */
3689a45ae5f8SJohn Marino 
3690a45ae5f8SJohn Marino struct cleanup *
make_cleanup_destroy_linespec_result(struct linespec_result * ls)3691a45ae5f8SJohn Marino make_cleanup_destroy_linespec_result (struct linespec_result *ls)
3692a45ae5f8SJohn Marino {
3693a45ae5f8SJohn Marino   return make_cleanup (cleanup_linespec_result, ls);
3694a45ae5f8SJohn Marino }
3695