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