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