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