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