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