Commit | Line | Data |
---|---|---|
50641945 | 1 | /* Parser for linespec for the GNU debugger, GDB. |
b6ba6518 | 2 | Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
2b0ee454 | 3 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 |
50641945 FN |
4 | Free Software Foundation, Inc. |
5 | ||
6 | This file is part of GDB. | |
7 | ||
8 | This program is free software; you can redistribute it and/or modify | |
9 | it under the terms of the GNU General Public License as published by | |
10 | the Free Software Foundation; either version 2 of the License, or | |
11 | (at your option) any later version. | |
12 | ||
13 | This program is distributed in the hope that it will be useful, | |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | GNU General Public License for more details. | |
17 | ||
18 | You should have received a copy of the GNU General Public License | |
19 | along with this program; if not, write to the Free Software | |
20 | Foundation, Inc., 59 Temple Place - Suite 330, | |
21 | Boston, MA 02111-1307, USA. */ | |
22 | ||
23 | #include "defs.h" | |
24 | #include "symtab.h" | |
c5f0f3d0 FN |
25 | #include "frame.h" |
26 | #include "command.h" | |
50641945 FN |
27 | #include "symfile.h" |
28 | #include "objfiles.h" | |
0378c332 | 29 | #include "source.h" |
50641945 | 30 | #include "demangle.h" |
c5f0f3d0 FN |
31 | #include "value.h" |
32 | #include "completer.h" | |
015a42b4 | 33 | #include "cp-abi.h" |
c38da1af | 34 | #include "parser-defs.h" |
fe898f56 | 35 | #include "block.h" |
d2630e69 | 36 | #include "objc-lang.h" |
b9362cc7 | 37 | #include "linespec.h" |
50641945 FN |
38 | |
39 | /* We share this one with symtab.c, but it is not exported widely. */ | |
40 | ||
41 | extern char *operator_chars (char *, char **); | |
42 | ||
50641945 FN |
43 | /* Prototypes for local functions */ |
44 | ||
44fe14ab DC |
45 | static void initialize_defaults (struct symtab **default_symtab, |
46 | int *default_line); | |
47 | ||
636b1a6d DC |
48 | static void set_flags (char *arg, int *is_quoted, char **paren_pointer); |
49 | ||
44fe14ab DC |
50 | static struct symtabs_and_lines decode_indirect (char **argptr); |
51 | ||
0960f083 DC |
52 | static char *locate_first_half (char **argptr, int *is_quote_enclosed); |
53 | ||
d2630e69 AF |
54 | static struct symtabs_and_lines decode_objc (char **argptr, |
55 | int funfirstline, | |
56 | struct symtab *file_symtab, | |
57 | char ***canonical, | |
58 | char *saved_arg); | |
59 | ||
614b3b14 DC |
60 | static struct symtabs_and_lines decode_compound (char **argptr, |
61 | int funfirstline, | |
62 | char ***canonical, | |
63 | char *saved_arg, | |
64 | char *p); | |
65 | ||
93d91629 DC |
66 | static struct symbol *lookup_prefix_sym (char **argptr, char *p); |
67 | ||
4224873a DC |
68 | static struct symtabs_and_lines find_method (int funfirstline, |
69 | char ***canonical, | |
70 | char *saved_arg, | |
71 | char *copy, | |
72 | struct type *t, | |
73 | struct symbol *sym_class); | |
74 | ||
78a11fb4 DC |
75 | static int collect_methods (char *copy, struct type *t, |
76 | struct symbol **sym_arr); | |
77 | ||
614b3b14 DC |
78 | static NORETURN void cplusplus_error (const char *name, |
79 | const char *fmt, ...) | |
80 | ATTR_NORETURN ATTR_FORMAT (printf, 2, 3); | |
50641945 FN |
81 | |
82 | static int total_number_of_methods (struct type *type); | |
83 | ||
84 | static int find_methods (struct type *, char *, struct symbol **); | |
85 | ||
aee8d8ba DC |
86 | static int add_matching_methods (int method_counter, struct type *t, |
87 | struct symbol **sym_arr); | |
88 | ||
89 | static int add_constructors (int method_counter, struct type *t, | |
90 | struct symbol **sym_arr); | |
91 | ||
50641945 FN |
92 | static void build_canonical_line_spec (struct symtab_and_line *, |
93 | char *, char ***); | |
94 | ||
95 | static char *find_toplevel_char (char *s, char c); | |
96 | ||
889f28e2 AF |
97 | static int is_objc_method_format (const char *s); |
98 | ||
50641945 FN |
99 | static struct symtabs_and_lines decode_line_2 (struct symbol *[], |
100 | int, int, char ***); | |
101 | ||
f3c39e76 DC |
102 | static struct symtab *symtab_from_filename (char **argptr, |
103 | char *p, int is_quote_enclosed); | |
104 | ||
84fba31b DC |
105 | static struct |
106 | symtabs_and_lines decode_all_digits (char **argptr, | |
107 | struct symtab *default_symtab, | |
108 | int default_line, | |
109 | char ***canonical, | |
88d262ca | 110 | struct symtab *file_symtab, |
84fba31b DC |
111 | char *q); |
112 | ||
14e91ac5 DC |
113 | static struct symtabs_and_lines decode_dollar (char *copy, |
114 | int funfirstline, | |
115 | struct symtab *default_symtab, | |
116 | char ***canonical, | |
88d262ca | 117 | struct symtab *file_symtab); |
14e91ac5 | 118 | |
bca02a8a DC |
119 | static struct symtabs_and_lines decode_variable (char *copy, |
120 | int funfirstline, | |
121 | char ***canonical, | |
88d262ca | 122 | struct symtab *file_symtab); |
bca02a8a | 123 | |
413dad4d DC |
124 | static struct |
125 | symtabs_and_lines symbol_found (int funfirstline, | |
126 | char ***canonical, | |
127 | char *copy, | |
128 | struct symbol *sym, | |
88d262ca | 129 | struct symtab *file_symtab, |
413dad4d DC |
130 | struct symtab *sym_symtab); |
131 | ||
132 | static struct | |
133 | symtabs_and_lines minsym_found (int funfirstline, | |
134 | struct minimal_symbol *msymbol); | |
135 | ||
50641945 FN |
136 | /* Helper functions. */ |
137 | ||
255e7dbf AC |
138 | /* Issue a helpful hint on using the command completion feature on |
139 | single quoted demangled C++ symbols as part of the completion | |
140 | error. */ | |
50641945 | 141 | |
614b3b14 | 142 | static NORETURN void |
255e7dbf | 143 | cplusplus_error (const char *name, const char *fmt, ...) |
50641945 | 144 | { |
255e7dbf AC |
145 | struct ui_file *tmp_stream; |
146 | tmp_stream = mem_fileopen (); | |
147 | make_cleanup_ui_file_delete (tmp_stream); | |
148 | ||
149 | { | |
150 | va_list args; | |
151 | va_start (args, fmt); | |
152 | vfprintf_unfiltered (tmp_stream, fmt, args); | |
153 | va_end (args); | |
154 | } | |
155 | ||
50641945 FN |
156 | while (*name == '\'') |
157 | name++; | |
255e7dbf AC |
158 | fprintf_unfiltered (tmp_stream, |
159 | ("Hint: try '%s<TAB> or '%s<ESC-?>\n" | |
160 | "(Note leading single quote.)"), | |
161 | name, name); | |
162 | error_stream (tmp_stream); | |
50641945 FN |
163 | } |
164 | ||
165 | /* Return the number of methods described for TYPE, including the | |
166 | methods from types it derives from. This can't be done in the symbol | |
167 | reader because the type of the baseclass might still be stubbed | |
168 | when the definition of the derived class is parsed. */ | |
169 | ||
170 | static int | |
171 | total_number_of_methods (struct type *type) | |
172 | { | |
173 | int n; | |
174 | int count; | |
175 | ||
176 | CHECK_TYPEDEF (type); | |
177 | if (TYPE_CPLUS_SPECIFIC (type) == NULL) | |
178 | return 0; | |
179 | count = TYPE_NFN_FIELDS_TOTAL (type); | |
180 | ||
181 | for (n = 0; n < TYPE_N_BASECLASSES (type); n++) | |
182 | count += total_number_of_methods (TYPE_BASECLASS (type, n)); | |
183 | ||
184 | return count; | |
185 | } | |
186 | ||
187 | /* Recursive helper function for decode_line_1. | |
188 | Look for methods named NAME in type T. | |
189 | Return number of matches. | |
190 | Put matches in SYM_ARR, which should have been allocated with | |
191 | a size of total_number_of_methods (T) * sizeof (struct symbol *). | |
192 | Note that this function is g++ specific. */ | |
193 | ||
194 | static int | |
195 | find_methods (struct type *t, char *name, struct symbol **sym_arr) | |
196 | { | |
197 | int i1 = 0; | |
198 | int ibase; | |
50641945 FN |
199 | char *class_name = type_name_no_tag (t); |
200 | ||
201 | /* Ignore this class if it doesn't have a name. This is ugly, but | |
202 | unless we figure out how to get the physname without the name of | |
203 | the class, then the loop can't do any good. */ | |
204 | if (class_name | |
8bd1f2c6 | 205 | && (lookup_symbol (class_name, (struct block *) NULL, |
176620f1 | 206 | STRUCT_DOMAIN, (int *) NULL, |
8bd1f2c6 | 207 | (struct symtab **) NULL))) |
50641945 FN |
208 | { |
209 | int method_counter; | |
5c717440 | 210 | int name_len = strlen (name); |
50641945 | 211 | |
8bd1f2c6 | 212 | CHECK_TYPEDEF (t); |
50641945 FN |
213 | |
214 | /* Loop over each method name. At this level, all overloads of a name | |
215 | are counted as a single name. There is an inner loop which loops over | |
216 | each overload. */ | |
217 | ||
218 | for (method_counter = TYPE_NFN_FIELDS (t) - 1; | |
219 | method_counter >= 0; | |
220 | --method_counter) | |
221 | { | |
50641945 FN |
222 | char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter); |
223 | char dem_opname[64]; | |
224 | ||
225 | if (strncmp (method_name, "__", 2) == 0 || | |
226 | strncmp (method_name, "op", 2) == 0 || | |
227 | strncmp (method_name, "type", 4) == 0) | |
228 | { | |
229 | if (cplus_demangle_opname (method_name, dem_opname, DMGL_ANSI)) | |
230 | method_name = dem_opname; | |
231 | else if (cplus_demangle_opname (method_name, dem_opname, 0)) | |
232 | method_name = dem_opname; | |
233 | } | |
234 | ||
13b57657 | 235 | if (strcmp_iw (name, method_name) == 0) |
50641945 | 236 | /* Find all the overloaded methods with that name. */ |
aee8d8ba DC |
237 | i1 += add_matching_methods (method_counter, t, |
238 | sym_arr + i1); | |
5c717440 DJ |
239 | else if (strncmp (class_name, name, name_len) == 0 |
240 | && (class_name[name_len] == '\0' | |
241 | || class_name[name_len] == '<')) | |
aee8d8ba DC |
242 | i1 += add_constructors (method_counter, t, |
243 | sym_arr + i1); | |
50641945 FN |
244 | } |
245 | } | |
246 | ||
247 | /* Only search baseclasses if there is no match yet, since names in | |
248 | derived classes override those in baseclasses. | |
249 | ||
250 | FIXME: The above is not true; it is only true of member functions | |
251 | if they have the same number of arguments (??? - section 13.1 of the | |
252 | ARM says the function members are not in the same scope but doesn't | |
253 | really spell out the rules in a way I understand. In any case, if | |
254 | the number of arguments differ this is a case in which we can overload | |
255 | rather than hiding without any problem, and gcc 2.4.5 does overload | |
256 | rather than hiding in this case). */ | |
257 | ||
258 | if (i1 == 0) | |
259 | for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++) | |
260 | i1 += find_methods (TYPE_BASECLASS (t, ibase), name, sym_arr + i1); | |
261 | ||
262 | return i1; | |
263 | } | |
264 | ||
aee8d8ba DC |
265 | /* Add the symbols associated to methods of the class whose type is T |
266 | and whose name matches the method indexed by METHOD_COUNTER in the | |
267 | array SYM_ARR. Return the number of methods added. */ | |
268 | ||
269 | static int | |
270 | add_matching_methods (int method_counter, struct type *t, | |
271 | struct symbol **sym_arr) | |
272 | { | |
273 | int field_counter; | |
274 | int i1 = 0; | |
275 | ||
276 | for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1; | |
277 | field_counter >= 0; | |
278 | --field_counter) | |
279 | { | |
280 | struct fn_field *f; | |
281 | char *phys_name; | |
282 | ||
283 | f = TYPE_FN_FIELDLIST1 (t, method_counter); | |
284 | ||
285 | if (TYPE_FN_FIELD_STUB (f, field_counter)) | |
286 | { | |
287 | char *tmp_name; | |
288 | ||
289 | tmp_name = gdb_mangle_name (t, | |
290 | method_counter, | |
291 | field_counter); | |
292 | phys_name = alloca (strlen (tmp_name) + 1); | |
293 | strcpy (phys_name, tmp_name); | |
294 | xfree (tmp_name); | |
295 | } | |
296 | else | |
297 | phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter); | |
298 | ||
299 | /* Destructor is handled by caller, don't add it to | |
300 | the list. */ | |
301 | if (is_destructor_name (phys_name) != 0) | |
302 | continue; | |
303 | ||
304 | sym_arr[i1] = lookup_symbol (phys_name, | |
305 | NULL, VAR_DOMAIN, | |
306 | (int *) NULL, | |
307 | (struct symtab **) NULL); | |
308 | if (sym_arr[i1]) | |
309 | i1++; | |
310 | else | |
311 | { | |
312 | /* This error message gets printed, but the method | |
313 | still seems to be found | |
314 | fputs_filtered("(Cannot find method ", gdb_stdout); | |
315 | fprintf_symbol_filtered (gdb_stdout, phys_name, | |
316 | language_cplus, | |
317 | DMGL_PARAMS | DMGL_ANSI); | |
318 | fputs_filtered(" - possibly inlined.)\n", gdb_stdout); | |
319 | */ | |
320 | } | |
321 | } | |
322 | ||
323 | return i1; | |
324 | } | |
325 | ||
326 | /* Add the symbols associated to constructors of the class whose type | |
327 | is CLASS_TYPE and which are indexed by by METHOD_COUNTER to the | |
328 | array SYM_ARR. Return the number of methods added. */ | |
329 | ||
330 | static int | |
331 | add_constructors (int method_counter, struct type *t, | |
332 | struct symbol **sym_arr) | |
333 | { | |
334 | int field_counter; | |
335 | int i1 = 0; | |
336 | ||
337 | /* For GCC 3.x and stabs, constructors and destructors | |
338 | have names like __base_ctor and __complete_dtor. | |
339 | Check the physname for now if we're looking for a | |
340 | constructor. */ | |
341 | for (field_counter | |
342 | = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1; | |
343 | field_counter >= 0; | |
344 | --field_counter) | |
345 | { | |
346 | struct fn_field *f; | |
347 | char *phys_name; | |
348 | ||
349 | f = TYPE_FN_FIELDLIST1 (t, method_counter); | |
350 | ||
351 | /* GCC 3.x will never produce stabs stub methods, so | |
352 | we don't need to handle this case. */ | |
353 | if (TYPE_FN_FIELD_STUB (f, field_counter)) | |
354 | continue; | |
355 | phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter); | |
356 | if (! is_constructor_name (phys_name)) | |
357 | continue; | |
358 | ||
359 | /* If this method is actually defined, include it in the | |
360 | list. */ | |
361 | sym_arr[i1] = lookup_symbol (phys_name, | |
362 | NULL, VAR_DOMAIN, | |
363 | (int *) NULL, | |
364 | (struct symtab **) NULL); | |
365 | if (sym_arr[i1]) | |
366 | i1++; | |
367 | } | |
368 | ||
369 | return i1; | |
370 | } | |
371 | ||
50641945 FN |
372 | /* Helper function for decode_line_1. |
373 | Build a canonical line spec in CANONICAL if it is non-NULL and if | |
374 | the SAL has a symtab. | |
375 | If SYMNAME is non-NULL the canonical line spec is `filename:symname'. | |
376 | If SYMNAME is NULL the line number from SAL is used and the canonical | |
377 | line spec is `filename:linenum'. */ | |
378 | ||
379 | static void | |
380 | build_canonical_line_spec (struct symtab_and_line *sal, char *symname, | |
381 | char ***canonical) | |
382 | { | |
383 | char **canonical_arr; | |
384 | char *canonical_name; | |
385 | char *filename; | |
386 | struct symtab *s = sal->symtab; | |
387 | ||
388 | if (s == (struct symtab *) NULL | |
389 | || s->filename == (char *) NULL | |
390 | || canonical == (char ***) NULL) | |
391 | return; | |
392 | ||
393 | canonical_arr = (char **) xmalloc (sizeof (char *)); | |
394 | *canonical = canonical_arr; | |
395 | ||
396 | filename = s->filename; | |
397 | if (symname != NULL) | |
398 | { | |
399 | canonical_name = xmalloc (strlen (filename) + strlen (symname) + 2); | |
400 | sprintf (canonical_name, "%s:%s", filename, symname); | |
401 | } | |
402 | else | |
403 | { | |
404 | canonical_name = xmalloc (strlen (filename) + 30); | |
405 | sprintf (canonical_name, "%s:%d", filename, sal->line); | |
406 | } | |
407 | canonical_arr[0] = canonical_name; | |
408 | } | |
409 | ||
410 | ||
411 | ||
412 | /* Find an instance of the character C in the string S that is outside | |
413 | of all parenthesis pairs, single-quoted strings, and double-quoted | |
8120c9d5 EZ |
414 | strings. Also, ignore the char within a template name, like a ',' |
415 | within foo<int, int>. */ | |
416 | ||
50641945 FN |
417 | static char * |
418 | find_toplevel_char (char *s, char c) | |
419 | { | |
420 | int quoted = 0; /* zero if we're not in quotes; | |
421 | '"' if we're in a double-quoted string; | |
422 | '\'' if we're in a single-quoted string. */ | |
a04257e6 | 423 | int depth = 0; /* Number of unclosed parens we've seen. */ |
50641945 FN |
424 | char *scan; |
425 | ||
426 | for (scan = s; *scan; scan++) | |
427 | { | |
428 | if (quoted) | |
429 | { | |
430 | if (*scan == quoted) | |
431 | quoted = 0; | |
432 | else if (*scan == '\\' && *(scan + 1)) | |
433 | scan++; | |
434 | } | |
435 | else if (*scan == c && ! quoted && depth == 0) | |
436 | return scan; | |
437 | else if (*scan == '"' || *scan == '\'') | |
438 | quoted = *scan; | |
8120c9d5 | 439 | else if (*scan == '(' || *scan == '<') |
50641945 | 440 | depth++; |
8120c9d5 | 441 | else if ((*scan == ')' || *scan == '>') && depth > 0) |
50641945 FN |
442 | depth--; |
443 | } | |
444 | ||
445 | return 0; | |
446 | } | |
447 | ||
889f28e2 AF |
448 | /* Determines if the gives string corresponds to an Objective-C method |
449 | representation, such as -[Foo bar:] or +[Foo bar]. Objective-C symbols | |
450 | are allowed to have spaces and parentheses in them. */ | |
451 | ||
452 | static int | |
453 | is_objc_method_format (const char *s) | |
454 | { | |
455 | if (s == NULL || *s == '\0') | |
456 | return 0; | |
457 | /* Handle arguments with the format FILENAME:SYMBOL. */ | |
458 | if ((s[0] == ':') && (strchr ("+-", s[1]) != NULL) | |
459 | && (s[2] == '[') && strchr(s, ']')) | |
460 | return 1; | |
461 | /* Handle arguments that are just SYMBOL. */ | |
462 | else if ((strchr ("+-", s[0]) != NULL) && (s[1] == '[') && strchr(s, ']')) | |
463 | return 1; | |
464 | return 0; | |
465 | } | |
466 | ||
50641945 FN |
467 | /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to |
468 | operate on (ask user if necessary). | |
469 | If CANONICAL is non-NULL return a corresponding array of mangled names | |
470 | as canonical line specs there. */ | |
471 | ||
472 | static struct symtabs_and_lines | |
473 | decode_line_2 (struct symbol *sym_arr[], int nelts, int funfirstline, | |
474 | char ***canonical) | |
475 | { | |
476 | struct symtabs_and_lines values, return_values; | |
477 | char *args, *arg1; | |
478 | int i; | |
479 | char *prompt; | |
480 | char *symname; | |
481 | struct cleanup *old_chain; | |
482 | char **canonical_arr = (char **) NULL; | |
483 | ||
484 | values.sals = (struct symtab_and_line *) | |
485 | alloca (nelts * sizeof (struct symtab_and_line)); | |
486 | return_values.sals = (struct symtab_and_line *) | |
487 | xmalloc (nelts * sizeof (struct symtab_and_line)); | |
b8c9b27d | 488 | old_chain = make_cleanup (xfree, return_values.sals); |
50641945 FN |
489 | |
490 | if (canonical) | |
491 | { | |
492 | canonical_arr = (char **) xmalloc (nelts * sizeof (char *)); | |
b8c9b27d | 493 | make_cleanup (xfree, canonical_arr); |
50641945 FN |
494 | memset (canonical_arr, 0, nelts * sizeof (char *)); |
495 | *canonical = canonical_arr; | |
496 | } | |
497 | ||
498 | i = 0; | |
499 | printf_unfiltered ("[0] cancel\n[1] all\n"); | |
500 | while (i < nelts) | |
501 | { | |
a04257e6 | 502 | init_sal (&return_values.sals[i]); /* Initialize to zeroes. */ |
fe39c653 | 503 | init_sal (&values.sals[i]); |
50641945 FN |
504 | if (sym_arr[i] && SYMBOL_CLASS (sym_arr[i]) == LOC_BLOCK) |
505 | { | |
506 | values.sals[i] = find_function_start_sal (sym_arr[i], funfirstline); | |
63cd4198 EZ |
507 | if (values.sals[i].symtab) |
508 | printf_unfiltered ("[%d] %s at %s:%d\n", | |
509 | (i + 2), | |
510 | SYMBOL_PRINT_NAME (sym_arr[i]), | |
511 | values.sals[i].symtab->filename, | |
512 | values.sals[i].line); | |
513 | else | |
514 | printf_unfiltered ("[%d] %s at ?FILE:%d [No symtab? Probably broken debug info...]\n", | |
515 | (i + 2), | |
516 | SYMBOL_PRINT_NAME (sym_arr[i]), | |
517 | values.sals[i].line); | |
518 | ||
50641945 FN |
519 | } |
520 | else | |
521 | printf_unfiltered ("?HERE\n"); | |
522 | i++; | |
523 | } | |
524 | ||
5cb316ef AC |
525 | prompt = getenv ("PS2"); |
526 | if (prompt == NULL) | |
50641945 FN |
527 | { |
528 | prompt = "> "; | |
529 | } | |
530 | args = command_line_input (prompt, 0, "overload-choice"); | |
531 | ||
532 | if (args == 0 || *args == 0) | |
533 | error_no_arg ("one or more choice numbers"); | |
534 | ||
535 | i = 0; | |
536 | while (*args) | |
537 | { | |
538 | int num; | |
539 | ||
540 | arg1 = args; | |
541 | while (*arg1 >= '0' && *arg1 <= '9') | |
542 | arg1++; | |
543 | if (*arg1 && *arg1 != ' ' && *arg1 != '\t') | |
544 | error ("Arguments must be choice numbers."); | |
545 | ||
546 | num = atoi (args); | |
547 | ||
548 | if (num == 0) | |
549 | error ("canceled"); | |
550 | else if (num == 1) | |
551 | { | |
552 | if (canonical_arr) | |
553 | { | |
554 | for (i = 0; i < nelts; i++) | |
555 | { | |
556 | if (canonical_arr[i] == NULL) | |
557 | { | |
22abf04a | 558 | symname = DEPRECATED_SYMBOL_NAME (sym_arr[i]); |
50641945 FN |
559 | canonical_arr[i] = savestring (symname, strlen (symname)); |
560 | } | |
561 | } | |
562 | } | |
563 | memcpy (return_values.sals, values.sals, | |
564 | (nelts * sizeof (struct symtab_and_line))); | |
565 | return_values.nelts = nelts; | |
566 | discard_cleanups (old_chain); | |
567 | return return_values; | |
568 | } | |
569 | ||
570 | if (num >= nelts + 2) | |
571 | { | |
572 | printf_unfiltered ("No choice number %d.\n", num); | |
573 | } | |
574 | else | |
575 | { | |
576 | num -= 2; | |
577 | if (values.sals[num].pc) | |
578 | { | |
579 | if (canonical_arr) | |
580 | { | |
22abf04a | 581 | symname = DEPRECATED_SYMBOL_NAME (sym_arr[num]); |
b8c9b27d | 582 | make_cleanup (xfree, symname); |
50641945 FN |
583 | canonical_arr[i] = savestring (symname, strlen (symname)); |
584 | } | |
585 | return_values.sals[i++] = values.sals[num]; | |
586 | values.sals[num].pc = 0; | |
587 | } | |
588 | else | |
589 | { | |
590 | printf_unfiltered ("duplicate request for %d ignored.\n", num); | |
591 | } | |
592 | } | |
593 | ||
594 | args = arg1; | |
595 | while (*args == ' ' || *args == '\t') | |
596 | args++; | |
597 | } | |
598 | return_values.nelts = i; | |
599 | discard_cleanups (old_chain); | |
600 | return return_values; | |
601 | } | |
602 | \f | |
603 | /* The parser of linespec itself. */ | |
604 | ||
605 | /* Parse a string that specifies a line number. | |
606 | Pass the address of a char * variable; that variable will be | |
607 | advanced over the characters actually parsed. | |
608 | ||
609 | The string can be: | |
610 | ||
611 | LINENUM -- that line number in current file. PC returned is 0. | |
612 | FILE:LINENUM -- that line in that file. PC returned is 0. | |
613 | FUNCTION -- line number of openbrace of that function. | |
614 | PC returned is the start of the function. | |
615 | VARIABLE -- line number of definition of that variable. | |
616 | PC returned is 0. | |
617 | FILE:FUNCTION -- likewise, but prefer functions in that file. | |
618 | *EXPR -- line in which address EXPR appears. | |
619 | ||
620 | This may all be followed by an "if EXPR", which we ignore. | |
621 | ||
622 | FUNCTION may be an undebuggable function found in minimal symbol table. | |
623 | ||
624 | If the argument FUNFIRSTLINE is nonzero, we want the first line | |
625 | of real code inside a function when a function is specified, and it is | |
626 | not OK to specify a variable or type to get its line number. | |
627 | ||
628 | DEFAULT_SYMTAB specifies the file to use if none is specified. | |
629 | It defaults to current_source_symtab. | |
630 | DEFAULT_LINE specifies the line number to use for relative | |
631 | line numbers (that start with signs). Defaults to current_source_line. | |
632 | If CANONICAL is non-NULL, store an array of strings containing the canonical | |
633 | line specs there if necessary. Currently overloaded member functions and | |
634 | line numbers or static functions without a filename yield a canonical | |
635 | line spec. The array and the line spec strings are allocated on the heap, | |
636 | it is the callers responsibility to free them. | |
637 | ||
638 | Note that it is possible to return zero for the symtab | |
639 | if no file is validly specified. Callers must check that. | |
640 | Also, the line number returned may be invalid. */ | |
641 | ||
642 | /* We allow single quotes in various places. This is a hideous | |
643 | kludge, which exists because the completer can't yet deal with the | |
644 | lack of single quotes. FIXME: write a linespec_completer which we | |
645 | can use as appropriate instead of make_symbol_completion_list. */ | |
646 | ||
647 | struct symtabs_and_lines | |
648 | decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab, | |
649 | int default_line, char ***canonical) | |
650 | { | |
f3c39e76 | 651 | char *p; |
614b3b14 | 652 | char *q; |
88d262ca DC |
653 | /* If a file name is specified, this is its symtab. */ |
654 | struct symtab *file_symtab = NULL; | |
50641945 | 655 | |
50641945 | 656 | char *copy; |
636b1a6d DC |
657 | /* This is NULL if there are no parens in *ARGPTR, or a pointer to |
658 | the closing parenthesis if there are parens. */ | |
659 | char *paren_pointer; | |
660 | /* This says whether or not something in *ARGPTR is quoted with | |
661 | completer_quotes (i.e. with single quotes). */ | |
50641945 | 662 | int is_quoted; |
0960f083 | 663 | /* Is part of *ARGPTR is enclosed in double quotes? */ |
50641945 | 664 | int is_quote_enclosed; |
d2630e69 | 665 | int is_objc_method = 0; |
50641945 | 666 | char *saved_arg = *argptr; |
50641945 | 667 | |
50641945 FN |
668 | /* Defaults have defaults. */ |
669 | ||
44fe14ab DC |
670 | initialize_defaults (&default_symtab, &default_line); |
671 | ||
a04257e6 | 672 | /* See if arg is *PC. */ |
50641945 FN |
673 | |
674 | if (**argptr == '*') | |
44fe14ab | 675 | return decode_indirect (argptr); |
50641945 | 676 | |
a04257e6 DC |
677 | /* Set various flags. 'paren_pointer' is important for overload |
678 | checking, where we allow things like: | |
679 | (gdb) break c::f(int) | |
680 | */ | |
50641945 | 681 | |
636b1a6d | 682 | set_flags (*argptr, &is_quoted, &paren_pointer); |
50641945 | 683 | |
0960f083 DC |
684 | /* Check to see if it's a multipart linespec (with colons or |
685 | periods). */ | |
50641945 | 686 | |
0960f083 | 687 | /* Locate the end of the first half of the linespec. */ |
50641945 | 688 | |
0960f083 | 689 | p = locate_first_half (argptr, &is_quote_enclosed); |
50641945 | 690 | |
d2630e69 AF |
691 | /* Check if this is an Objective-C method (anything that starts with |
692 | a '+' or '-' and a '['). */ | |
889f28e2 | 693 | if (is_objc_method_format (p)) |
d2630e69 AF |
694 | { |
695 | is_objc_method = 1; | |
696 | paren_pointer = NULL; /* Just a category name. Ignore it. */ | |
697 | } | |
698 | ||
699 | /* Check if the symbol could be an Objective-C selector. */ | |
700 | ||
701 | { | |
702 | struct symtabs_and_lines values; | |
703 | values = decode_objc (argptr, funfirstline, NULL, | |
704 | canonical, saved_arg); | |
705 | if (values.sals != NULL) | |
706 | return values; | |
707 | } | |
708 | ||
0960f083 | 709 | /* Does it look like there actually were two parts? */ |
50641945 | 710 | |
636b1a6d | 711 | if ((p[0] == ':' || p[0] == '.') && paren_pointer == NULL) |
50641945 | 712 | { |
50641945 FN |
713 | if (is_quoted) |
714 | *argptr = *argptr + 1; | |
f3c39e76 DC |
715 | |
716 | /* Is it a C++ or Java compound data structure? */ | |
717 | ||
50641945 | 718 | if (p[0] == '.' || p[1] == ':') |
614b3b14 DC |
719 | return decode_compound (argptr, funfirstline, canonical, |
720 | saved_arg, p); | |
50641945 | 721 | |
f3c39e76 DC |
722 | /* No, the first part is a filename; set s to be that file's |
723 | symtab. Also, move argptr past the filename. */ | |
50641945 | 724 | |
88d262ca | 725 | file_symtab = symtab_from_filename (argptr, p, is_quote_enclosed); |
50641945 FN |
726 | } |
727 | #if 0 | |
728 | /* No one really seems to know why this was added. It certainly | |
729 | breaks the command line, though, whenever the passed | |
730 | name is of the form ClassName::Method. This bit of code | |
731 | singles out the class name, and if funfirstline is set (for | |
732 | example, you are setting a breakpoint at this function), | |
733 | you get an error. This did not occur with earlier | |
734 | verions, so I am ifdef'ing this out. 3/29/99 */ | |
735 | else | |
736 | { | |
737 | /* Check if what we have till now is a symbol name */ | |
738 | ||
739 | /* We may be looking at a template instantiation such | |
740 | as "foo<int>". Check here whether we know about it, | |
741 | instead of falling through to the code below which | |
742 | handles ordinary function names, because that code | |
743 | doesn't like seeing '<' and '>' in a name -- the | |
744 | skip_quoted call doesn't go past them. So see if we | |
745 | can figure it out right now. */ | |
746 | ||
747 | copy = (char *) alloca (p - *argptr + 1); | |
748 | memcpy (copy, *argptr, p - *argptr); | |
749 | copy[p - *argptr] = '\000'; | |
176620f1 | 750 | sym = lookup_symbol (copy, 0, VAR_DOMAIN, 0, &sym_symtab); |
50641945 FN |
751 | if (sym) |
752 | { | |
50641945 | 753 | *argptr = (*p == '\'') ? p + 1 : p; |
413dad4d DC |
754 | return symbol_found (funfirstline, canonical, copy, sym, |
755 | NULL, sym_symtab); | |
50641945 FN |
756 | } |
757 | /* Otherwise fall out from here and go to file/line spec | |
758 | processing, etc. */ | |
759 | } | |
760 | #endif | |
761 | ||
762 | /* S is specified file's symtab, or 0 if no file specified. | |
763 | arg no longer contains the file name. */ | |
764 | ||
a04257e6 | 765 | /* Check whether arg is all digits (and sign). */ |
50641945 FN |
766 | |
767 | q = *argptr; | |
768 | if (*q == '-' || *q == '+') | |
769 | q++; | |
770 | while (*q >= '0' && *q <= '9') | |
771 | q++; | |
772 | ||
773 | if (q != *argptr && (*q == 0 || *q == ' ' || *q == '\t' || *q == ',')) | |
84fba31b DC |
774 | /* We found a token consisting of all digits -- at least one digit. */ |
775 | return decode_all_digits (argptr, default_symtab, default_line, | |
88d262ca | 776 | canonical, file_symtab, q); |
50641945 FN |
777 | |
778 | /* Arg token is not digits => try it as a variable name | |
779 | Find the next token (everything up to end or next whitespace). */ | |
780 | ||
a04257e6 DC |
781 | if (**argptr == '$') /* May be a convenience variable. */ |
782 | /* One or two $ chars possible. */ | |
783 | p = skip_quoted (*argptr + (((*argptr)[1] == '$') ? 2 : 1)); | |
50641945 FN |
784 | else if (is_quoted) |
785 | { | |
786 | p = skip_quoted (*argptr); | |
787 | if (p[-1] != '\'') | |
788 | error ("Unmatched single quote."); | |
789 | } | |
d2630e69 AF |
790 | else if (is_objc_method) |
791 | { | |
792 | /* allow word separators in method names for Obj-C */ | |
793 | p = skip_quoted_chars (*argptr, NULL, ""); | |
794 | } | |
636b1a6d | 795 | else if (paren_pointer != NULL) |
50641945 | 796 | { |
636b1a6d | 797 | p = paren_pointer + 1; |
50641945 FN |
798 | } |
799 | else | |
800 | { | |
801 | p = skip_quoted (*argptr); | |
802 | } | |
803 | ||
50641945 FN |
804 | copy = (char *) alloca (p - *argptr + 1); |
805 | memcpy (copy, *argptr, p - *argptr); | |
806 | copy[p - *argptr] = '\0'; | |
807 | if (p != *argptr | |
808 | && copy[0] | |
809 | && copy[0] == copy[p - *argptr - 1] | |
c5f0f3d0 | 810 | && strchr (get_gdb_completer_quote_characters (), copy[0]) != NULL) |
50641945 FN |
811 | { |
812 | copy[p - *argptr - 1] = '\0'; | |
813 | copy++; | |
814 | } | |
815 | while (*p == ' ' || *p == '\t') | |
816 | p++; | |
817 | *argptr = p; | |
818 | ||
819 | /* If it starts with $: may be a legitimate variable or routine name | |
820 | (e.g. HP-UX millicode routines such as $$dyncall), or it may | |
a04257e6 | 821 | be history value, or it may be a convenience variable. */ |
50641945 FN |
822 | |
823 | if (*copy == '$') | |
14e91ac5 | 824 | return decode_dollar (copy, funfirstline, default_symtab, |
88d262ca | 825 | canonical, file_symtab); |
50641945 FN |
826 | |
827 | /* Look up that token as a variable. | |
828 | If file specified, use that file's per-file block to start with. */ | |
829 | ||
88d262ca | 830 | return decode_variable (copy, funfirstline, canonical, file_symtab); |
413dad4d | 831 | } |
50641945 | 832 | |
44fe14ab DC |
833 | \f |
834 | ||
614b3b14 DC |
835 | /* Now, more helper functions for decode_line_1. Some conventions |
836 | that these functions follow: | |
837 | ||
838 | Decode_line_1 typically passes along some of its arguments or local | |
839 | variables to the subfunctions. It passes the variables by | |
840 | reference if they are modified by the subfunction, and by value | |
841 | otherwise. | |
842 | ||
843 | Some of the functions have side effects that don't arise from | |
844 | variables that are passed by reference. In particular, if a | |
845 | function is passed ARGPTR as an argument, it modifies what ARGPTR | |
846 | points to; typically, it advances *ARGPTR past whatever substring | |
847 | it has just looked at. (If it doesn't modify *ARGPTR, then the | |
848 | function gets passed *ARGPTR instead, which is then called ARG: see | |
849 | set_flags, for example.) Also, functions that return a struct | |
850 | symtabs_and_lines may modify CANONICAL, as in the description of | |
851 | decode_line_1. | |
852 | ||
853 | If a function returns a struct symtabs_and_lines, then that struct | |
854 | will immediately make its way up the call chain to be returned by | |
855 | decode_line_1. In particular, all of the functions decode_XXX | |
856 | calculate the appropriate struct symtabs_and_lines, under the | |
857 | assumption that their argument is of the form XXX. */ | |
44fe14ab DC |
858 | |
859 | /* First, some functions to initialize stuff at the beggining of the | |
860 | function. */ | |
861 | ||
862 | static void | |
863 | initialize_defaults (struct symtab **default_symtab, int *default_line) | |
864 | { | |
865 | if (*default_symtab == 0) | |
866 | { | |
867 | /* Use whatever we have for the default source line. We don't use | |
868 | get_current_or_default_symtab_and_line as it can recurse and call | |
869 | us back! */ | |
870 | struct symtab_and_line cursal = | |
871 | get_current_source_symtab_and_line (); | |
872 | ||
873 | *default_symtab = cursal.symtab; | |
874 | *default_line = cursal.line; | |
875 | } | |
876 | } | |
877 | ||
636b1a6d DC |
878 | static void |
879 | set_flags (char *arg, int *is_quoted, char **paren_pointer) | |
880 | { | |
881 | char *ii; | |
882 | int has_if = 0; | |
883 | ||
884 | /* 'has_if' is for the syntax: | |
a04257e6 DC |
885 | (gdb) break foo if (a==b) |
886 | */ | |
636b1a6d DC |
887 | if ((ii = strstr (arg, " if ")) != NULL || |
888 | (ii = strstr (arg, "\tif ")) != NULL || | |
889 | (ii = strstr (arg, " if\t")) != NULL || | |
890 | (ii = strstr (arg, "\tif\t")) != NULL || | |
891 | (ii = strstr (arg, " if(")) != NULL || | |
892 | (ii = strstr (arg, "\tif( ")) != NULL) | |
893 | has_if = 1; | |
a04257e6 DC |
894 | /* Temporarily zap out "if (condition)" to not confuse the |
895 | parenthesis-checking code below. This is undone below. Do not | |
896 | change ii!! */ | |
636b1a6d DC |
897 | if (has_if) |
898 | { | |
899 | *ii = '\0'; | |
900 | } | |
901 | ||
902 | *is_quoted = (*arg | |
903 | && strchr (get_gdb_completer_quote_characters (), | |
904 | *arg) != NULL); | |
905 | ||
906 | *paren_pointer = strchr (arg, '('); | |
907 | if (*paren_pointer != NULL) | |
908 | *paren_pointer = strrchr (*paren_pointer, ')'); | |
909 | ||
a04257e6 DC |
910 | /* Now that we're safely past the paren_pointer check, put back " if |
911 | (condition)" so outer layers can see it. */ | |
636b1a6d DC |
912 | if (has_if) |
913 | *ii = ' '; | |
914 | } | |
915 | ||
44fe14ab DC |
916 | \f |
917 | ||
918 | /* Decode arg of the form *PC. */ | |
919 | ||
920 | static struct symtabs_and_lines | |
921 | decode_indirect (char **argptr) | |
922 | { | |
923 | struct symtabs_and_lines values; | |
924 | CORE_ADDR pc; | |
925 | ||
926 | (*argptr)++; | |
927 | pc = parse_and_eval_address_1 (argptr); | |
928 | ||
929 | values.sals = (struct symtab_and_line *) | |
930 | xmalloc (sizeof (struct symtab_and_line)); | |
931 | ||
932 | values.nelts = 1; | |
933 | values.sals[0] = find_pc_line (pc, 0); | |
934 | values.sals[0].pc = pc; | |
935 | values.sals[0].section = find_pc_overlay (pc); | |
936 | ||
937 | return values; | |
938 | } | |
413dad4d DC |
939 | |
940 | \f | |
941 | ||
0960f083 DC |
942 | /* Locate the first half of the linespec, ending in a colon, period, |
943 | or whitespace. (More or less.) Also, check to see if *ARGPTR is | |
944 | enclosed in double quotes; if so, set is_quote_enclosed, advance | |
945 | ARGPTR past that and zero out the trailing double quote. */ | |
946 | ||
947 | static char * | |
948 | locate_first_half (char **argptr, int *is_quote_enclosed) | |
949 | { | |
950 | char *ii; | |
951 | char *p, *p1; | |
952 | int has_comma; | |
953 | ||
954 | /* Maybe we were called with a line range FILENAME:LINENUM,FILENAME:LINENUM | |
955 | and we must isolate the first half. Outer layers will call again later | |
956 | for the second half. | |
957 | ||
958 | Don't count commas that appear in argument lists of overloaded | |
959 | functions, or in quoted strings. It's stupid to go to this much | |
960 | trouble when the rest of the function is such an obvious roach hotel. */ | |
961 | ii = find_toplevel_char (*argptr, ','); | |
962 | has_comma = (ii != 0); | |
963 | ||
a04257e6 DC |
964 | /* Temporarily zap out second half to not confuse the code below. |
965 | This is undone below. Do not change ii!! */ | |
0960f083 DC |
966 | if (has_comma) |
967 | { | |
968 | *ii = '\0'; | |
969 | } | |
970 | ||
a04257e6 DC |
971 | /* Maybe arg is FILE : LINENUM or FILE : FUNCTION. May also be |
972 | CLASS::MEMBER, or NAMESPACE::NAME. Look for ':', but ignore | |
973 | inside of <>. */ | |
0960f083 DC |
974 | |
975 | p = *argptr; | |
976 | if (p[0] == '"') | |
977 | { | |
978 | *is_quote_enclosed = 1; | |
979 | (*argptr)++; | |
980 | p++; | |
981 | } | |
982 | else | |
983 | *is_quote_enclosed = 0; | |
984 | for (; *p; p++) | |
985 | { | |
986 | if (p[0] == '<') | |
987 | { | |
988 | char *temp_end = find_template_name_end (p); | |
989 | if (!temp_end) | |
990 | error ("malformed template specification in command"); | |
991 | p = temp_end; | |
992 | } | |
d2630e69 AF |
993 | /* Check for a colon and a plus or minus and a [ (which |
994 | indicates an Objective-C method) */ | |
889f28e2 | 995 | if (is_objc_method_format (p)) |
d2630e69 AF |
996 | { |
997 | break; | |
998 | } | |
a04257e6 DC |
999 | /* Check for the end of the first half of the linespec. End of |
1000 | line, a tab, a double colon or the last single colon, or a | |
1001 | space. But if enclosed in double quotes we do not break on | |
1002 | enclosed spaces. */ | |
0960f083 DC |
1003 | if (!*p |
1004 | || p[0] == '\t' | |
1005 | || ((p[0] == ':') | |
1006 | && ((p[1] == ':') || (strchr (p + 1, ':') == NULL))) | |
1007 | || ((p[0] == ' ') && !*is_quote_enclosed)) | |
1008 | break; | |
a04257e6 | 1009 | if (p[0] == '.' && strchr (p, ':') == NULL) |
0960f083 | 1010 | { |
a04257e6 DC |
1011 | /* Java qualified method. Find the *last* '.', since the |
1012 | others are package qualifiers. */ | |
0960f083 DC |
1013 | for (p1 = p; *p1; p1++) |
1014 | { | |
1015 | if (*p1 == '.') | |
1016 | p = p1; | |
1017 | } | |
1018 | break; | |
1019 | } | |
1020 | } | |
1021 | while (p[0] == ' ' || p[0] == '\t') | |
1022 | p++; | |
1023 | ||
a04257e6 | 1024 | /* If the closing double quote was left at the end, remove it. */ |
0960f083 DC |
1025 | if (*is_quote_enclosed) |
1026 | { | |
1027 | char *closing_quote = strchr (p - 1, '"'); | |
1028 | if (closing_quote && closing_quote[1] == '\0') | |
1029 | *closing_quote = '\0'; | |
1030 | } | |
1031 | ||
a04257e6 DC |
1032 | /* Now that we've safely parsed the first half, put back ',' so |
1033 | outer layers can see it. */ | |
0960f083 DC |
1034 | if (has_comma) |
1035 | *ii = ','; | |
1036 | ||
1037 | return p; | |
1038 | } | |
1039 | ||
1040 | \f | |
1041 | ||
d2630e69 AF |
1042 | /* Here's where we recognise an Objective-C Selector. An Objective C |
1043 | selector may be implemented by more than one class, therefore it | |
1044 | may represent more than one method/function. This gives us a | |
1045 | situation somewhat analogous to C++ overloading. If there's more | |
1046 | than one method that could represent the selector, then use some of | |
1047 | the existing C++ code to let the user choose one. */ | |
1048 | ||
1049 | struct symtabs_and_lines | |
1050 | decode_objc (char **argptr, int funfirstline, struct symtab *file_symtab, | |
1051 | char ***canonical, char *saved_arg) | |
1052 | { | |
1053 | struct symtabs_and_lines values; | |
1054 | struct symbol **sym_arr = NULL; | |
1055 | struct symbol *sym = NULL; | |
1056 | char *copy = NULL; | |
1057 | struct block *block = NULL; | |
1058 | int i1 = 0; | |
1059 | int i2 = 0; | |
1060 | ||
1061 | values.sals = NULL; | |
1062 | values.nelts = 0; | |
1063 | ||
1064 | if (file_symtab != NULL) | |
1065 | block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_symtab), STATIC_BLOCK); | |
1066 | else | |
1067 | block = get_selected_block (0); | |
1068 | ||
1069 | copy = find_imps (file_symtab, block, *argptr, NULL, &i1, &i2); | |
1070 | ||
1071 | if (i1 > 0) | |
1072 | { | |
1073 | sym_arr = (struct symbol **) alloca ((i1 + 1) * sizeof (struct symbol *)); | |
1074 | sym_arr[i1] = 0; | |
1075 | ||
1076 | copy = find_imps (file_symtab, block, *argptr, sym_arr, &i1, &i2); | |
1077 | *argptr = copy; | |
1078 | } | |
1079 | ||
1080 | /* i1 now represents the TOTAL number of matches found. | |
1081 | i2 represents how many HIGH-LEVEL (struct symbol) matches, | |
1082 | which will come first in the sym_arr array. Any low-level | |
1083 | (minimal_symbol) matches will follow those. */ | |
1084 | ||
1085 | if (i1 == 1) | |
1086 | { | |
1087 | if (i2 > 0) | |
1088 | { | |
1089 | /* Already a struct symbol. */ | |
1090 | sym = sym_arr[0]; | |
1091 | } | |
1092 | else | |
1093 | { | |
1094 | sym = find_pc_function (SYMBOL_VALUE_ADDRESS (sym_arr[0])); | |
1095 | if ((sym != NULL) && strcmp (SYMBOL_LINKAGE_NAME (sym_arr[0]), SYMBOL_LINKAGE_NAME (sym)) != 0) | |
1096 | { | |
1097 | warning ("debugging symbol \"%s\" does not match selector; ignoring", SYMBOL_LINKAGE_NAME (sym)); | |
1098 | sym = NULL; | |
1099 | } | |
1100 | } | |
1101 | ||
1102 | values.sals = (struct symtab_and_line *) xmalloc (sizeof (struct symtab_and_line)); | |
1103 | values.nelts = 1; | |
1104 | ||
1105 | if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) | |
1106 | { | |
1107 | /* Canonicalize this, so it remains resolved for dylib loads. */ | |
1108 | values.sals[0] = find_function_start_sal (sym, funfirstline); | |
1109 | build_canonical_line_spec (values.sals, SYMBOL_NATURAL_NAME (sym), canonical); | |
1110 | } | |
1111 | else | |
1112 | { | |
1113 | /* The only match was a non-debuggable symbol. */ | |
1114 | values.sals[0].symtab = 0; | |
1115 | values.sals[0].line = 0; | |
1116 | values.sals[0].end = 0; | |
1117 | values.sals[0].pc = SYMBOL_VALUE_ADDRESS (sym_arr[0]); | |
1118 | } | |
1119 | return values; | |
1120 | } | |
1121 | ||
1122 | if (i1 > 1) | |
1123 | { | |
1124 | /* More than one match. The user must choose one or more. */ | |
1125 | return decode_line_2 (sym_arr, i2, funfirstline, canonical); | |
1126 | } | |
1127 | ||
1128 | return values; | |
1129 | } | |
1130 | ||
614b3b14 DC |
1131 | /* This handles C++ and Java compound data structures. P should point |
1132 | at the first component separator, i.e. double-colon or period. */ | |
1133 | ||
1134 | static struct symtabs_and_lines | |
1135 | decode_compound (char **argptr, int funfirstline, char ***canonical, | |
1136 | char *saved_arg, char *p) | |
1137 | { | |
1138 | struct symtabs_and_lines values; | |
93d91629 | 1139 | char *p2; |
614b3b14 DC |
1140 | #if 0 |
1141 | char *q, *q1; | |
1142 | #endif | |
1143 | char *saved_arg2 = *argptr; | |
1144 | char *temp_end; | |
1145 | struct symbol *sym; | |
1146 | /* The symtab that SYM was found in. */ | |
1147 | struct symtab *sym_symtab; | |
1148 | char *copy; | |
1149 | struct symbol *sym_class; | |
614b3b14 DC |
1150 | struct symbol **sym_arr; |
1151 | struct type *t; | |
1152 | ||
1153 | /* First check for "global" namespace specification, | |
a04257e6 DC |
1154 | of the form "::foo". If found, skip over the colons |
1155 | and jump to normal symbol processing. */ | |
614b3b14 DC |
1156 | if (p[0] == ':' |
1157 | && ((*argptr == p) || (p[-1] == ' ') || (p[-1] == '\t'))) | |
1158 | saved_arg2 += 2; | |
1159 | ||
1160 | /* We have what looks like a class or namespace | |
1161 | scope specification (A::B), possibly with many | |
1162 | levels of namespaces or classes (A::B::C::D). | |
1163 | ||
1164 | Some versions of the HP ANSI C++ compiler (as also possibly | |
1165 | other compilers) generate class/function/member names with | |
1166 | embedded double-colons if they are inside namespaces. To | |
1167 | handle this, we loop a few times, considering larger and | |
1168 | larger prefixes of the string as though they were single | |
1169 | symbols. So, if the initially supplied string is | |
1170 | A::B::C::D::foo, we have to look up "A", then "A::B", | |
1171 | then "A::B::C", then "A::B::C::D", and finally | |
1172 | "A::B::C::D::foo" as single, monolithic symbols, because | |
1173 | A, B, C or D may be namespaces. | |
1174 | ||
1175 | Note that namespaces can nest only inside other | |
1176 | namespaces, and not inside classes. So we need only | |
1177 | consider *prefixes* of the string; there is no need to look up | |
a04257e6 | 1178 | "B::C" separately as a symbol in the previous example. */ |
614b3b14 | 1179 | |
a04257e6 | 1180 | p2 = p; /* Save for restart. */ |
614b3b14 DC |
1181 | while (1) |
1182 | { | |
93d91629 | 1183 | sym_class = lookup_prefix_sym (argptr, p); |
614b3b14 DC |
1184 | |
1185 | if (sym_class && | |
1186 | (t = check_typedef (SYMBOL_TYPE (sym_class)), | |
1187 | (TYPE_CODE (t) == TYPE_CODE_STRUCT | |
1188 | || TYPE_CODE (t) == TYPE_CODE_UNION))) | |
1189 | { | |
a04257e6 DC |
1190 | /* Arg token is not digits => try it as a function name. |
1191 | Find the next token (everything up to end or next | |
1192 | blank). */ | |
614b3b14 DC |
1193 | if (**argptr |
1194 | && strchr (get_gdb_completer_quote_characters (), | |
1195 | **argptr) != NULL) | |
1196 | { | |
1197 | p = skip_quoted (*argptr); | |
1198 | *argptr = *argptr + 1; | |
1199 | } | |
1200 | else | |
1201 | { | |
1202 | p = *argptr; | |
1203 | while (*p && *p != ' ' && *p != '\t' && *p != ',' && *p != ':') | |
1204 | p++; | |
1205 | } | |
1206 | /* | |
1207 | q = operator_chars (*argptr, &q1); | |
1208 | if (q1 - q) | |
1209 | { | |
1210 | char *opname; | |
1211 | char *tmp = alloca (q1 - q + 1); | |
1212 | memcpy (tmp, q, q1 - q); | |
1213 | tmp[q1 - q] = '\0'; | |
1214 | opname = cplus_mangle_opname (tmp, DMGL_ANSI); | |
1215 | if (opname == NULL) | |
1216 | { | |
1217 | cplusplus_error (saved_arg, "no mangling for \"%s\"\n", tmp); | |
1218 | } | |
1219 | copy = (char*) alloca (3 + strlen(opname)); | |
1220 | sprintf (copy, "__%s", opname); | |
1221 | p = q1; | |
1222 | } | |
1223 | else | |
1224 | */ | |
1225 | { | |
1226 | copy = (char *) alloca (p - *argptr + 1); | |
1227 | memcpy (copy, *argptr, p - *argptr); | |
1228 | copy[p - *argptr] = '\0'; | |
1229 | if (p != *argptr | |
1230 | && copy[p - *argptr - 1] | |
1231 | && strchr (get_gdb_completer_quote_characters (), | |
1232 | copy[p - *argptr - 1]) != NULL) | |
1233 | copy[p - *argptr - 1] = '\0'; | |
1234 | } | |
1235 | ||
a04257e6 | 1236 | /* No line number may be specified. */ |
614b3b14 DC |
1237 | while (*p == ' ' || *p == '\t') |
1238 | p++; | |
1239 | *argptr = p; | |
1240 | ||
4224873a DC |
1241 | return find_method (funfirstline, canonical, saved_arg, |
1242 | copy, t, sym_class); | |
614b3b14 DC |
1243 | } |
1244 | ||
a04257e6 DC |
1245 | /* Move pointer up to next possible class/namespace token. */ |
1246 | p = p2 + 1; /* Restart with old value +1. */ | |
1247 | /* Move pointer ahead to next double-colon. */ | |
614b3b14 DC |
1248 | while (*p && (p[0] != ' ') && (p[0] != '\t') && (p[0] != '\'')) |
1249 | { | |
1250 | if (p[0] == '<') | |
1251 | { | |
1252 | temp_end = find_template_name_end (p); | |
1253 | if (!temp_end) | |
1254 | error ("malformed template specification in command"); | |
1255 | p = temp_end; | |
1256 | } | |
1257 | else if ((p[0] == ':') && (p[1] == ':')) | |
a04257e6 | 1258 | break; /* Found double-colon. */ |
614b3b14 DC |
1259 | else |
1260 | p++; | |
1261 | } | |
1262 | ||
1263 | if (*p != ':') | |
a04257e6 | 1264 | break; /* Out of the while (1). */ |
614b3b14 | 1265 | |
a04257e6 DC |
1266 | p2 = p; /* Save restart for next time around. */ |
1267 | *argptr = saved_arg2; /* Restore argptr. */ | |
614b3b14 DC |
1268 | } /* while (1) */ |
1269 | ||
a04257e6 DC |
1270 | /* Last chance attempt -- check entire name as a symbol. Use "copy" |
1271 | in preparation for jumping out of this block, to be consistent | |
1272 | with usage following the jump target. */ | |
614b3b14 DC |
1273 | copy = (char *) alloca (p - saved_arg2 + 1); |
1274 | memcpy (copy, saved_arg2, p - saved_arg2); | |
a04257e6 DC |
1275 | /* Note: if is_quoted should be true, we snuff out quote here |
1276 | anyway. */ | |
614b3b14 | 1277 | copy[p - saved_arg2] = '\000'; |
a04257e6 | 1278 | /* Set argptr to skip over the name. */ |
614b3b14 DC |
1279 | *argptr = (*p == '\'') ? p + 1 : p; |
1280 | /* Look up entire name */ | |
176620f1 | 1281 | sym = lookup_symbol (copy, 0, VAR_DOMAIN, 0, &sym_symtab); |
614b3b14 DC |
1282 | if (sym) |
1283 | return symbol_found (funfirstline, canonical, copy, sym, | |
1284 | NULL, sym_symtab); | |
1285 | ||
a04257e6 DC |
1286 | /* Couldn't find any interpretation as classes/namespaces, so give |
1287 | up. The quotes are important if copy is empty. */ | |
614b3b14 DC |
1288 | cplusplus_error (saved_arg, |
1289 | "Can't find member of namespace, class, struct, or union named \"%s\"\n", | |
1290 | copy); | |
1291 | } | |
1292 | ||
93d91629 DC |
1293 | /* Next come some helper functions for decode_compound. */ |
1294 | ||
1295 | /* Return the symbol corresponding to the substring of *ARGPTR ending | |
1296 | at P, allowing whitespace. Also, advance *ARGPTR past the symbol | |
1297 | name in question, the compound object separator ("::" or "."), and | |
1298 | whitespace. */ | |
1299 | ||
1300 | static struct symbol * | |
1301 | lookup_prefix_sym (char **argptr, char *p) | |
1302 | { | |
1303 | char *p1; | |
1304 | char *copy; | |
1305 | ||
1306 | /* Extract the class name. */ | |
1307 | p1 = p; | |
1308 | while (p != *argptr && p[-1] == ' ') | |
1309 | --p; | |
1310 | copy = (char *) alloca (p - *argptr + 1); | |
1311 | memcpy (copy, *argptr, p - *argptr); | |
1312 | copy[p - *argptr] = 0; | |
1313 | ||
1314 | /* Discard the class name from the arg. */ | |
1315 | p = p1 + (p1[0] == ':' ? 2 : 1); | |
1316 | while (*p == ' ' || *p == '\t') | |
1317 | p++; | |
1318 | *argptr = p; | |
1319 | ||
176620f1 | 1320 | return lookup_symbol (copy, 0, STRUCT_DOMAIN, 0, |
93d91629 DC |
1321 | (struct symtab **) NULL); |
1322 | } | |
1323 | ||
4224873a DC |
1324 | /* This finds the method COPY in the class whose type is T and whose |
1325 | symbol is SYM_CLASS. */ | |
1326 | ||
1327 | static struct symtabs_and_lines | |
1328 | find_method (int funfirstline, char ***canonical, char *saved_arg, | |
1329 | char *copy, struct type *t, struct symbol *sym_class) | |
1330 | { | |
1331 | struct symtabs_and_lines values; | |
1332 | struct symbol *sym = 0; | |
78a11fb4 | 1333 | int i1; /* Counter for the symbol array. */ |
4224873a DC |
1334 | struct symbol **sym_arr = alloca (total_number_of_methods (t) |
1335 | * sizeof (struct symbol *)); | |
1336 | ||
78a11fb4 DC |
1337 | /* Find all methods with a matching name, and put them in |
1338 | sym_arr. */ | |
4224873a | 1339 | |
78a11fb4 | 1340 | i1 = collect_methods (copy, t, sym_arr); |
4224873a | 1341 | |
4224873a DC |
1342 | if (i1 == 1) |
1343 | { | |
1344 | /* There is exactly one field with that name. */ | |
1345 | sym = sym_arr[0]; | |
1346 | ||
1347 | if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK) | |
1348 | { | |
1349 | values.sals = (struct symtab_and_line *) | |
1350 | xmalloc (sizeof (struct symtab_and_line)); | |
1351 | values.nelts = 1; | |
1352 | values.sals[0] = find_function_start_sal (sym, | |
1353 | funfirstline); | |
1354 | } | |
1355 | else | |
1356 | { | |
1357 | values.nelts = 0; | |
1358 | } | |
1359 | return values; | |
1360 | } | |
1361 | if (i1 > 0) | |
1362 | { | |
1363 | /* There is more than one field with that name | |
1364 | (overloaded). Ask the user which one to use. */ | |
1365 | return decode_line_2 (sym_arr, i1, funfirstline, canonical); | |
1366 | } | |
1367 | else | |
1368 | { | |
1369 | char *tmp; | |
1370 | ||
1371 | if (is_operator_name (copy)) | |
1372 | { | |
1373 | tmp = (char *) alloca (strlen (copy + 3) + 9); | |
1374 | strcpy (tmp, "operator "); | |
1375 | strcat (tmp, copy + 3); | |
1376 | } | |
1377 | else | |
1378 | tmp = copy; | |
1379 | if (tmp[0] == '~') | |
1380 | cplusplus_error (saved_arg, | |
1381 | "the class `%s' does not have destructor defined\n", | |
1382 | SYMBOL_PRINT_NAME (sym_class)); | |
1383 | else | |
1384 | cplusplus_error (saved_arg, | |
1385 | "the class %s does not have any method named %s\n", | |
1386 | SYMBOL_PRINT_NAME (sym_class), tmp); | |
1387 | } | |
1388 | } | |
1389 | ||
78a11fb4 DC |
1390 | /* Find all methods named COPY in the class whose type is T, and put |
1391 | them in SYM_ARR. Return the number of methods found. */ | |
1392 | ||
1393 | static int | |
1394 | collect_methods (char *copy, struct type *t, | |
1395 | struct symbol **sym_arr) | |
1396 | { | |
1397 | int i1 = 0; /* Counter for the symbol array. */ | |
1398 | ||
1399 | if (destructor_name_p (copy, t)) | |
1400 | { | |
1401 | /* Destructors are a special case. */ | |
1402 | int m_index, f_index; | |
1403 | ||
1404 | if (get_destructor_fn_field (t, &m_index, &f_index)) | |
1405 | { | |
1406 | struct fn_field *f = TYPE_FN_FIELDLIST1 (t, m_index); | |
1407 | ||
1408 | sym_arr[i1] = | |
1409 | lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f, f_index), | |
176620f1 | 1410 | NULL, VAR_DOMAIN, (int *) NULL, |
78a11fb4 DC |
1411 | (struct symtab **) NULL); |
1412 | if (sym_arr[i1]) | |
1413 | i1++; | |
1414 | } | |
1415 | } | |
1416 | else | |
1417 | i1 = find_methods (t, copy, sym_arr); | |
1418 | ||
1419 | return i1; | |
1420 | } | |
1421 | ||
f3c39e76 DC |
1422 | \f |
1423 | ||
1424 | /* Return the symtab associated to the filename given by the substring | |
1425 | of *ARGPTR ending at P, and advance ARGPTR past that filename. */ | |
1426 | ||
1427 | static struct symtab * | |
1428 | symtab_from_filename (char **argptr, char *p, int is_quote_enclosed) | |
1429 | { | |
1430 | char *p1; | |
1431 | char *copy; | |
94cd26f8 | 1432 | struct symtab *file_symtab; |
f3c39e76 DC |
1433 | |
1434 | p1 = p; | |
1435 | while (p != *argptr && p[-1] == ' ') | |
1436 | --p; | |
1437 | if ((*p == '"') && is_quote_enclosed) | |
1438 | --p; | |
1439 | copy = (char *) alloca (p - *argptr + 1); | |
1440 | memcpy (copy, *argptr, p - *argptr); | |
a04257e6 | 1441 | /* It may have the ending quote right after the file name. */ |
f3c39e76 DC |
1442 | if (is_quote_enclosed && copy[p - *argptr - 1] == '"') |
1443 | copy[p - *argptr - 1] = 0; | |
1444 | else | |
1445 | copy[p - *argptr] = 0; | |
1446 | ||
1447 | /* Find that file's data. */ | |
94cd26f8 DC |
1448 | file_symtab = lookup_symtab (copy); |
1449 | if (file_symtab == 0) | |
f3c39e76 DC |
1450 | { |
1451 | if (!have_full_symbols () && !have_partial_symbols ()) | |
1452 | error ("No symbol table is loaded. Use the \"file\" command."); | |
1453 | error ("No source file named %s.", copy); | |
1454 | } | |
1455 | ||
1456 | /* Discard the file name from the arg. */ | |
1457 | p = p1 + 1; | |
1458 | while (*p == ' ' || *p == '\t') | |
1459 | p++; | |
1460 | *argptr = p; | |
1461 | ||
94cd26f8 | 1462 | return file_symtab; |
f3c39e76 DC |
1463 | } |
1464 | ||
84fba31b DC |
1465 | \f |
1466 | ||
1467 | /* This decodes a line where the argument is all digits (possibly | |
1468 | preceded by a sign). Q should point to the end of those digits; | |
1469 | the other arguments are as usual. */ | |
1470 | ||
1471 | static struct symtabs_and_lines | |
1472 | decode_all_digits (char **argptr, struct symtab *default_symtab, | |
1473 | int default_line, char ***canonical, | |
88d262ca | 1474 | struct symtab *file_symtab, char *q) |
84fba31b DC |
1475 | |
1476 | { | |
1477 | struct symtabs_and_lines values; | |
1478 | struct symtab_and_line val; | |
1479 | ||
1480 | enum sign | |
1481 | { | |
1482 | none, plus, minus | |
1483 | } | |
1484 | sign = none; | |
1485 | ||
1486 | /* We might need a canonical line spec if no file was specified. */ | |
88d262ca | 1487 | int need_canonical = (file_symtab == 0) ? 1 : 0; |
84fba31b DC |
1488 | |
1489 | init_sal (&val); | |
1490 | ||
1491 | /* This is where we need to make sure that we have good defaults. | |
1492 | We must guarantee that this section of code is never executed | |
1493 | when we are called with just a function name, since | |
1494 | set_default_source_symtab_and_line uses | |
a04257e6 | 1495 | select_source_symtab that calls us with such an argument. */ |
84fba31b | 1496 | |
88d262ca | 1497 | if (file_symtab == 0 && default_symtab == 0) |
84fba31b | 1498 | { |
a04257e6 | 1499 | /* Make sure we have at least a default source file. */ |
84fba31b DC |
1500 | set_default_source_symtab_and_line (); |
1501 | initialize_defaults (&default_symtab, &default_line); | |
1502 | } | |
1503 | ||
1504 | if (**argptr == '+') | |
1505 | sign = plus, (*argptr)++; | |
1506 | else if (**argptr == '-') | |
1507 | sign = minus, (*argptr)++; | |
1508 | val.line = atoi (*argptr); | |
1509 | switch (sign) | |
1510 | { | |
1511 | case plus: | |
1512 | if (q == *argptr) | |
1513 | val.line = 5; | |
88d262ca | 1514 | if (file_symtab == 0) |
84fba31b DC |
1515 | val.line = default_line + val.line; |
1516 | break; | |
1517 | case minus: | |
1518 | if (q == *argptr) | |
1519 | val.line = 15; | |
88d262ca | 1520 | if (file_symtab == 0) |
84fba31b DC |
1521 | val.line = default_line - val.line; |
1522 | else | |
1523 | val.line = 1; | |
1524 | break; | |
1525 | case none: | |
1526 | break; /* No need to adjust val.line. */ | |
1527 | } | |
1528 | ||
1529 | while (*q == ' ' || *q == '\t') | |
1530 | q++; | |
1531 | *argptr = q; | |
88d262ca DC |
1532 | if (file_symtab == 0) |
1533 | file_symtab = default_symtab; | |
84fba31b DC |
1534 | |
1535 | /* It is possible that this source file has more than one symtab, | |
1536 | and that the new line number specification has moved us from the | |
88d262ca DC |
1537 | default (in file_symtab) to a new one. */ |
1538 | val.symtab = find_line_symtab (file_symtab, val.line, NULL, NULL); | |
84fba31b | 1539 | if (val.symtab == 0) |
88d262ca | 1540 | val.symtab = file_symtab; |
84fba31b DC |
1541 | |
1542 | val.pc = 0; | |
1543 | values.sals = (struct symtab_and_line *) | |
1544 | xmalloc (sizeof (struct symtab_and_line)); | |
1545 | values.sals[0] = val; | |
1546 | values.nelts = 1; | |
1547 | if (need_canonical) | |
1548 | build_canonical_line_spec (values.sals, NULL, canonical); | |
1549 | return values; | |
1550 | } | |
f3c39e76 | 1551 | |
614b3b14 DC |
1552 | \f |
1553 | ||
14e91ac5 DC |
1554 | /* Decode a linespec starting with a dollar sign. */ |
1555 | ||
1556 | static struct symtabs_and_lines | |
1557 | decode_dollar (char *copy, int funfirstline, struct symtab *default_symtab, | |
88d262ca | 1558 | char ***canonical, struct symtab *file_symtab) |
14e91ac5 DC |
1559 | { |
1560 | struct value *valx; | |
1561 | int index = 0; | |
1562 | int need_canonical = 0; | |
1563 | struct symtabs_and_lines values; | |
1564 | struct symtab_and_line val; | |
1565 | char *p; | |
1566 | struct symbol *sym; | |
1567 | /* The symtab that SYM was found in. */ | |
1568 | struct symtab *sym_symtab; | |
1569 | struct minimal_symbol *msymbol; | |
1570 | ||
1571 | p = (copy[1] == '$') ? copy + 2 : copy + 1; | |
1572 | while (*p >= '0' && *p <= '9') | |
1573 | p++; | |
a04257e6 | 1574 | if (!*p) /* Reached end of token without hitting non-digit. */ |
14e91ac5 | 1575 | { |
a04257e6 | 1576 | /* We have a value history reference. */ |
14e91ac5 DC |
1577 | sscanf ((copy[1] == '$') ? copy + 2 : copy + 1, "%d", &index); |
1578 | valx = access_value_history ((copy[1] == '$') ? -index : index); | |
1579 | if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT) | |
1580 | error ("History values used in line specs must have integer values."); | |
1581 | } | |
1582 | else | |
1583 | { | |
1584 | /* Not all digits -- may be user variable/function or a | |
a04257e6 | 1585 | convenience variable. */ |
14e91ac5 | 1586 | |
a04257e6 | 1587 | /* Look up entire name as a symbol first. */ |
176620f1 | 1588 | sym = lookup_symbol (copy, 0, VAR_DOMAIN, 0, &sym_symtab); |
88d262ca | 1589 | file_symtab = (struct symtab *) 0; |
14e91ac5 DC |
1590 | need_canonical = 1; |
1591 | /* Symbol was found --> jump to normal symbol processing. */ | |
1592 | if (sym) | |
1593 | return symbol_found (funfirstline, canonical, copy, sym, | |
1594 | NULL, sym_symtab); | |
1595 | ||
a04257e6 | 1596 | /* If symbol was not found, look in minimal symbol tables. */ |
14e91ac5 | 1597 | msymbol = lookup_minimal_symbol (copy, NULL, NULL); |
a04257e6 | 1598 | /* Min symbol was found --> jump to minsym processing. */ |
14e91ac5 DC |
1599 | if (msymbol) |
1600 | return minsym_found (funfirstline, msymbol); | |
1601 | ||
a04257e6 | 1602 | /* Not a user variable or function -- must be convenience variable. */ |
88d262ca | 1603 | need_canonical = (file_symtab == 0) ? 1 : 0; |
14e91ac5 DC |
1604 | valx = value_of_internalvar (lookup_internalvar (copy + 1)); |
1605 | if (TYPE_CODE (VALUE_TYPE (valx)) != TYPE_CODE_INT) | |
1606 | error ("Convenience variables used in line specs must have integer values."); | |
1607 | } | |
1608 | ||
1609 | init_sal (&val); | |
1610 | ||
a04257e6 | 1611 | /* Either history value or convenience value from above, in valx. */ |
88d262ca | 1612 | val.symtab = file_symtab ? file_symtab : default_symtab; |
14e91ac5 DC |
1613 | val.line = value_as_long (valx); |
1614 | val.pc = 0; | |
1615 | ||
1616 | values.sals = (struct symtab_and_line *) xmalloc (sizeof val); | |
1617 | values.sals[0] = val; | |
1618 | values.nelts = 1; | |
1619 | ||
1620 | if (need_canonical) | |
1621 | build_canonical_line_spec (values.sals, NULL, canonical); | |
1622 | ||
1623 | return values; | |
1624 | } | |
1625 | ||
bca02a8a DC |
1626 | \f |
1627 | ||
88d262ca | 1628 | /* Decode a linespec that's a variable. If FILE_SYMTAB is non-NULL, |
bca02a8a DC |
1629 | look in that symtab's static variables first. */ |
1630 | ||
1631 | static struct symtabs_and_lines | |
1632 | decode_variable (char *copy, int funfirstline, char ***canonical, | |
88d262ca | 1633 | struct symtab *file_symtab) |
bca02a8a DC |
1634 | { |
1635 | struct symbol *sym; | |
1636 | /* The symtab that SYM was found in. */ | |
1637 | struct symtab *sym_symtab; | |
1638 | ||
1639 | struct minimal_symbol *msymbol; | |
1640 | ||
1641 | sym = lookup_symbol (copy, | |
88d262ca DC |
1642 | (file_symtab |
1643 | ? BLOCKVECTOR_BLOCK (BLOCKVECTOR (file_symtab), | |
1644 | STATIC_BLOCK) | |
bca02a8a | 1645 | : get_selected_block (0)), |
176620f1 | 1646 | VAR_DOMAIN, 0, &sym_symtab); |
bca02a8a DC |
1647 | |
1648 | if (sym != NULL) | |
88d262ca DC |
1649 | return symbol_found (funfirstline, canonical, copy, sym, |
1650 | file_symtab, sym_symtab); | |
bca02a8a DC |
1651 | |
1652 | msymbol = lookup_minimal_symbol (copy, NULL, NULL); | |
1653 | ||
1654 | if (msymbol != NULL) | |
1655 | return minsym_found (funfirstline, msymbol); | |
1656 | ||
1657 | if (!have_full_symbols () && | |
1658 | !have_partial_symbols () && !have_minimal_symbols ()) | |
1659 | error ("No symbol table is loaded. Use the \"file\" command."); | |
1660 | ||
1661 | error ("Function \"%s\" not defined.", copy); | |
1662 | } | |
1663 | ||
1664 | ||
14e91ac5 DC |
1665 | \f |
1666 | ||
413dad4d DC |
1667 | /* Now come some functions that are called from multiple places within |
1668 | decode_line_1. */ | |
1669 | ||
1670 | /* We've found a symbol SYM to associate with our linespec; build a | |
1671 | corresponding struct symtabs_and_lines. */ | |
1672 | ||
1673 | static struct symtabs_and_lines | |
1674 | symbol_found (int funfirstline, char ***canonical, char *copy, | |
88d262ca | 1675 | struct symbol *sym, struct symtab *file_symtab, |
413dad4d DC |
1676 | struct symtab *sym_symtab) |
1677 | { | |
1678 | struct symtabs_and_lines values; | |
1679 | ||
1680 | if (SYMBOL_CLASS (sym) == LOC_BLOCK) | |
50641945 | 1681 | { |
413dad4d | 1682 | /* Arg is the name of a function */ |
50641945 FN |
1683 | values.sals = (struct symtab_and_line *) |
1684 | xmalloc (sizeof (struct symtab_and_line)); | |
413dad4d DC |
1685 | values.sals[0] = find_function_start_sal (sym, funfirstline); |
1686 | values.nelts = 1; | |
1687 | ||
1688 | /* Don't use the SYMBOL_LINE; if used at all it points to | |
1689 | the line containing the parameters or thereabouts, not | |
1690 | the first line of code. */ | |
1691 | ||
1692 | /* We might need a canonical line spec if it is a static | |
1693 | function. */ | |
88d262ca | 1694 | if (file_symtab == 0) |
50641945 | 1695 | { |
413dad4d DC |
1696 | struct blockvector *bv = BLOCKVECTOR (sym_symtab); |
1697 | struct block *b = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); | |
176620f1 | 1698 | if (lookup_block_symbol (b, copy, NULL, VAR_DOMAIN) != NULL) |
413dad4d | 1699 | build_canonical_line_spec (values.sals, copy, canonical); |
50641945 | 1700 | } |
50641945 FN |
1701 | return values; |
1702 | } | |
413dad4d DC |
1703 | else |
1704 | { | |
1705 | if (funfirstline) | |
1706 | error ("\"%s\" is not a function", copy); | |
1707 | else if (SYMBOL_LINE (sym) != 0) | |
1708 | { | |
1709 | /* We know its line number. */ | |
1710 | values.sals = (struct symtab_and_line *) | |
1711 | xmalloc (sizeof (struct symtab_and_line)); | |
1712 | values.nelts = 1; | |
1713 | memset (&values.sals[0], 0, sizeof (values.sals[0])); | |
1714 | values.sals[0].symtab = sym_symtab; | |
1715 | values.sals[0].line = SYMBOL_LINE (sym); | |
1716 | return values; | |
1717 | } | |
1718 | else | |
1719 | /* This can happen if it is compiled with a compiler which doesn't | |
1720 | put out line numbers for variables. */ | |
1721 | /* FIXME: Shouldn't we just set .line and .symtab to zero | |
1722 | and return? For example, "info line foo" could print | |
1723 | the address. */ | |
1724 | error ("Line number not known for symbol \"%s\"", copy); | |
1725 | } | |
1726 | } | |
50641945 | 1727 | |
413dad4d DC |
1728 | /* We've found a minimal symbol MSYMBOL to associate with our |
1729 | linespec; build a corresponding struct symtabs_and_lines. */ | |
50641945 | 1730 | |
413dad4d DC |
1731 | static struct symtabs_and_lines |
1732 | minsym_found (int funfirstline, struct minimal_symbol *msymbol) | |
1733 | { | |
1734 | struct symtabs_and_lines values; | |
1735 | ||
1736 | values.sals = (struct symtab_and_line *) | |
1737 | xmalloc (sizeof (struct symtab_and_line)); | |
1738 | values.sals[0] = find_pc_sect_line (SYMBOL_VALUE_ADDRESS (msymbol), | |
198beae2 | 1739 | (struct bfd_section *) 0, 0); |
413dad4d DC |
1740 | values.sals[0].section = SYMBOL_BFD_SECTION (msymbol); |
1741 | if (funfirstline) | |
1742 | { | |
1743 | values.sals[0].pc += FUNCTION_START_OFFSET; | |
1744 | values.sals[0].pc = SKIP_PROLOGUE (values.sals[0].pc); | |
1745 | } | |
1746 | values.nelts = 1; | |
1747 | return values; | |
50641945 | 1748 | } |