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
4 Free Software Foundation, Inc.
6 This file is part of GDB.
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.
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.
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. */
31 #include "completer.h"
33 /* Prototype for one function in parser-defs.h,
34 instead of including that entire file. */
36 extern char *find_template_name_end (char *);
38 /* We share this one with symtab.c, but it is not exported widely. */
40 extern char *operator_chars (char *, char **);
42 /* Prototypes for local functions */
44 static void cplusplus_hint (char *name
);
46 static int total_number_of_methods (struct type
*type
);
48 static int find_methods (struct type
*, char *, struct symbol
**);
50 static void build_canonical_line_spec (struct symtab_and_line
*,
53 static char *find_toplevel_char (char *s
, char c
);
55 static struct symtabs_and_lines
decode_line_2 (struct symbol
*[],
58 /* Helper functions. */
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 */
65 cplusplus_hint (char *name
)
69 printf_filtered ("Hint: try '%s<TAB> or '%s<ESC-?>\n", name
, name
);
70 printf_filtered ("(Note leading single quote.)\n");
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. */
79 total_number_of_methods (struct type
*type
)
85 if (TYPE_CPLUS_SPECIFIC (type
) == NULL
)
87 count
= TYPE_NFN_FIELDS_TOTAL (type
);
89 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
90 count
+= total_number_of_methods (TYPE_BASECLASS (type
, n
));
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. */
103 find_methods (struct type
*t
, char *name
, struct symbol
**sym_arr
)
107 char *class_name
= type_name_no_tag (t
);
109 /* Ignore this class if it doesn't have a name. This is ugly, but
110 unless we figure out how to get the physname without the name of
111 the class, then the loop can't do any good. */
113 && (lookup_symbol (class_name
, (struct block
*) NULL
,
114 STRUCT_NAMESPACE
, (int *) NULL
,
115 (struct symtab
**) NULL
)))
121 /* Loop over each method name. At this level, all overloads of a name
122 are counted as a single name. There is an inner loop which loops over
125 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
130 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
133 if (strncmp (method_name
, "__", 2) == 0 ||
134 strncmp (method_name
, "op", 2) == 0 ||
135 strncmp (method_name
, "type", 4) == 0)
137 if (cplus_demangle_opname (method_name
, dem_opname
, DMGL_ANSI
))
138 method_name
= dem_opname
;
139 else if (cplus_demangle_opname (method_name
, dem_opname
, 0))
140 method_name
= dem_opname
;
143 if (STREQ (name
, method_name
))
144 /* Find all the overloaded methods with that name. */
145 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
152 f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
154 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
158 tmp_name
= gdb_mangle_name (t
,
161 phys_name
= alloca (strlen (tmp_name
) + 1);
162 strcpy (phys_name
, tmp_name
);
166 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
168 /* Destructor is handled by caller, dont add it to the list */
169 if (DESTRUCTOR_PREFIX_P (phys_name
))
172 sym_arr
[i1
] = lookup_symbol (phys_name
,
175 (struct symtab
**) NULL
);
180 /* This error message gets printed, but the method
181 still seems to be found
182 fputs_filtered("(Cannot find method ", gdb_stdout);
183 fprintf_symbol_filtered (gdb_stdout, phys_name,
185 DMGL_PARAMS | DMGL_ANSI);
186 fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
193 /* Only search baseclasses if there is no match yet, since names in
194 derived classes override those in baseclasses.
196 FIXME: The above is not true; it is only true of member functions
197 if they have the same number of arguments (??? - section 13.1 of the
198 ARM says the function members are not in the same scope but doesn't
199 really spell out the rules in a way I understand. In any case, if
200 the number of arguments differ this is a case in which we can overload
201 rather than hiding without any problem, and gcc 2.4.5 does overload
202 rather than hiding in this case). */
205 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
206 i1
+= find_methods (TYPE_BASECLASS (t
, ibase
), name
, sym_arr
+ i1
);
211 /* Helper function for decode_line_1.
212 Build a canonical line spec in CANONICAL if it is non-NULL and if
213 the SAL has a symtab.
214 If SYMNAME is non-NULL the canonical line spec is `filename:symname'.
215 If SYMNAME is NULL the line number from SAL is used and the canonical
216 line spec is `filename:linenum'. */
219 build_canonical_line_spec (struct symtab_and_line
*sal
, char *symname
,
222 char **canonical_arr
;
223 char *canonical_name
;
225 struct symtab
*s
= sal
->symtab
;
227 if (s
== (struct symtab
*) NULL
228 || s
->filename
== (char *) NULL
229 || canonical
== (char ***) NULL
)
232 canonical_arr
= (char **) xmalloc (sizeof (char *));
233 *canonical
= canonical_arr
;
235 filename
= s
->filename
;
238 canonical_name
= xmalloc (strlen (filename
) + strlen (symname
) + 2);
239 sprintf (canonical_name
, "%s:%s", filename
, symname
);
243 canonical_name
= xmalloc (strlen (filename
) + 30);
244 sprintf (canonical_name
, "%s:%d", filename
, sal
->line
);
246 canonical_arr
[0] = canonical_name
;
251 /* Find an instance of the character C in the string S that is outside
252 of all parenthesis pairs, single-quoted strings, and double-quoted
255 find_toplevel_char (char *s
, char c
)
257 int quoted
= 0; /* zero if we're not in quotes;
258 '"' if we're in a double-quoted string;
259 '\'' if we're in a single-quoted string. */
260 int depth
= 0; /* number of unclosed parens we've seen */
263 for (scan
= s
; *scan
; scan
++)
269 else if (*scan
== '\\' && *(scan
+ 1))
272 else if (*scan
== c
&& ! quoted
&& depth
== 0)
274 else if (*scan
== '"' || *scan
== '\'')
276 else if (*scan
== '(')
278 else if (*scan
== ')' && depth
> 0)
285 /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
286 operate on (ask user if necessary).
287 If CANONICAL is non-NULL return a corresponding array of mangled names
288 as canonical line specs there. */
290 static struct symtabs_and_lines
291 decode_line_2 (struct symbol
*sym_arr
[], int nelts
, int funfirstline
,
294 struct symtabs_and_lines values
, return_values
;
299 struct cleanup
*old_chain
;
300 char **canonical_arr
= (char **) NULL
;
302 values
.sals
= (struct symtab_and_line
*)
303 alloca (nelts
* sizeof (struct symtab_and_line
));
304 return_values
.sals
= (struct symtab_and_line
*)
305 xmalloc (nelts
* sizeof (struct symtab_and_line
));
306 old_chain
= make_cleanup (xfree
, return_values
.sals
);
310 canonical_arr
= (char **) xmalloc (nelts
* sizeof (char *));
311 make_cleanup (xfree
, canonical_arr
);
312 memset (canonical_arr
, 0, nelts
* sizeof (char *));
313 *canonical
= canonical_arr
;
317 printf_unfiltered ("[0] cancel\n[1] all\n");
320 INIT_SAL (&return_values
.sals
[i
]); /* initialize to zeroes */
321 INIT_SAL (&values
.sals
[i
]);
322 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
324 values
.sals
[i
] = find_function_start_sal (sym_arr
[i
], funfirstline
);
325 printf_unfiltered ("[%d] %s at %s:%d\n",
327 SYMBOL_SOURCE_NAME (sym_arr
[i
]),
328 values
.sals
[i
].symtab
->filename
,
329 values
.sals
[i
].line
);
332 printf_unfiltered ("?HERE\n");
336 if ((prompt
= getenv ("PS2")) == NULL
)
340 args
= command_line_input (prompt
, 0, "overload-choice");
342 if (args
== 0 || *args
== 0)
343 error_no_arg ("one or more choice numbers");
351 while (*arg1
>= '0' && *arg1
<= '9')
353 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
354 error ("Arguments must be choice numbers.");
364 for (i
= 0; i
< nelts
; i
++)
366 if (canonical_arr
[i
] == NULL
)
368 symname
= SYMBOL_NAME (sym_arr
[i
]);
369 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
373 memcpy (return_values
.sals
, values
.sals
,
374 (nelts
* sizeof (struct symtab_and_line
)));
375 return_values
.nelts
= nelts
;
376 discard_cleanups (old_chain
);
377 return return_values
;
380 if (num
>= nelts
+ 2)
382 printf_unfiltered ("No choice number %d.\n", num
);
387 if (values
.sals
[num
].pc
)
391 symname
= SYMBOL_NAME (sym_arr
[num
]);
392 make_cleanup (xfree
, symname
);
393 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
395 return_values
.sals
[i
++] = values
.sals
[num
];
396 values
.sals
[num
].pc
= 0;
400 printf_unfiltered ("duplicate request for %d ignored.\n", num
);
405 while (*args
== ' ' || *args
== '\t')
408 return_values
.nelts
= i
;
409 discard_cleanups (old_chain
);
410 return return_values
;
413 /* The parser of linespec itself. */
415 /* Parse a string that specifies a line number.
416 Pass the address of a char * variable; that variable will be
417 advanced over the characters actually parsed.
421 LINENUM -- that line number in current file. PC returned is 0.
422 FILE:LINENUM -- that line in that file. PC returned is 0.
423 FUNCTION -- line number of openbrace of that function.
424 PC returned is the start of the function.
425 VARIABLE -- line number of definition of that variable.
427 FILE:FUNCTION -- likewise, but prefer functions in that file.
428 *EXPR -- line in which address EXPR appears.
430 This may all be followed by an "if EXPR", which we ignore.
432 FUNCTION may be an undebuggable function found in minimal symbol table.
434 If the argument FUNFIRSTLINE is nonzero, we want the first line
435 of real code inside a function when a function is specified, and it is
436 not OK to specify a variable or type to get its line number.
438 DEFAULT_SYMTAB specifies the file to use if none is specified.
439 It defaults to current_source_symtab.
440 DEFAULT_LINE specifies the line number to use for relative
441 line numbers (that start with signs). Defaults to current_source_line.
442 If CANONICAL is non-NULL, store an array of strings containing the canonical
443 line specs there if necessary. Currently overloaded member functions and
444 line numbers or static functions without a filename yield a canonical
445 line spec. The array and the line spec strings are allocated on the heap,
446 it is the callers responsibility to free them.
448 Note that it is possible to return zero for the symtab
449 if no file is validly specified. Callers must check that.
450 Also, the line number returned may be invalid. */
452 /* We allow single quotes in various places. This is a hideous
453 kludge, which exists because the completer can't yet deal with the
454 lack of single quotes. FIXME: write a linespec_completer which we
455 can use as appropriate instead of make_symbol_completion_list. */
457 struct symtabs_and_lines
458 decode_line_1 (char **argptr
, int funfirstline
, struct symtab
*default_symtab
,
459 int default_line
, char ***canonical
)
461 struct symtabs_and_lines values
;
462 #ifdef HPPA_COMPILER_BUG
463 /* FIXME: The native HP 9000/700 compiler has a bug which appears
464 when optimizing this file with target i960-vxworks. I haven't
465 been able to construct a simple test case. The problem is that
466 in the second call to SKIP_PROLOGUE below, the compiler somehow
467 does not realize that the statement val = find_pc_line (...) will
468 change the values of the fields of val. It extracts the elements
469 into registers at the top of the block, and does not update the
470 registers after the call to find_pc_line. You can check this by
471 inserting a printf at the end of find_pc_line to show what values
472 it is returning for val.pc and val.end and another printf after
473 the call to see what values the function actually got (remember,
474 this is compiling with cc -O, with this patch removed). You can
475 also examine the assembly listing: search for the second call to
476 skip_prologue; the LDO statement before the next call to
477 find_pc_line loads the address of the structure which
478 find_pc_line will return; if there is a LDW just before the LDO,
479 which fetches an element of the structure, then the compiler
482 Setting val to volatile avoids the problem. We must undef
483 volatile, because the HPPA native compiler does not define
484 __STDC__, although it does understand volatile, and so volatile
485 will have been defined away in defs.h. */
487 volatile struct symtab_and_line val
;
488 #define volatile /*nothing */
490 struct symtab_and_line val
;
492 register char *p
, *p1
;
493 char *q
, *pp
, *ii
, *p2
;
497 register struct symtab
*s
;
499 register struct symbol
*sym
;
500 /* The symtab that SYM was found in. */
501 struct symtab
*sym_symtab
;
503 register CORE_ADDR pc
;
504 register struct minimal_symbol
*msymbol
;
506 struct symbol
*sym_class
;
509 int is_quote_enclosed
;
513 struct symbol
**sym_arr
;
515 char *saved_arg
= *argptr
;
516 extern char *gdb_completer_quote_characters
;
518 INIT_SAL (&val
); /* initialize to zeroes */
520 /* Defaults have defaults. */
522 if (default_symtab
== 0)
524 default_symtab
= current_source_symtab
;
525 default_line
= current_source_line
;
528 /* See if arg is *PC */
533 pc
= parse_and_eval_address_1 (argptr
);
535 values
.sals
= (struct symtab_and_line
*)
536 xmalloc (sizeof (struct symtab_and_line
));
539 values
.sals
[0] = find_pc_line (pc
, 0);
540 values
.sals
[0].pc
= pc
;
541 values
.sals
[0].section
= find_pc_overlay (pc
);
546 /* 'has_if' is for the syntax:
547 * (gdb) break foo if (a==b)
549 if ((ii
= strstr (*argptr
, " if ")) != NULL
||
550 (ii
= strstr (*argptr
, "\tif ")) != NULL
||
551 (ii
= strstr (*argptr
, " if\t")) != NULL
||
552 (ii
= strstr (*argptr
, "\tif\t")) != NULL
||
553 (ii
= strstr (*argptr
, " if(")) != NULL
||
554 (ii
= strstr (*argptr
, "\tif( ")) != NULL
)
556 /* Temporarily zap out "if (condition)" to not
557 * confuse the parenthesis-checking code below.
558 * This is undone below. Do not change ii!!
565 /* Set various flags.
566 * 'has_parens' is important for overload checking, where
567 * we allow things like:
568 * (gdb) break c::f(int)
571 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
573 is_quoted
= (**argptr
574 && strchr (get_gdb_completer_quote_characters (),
577 has_parens
= ((pp
= strchr (*argptr
, '(')) != NULL
578 && (pp
= strrchr (pp
, ')')) != NULL
);
580 /* Now that we're safely past the has_parens check,
581 * put back " if (condition)" so outer layers can see it
586 /* Maybe we were called with a line range FILENAME:LINENUM,FILENAME:LINENUM
587 and we must isolate the first half. Outer layers will call again later
590 Don't count commas that appear in argument lists of overloaded
591 functions, or in quoted strings. It's stupid to go to this much
592 trouble when the rest of the function is such an obvious roach hotel. */
593 ii
= find_toplevel_char (*argptr
, ',');
594 has_comma
= (ii
!= 0);
596 /* Temporarily zap out second half to not
597 * confuse the code below.
598 * This is undone below. Do not change ii!!
605 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
606 /* May also be CLASS::MEMBER, or NAMESPACE::NAME */
607 /* Look for ':', but ignore inside of <> */
613 is_quote_enclosed
= 1;
618 is_quote_enclosed
= 0;
623 char *temp_end
= find_template_name_end (p
);
625 error ("malformed template specification in command");
628 /* Check for the end of the first half of the linespec. End of line,
629 a tab, a double colon or the last single colon, or a space. But
630 if enclosed in double quotes we do not break on enclosed spaces */
634 && ((p
[1] == ':') || (strchr (p
+ 1, ':') == NULL
)))
635 || ((p
[0] == ' ') && !is_quote_enclosed
))
637 if (p
[0] == '.' && strchr (p
, ':') == NULL
) /* Java qualified method. */
639 /* Find the *last* '.', since the others are package qualifiers. */
640 for (p1
= p
; *p1
; p1
++)
648 while (p
[0] == ' ' || p
[0] == '\t')
651 /* if the closing double quote was left at the end, remove it */
652 if (is_quote_enclosed
)
654 char *closing_quote
= strchr (p
- 1, '"');
655 if (closing_quote
&& closing_quote
[1] == '\0')
656 *closing_quote
= '\0';
659 /* Now that we've safely parsed the first half,
660 * put back ',' so outer layers can see it
665 if ((p
[0] == ':' || p
[0] == '.') && !has_parens
)
670 *argptr
= *argptr
+ 1;
671 if (p
[0] == '.' || p
[1] == ':')
673 char *saved_arg2
= *argptr
;
675 /* First check for "global" namespace specification,
676 of the form "::foo". If found, skip over the colons
677 and jump to normal symbol processing */
679 && ((*argptr
== p
) || (p
[-1] == ' ') || (p
[-1] == '\t')))
682 /* We have what looks like a class or namespace
683 scope specification (A::B), possibly with many
684 levels of namespaces or classes (A::B::C::D).
686 Some versions of the HP ANSI C++ compiler (as also possibly
687 other compilers) generate class/function/member names with
688 embedded double-colons if they are inside namespaces. To
689 handle this, we loop a few times, considering larger and
690 larger prefixes of the string as though they were single
691 symbols. So, if the initially supplied string is
692 A::B::C::D::foo, we have to look up "A", then "A::B",
693 then "A::B::C", then "A::B::C::D", and finally
694 "A::B::C::D::foo" as single, monolithic symbols, because
695 A, B, C or D may be namespaces.
697 Note that namespaces can nest only inside other
698 namespaces, and not inside classes. So we need only
699 consider *prefixes* of the string; there is no need to look up
700 "B::C" separately as a symbol in the previous example. */
702 p2
= p
; /* save for restart */
705 /* Extract the class name. */
707 while (p
!= *argptr
&& p
[-1] == ' ')
709 copy
= (char *) alloca (p
- *argptr
+ 1);
710 memcpy (copy
, *argptr
, p
- *argptr
);
711 copy
[p
- *argptr
] = 0;
713 /* Discard the class name from the arg. */
714 p
= p1
+ (p1
[0] == ':' ? 2 : 1);
715 while (*p
== ' ' || *p
== '\t')
719 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
720 (struct symtab
**) NULL
);
723 (t
= check_typedef (SYMBOL_TYPE (sym_class
)),
724 (TYPE_CODE (t
) == TYPE_CODE_STRUCT
725 || TYPE_CODE (t
) == TYPE_CODE_UNION
)))
727 /* Arg token is not digits => try it as a function name
728 Find the next token(everything up to end or next blank). */
730 && strchr (get_gdb_completer_quote_characters (),
733 p
= skip_quoted (*argptr
);
734 *argptr
= *argptr
+ 1;
739 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!= ':')
743 q = operator_chars (*argptr, &q1);
747 char *tmp = alloca (q1 - q + 1);
748 memcpy (tmp, q, q1 - q);
750 opname = cplus_mangle_opname (tmp, DMGL_ANSI);
754 printf_filtered ("no mangling for \"%s\"\n", tmp);
755 cplusplus_hint (saved_arg);
756 return_to_top_level (RETURN_ERROR);
758 copy = (char*) alloca (3 + strlen(opname));
759 sprintf (copy, "__%s", opname);
765 copy
= (char *) alloca (p
- *argptr
+ 1);
766 memcpy (copy
, *argptr
, p
- *argptr
);
767 copy
[p
- *argptr
] = '\0';
769 && copy
[p
- *argptr
- 1]
770 && strchr (get_gdb_completer_quote_characters (),
771 copy
[p
- *argptr
- 1]) != NULL
)
772 copy
[p
- *argptr
- 1] = '\0';
775 /* no line number may be specified */
776 while (*p
== ' ' || *p
== '\t')
781 i1
= 0; /* counter for the symbol array */
782 sym_arr
= (struct symbol
**) alloca (total_number_of_methods (t
)
783 * sizeof (struct symbol
*));
785 if (destructor_name_p (copy
, t
))
787 /* Destructors are a special case. */
788 int m_index
, f_index
;
790 if (get_destructor_fn_field (t
, &m_index
, &f_index
))
792 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, m_index
);
795 lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f
, f_index
),
796 NULL
, VAR_NAMESPACE
, (int *) NULL
,
797 (struct symtab
**) NULL
);
803 i1
= find_methods (t
, copy
, sym_arr
);
806 /* There is exactly one field with that name. */
809 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
811 values
.sals
= (struct symtab_and_line
*)
812 xmalloc (sizeof (struct symtab_and_line
));
814 values
.sals
[0] = find_function_start_sal (sym
,
825 /* There is more than one field with that name
826 (overloaded). Ask the user which one to use. */
827 return decode_line_2 (sym_arr
, i1
, funfirstline
, canonical
);
833 if (OPNAME_PREFIX_P (copy
))
835 tmp
= (char *) alloca (strlen (copy
+ 3) + 9);
836 strcpy (tmp
, "operator ");
837 strcat (tmp
, copy
+ 3);
844 ("the class `%s' does not have destructor defined\n",
845 SYMBOL_SOURCE_NAME (sym_class
));
848 ("the class %s does not have any method named %s\n",
849 SYMBOL_SOURCE_NAME (sym_class
), tmp
);
850 cplusplus_hint (saved_arg
);
851 return_to_top_level (RETURN_ERROR
);
855 /* Move pointer up to next possible class/namespace token */
856 p
= p2
+ 1; /* restart with old value +1 */
857 /* Move pointer ahead to next double-colon */
858 while (*p
&& (p
[0] != ' ') && (p
[0] != '\t') && (p
[0] != '\''))
862 temp_end
= find_template_name_end (p
);
864 error ("malformed template specification in command");
867 else if ((p
[0] == ':') && (p
[1] == ':'))
868 break; /* found double-colon */
874 break; /* out of the while (1) */
876 p2
= p
; /* save restart for next time around */
877 *argptr
= saved_arg2
; /* restore argptr */
880 /* Last chance attempt -- check entire name as a symbol */
881 /* Use "copy" in preparation for jumping out of this block,
882 to be consistent with usage following the jump target */
883 copy
= (char *) alloca (p
- saved_arg2
+ 1);
884 memcpy (copy
, saved_arg2
, p
- saved_arg2
);
885 /* Note: if is_quoted should be true, we snuff out quote here anyway */
886 copy
[p
- saved_arg2
] = '\000';
887 /* Set argptr to skip over the name */
888 *argptr
= (*p
== '\'') ? p
+ 1 : p
;
889 /* Look up entire name */
890 sym
= lookup_symbol (copy
, 0, VAR_NAMESPACE
, 0, &sym_symtab
);
891 s
= (struct symtab
*) 0;
892 /* Prepare to jump: restore the " if (condition)" so outer layers see it */
893 /* Symbol was found --> jump to normal symbol processing.
894 Code following "symbol_found" expects "copy" to have the
895 symbol name, "sym" to have the symbol pointer, "s" to be
896 a specified file's symtab, and sym_symtab to be the symbol's
898 /* By jumping there we avoid falling through the FILE:LINE and
899 FILE:FUNC processing stuff below */
903 /* Couldn't find any interpretation as classes/namespaces, so give up */
905 /* The quotes are important if copy is empty. */
907 ("Can't find member of namespace, class, struct, or union named \"%s\"\n", copy
);
908 cplusplus_hint (saved_arg
);
909 return_to_top_level (RETURN_ERROR
);
914 /* Extract the file name. */
916 while (p
!= *argptr
&& p
[-1] == ' ')
918 if ((*p
== '"') && is_quote_enclosed
)
920 copy
= (char *) alloca (p
- *argptr
+ 1);
921 if ((**argptr
== '"') && is_quote_enclosed
)
923 memcpy (copy
, *argptr
+ 1, p
- *argptr
- 1);
924 /* It may have the ending quote right after the file name */
925 if (copy
[p
- *argptr
- 2] == '"')
926 copy
[p
- *argptr
- 2] = 0;
928 copy
[p
- *argptr
- 1] = 0;
932 memcpy (copy
, *argptr
, p
- *argptr
);
933 copy
[p
- *argptr
] = 0;
936 /* Find that file's data. */
937 s
= lookup_symtab (copy
);
940 if (!have_full_symbols () && !have_partial_symbols ())
941 error ("No symbol table is loaded. Use the \"file\" command.");
942 error ("No source file named %s.", copy
);
945 /* Discard the file name from the arg. */
947 while (*p
== ' ' || *p
== '\t')
952 /* No one really seems to know why this was added. It certainly
953 breaks the command line, though, whenever the passed
954 name is of the form ClassName::Method. This bit of code
955 singles out the class name, and if funfirstline is set (for
956 example, you are setting a breakpoint at this function),
957 you get an error. This did not occur with earlier
958 verions, so I am ifdef'ing this out. 3/29/99 */
961 /* Check if what we have till now is a symbol name */
963 /* We may be looking at a template instantiation such
964 as "foo<int>". Check here whether we know about it,
965 instead of falling through to the code below which
966 handles ordinary function names, because that code
967 doesn't like seeing '<' and '>' in a name -- the
968 skip_quoted call doesn't go past them. So see if we
969 can figure it out right now. */
971 copy
= (char *) alloca (p
- *argptr
+ 1);
972 memcpy (copy
, *argptr
, p
- *argptr
);
973 copy
[p
- *argptr
] = '\000';
974 sym
= lookup_symbol (copy
, 0, VAR_NAMESPACE
, 0, &sym_symtab
);
977 /* Yes, we have a symbol; jump to symbol processing */
978 /* Code after symbol_found expects S, SYM_SYMTAB, SYM,
979 and COPY to be set correctly */
980 *argptr
= (*p
== '\'') ? p
+ 1 : p
;
981 s
= (struct symtab
*) 0;
984 /* Otherwise fall out from here and go to file/line spec
989 /* S is specified file's symtab, or 0 if no file specified.
990 arg no longer contains the file name. */
992 /* Check whether arg is all digits (and sign) */
995 if (*q
== '-' || *q
== '+')
997 while (*q
>= '0' && *q
<= '9')
1000 if (q
!= *argptr
&& (*q
== 0 || *q
== ' ' || *q
== '\t' || *q
== ','))
1002 /* We found a token consisting of all digits -- at least one digit. */
1009 /* We might need a canonical line spec if no file was specified. */
1010 int need_canonical
= (s
== 0) ? 1 : 0;
1012 /* This is where we need to make sure that we have good defaults.
1013 We must guarantee that this section of code is never executed
1014 when we are called with just a function name, since
1015 select_source_symtab calls us with such an argument */
1017 if (s
== 0 && default_symtab
== 0)
1019 select_source_symtab (0);
1020 default_symtab
= current_source_symtab
;
1021 default_line
= current_source_line
;
1024 if (**argptr
== '+')
1025 sign
= plus
, (*argptr
)++;
1026 else if (**argptr
== '-')
1027 sign
= minus
, (*argptr
)++;
1028 val
.line
= atoi (*argptr
);
1035 val
.line
= default_line
+ val
.line
;
1041 val
.line
= default_line
- val
.line
;
1046 break; /* No need to adjust val.line. */
1049 while (*q
== ' ' || *q
== '\t')
1055 /* It is possible that this source file has more than one symtab,
1056 and that the new line number specification has moved us from the
1057 default (in s) to a new one. */
1058 val
.symtab
= find_line_symtab (s
, val
.line
, NULL
, NULL
);
1059 if (val
.symtab
== 0)
1063 values
.sals
= (struct symtab_and_line
*)
1064 xmalloc (sizeof (struct symtab_and_line
));
1065 values
.sals
[0] = val
;
1068 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
1072 /* Arg token is not digits => try it as a variable name
1073 Find the next token (everything up to end or next whitespace). */
1075 if (**argptr
== '$') /* May be a convenience variable */
1076 p
= skip_quoted (*argptr
+ (((*argptr
)[1] == '$') ? 2 : 1)); /* One or two $ chars possible */
1079 p
= skip_quoted (*argptr
);
1081 error ("Unmatched single quote.");
1083 else if (has_parens
)
1089 p
= skip_quoted (*argptr
);
1092 copy
= (char *) alloca (p
- *argptr
+ 1);
1093 memcpy (copy
, *argptr
, p
- *argptr
);
1094 copy
[p
- *argptr
] = '\0';
1097 && copy
[0] == copy
[p
- *argptr
- 1]
1098 && strchr (get_gdb_completer_quote_characters (), copy
[0]) != NULL
)
1100 copy
[p
- *argptr
- 1] = '\0';
1103 while (*p
== ' ' || *p
== '\t')
1107 /* If it starts with $: may be a legitimate variable or routine name
1108 (e.g. HP-UX millicode routines such as $$dyncall), or it may
1109 be history value, or it may be a convenience variable */
1115 int need_canonical
= 0;
1117 p
= (copy
[1] == '$') ? copy
+ 2 : copy
+ 1;
1118 while (*p
>= '0' && *p
<= '9')
1120 if (!*p
) /* reached end of token without hitting non-digit */
1122 /* We have a value history reference */
1123 sscanf ((copy
[1] == '$') ? copy
+ 2 : copy
+ 1, "%d", &index
);
1124 valx
= access_value_history ((copy
[1] == '$') ? -index
: index
);
1125 if (TYPE_CODE (VALUE_TYPE (valx
)) != TYPE_CODE_INT
)
1126 error ("History values used in line specs must have integer values.");
1130 /* Not all digits -- may be user variable/function or a
1131 convenience variable */
1133 /* Look up entire name as a symbol first */
1134 sym
= lookup_symbol (copy
, 0, VAR_NAMESPACE
, 0, &sym_symtab
);
1135 s
= (struct symtab
*) 0;
1137 /* Symbol was found --> jump to normal symbol processing.
1138 Code following "symbol_found" expects "copy" to have the
1139 symbol name, "sym" to have the symbol pointer, "s" to be
1140 a specified file's symtab, and sym_symtab to be the symbol's
1145 /* If symbol was not found, look in minimal symbol tables */
1146 msymbol
= lookup_minimal_symbol (copy
, 0, 0);
1147 /* Min symbol was found --> jump to minsym processing. */
1149 goto minimal_symbol_found
;
1151 /* Not a user variable or function -- must be convenience variable */
1152 need_canonical
= (s
== 0) ? 1 : 0;
1153 valx
= value_of_internalvar (lookup_internalvar (copy
+ 1));
1154 if (TYPE_CODE (VALUE_TYPE (valx
)) != TYPE_CODE_INT
)
1155 error ("Convenience variables used in line specs must have integer values.");
1158 /* Either history value or convenience value from above, in valx */
1159 val
.symtab
= s
? s
: default_symtab
;
1160 val
.line
= value_as_long (valx
);
1163 values
.sals
= (struct symtab_and_line
*) xmalloc (sizeof val
);
1164 values
.sals
[0] = val
;
1168 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
1174 /* Look up that token as a variable.
1175 If file specified, use that file's per-file block to start with. */
1177 sym
= lookup_symbol (copy
,
1178 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
1179 : get_selected_block ()),
1180 VAR_NAMESPACE
, 0, &sym_symtab
);
1182 symbol_found
: /* We also jump here from inside the C++ class/namespace
1183 code on finding a symbol of the form "A::B::C" */
1187 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1189 /* Arg is the name of a function */
1190 values
.sals
= (struct symtab_and_line
*)
1191 xmalloc (sizeof (struct symtab_and_line
));
1192 values
.sals
[0] = find_function_start_sal (sym
, funfirstline
);
1195 /* Don't use the SYMBOL_LINE; if used at all it points to
1196 the line containing the parameters or thereabouts, not
1197 the first line of code. */
1199 /* We might need a canonical line spec if it is a static
1203 struct blockvector
*bv
= BLOCKVECTOR (sym_symtab
);
1204 struct block
*b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1205 if (lookup_block_symbol (b
, copy
, VAR_NAMESPACE
) != NULL
)
1206 build_canonical_line_spec (values
.sals
, copy
, canonical
);
1213 error ("\"%s\" is not a function", copy
);
1214 else if (SYMBOL_LINE (sym
) != 0)
1216 /* We know its line number. */
1217 values
.sals
= (struct symtab_and_line
*)
1218 xmalloc (sizeof (struct symtab_and_line
));
1220 memset (&values
.sals
[0], 0, sizeof (values
.sals
[0]));
1221 values
.sals
[0].symtab
= sym_symtab
;
1222 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1226 /* This can happen if it is compiled with a compiler which doesn't
1227 put out line numbers for variables. */
1228 /* FIXME: Shouldn't we just set .line and .symtab to zero
1229 and return? For example, "info line foo" could print
1231 error ("Line number not known for symbol \"%s\"", copy
);
1235 msymbol
= lookup_minimal_symbol (copy
, NULL
, NULL
);
1237 minimal_symbol_found
: /* We also jump here from the case for variables
1238 that begin with '$' */
1240 if (msymbol
!= NULL
)
1242 values
.sals
= (struct symtab_and_line
*)
1243 xmalloc (sizeof (struct symtab_and_line
));
1244 values
.sals
[0] = find_pc_sect_line (SYMBOL_VALUE_ADDRESS (msymbol
),
1245 (struct sec
*) 0, 0);
1246 values
.sals
[0].section
= SYMBOL_BFD_SECTION (msymbol
);
1249 values
.sals
[0].pc
+= FUNCTION_START_OFFSET
;
1250 values
.sals
[0].pc
= SKIP_PROLOGUE (values
.sals
[0].pc
);
1256 if (!have_full_symbols () &&
1257 !have_partial_symbols () && !have_minimal_symbols ())
1258 error ("No symbol table is loaded. Use the \"file\" command.");
1260 error ("Function \"%s\" not defined.", copy
);
1261 return values
; /* for lint */