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