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