1 /* Helper routines for C++ support in GDB.
2 Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
3 Free Software Foundation, Inc.
5 Contributed by MontaVista Software.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
23 #include "cp-support.h"
24 #include "gdb_string.h"
26 #include "gdb_assert.h"
28 #include "dictionary.h"
33 #include "complaints.h"
35 #include "exceptions.h"
36 #include "expression.h"
39 #include "safe-ctype.h"
43 #define d_left(dc) (dc)->u.s_binary.left
44 #define d_right(dc) (dc)->u.s_binary.right
46 /* Functions related to demangled name parsing. */
48 static unsigned int cp_find_first_component_aux (const char *name
,
51 static void demangled_name_complaint (const char *name
);
53 /* Functions/variables related to overload resolution. */
55 static int sym_return_val_size
= -1;
56 static int sym_return_val_index
;
57 static struct symbol
**sym_return_val
;
59 static void overload_list_add_symbol (struct symbol
*sym
,
60 const char *oload_name
);
62 static void make_symbol_overload_list_using (const char *func_name
,
63 const char *namespace);
65 static void make_symbol_overload_list_qualified (const char *func_name
);
67 /* The list of "maint cplus" commands. */
69 struct cmd_list_element
*maint_cplus_cmd_list
= NULL
;
71 /* The actual commands. */
73 static void maint_cplus_command (char *arg
, int from_tty
);
74 static void first_component_command (char *arg
, int from_tty
);
76 /* Operator validation.
77 NOTE: Multi-byte operators (usually the assignment variety operator)
78 must appear before the single byte version, i.e., "+=" before "+". */
79 static const char *operator_tokens
[] =
81 "++", "+=", "+", "->*", "->", "--", "-=", "-", "*=", "*", "/=", "/",
82 "%=", "%", "!=", "==", "!", "&&", "<<=", "<<", ">>=", ">>",
83 "<=", "<", ">=", ">", "~", "&=", "&", "|=", "||", "|", "^=", "^",
84 "=", "()", "[]", ",", "new", "delete"
85 /* new[] and delete[] require special whitespace handling */
88 /* Return 1 if STRING is clearly already in canonical form. This
89 function is conservative; things which it does not recognize are
90 assumed to be non-canonical, and the parser will sort them out
91 afterwards. This speeds up the critical path for alphanumeric
95 cp_already_canonical (const char *string
)
97 /* Identifier start character [a-zA-Z_]. */
98 if (!ISIDST (string
[0]))
101 /* These are the only two identifiers which canonicalize to other
102 than themselves or an error: unsigned -> unsigned int and
104 if (string
[0] == 'u' && strcmp (&string
[1], "nsigned") == 0)
106 else if (string
[0] == 's' && strcmp (&string
[1], "igned") == 0)
109 /* Identifier character [a-zA-Z0-9_]. */
110 while (ISIDNUM (string
[1]))
113 if (string
[1] == '\0')
119 /* Parse STRING and convert it to canonical form. If parsing fails,
120 or if STRING is already canonical, return NULL. Otherwise return
121 the canonical form. The return value is allocated via xmalloc. */
124 cp_canonicalize_string (const char *string
)
126 struct demangle_component
*ret_comp
;
127 unsigned int estimated_len
;
130 if (cp_already_canonical (string
))
133 ret_comp
= cp_demangled_name_to_comp (string
, NULL
);
134 if (ret_comp
== NULL
)
137 estimated_len
= strlen (string
) * 2;
138 ret
= cp_comp_to_string (ret_comp
, estimated_len
);
140 if (strcmp (string
, ret
) == 0)
149 /* Convert a mangled name to a demangle_component tree. *MEMORY is set to the
150 block of used memory that should be freed when finished with the tree.
151 DEMANGLED_P is set to the char * that should be freed when finished with
152 the tree, or NULL if none was needed. OPTIONS will be passed to the
155 static struct demangle_component
*
156 mangled_name_to_comp (const char *mangled_name
, int options
,
157 void **memory
, char **demangled_p
)
159 struct demangle_component
*ret
;
160 char *demangled_name
;
162 /* If it looks like a v3 mangled name, then try to go directly
164 if (mangled_name
[0] == '_' && mangled_name
[1] == 'Z')
166 ret
= cplus_demangle_v3_components (mangled_name
, options
, memory
);
174 /* If it doesn't, or if that failed, then try to demangle the name. */
175 demangled_name
= cplus_demangle (mangled_name
, options
);
176 if (demangled_name
== NULL
)
179 /* If we could demangle the name, parse it to build the component tree. */
180 ret
= cp_demangled_name_to_comp (demangled_name
, NULL
);
184 xfree (demangled_name
);
188 *demangled_p
= demangled_name
;
192 /* Return the name of the class containing method PHYSNAME. */
195 cp_class_name_from_physname (const char *physname
)
197 void *storage
= NULL
;
198 char *demangled_name
= NULL
, *ret
;
199 struct demangle_component
*ret_comp
, *prev_comp
, *cur_comp
;
202 ret_comp
= mangled_name_to_comp (physname
, DMGL_ANSI
, &storage
,
204 if (ret_comp
== NULL
)
209 /* First strip off any qualifiers, if we have a function or method. */
211 switch (ret_comp
->type
)
213 case DEMANGLE_COMPONENT_CONST
:
214 case DEMANGLE_COMPONENT_RESTRICT
:
215 case DEMANGLE_COMPONENT_VOLATILE
:
216 case DEMANGLE_COMPONENT_CONST_THIS
:
217 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
218 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
219 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
220 ret_comp
= d_left (ret_comp
);
227 /* If what we have now is a function, discard the argument list. */
228 if (ret_comp
->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
229 ret_comp
= d_left (ret_comp
);
231 /* If what we have now is a template, strip off the template
232 arguments. The left subtree may be a qualified name. */
233 if (ret_comp
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
234 ret_comp
= d_left (ret_comp
);
236 /* What we have now should be a name, possibly qualified. Additional
237 qualifiers could live in the left subtree or the right subtree. Find
243 switch (cur_comp
->type
)
245 case DEMANGLE_COMPONENT_QUAL_NAME
:
246 case DEMANGLE_COMPONENT_LOCAL_NAME
:
247 prev_comp
= cur_comp
;
248 cur_comp
= d_right (cur_comp
);
250 case DEMANGLE_COMPONENT_TEMPLATE
:
251 case DEMANGLE_COMPONENT_NAME
:
252 case DEMANGLE_COMPONENT_CTOR
:
253 case DEMANGLE_COMPONENT_DTOR
:
254 case DEMANGLE_COMPONENT_OPERATOR
:
255 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
265 if (cur_comp
!= NULL
&& prev_comp
!= NULL
)
267 /* We want to discard the rightmost child of PREV_COMP. */
268 *prev_comp
= *d_left (prev_comp
);
269 /* The ten is completely arbitrary; we don't have a good estimate. */
270 ret
= cp_comp_to_string (ret_comp
, 10);
275 xfree (demangled_name
);
279 /* Return the child of COMP which is the basename of a method, variable,
280 et cetera. All scope qualifiers are discarded, but template arguments
281 will be included. The component tree may be modified. */
283 static struct demangle_component
*
284 unqualified_name_from_comp (struct demangle_component
*comp
)
286 struct demangle_component
*ret_comp
= comp
, *last_template
;
290 last_template
= NULL
;
292 switch (ret_comp
->type
)
294 case DEMANGLE_COMPONENT_QUAL_NAME
:
295 case DEMANGLE_COMPONENT_LOCAL_NAME
:
296 ret_comp
= d_right (ret_comp
);
298 case DEMANGLE_COMPONENT_TYPED_NAME
:
299 ret_comp
= d_left (ret_comp
);
301 case DEMANGLE_COMPONENT_TEMPLATE
:
302 gdb_assert (last_template
== NULL
);
303 last_template
= ret_comp
;
304 ret_comp
= d_left (ret_comp
);
306 case DEMANGLE_COMPONENT_CONST
:
307 case DEMANGLE_COMPONENT_RESTRICT
:
308 case DEMANGLE_COMPONENT_VOLATILE
:
309 case DEMANGLE_COMPONENT_CONST_THIS
:
310 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
311 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
312 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
313 ret_comp
= d_left (ret_comp
);
315 case DEMANGLE_COMPONENT_NAME
:
316 case DEMANGLE_COMPONENT_CTOR
:
317 case DEMANGLE_COMPONENT_DTOR
:
318 case DEMANGLE_COMPONENT_OPERATOR
:
319 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
329 d_left (last_template
) = ret_comp
;
330 return last_template
;
336 /* Return the name of the method whose linkage name is PHYSNAME. */
339 method_name_from_physname (const char *physname
)
341 void *storage
= NULL
;
342 char *demangled_name
= NULL
, *ret
;
343 struct demangle_component
*ret_comp
;
345 ret_comp
= mangled_name_to_comp (physname
, DMGL_ANSI
, &storage
,
347 if (ret_comp
== NULL
)
350 ret_comp
= unqualified_name_from_comp (ret_comp
);
353 if (ret_comp
!= NULL
)
354 /* The ten is completely arbitrary; we don't have a good estimate. */
355 ret
= cp_comp_to_string (ret_comp
, 10);
359 xfree (demangled_name
);
363 /* If FULL_NAME is the demangled name of a C++ function (including an
364 arg list, possibly including namespace/class qualifications),
365 return a new string containing only the function name (without the
366 arg list/class qualifications). Otherwise, return NULL. The
367 caller is responsible for freeing the memory in question. */
370 cp_func_name (const char *full_name
)
373 struct demangle_component
*ret_comp
;
375 ret_comp
= cp_demangled_name_to_comp (full_name
, NULL
);
379 ret_comp
= unqualified_name_from_comp (ret_comp
);
382 if (ret_comp
!= NULL
)
383 ret
= cp_comp_to_string (ret_comp
, 10);
388 /* DEMANGLED_NAME is the name of a function, including parameters and
389 (optionally) a return type. Return the name of the function without
390 parameters or return type, or NULL if we can not parse the name. */
393 cp_remove_params (const char *demangled_name
)
396 struct demangle_component
*ret_comp
;
399 if (demangled_name
== NULL
)
402 ret_comp
= cp_demangled_name_to_comp (demangled_name
, NULL
);
403 if (ret_comp
== NULL
)
406 /* First strip off any qualifiers, if we have a function or method. */
408 switch (ret_comp
->type
)
410 case DEMANGLE_COMPONENT_CONST
:
411 case DEMANGLE_COMPONENT_RESTRICT
:
412 case DEMANGLE_COMPONENT_VOLATILE
:
413 case DEMANGLE_COMPONENT_CONST_THIS
:
414 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
415 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
416 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
417 ret_comp
= d_left (ret_comp
);
424 /* What we have now should be a function. Return its name. */
425 if (ret_comp
->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
426 ret
= cp_comp_to_string (d_left (ret_comp
), 10);
431 /* Here are some random pieces of trivia to keep in mind while trying
432 to take apart demangled names:
434 - Names can contain function arguments or templates, so the process
435 has to be, to some extent recursive: maybe keep track of your
436 depth based on encountering <> and ().
438 - Parentheses don't just have to happen at the end of a name: they
439 can occur even if the name in question isn't a function, because
440 a template argument might be a type that's a function.
442 - Conversely, even if you're trying to deal with a function, its
443 demangled name might not end with ')': it could be a const or
444 volatile class method, in which case it ends with "const" or
447 - Parentheses are also used in anonymous namespaces: a variable
448 'foo' in an anonymous namespace gets demangled as "(anonymous
451 - And operator names can contain parentheses or angle brackets. */
453 /* FIXME: carlton/2003-03-13: We have several functions here with
454 overlapping functionality; can we combine them? Also, do they
455 handle all the above considerations correctly? */
458 /* This returns the length of first component of NAME, which should be
459 the demangled name of a C++ variable/function/method/etc.
460 Specifically, it returns the index of the first colon forming the
461 boundary of the first component: so, given 'A::foo' or 'A::B::foo'
462 it returns the 1, and given 'foo', it returns 0. */
464 /* The character in NAME indexed by the return value is guaranteed to
465 always be either ':' or '\0'. */
467 /* NOTE: carlton/2003-03-13: This function is currently only intended
468 for internal use: it's probably not entirely safe when called on
469 user-generated input, because some of the 'index += 2' lines in
470 cp_find_first_component_aux might go past the end of malformed
474 cp_find_first_component (const char *name
)
476 return cp_find_first_component_aux (name
, 0);
479 /* Helper function for cp_find_first_component. Like that function,
480 it returns the length of the first component of NAME, but to make
481 the recursion easier, it also stops if it reaches an unexpected ')'
482 or '>' if the value of PERMISSIVE is nonzero. */
484 /* Let's optimize away calls to strlen("operator"). */
486 #define LENGTH_OF_OPERATOR 8
489 cp_find_first_component_aux (const char *name
, int permissive
)
491 unsigned int index
= 0;
492 /* Operator names can show up in unexpected places. Since these can
493 contain parentheses or angle brackets, they can screw up the
494 recursion. But not every string 'operator' is part of an
495 operater name: e.g. you could have a variable 'cooperator'. So
496 this variable tells us whether or not we should treat the string
497 'operator' as starting an operator. */
498 int operator_possible
= 1;
505 /* Template; eat it up. The calls to cp_first_component
506 should only return (I hope!) when they reach the '>'
507 terminating the component or a '::' between two
508 components. (Hence the '+ 2'.) */
510 for (index
+= cp_find_first_component_aux (name
+ index
, 1);
512 index
+= cp_find_first_component_aux (name
+ index
, 1))
514 if (name
[index
] != ':')
516 demangled_name_complaint (name
);
517 return strlen (name
);
521 operator_possible
= 1;
524 /* Similar comment as to '<'. */
526 for (index
+= cp_find_first_component_aux (name
+ index
, 1);
528 index
+= cp_find_first_component_aux (name
+ index
, 1))
530 if (name
[index
] != ':')
532 demangled_name_complaint (name
);
533 return strlen (name
);
537 operator_possible
= 1;
545 demangled_name_complaint (name
);
546 return strlen (name
);
552 /* Operator names can screw up the recursion. */
553 if (operator_possible
554 && strncmp (name
+ index
, "operator", LENGTH_OF_OPERATOR
) == 0)
556 index
+= LENGTH_OF_OPERATOR
;
557 while (ISSPACE(name
[index
]))
561 /* Skip over one less than the appropriate number of
562 characters: the for loop will skip over the last
565 if (name
[index
+ 1] == '<')
572 if (name
[index
+ 1] == '>')
585 operator_possible
= 0;
592 /* NOTE: carlton/2003-04-18: I'm not sure what the precise
593 set of relevant characters are here: it's necessary to
594 include any character that can show up before 'operator'
595 in a demangled name, and it's safe to include any
596 character that can't be part of an identifier's name. */
597 operator_possible
= 1;
600 operator_possible
= 0;
606 /* Complain about a demangled name that we don't know how to parse.
607 NAME is the demangled name in question. */
610 demangled_name_complaint (const char *name
)
612 complaint (&symfile_complaints
,
613 "unexpected demangled name '%s'", name
);
616 /* If NAME is the fully-qualified name of a C++
617 function/variable/method/etc., this returns the length of its
618 entire prefix: all of the namespaces and classes that make up its
619 name. Given 'A::foo', it returns 1, given 'A::B::foo', it returns
620 4, given 'foo', it returns 0. */
623 cp_entire_prefix_len (const char *name
)
625 unsigned int current_len
= cp_find_first_component (name
);
626 unsigned int previous_len
= 0;
628 while (name
[current_len
] != '\0')
630 gdb_assert (name
[current_len
] == ':');
631 previous_len
= current_len
;
634 current_len
+= cp_find_first_component (name
+ current_len
);
640 /* Overload resolution functions. */
642 /* Test to see if SYM is a symbol that we haven't seen corresponding
643 to a function named OLOAD_NAME. If so, add it to the current
647 overload_list_add_symbol (struct symbol
*sym
, const char *oload_name
)
653 /* If there is no type information, we can't do anything, so skip */
654 if (SYMBOL_TYPE (sym
) == NULL
)
657 /* skip any symbols that we've already considered. */
658 for (i
= 0; i
< sym_return_val_index
; ++i
)
659 if (strcmp (SYMBOL_LINKAGE_NAME (sym
),
660 SYMBOL_LINKAGE_NAME (sym_return_val
[i
])) == 0)
663 /* Get the demangled name without parameters */
664 sym_name
= cp_remove_params (SYMBOL_NATURAL_NAME (sym
));
668 /* skip symbols that cannot match */
669 if (strcmp (sym_name
, oload_name
) != 0)
677 /* We have a match for an overload instance, so add SYM to the current list
678 * of overload instances */
679 if (sym_return_val_index
+ 3 > sym_return_val_size
)
681 newsize
= (sym_return_val_size
*= 2) * sizeof (struct symbol
*);
682 sym_return_val
= (struct symbol
**) xrealloc ((char *) sym_return_val
, newsize
);
684 sym_return_val
[sym_return_val_index
++] = sym
;
685 sym_return_val
[sym_return_val_index
] = NULL
;
688 /* Return a null-terminated list of pointers to function symbols that
689 are named FUNC_NAME and are visible within NAMESPACE. */
692 make_symbol_overload_list (const char *func_name
,
693 const char *namespace)
695 struct cleanup
*old_cleanups
;
698 sym_return_val_size
= 100;
699 sym_return_val_index
= 0;
700 sym_return_val
= xmalloc ((sym_return_val_size
+ 1) *
701 sizeof (struct symbol
*));
702 sym_return_val
[0] = NULL
;
704 old_cleanups
= make_cleanup (xfree
, sym_return_val
);
706 make_symbol_overload_list_using (func_name
, namespace);
708 if (namespace[0] == '\0')
712 char *concatenated_name
713 = alloca (strlen (namespace) + 2 + strlen (func_name
) + 1);
714 strcpy (concatenated_name
, namespace);
715 strcat (concatenated_name
, "::");
716 strcat (concatenated_name
, func_name
);
717 name
= concatenated_name
;
720 make_symbol_overload_list_qualified (name
);
722 discard_cleanups (old_cleanups
);
724 return sym_return_val
;
727 /* Add all symbols with a name matching NAME in BLOCK to the overload
731 make_symbol_overload_list_block (const char *name
,
732 const struct block
*block
)
734 struct dict_iterator iter
;
737 const struct dictionary
*dict
= BLOCK_DICT (block
);
739 for (sym
= dict_iter_name_first (dict
, name
, &iter
);
741 sym
= dict_iter_name_next (name
, &iter
))
742 overload_list_add_symbol (sym
, name
);
745 /* Adds the function FUNC_NAME from NAMESPACE to the overload set. */
748 make_symbol_overload_list_namespace (const char *func_name
,
749 const char *namespace)
752 const struct block
*block
= NULL
;
754 if (namespace[0] == '\0')
758 char *concatenated_name
759 = alloca (strlen (namespace) + 2 + strlen (func_name
) + 1);
761 strcpy (concatenated_name
, namespace);
762 strcat (concatenated_name
, "::");
763 strcat (concatenated_name
, func_name
);
764 name
= concatenated_name
;
767 /* Look in the static block. */
768 block
= block_static_block (get_selected_block (0));
769 make_symbol_overload_list_block (name
, block
);
771 /* Look in the global block. */
772 block
= block_global_block (block
);
773 make_symbol_overload_list_block (name
, block
);
777 /* Search the namespace of the given type and namespace of and public base
781 make_symbol_overload_list_adl_namespace (struct type
*type
,
782 const char *func_name
)
788 while (TYPE_CODE (type
) == TYPE_CODE_PTR
|| TYPE_CODE (type
) == TYPE_CODE_REF
789 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
790 || TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
792 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
793 type
= check_typedef(type
);
795 type
= TYPE_TARGET_TYPE (type
);
798 type_name
= TYPE_NAME (type
);
800 if (type_name
== NULL
)
803 prefix_len
= cp_entire_prefix_len (type_name
);
807 namespace = alloca (prefix_len
+ 1);
808 strncpy (namespace, type_name
, prefix_len
);
809 namespace[prefix_len
] = '\0';
811 make_symbol_overload_list_namespace (func_name
, namespace);
814 /* Check public base type */
815 if (TYPE_CODE (type
) == TYPE_CODE_CLASS
)
816 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
818 if (BASETYPE_VIA_PUBLIC (type
, i
))
819 make_symbol_overload_list_adl_namespace (TYPE_BASECLASS (type
, i
),
824 /* Adds the the overload list overload candidates for FUNC_NAME found through
825 argument dependent lookup. */
828 make_symbol_overload_list_adl (struct type
**arg_types
, int nargs
,
829 const char *func_name
)
833 gdb_assert (sym_return_val_size
!= -1);
835 for (i
= 1; i
<= nargs
; i
++)
836 make_symbol_overload_list_adl_namespace (arg_types
[i
- 1], func_name
);
838 return sym_return_val
;
841 /* Used for cleanups to reset the "searched" flag in case of an error. */
844 reset_directive_searched (void *data
)
846 struct using_direct
*direct
= data
;
847 direct
->searched
= 0;
850 /* This applies the using directives to add namespaces to search in,
851 and then searches for overloads in all of those namespaces. It
852 adds the symbols found to sym_return_val. Arguments are as in
853 make_symbol_overload_list. */
856 make_symbol_overload_list_using (const char *func_name
,
857 const char *namespace)
859 struct using_direct
*current
;
860 const struct block
*block
;
862 /* First, go through the using directives. If any of them apply,
863 look in the appropriate namespaces for new functions to match
866 for (block
= get_selected_block (0);
868 block
= BLOCK_SUPERBLOCK (block
))
869 for (current
= block_using (block
);
871 current
= current
->next
)
873 /* Prevent recursive calls. */
874 if (current
->searched
)
877 /* If this is a namespace alias or imported declaration ignore it. */
878 if (current
->alias
!= NULL
|| current
->declaration
!= NULL
)
881 if (strcmp (namespace, current
->import_dest
) == 0)
883 /* Mark this import as searched so that the recursive call does
884 not search it again. */
885 struct cleanup
*old_chain
;
886 current
->searched
= 1;
887 old_chain
= make_cleanup (reset_directive_searched
, current
);
889 make_symbol_overload_list_using (func_name
, current
->import_src
);
891 current
->searched
= 0;
892 discard_cleanups (old_chain
);
896 /* Now, add names for this namespace. */
897 make_symbol_overload_list_namespace (func_name
, namespace);
900 /* This does the bulk of the work of finding overloaded symbols.
901 FUNC_NAME is the name of the overloaded function we're looking for
902 (possibly including namespace info). */
905 make_symbol_overload_list_qualified (const char *func_name
)
909 struct objfile
*objfile
;
910 const struct block
*b
, *surrounding_static_block
= 0;
911 struct dict_iterator iter
;
912 const struct dictionary
*dict
;
914 /* Look through the partial symtabs for all symbols which begin
915 by matching FUNC_NAME. Make sure we read that symbol table in. */
917 ALL_OBJFILES (objfile
)
920 objfile
->sf
->qf
->expand_symtabs_for_function (objfile
, func_name
);
923 /* Search upwards from currently selected frame (so that we can
924 complete on local vars. */
926 for (b
= get_selected_block (0); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
927 make_symbol_overload_list_block (func_name
, b
);
929 surrounding_static_block
= block_static_block (get_selected_block (0));
931 /* Go through the symtabs and check the externs and statics for
932 symbols which match. */
934 ALL_PRIMARY_SYMTABS (objfile
, s
)
937 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
938 make_symbol_overload_list_block (func_name
, b
);
941 ALL_PRIMARY_SYMTABS (objfile
, s
)
944 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
945 /* Don't do this block twice. */
946 if (b
== surrounding_static_block
)
948 make_symbol_overload_list_block (func_name
, b
);
952 /* Lookup the rtti type for a class name. */
955 cp_lookup_rtti_type (const char *name
, struct block
*block
)
957 struct symbol
* rtti_sym
;
958 struct type
* rtti_type
;
960 rtti_sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, NULL
);
962 if (rtti_sym
== NULL
)
964 warning (_("RTTI symbol not found for class '%s'"), name
);
968 if (SYMBOL_CLASS (rtti_sym
) != LOC_TYPEDEF
)
970 warning (_("RTTI symbol for class '%s' is not a type"), name
);
974 rtti_type
= SYMBOL_TYPE (rtti_sym
);
976 switch (TYPE_CODE (rtti_type
))
978 case TYPE_CODE_CLASS
:
980 case TYPE_CODE_NAMESPACE
:
981 /* chastain/2003-11-26: the symbol tables often contain fake
982 symbols for namespaces with the same name as the struct.
983 This warning is an indication of a bug in the lookup order
984 or a bug in the way that the symbol tables are populated. */
985 warning (_("RTTI symbol for class '%s' is a namespace"), name
);
988 warning (_("RTTI symbol for class '%s' has bad type"), name
);
995 /* Don't allow just "maintenance cplus". */
998 maint_cplus_command (char *arg
, int from_tty
)
1000 printf_unfiltered (_("\"maintenance cplus\" must be followed by the name of a command.\n"));
1001 help_list (maint_cplus_cmd_list
, "maintenance cplus ", -1, gdb_stdout
);
1004 /* This is a front end for cp_find_first_component, for unit testing.
1005 Be careful when using it: see the NOTE above
1006 cp_find_first_component. */
1009 first_component_command (char *arg
, int from_tty
)
1017 len
= cp_find_first_component (arg
);
1018 prefix
= alloca (len
+ 1);
1020 memcpy (prefix
, arg
, len
);
1023 printf_unfiltered ("%s\n", prefix
);
1026 extern initialize_file_ftype _initialize_cp_support
; /* -Wmissing-prototypes */
1028 #define SKIP_SPACE(P) \
1031 while (*(P) == ' ' || *(P) == '\t') \
1036 /* Returns the length of the operator name or 0 if INPUT does not
1037 point to a valid C++ operator. INPUT should start with "operator". */
1039 cp_validate_operator (const char *input
)
1044 struct expression
*expr
;
1046 struct gdb_exception except
;
1050 if (strncmp (p
, "operator", 8) == 0)
1056 for (i
= 0; i
< sizeof (operator_tokens
) / sizeof (operator_tokens
[0]);
1059 int length
= strlen (operator_tokens
[i
]);
1061 /* By using strncmp here, we MUST have operator_tokens ordered!
1062 See additional notes where operator_tokens is defined above. */
1063 if (strncmp (p
, operator_tokens
[i
], length
) == 0)
1070 if (strncmp (op
, "new", 3) == 0
1071 || strncmp (op
, "delete", 6) == 0)
1074 /* Special case: new[] and delete[]. We must be careful
1075 to swallow whitespace before/in "[]". */
1094 /* Check input for a conversion operator. */
1096 /* Skip past base typename */
1097 while (*p
!= '*' && *p
!= '&' && *p
!= 0 && *p
!= ' ')
1101 /* Add modifiers '*'/'&' */
1102 while (*p
== '*' || *p
== '&')
1108 /* Check for valid type. [Remember: input starts with
1110 copy
= savestring (input
+ 8, p
- input
- 8);
1113 TRY_CATCH (except
, RETURN_MASK_ALL
)
1115 expr
= parse_expression (copy
);
1116 val
= evaluate_type (expr
);
1123 if (val
!= NULL
&& value_type (val
) != NULL
)
1131 _initialize_cp_support (void)
1133 add_prefix_cmd ("cplus", class_maintenance
, maint_cplus_command
,
1134 _("C++ maintenance commands."), &maint_cplus_cmd_list
,
1135 "maintenance cplus ", 0, &maintenancelist
);
1136 add_alias_cmd ("cp", "cplus", class_maintenance
, 1, &maintenancelist
);
1138 add_cmd ("first_component", class_maintenance
, first_component_command
,
1139 _("Print the first class/namespace component of NAME."),
1140 &maint_cplus_cmd_list
);