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. */
32 #include "completer.h"
35 /* Prototype for one function in parser-defs.h,
36 instead of including that entire file. */
38 extern char *find_template_name_end (char *);
40 /* We share this one with symtab.c, but it is not exported widely. */
42 extern char *operator_chars (char *, char **);
44 /* Prototypes for local functions */
46 static void cplusplus_error (const char *name
, const char *fmt
, ...) ATTR_FORMAT (printf
, 2, 3);
48 static int total_number_of_methods (struct type
*type
);
50 static int find_methods (struct type
*, char *, struct symbol
**);
52 static void build_canonical_line_spec (struct symtab_and_line
*,
55 static char *find_toplevel_char (char *s
, char c
);
57 static struct symtabs_and_lines
decode_line_2 (struct symbol
*[],
60 /* Helper functions. */
62 /* Issue a helpful hint on using the command completion feature on
63 single quoted demangled C++ symbols as part of the completion
67 cplusplus_error (const char *name
, const char *fmt
, ...)
69 struct ui_file
*tmp_stream
;
70 tmp_stream
= mem_fileopen ();
71 make_cleanup_ui_file_delete (tmp_stream
);
76 vfprintf_unfiltered (tmp_stream
, fmt
, args
);
82 fprintf_unfiltered (tmp_stream
,
83 ("Hint: try '%s<TAB> or '%s<ESC-?>\n"
84 "(Note leading single quote.)"),
86 error_stream (tmp_stream
);
89 /* Return the number of methods described for TYPE, including the
90 methods from types it derives from. This can't be done in the symbol
91 reader because the type of the baseclass might still be stubbed
92 when the definition of the derived class is parsed. */
95 total_number_of_methods (struct type
*type
)
100 CHECK_TYPEDEF (type
);
101 if (TYPE_CPLUS_SPECIFIC (type
) == NULL
)
103 count
= TYPE_NFN_FIELDS_TOTAL (type
);
105 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
106 count
+= total_number_of_methods (TYPE_BASECLASS (type
, n
));
111 /* Recursive helper function for decode_line_1.
112 Look for methods named NAME in type T.
113 Return number of matches.
114 Put matches in SYM_ARR, which should have been allocated with
115 a size of total_number_of_methods (T) * sizeof (struct symbol *).
116 Note that this function is g++ specific. */
119 find_methods (struct type
*t
, char *name
, struct symbol
**sym_arr
)
123 char *class_name
= type_name_no_tag (t
);
125 /* Ignore this class if it doesn't have a name. This is ugly, but
126 unless we figure out how to get the physname without the name of
127 the class, then the loop can't do any good. */
129 && (lookup_symbol (class_name
, (struct block
*) NULL
,
130 STRUCT_NAMESPACE
, (int *) NULL
,
131 (struct symtab
**) NULL
)))
134 int name_len
= strlen (name
);
138 /* Loop over each method name. At this level, all overloads of a name
139 are counted as a single name. There is an inner loop which loops over
142 for (method_counter
= TYPE_NFN_FIELDS (t
) - 1;
147 char *method_name
= TYPE_FN_FIELDLIST_NAME (t
, method_counter
);
150 if (strncmp (method_name
, "__", 2) == 0 ||
151 strncmp (method_name
, "op", 2) == 0 ||
152 strncmp (method_name
, "type", 4) == 0)
154 if (cplus_demangle_opname (method_name
, dem_opname
, DMGL_ANSI
))
155 method_name
= dem_opname
;
156 else if (cplus_demangle_opname (method_name
, dem_opname
, 0))
157 method_name
= dem_opname
;
160 if (strcmp_iw (name
, method_name
) == 0)
161 /* Find all the overloaded methods with that name. */
162 for (field_counter
= TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
169 f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
171 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
175 tmp_name
= gdb_mangle_name (t
,
178 phys_name
= alloca (strlen (tmp_name
) + 1);
179 strcpy (phys_name
, tmp_name
);
183 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
185 /* Destructor is handled by caller, dont add it to the list */
186 if (is_destructor_name (phys_name
) != 0)
189 sym_arr
[i1
] = lookup_symbol (phys_name
,
192 (struct symtab
**) NULL
);
197 /* This error message gets printed, but the method
198 still seems to be found
199 fputs_filtered("(Cannot find method ", gdb_stdout);
200 fprintf_symbol_filtered (gdb_stdout, phys_name,
202 DMGL_PARAMS | DMGL_ANSI);
203 fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
207 else if (strncmp (class_name
, name
, name_len
) == 0
208 && (class_name
[name_len
] == '\0'
209 || class_name
[name_len
] == '<'))
211 /* For GCC 3.x and stabs, constructors and destructors have names
212 like __base_ctor and __complete_dtor. Check the physname for now
213 if we're looking for a constructor. */
215 = TYPE_FN_FIELDLIST_LENGTH (t
, method_counter
) - 1;
222 f
= TYPE_FN_FIELDLIST1 (t
, method_counter
);
224 /* GCC 3.x will never produce stabs stub methods, so we don't need
225 to handle this case. */
226 if (TYPE_FN_FIELD_STUB (f
, field_counter
))
228 phys_name
= TYPE_FN_FIELD_PHYSNAME (f
, field_counter
);
229 if (! is_constructor_name (phys_name
))
232 /* If this method is actually defined, include it in the
234 sym_arr
[i1
] = lookup_symbol (phys_name
,
237 (struct symtab
**) NULL
);
245 /* Only search baseclasses if there is no match yet, since names in
246 derived classes override those in baseclasses.
248 FIXME: The above is not true; it is only true of member functions
249 if they have the same number of arguments (??? - section 13.1 of the
250 ARM says the function members are not in the same scope but doesn't
251 really spell out the rules in a way I understand. In any case, if
252 the number of arguments differ this is a case in which we can overload
253 rather than hiding without any problem, and gcc 2.4.5 does overload
254 rather than hiding in this case). */
257 for (ibase
= 0; ibase
< TYPE_N_BASECLASSES (t
); ibase
++)
258 i1
+= find_methods (TYPE_BASECLASS (t
, ibase
), name
, sym_arr
+ i1
);
263 /* Helper function for decode_line_1.
264 Build a canonical line spec in CANONICAL if it is non-NULL and if
265 the SAL has a symtab.
266 If SYMNAME is non-NULL the canonical line spec is `filename:symname'.
267 If SYMNAME is NULL the line number from SAL is used and the canonical
268 line spec is `filename:linenum'. */
271 build_canonical_line_spec (struct symtab_and_line
*sal
, char *symname
,
274 char **canonical_arr
;
275 char *canonical_name
;
277 struct symtab
*s
= sal
->symtab
;
279 if (s
== (struct symtab
*) NULL
280 || s
->filename
== (char *) NULL
281 || canonical
== (char ***) NULL
)
284 canonical_arr
= (char **) xmalloc (sizeof (char *));
285 *canonical
= canonical_arr
;
287 filename
= s
->filename
;
290 canonical_name
= xmalloc (strlen (filename
) + strlen (symname
) + 2);
291 sprintf (canonical_name
, "%s:%s", filename
, symname
);
295 canonical_name
= xmalloc (strlen (filename
) + 30);
296 sprintf (canonical_name
, "%s:%d", filename
, sal
->line
);
298 canonical_arr
[0] = canonical_name
;
303 /* Find an instance of the character C in the string S that is outside
304 of all parenthesis pairs, single-quoted strings, and double-quoted
305 strings. Also, ignore the char within a template name, like a ','
306 within foo<int, int>. */
309 find_toplevel_char (char *s
, char c
)
311 int quoted
= 0; /* zero if we're not in quotes;
312 '"' if we're in a double-quoted string;
313 '\'' if we're in a single-quoted string. */
314 int depth
= 0; /* number of unclosed parens we've seen */
317 for (scan
= s
; *scan
; scan
++)
323 else if (*scan
== '\\' && *(scan
+ 1))
326 else if (*scan
== c
&& ! quoted
&& depth
== 0)
328 else if (*scan
== '"' || *scan
== '\'')
330 else if (*scan
== '(' || *scan
== '<')
332 else if ((*scan
== ')' || *scan
== '>') && depth
> 0)
339 /* Given a list of NELTS symbols in SYM_ARR, return a list of lines to
340 operate on (ask user if necessary).
341 If CANONICAL is non-NULL return a corresponding array of mangled names
342 as canonical line specs there. */
344 static struct symtabs_and_lines
345 decode_line_2 (struct symbol
*sym_arr
[], int nelts
, int funfirstline
,
348 struct symtabs_and_lines values
, return_values
;
353 struct cleanup
*old_chain
;
354 char **canonical_arr
= (char **) NULL
;
356 values
.sals
= (struct symtab_and_line
*)
357 alloca (nelts
* sizeof (struct symtab_and_line
));
358 return_values
.sals
= (struct symtab_and_line
*)
359 xmalloc (nelts
* sizeof (struct symtab_and_line
));
360 old_chain
= make_cleanup (xfree
, return_values
.sals
);
364 canonical_arr
= (char **) xmalloc (nelts
* sizeof (char *));
365 make_cleanup (xfree
, canonical_arr
);
366 memset (canonical_arr
, 0, nelts
* sizeof (char *));
367 *canonical
= canonical_arr
;
371 printf_unfiltered ("[0] cancel\n[1] all\n");
374 INIT_SAL (&return_values
.sals
[i
]); /* initialize to zeroes */
375 INIT_SAL (&values
.sals
[i
]);
376 if (sym_arr
[i
] && SYMBOL_CLASS (sym_arr
[i
]) == LOC_BLOCK
)
378 values
.sals
[i
] = find_function_start_sal (sym_arr
[i
], funfirstline
);
379 printf_unfiltered ("[%d] %s at %s:%d\n",
381 SYMBOL_SOURCE_NAME (sym_arr
[i
]),
382 values
.sals
[i
].symtab
->filename
,
383 values
.sals
[i
].line
);
386 printf_unfiltered ("?HERE\n");
390 if ((prompt
= getenv ("PS2")) == NULL
)
394 args
= command_line_input (prompt
, 0, "overload-choice");
396 if (args
== 0 || *args
== 0)
397 error_no_arg ("one or more choice numbers");
405 while (*arg1
>= '0' && *arg1
<= '9')
407 if (*arg1
&& *arg1
!= ' ' && *arg1
!= '\t')
408 error ("Arguments must be choice numbers.");
418 for (i
= 0; i
< nelts
; i
++)
420 if (canonical_arr
[i
] == NULL
)
422 symname
= SYMBOL_NAME (sym_arr
[i
]);
423 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
427 memcpy (return_values
.sals
, values
.sals
,
428 (nelts
* sizeof (struct symtab_and_line
)));
429 return_values
.nelts
= nelts
;
430 discard_cleanups (old_chain
);
431 return return_values
;
434 if (num
>= nelts
+ 2)
436 printf_unfiltered ("No choice number %d.\n", num
);
441 if (values
.sals
[num
].pc
)
445 symname
= SYMBOL_NAME (sym_arr
[num
]);
446 make_cleanup (xfree
, symname
);
447 canonical_arr
[i
] = savestring (symname
, strlen (symname
));
449 return_values
.sals
[i
++] = values
.sals
[num
];
450 values
.sals
[num
].pc
= 0;
454 printf_unfiltered ("duplicate request for %d ignored.\n", num
);
459 while (*args
== ' ' || *args
== '\t')
462 return_values
.nelts
= i
;
463 discard_cleanups (old_chain
);
464 return return_values
;
467 /* The parser of linespec itself. */
469 /* Parse a string that specifies a line number.
470 Pass the address of a char * variable; that variable will be
471 advanced over the characters actually parsed.
475 LINENUM -- that line number in current file. PC returned is 0.
476 FILE:LINENUM -- that line in that file. PC returned is 0.
477 FUNCTION -- line number of openbrace of that function.
478 PC returned is the start of the function.
479 VARIABLE -- line number of definition of that variable.
481 FILE:FUNCTION -- likewise, but prefer functions in that file.
482 *EXPR -- line in which address EXPR appears.
484 This may all be followed by an "if EXPR", which we ignore.
486 FUNCTION may be an undebuggable function found in minimal symbol table.
488 If the argument FUNFIRSTLINE is nonzero, we want the first line
489 of real code inside a function when a function is specified, and it is
490 not OK to specify a variable or type to get its line number.
492 DEFAULT_SYMTAB specifies the file to use if none is specified.
493 It defaults to current_source_symtab.
494 DEFAULT_LINE specifies the line number to use for relative
495 line numbers (that start with signs). Defaults to current_source_line.
496 If CANONICAL is non-NULL, store an array of strings containing the canonical
497 line specs there if necessary. Currently overloaded member functions and
498 line numbers or static functions without a filename yield a canonical
499 line spec. The array and the line spec strings are allocated on the heap,
500 it is the callers responsibility to free them.
502 Note that it is possible to return zero for the symtab
503 if no file is validly specified. Callers must check that.
504 Also, the line number returned may be invalid. */
506 /* We allow single quotes in various places. This is a hideous
507 kludge, which exists because the completer can't yet deal with the
508 lack of single quotes. FIXME: write a linespec_completer which we
509 can use as appropriate instead of make_symbol_completion_list. */
511 struct symtabs_and_lines
512 decode_line_1 (char **argptr
, int funfirstline
, struct symtab
*default_symtab
,
513 int default_line
, char ***canonical
)
515 struct symtabs_and_lines values
;
516 struct symtab_and_line val
;
517 register char *p
, *p1
;
518 char *q
, *pp
, *ii
, *p2
;
522 register struct symtab
*s
;
524 register struct symbol
*sym
;
525 /* The symtab that SYM was found in. */
526 struct symtab
*sym_symtab
;
528 register CORE_ADDR pc
;
529 register struct minimal_symbol
*msymbol
;
531 struct symbol
*sym_class
;
534 int is_quote_enclosed
;
538 struct symbol
**sym_arr
;
540 char *saved_arg
= *argptr
;
541 extern char *gdb_completer_quote_characters
;
543 INIT_SAL (&val
); /* initialize to zeroes */
545 /* Defaults have defaults. */
547 if (default_symtab
== 0)
549 /* Use whatever we have for the default source line. We don't use
550 get_current_or_default_symtab_and_line as it can recurse and call
552 struct symtab_and_line cursal
=
553 get_current_source_symtab_and_line ();
555 default_symtab
= cursal
.symtab
;
556 default_line
= cursal
.line
;
559 /* See if arg is *PC */
564 pc
= parse_and_eval_address_1 (argptr
);
566 values
.sals
= (struct symtab_and_line
*)
567 xmalloc (sizeof (struct symtab_and_line
));
570 values
.sals
[0] = find_pc_line (pc
, 0);
571 values
.sals
[0].pc
= pc
;
572 values
.sals
[0].section
= find_pc_overlay (pc
);
577 /* 'has_if' is for the syntax:
578 * (gdb) break foo if (a==b)
580 if ((ii
= strstr (*argptr
, " if ")) != NULL
||
581 (ii
= strstr (*argptr
, "\tif ")) != NULL
||
582 (ii
= strstr (*argptr
, " if\t")) != NULL
||
583 (ii
= strstr (*argptr
, "\tif\t")) != NULL
||
584 (ii
= strstr (*argptr
, " if(")) != NULL
||
585 (ii
= strstr (*argptr
, "\tif( ")) != NULL
)
587 /* Temporarily zap out "if (condition)" to not
588 * confuse the parenthesis-checking code below.
589 * This is undone below. Do not change ii!!
596 /* Set various flags.
597 * 'has_parens' is important for overload checking, where
598 * we allow things like:
599 * (gdb) break c::f(int)
602 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
604 is_quoted
= (**argptr
605 && strchr (get_gdb_completer_quote_characters (),
608 has_parens
= ((pp
= strchr (*argptr
, '(')) != NULL
609 && (pp
= strrchr (pp
, ')')) != NULL
);
611 /* Now that we're safely past the has_parens check,
612 * put back " if (condition)" so outer layers can see it
617 /* Maybe we were called with a line range FILENAME:LINENUM,FILENAME:LINENUM
618 and we must isolate the first half. Outer layers will call again later
621 Don't count commas that appear in argument lists of overloaded
622 functions, or in quoted strings. It's stupid to go to this much
623 trouble when the rest of the function is such an obvious roach hotel. */
624 ii
= find_toplevel_char (*argptr
, ',');
625 has_comma
= (ii
!= 0);
627 /* Temporarily zap out second half to not
628 * confuse the code below.
629 * This is undone below. Do not change ii!!
636 /* Maybe arg is FILE : LINENUM or FILE : FUNCTION */
637 /* May also be CLASS::MEMBER, or NAMESPACE::NAME */
638 /* Look for ':', but ignore inside of <> */
644 is_quote_enclosed
= 1;
649 is_quote_enclosed
= 0;
654 char *temp_end
= find_template_name_end (p
);
656 error ("malformed template specification in command");
659 /* Check for the end of the first half of the linespec. End of line,
660 a tab, a double colon or the last single colon, or a space. But
661 if enclosed in double quotes we do not break on enclosed spaces */
665 && ((p
[1] == ':') || (strchr (p
+ 1, ':') == NULL
)))
666 || ((p
[0] == ' ') && !is_quote_enclosed
))
668 if (p
[0] == '.' && strchr (p
, ':') == NULL
) /* Java qualified method. */
670 /* Find the *last* '.', since the others are package qualifiers. */
671 for (p1
= p
; *p1
; p1
++)
679 while (p
[0] == ' ' || p
[0] == '\t')
682 /* if the closing double quote was left at the end, remove it */
683 if (is_quote_enclosed
)
685 char *closing_quote
= strchr (p
- 1, '"');
686 if (closing_quote
&& closing_quote
[1] == '\0')
687 *closing_quote
= '\0';
690 /* Now that we've safely parsed the first half,
691 * put back ',' so outer layers can see it
696 if ((p
[0] == ':' || p
[0] == '.') && !has_parens
)
701 *argptr
= *argptr
+ 1;
702 if (p
[0] == '.' || p
[1] == ':')
704 char *saved_arg2
= *argptr
;
706 /* First check for "global" namespace specification,
707 of the form "::foo". If found, skip over the colons
708 and jump to normal symbol processing */
710 && ((*argptr
== p
) || (p
[-1] == ' ') || (p
[-1] == '\t')))
713 /* We have what looks like a class or namespace
714 scope specification (A::B), possibly with many
715 levels of namespaces or classes (A::B::C::D).
717 Some versions of the HP ANSI C++ compiler (as also possibly
718 other compilers) generate class/function/member names with
719 embedded double-colons if they are inside namespaces. To
720 handle this, we loop a few times, considering larger and
721 larger prefixes of the string as though they were single
722 symbols. So, if the initially supplied string is
723 A::B::C::D::foo, we have to look up "A", then "A::B",
724 then "A::B::C", then "A::B::C::D", and finally
725 "A::B::C::D::foo" as single, monolithic symbols, because
726 A, B, C or D may be namespaces.
728 Note that namespaces can nest only inside other
729 namespaces, and not inside classes. So we need only
730 consider *prefixes* of the string; there is no need to look up
731 "B::C" separately as a symbol in the previous example. */
733 p2
= p
; /* save for restart */
736 /* Extract the class name. */
738 while (p
!= *argptr
&& p
[-1] == ' ')
740 copy
= (char *) alloca (p
- *argptr
+ 1);
741 memcpy (copy
, *argptr
, p
- *argptr
);
742 copy
[p
- *argptr
] = 0;
744 /* Discard the class name from the arg. */
745 p
= p1
+ (p1
[0] == ':' ? 2 : 1);
746 while (*p
== ' ' || *p
== '\t')
750 sym_class
= lookup_symbol (copy
, 0, STRUCT_NAMESPACE
, 0,
751 (struct symtab
**) NULL
);
754 (t
= check_typedef (SYMBOL_TYPE (sym_class
)),
755 (TYPE_CODE (t
) == TYPE_CODE_STRUCT
756 || TYPE_CODE (t
) == TYPE_CODE_UNION
)))
758 /* Arg token is not digits => try it as a function name
759 Find the next token(everything up to end or next blank). */
761 && strchr (get_gdb_completer_quote_characters (),
764 p
= skip_quoted (*argptr
);
765 *argptr
= *argptr
+ 1;
770 while (*p
&& *p
!= ' ' && *p
!= '\t' && *p
!= ',' && *p
!= ':')
774 q = operator_chars (*argptr, &q1);
778 char *tmp = alloca (q1 - q + 1);
779 memcpy (tmp, q, q1 - q);
781 opname = cplus_mangle_opname (tmp, DMGL_ANSI);
784 cplusplus_error (saved_arg, "no mangling for \"%s\"\n", tmp);
786 copy = (char*) alloca (3 + strlen(opname));
787 sprintf (copy, "__%s", opname);
793 copy
= (char *) alloca (p
- *argptr
+ 1);
794 memcpy (copy
, *argptr
, p
- *argptr
);
795 copy
[p
- *argptr
] = '\0';
797 && copy
[p
- *argptr
- 1]
798 && strchr (get_gdb_completer_quote_characters (),
799 copy
[p
- *argptr
- 1]) != NULL
)
800 copy
[p
- *argptr
- 1] = '\0';
803 /* no line number may be specified */
804 while (*p
== ' ' || *p
== '\t')
809 i1
= 0; /* counter for the symbol array */
810 sym_arr
= (struct symbol
**) alloca (total_number_of_methods (t
)
811 * sizeof (struct symbol
*));
813 if (destructor_name_p (copy
, t
))
815 /* Destructors are a special case. */
816 int m_index
, f_index
;
818 if (get_destructor_fn_field (t
, &m_index
, &f_index
))
820 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (t
, m_index
);
823 lookup_symbol (TYPE_FN_FIELD_PHYSNAME (f
, f_index
),
824 NULL
, VAR_NAMESPACE
, (int *) NULL
,
825 (struct symtab
**) NULL
);
831 i1
= find_methods (t
, copy
, sym_arr
);
834 /* There is exactly one field with that name. */
837 if (sym
&& SYMBOL_CLASS (sym
) == LOC_BLOCK
)
839 values
.sals
= (struct symtab_and_line
*)
840 xmalloc (sizeof (struct symtab_and_line
));
842 values
.sals
[0] = find_function_start_sal (sym
,
853 /* There is more than one field with that name
854 (overloaded). Ask the user which one to use. */
855 return decode_line_2 (sym_arr
, i1
, funfirstline
, canonical
);
861 if (is_operator_name (copy
))
863 tmp
= (char *) alloca (strlen (copy
+ 3) + 9);
864 strcpy (tmp
, "operator ");
865 strcat (tmp
, copy
+ 3);
870 cplusplus_error (saved_arg
,
871 "the class `%s' does not have destructor defined\n",
872 SYMBOL_SOURCE_NAME (sym_class
));
874 cplusplus_error (saved_arg
,
875 "the class %s does not have any method named %s\n",
876 SYMBOL_SOURCE_NAME (sym_class
), tmp
);
880 /* Move pointer up to next possible class/namespace token */
881 p
= p2
+ 1; /* restart with old value +1 */
882 /* Move pointer ahead to next double-colon */
883 while (*p
&& (p
[0] != ' ') && (p
[0] != '\t') && (p
[0] != '\''))
887 temp_end
= find_template_name_end (p
);
889 error ("malformed template specification in command");
892 else if ((p
[0] == ':') && (p
[1] == ':'))
893 break; /* found double-colon */
899 break; /* out of the while (1) */
901 p2
= p
; /* save restart for next time around */
902 *argptr
= saved_arg2
; /* restore argptr */
905 /* Last chance attempt -- check entire name as a symbol */
906 /* Use "copy" in preparation for jumping out of this block,
907 to be consistent with usage following the jump target */
908 copy
= (char *) alloca (p
- saved_arg2
+ 1);
909 memcpy (copy
, saved_arg2
, p
- saved_arg2
);
910 /* Note: if is_quoted should be true, we snuff out quote here anyway */
911 copy
[p
- saved_arg2
] = '\000';
912 /* Set argptr to skip over the name */
913 *argptr
= (*p
== '\'') ? p
+ 1 : p
;
914 /* Look up entire name */
915 sym
= lookup_symbol (copy
, 0, VAR_NAMESPACE
, 0, &sym_symtab
);
916 s
= (struct symtab
*) 0;
917 /* Prepare to jump: restore the " if (condition)" so outer layers see it */
918 /* Symbol was found --> jump to normal symbol processing.
919 Code following "symbol_found" expects "copy" to have the
920 symbol name, "sym" to have the symbol pointer, "s" to be
921 a specified file's symtab, and sym_symtab to be the symbol's
923 /* By jumping there we avoid falling through the FILE:LINE and
924 FILE:FUNC processing stuff below */
928 /* Couldn't find any interpretation as classes/namespaces, so give up */
929 /* The quotes are important if copy is empty. */
930 cplusplus_error (saved_arg
,
931 "Can't find member of namespace, class, struct, or union named \"%s\"\n",
937 /* Extract the file name. */
939 while (p
!= *argptr
&& p
[-1] == ' ')
941 if ((*p
== '"') && is_quote_enclosed
)
943 copy
= (char *) alloca (p
- *argptr
+ 1);
944 memcpy (copy
, *argptr
, p
- *argptr
);
945 /* It may have the ending quote right after the file name */
946 if (is_quote_enclosed
&& copy
[p
- *argptr
- 1] == '"')
947 copy
[p
- *argptr
- 1] = 0;
949 copy
[p
- *argptr
] = 0;
951 /* Find that file's data. */
952 s
= lookup_symtab (copy
);
955 if (!have_full_symbols () && !have_partial_symbols ())
956 error ("No symbol table is loaded. Use the \"file\" command.");
957 error ("No source file named %s.", copy
);
960 /* Discard the file name from the arg. */
962 while (*p
== ' ' || *p
== '\t')
967 /* No one really seems to know why this was added. It certainly
968 breaks the command line, though, whenever the passed
969 name is of the form ClassName::Method. This bit of code
970 singles out the class name, and if funfirstline is set (for
971 example, you are setting a breakpoint at this function),
972 you get an error. This did not occur with earlier
973 verions, so I am ifdef'ing this out. 3/29/99 */
976 /* Check if what we have till now is a symbol name */
978 /* We may be looking at a template instantiation such
979 as "foo<int>". Check here whether we know about it,
980 instead of falling through to the code below which
981 handles ordinary function names, because that code
982 doesn't like seeing '<' and '>' in a name -- the
983 skip_quoted call doesn't go past them. So see if we
984 can figure it out right now. */
986 copy
= (char *) alloca (p
- *argptr
+ 1);
987 memcpy (copy
, *argptr
, p
- *argptr
);
988 copy
[p
- *argptr
] = '\000';
989 sym
= lookup_symbol (copy
, 0, VAR_NAMESPACE
, 0, &sym_symtab
);
992 /* Yes, we have a symbol; jump to symbol processing */
993 /* Code after symbol_found expects S, SYM_SYMTAB, SYM,
994 and COPY to be set correctly */
995 *argptr
= (*p
== '\'') ? p
+ 1 : p
;
996 s
= (struct symtab
*) 0;
999 /* Otherwise fall out from here and go to file/line spec
1004 /* S is specified file's symtab, or 0 if no file specified.
1005 arg no longer contains the file name. */
1007 /* Check whether arg is all digits (and sign) */
1010 if (*q
== '-' || *q
== '+')
1012 while (*q
>= '0' && *q
<= '9')
1015 if (q
!= *argptr
&& (*q
== 0 || *q
== ' ' || *q
== '\t' || *q
== ','))
1017 /* We found a token consisting of all digits -- at least one digit. */
1024 /* We might need a canonical line spec if no file was specified. */
1025 int need_canonical
= (s
== 0) ? 1 : 0;
1027 /* This is where we need to make sure that we have good defaults.
1028 We must guarantee that this section of code is never executed
1029 when we are called with just a function name, since
1030 set_default_source_symtab_and_line uses
1031 select_source_symtab that calls us with such an argument */
1033 if (s
== 0 && default_symtab
== 0)
1035 struct symtab_and_line cursal
;
1037 /* Make sure we have at least a default source file. */
1038 set_default_source_symtab_and_line ();
1039 cursal
= get_current_source_symtab_and_line ();
1041 default_symtab
= cursal
.symtab
;
1042 default_line
= cursal
.line
;
1045 if (**argptr
== '+')
1046 sign
= plus
, (*argptr
)++;
1047 else if (**argptr
== '-')
1048 sign
= minus
, (*argptr
)++;
1049 val
.line
= atoi (*argptr
);
1056 val
.line
= default_line
+ val
.line
;
1062 val
.line
= default_line
- val
.line
;
1067 break; /* No need to adjust val.line. */
1070 while (*q
== ' ' || *q
== '\t')
1076 /* It is possible that this source file has more than one symtab,
1077 and that the new line number specification has moved us from the
1078 default (in s) to a new one. */
1079 val
.symtab
= find_line_symtab (s
, val
.line
, NULL
, NULL
);
1080 if (val
.symtab
== 0)
1084 values
.sals
= (struct symtab_and_line
*)
1085 xmalloc (sizeof (struct symtab_and_line
));
1086 values
.sals
[0] = val
;
1089 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
1093 /* Arg token is not digits => try it as a variable name
1094 Find the next token (everything up to end or next whitespace). */
1096 if (**argptr
== '$') /* May be a convenience variable */
1097 p
= skip_quoted (*argptr
+ (((*argptr
)[1] == '$') ? 2 : 1)); /* One or two $ chars possible */
1100 p
= skip_quoted (*argptr
);
1102 error ("Unmatched single quote.");
1104 else if (has_parens
)
1110 p
= skip_quoted (*argptr
);
1113 copy
= (char *) alloca (p
- *argptr
+ 1);
1114 memcpy (copy
, *argptr
, p
- *argptr
);
1115 copy
[p
- *argptr
] = '\0';
1118 && copy
[0] == copy
[p
- *argptr
- 1]
1119 && strchr (get_gdb_completer_quote_characters (), copy
[0]) != NULL
)
1121 copy
[p
- *argptr
- 1] = '\0';
1124 while (*p
== ' ' || *p
== '\t')
1128 /* If it starts with $: may be a legitimate variable or routine name
1129 (e.g. HP-UX millicode routines such as $$dyncall), or it may
1130 be history value, or it may be a convenience variable */
1136 int need_canonical
= 0;
1138 p
= (copy
[1] == '$') ? copy
+ 2 : copy
+ 1;
1139 while (*p
>= '0' && *p
<= '9')
1141 if (!*p
) /* reached end of token without hitting non-digit */
1143 /* We have a value history reference */
1144 sscanf ((copy
[1] == '$') ? copy
+ 2 : copy
+ 1, "%d", &index
);
1145 valx
= access_value_history ((copy
[1] == '$') ? -index
: index
);
1146 if (TYPE_CODE (VALUE_TYPE (valx
)) != TYPE_CODE_INT
)
1147 error ("History values used in line specs must have integer values.");
1151 /* Not all digits -- may be user variable/function or a
1152 convenience variable */
1154 /* Look up entire name as a symbol first */
1155 sym
= lookup_symbol (copy
, 0, VAR_NAMESPACE
, 0, &sym_symtab
);
1156 s
= (struct symtab
*) 0;
1158 /* Symbol was found --> jump to normal symbol processing.
1159 Code following "symbol_found" expects "copy" to have the
1160 symbol name, "sym" to have the symbol pointer, "s" to be
1161 a specified file's symtab, and sym_symtab to be the symbol's
1166 /* If symbol was not found, look in minimal symbol tables */
1167 msymbol
= lookup_minimal_symbol (copy
, NULL
, NULL
);
1168 /* Min symbol was found --> jump to minsym processing. */
1170 goto minimal_symbol_found
;
1172 /* Not a user variable or function -- must be convenience variable */
1173 need_canonical
= (s
== 0) ? 1 : 0;
1174 valx
= value_of_internalvar (lookup_internalvar (copy
+ 1));
1175 if (TYPE_CODE (VALUE_TYPE (valx
)) != TYPE_CODE_INT
)
1176 error ("Convenience variables used in line specs must have integer values.");
1179 /* Either history value or convenience value from above, in valx */
1180 val
.symtab
= s
? s
: default_symtab
;
1181 val
.line
= value_as_long (valx
);
1184 values
.sals
= (struct symtab_and_line
*) xmalloc (sizeof val
);
1185 values
.sals
[0] = val
;
1189 build_canonical_line_spec (values
.sals
, NULL
, canonical
);
1195 /* Look up that token as a variable.
1196 If file specified, use that file's per-file block to start with. */
1198 sym
= lookup_symbol (copy
,
1199 (s
? BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
)
1200 : get_selected_block (0)),
1201 VAR_NAMESPACE
, 0, &sym_symtab
);
1203 symbol_found
: /* We also jump here from inside the C++ class/namespace
1204 code on finding a symbol of the form "A::B::C" */
1208 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
1210 /* Arg is the name of a function */
1211 values
.sals
= (struct symtab_and_line
*)
1212 xmalloc (sizeof (struct symtab_and_line
));
1213 values
.sals
[0] = find_function_start_sal (sym
, funfirstline
);
1216 /* Don't use the SYMBOL_LINE; if used at all it points to
1217 the line containing the parameters or thereabouts, not
1218 the first line of code. */
1220 /* We might need a canonical line spec if it is a static
1224 struct blockvector
*bv
= BLOCKVECTOR (sym_symtab
);
1225 struct block
*b
= BLOCKVECTOR_BLOCK (bv
, STATIC_BLOCK
);
1226 if (lookup_block_symbol (b
, copy
, NULL
, VAR_NAMESPACE
) != NULL
)
1227 build_canonical_line_spec (values
.sals
, copy
, canonical
);
1234 error ("\"%s\" is not a function", copy
);
1235 else if (SYMBOL_LINE (sym
) != 0)
1237 /* We know its line number. */
1238 values
.sals
= (struct symtab_and_line
*)
1239 xmalloc (sizeof (struct symtab_and_line
));
1241 memset (&values
.sals
[0], 0, sizeof (values
.sals
[0]));
1242 values
.sals
[0].symtab
= sym_symtab
;
1243 values
.sals
[0].line
= SYMBOL_LINE (sym
);
1247 /* This can happen if it is compiled with a compiler which doesn't
1248 put out line numbers for variables. */
1249 /* FIXME: Shouldn't we just set .line and .symtab to zero
1250 and return? For example, "info line foo" could print
1252 error ("Line number not known for symbol \"%s\"", copy
);
1256 msymbol
= lookup_minimal_symbol (copy
, NULL
, NULL
);
1258 minimal_symbol_found
: /* We also jump here from the case for variables
1259 that begin with '$' */
1261 if (msymbol
!= NULL
)
1263 values
.sals
= (struct symtab_and_line
*)
1264 xmalloc (sizeof (struct symtab_and_line
));
1265 values
.sals
[0] = find_pc_sect_line (SYMBOL_VALUE_ADDRESS (msymbol
),
1266 (struct sec
*) 0, 0);
1267 values
.sals
[0].section
= SYMBOL_BFD_SECTION (msymbol
);
1270 values
.sals
[0].pc
+= FUNCTION_START_OFFSET
;
1271 values
.sals
[0].pc
= SKIP_PROLOGUE (values
.sals
[0].pc
);
1277 if (!have_full_symbols () &&
1278 !have_partial_symbols () && !have_minimal_symbols ())
1279 error ("No symbol table is loaded. Use the \"file\" command.");
1281 error ("Function \"%s\" not defined.", copy
);
1282 return values
; /* for lint */