1 /* Helper routines for C++ support in GDB.
2 Copyright (C) 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010, 2011
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
78 operator) must appear before the single byte version, i.e., "+="
80 static const char *operator_tokens
[] =
82 "++", "+=", "+", "->*", "->", "--", "-=", "-", "*=", "*",
83 "/=", "/", "%=", "%", "!=", "==", "!", "&&", "<<=", "<<",
84 ">>=", ">>", "<=", "<", ">=", ">", "~", "&=", "&", "|=",
85 "||", "|", "^=", "^", "=", "()", "[]", ",", "new", "delete"
86 /* new[] and delete[] require special whitespace handling */
89 /* Return 1 if STRING is clearly already in canonical form. This
90 function is conservative; things which it does not recognize are
91 assumed to be non-canonical, and the parser will sort them out
92 afterwards. This speeds up the critical path for alphanumeric
96 cp_already_canonical (const char *string
)
98 /* Identifier start character [a-zA-Z_]. */
99 if (!ISIDST (string
[0]))
102 /* These are the only two identifiers which canonicalize to other
103 than themselves or an error: unsigned -> unsigned int and
105 if (string
[0] == 'u' && strcmp (&string
[1], "nsigned") == 0)
107 else if (string
[0] == 's' && strcmp (&string
[1], "igned") == 0)
110 /* Identifier character [a-zA-Z0-9_]. */
111 while (ISIDNUM (string
[1]))
114 if (string
[1] == '\0')
120 /* Parse STRING and convert it to canonical form. If parsing fails,
121 or if STRING is already canonical, return NULL. Otherwise return
122 the canonical form. The return value is allocated via xmalloc. */
125 cp_canonicalize_string (const char *string
)
127 struct demangle_component
*ret_comp
;
128 unsigned int estimated_len
;
131 if (cp_already_canonical (string
))
134 ret_comp
= cp_demangled_name_to_comp (string
, NULL
);
135 if (ret_comp
== NULL
)
138 estimated_len
= strlen (string
) * 2;
139 ret
= cp_comp_to_string (ret_comp
, estimated_len
);
141 if (strcmp (string
, ret
) == 0)
150 /* Convert a mangled name to a demangle_component tree. *MEMORY is
151 set to the block of used memory that should be freed when finished
152 with the tree. DEMANGLED_P is set to the char * that should be
153 freed when finished with the tree, or NULL if none was needed.
154 OPTIONS will be passed to the demangler. */
156 static struct demangle_component
*
157 mangled_name_to_comp (const char *mangled_name
, int options
,
158 void **memory
, char **demangled_p
)
160 struct demangle_component
*ret
;
161 char *demangled_name
;
163 /* If it looks like a v3 mangled name, then try to go directly
165 if (mangled_name
[0] == '_' && mangled_name
[1] == 'Z')
167 ret
= cplus_demangle_v3_components (mangled_name
,
176 /* If it doesn't, or if that failed, then try to demangle the
178 demangled_name
= cplus_demangle (mangled_name
, options
);
179 if (demangled_name
== NULL
)
182 /* If we could demangle the name, parse it to build the component
184 ret
= cp_demangled_name_to_comp (demangled_name
, NULL
);
188 xfree (demangled_name
);
192 *demangled_p
= demangled_name
;
196 /* Return the name of the class containing method PHYSNAME. */
199 cp_class_name_from_physname (const char *physname
)
201 void *storage
= NULL
;
202 char *demangled_name
= NULL
, *ret
;
203 struct demangle_component
*ret_comp
, *prev_comp
, *cur_comp
;
206 ret_comp
= mangled_name_to_comp (physname
, DMGL_ANSI
,
207 &storage
, &demangled_name
);
208 if (ret_comp
== NULL
)
213 /* First strip off any qualifiers, if we have a function or
216 switch (ret_comp
->type
)
218 case DEMANGLE_COMPONENT_CONST
:
219 case DEMANGLE_COMPONENT_RESTRICT
:
220 case DEMANGLE_COMPONENT_VOLATILE
:
221 case DEMANGLE_COMPONENT_CONST_THIS
:
222 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
223 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
224 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
225 ret_comp
= d_left (ret_comp
);
232 /* If what we have now is a function, discard the argument list. */
233 if (ret_comp
->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
234 ret_comp
= d_left (ret_comp
);
236 /* If what we have now is a template, strip off the template
237 arguments. The left subtree may be a qualified name. */
238 if (ret_comp
->type
== DEMANGLE_COMPONENT_TEMPLATE
)
239 ret_comp
= d_left (ret_comp
);
241 /* What we have now should be a name, possibly qualified.
242 Additional qualifiers could live in the left subtree or the right
243 subtree. Find the last piece. */
248 switch (cur_comp
->type
)
250 case DEMANGLE_COMPONENT_QUAL_NAME
:
251 case DEMANGLE_COMPONENT_LOCAL_NAME
:
252 prev_comp
= cur_comp
;
253 cur_comp
= d_right (cur_comp
);
255 case DEMANGLE_COMPONENT_TEMPLATE
:
256 case DEMANGLE_COMPONENT_NAME
:
257 case DEMANGLE_COMPONENT_CTOR
:
258 case DEMANGLE_COMPONENT_DTOR
:
259 case DEMANGLE_COMPONENT_OPERATOR
:
260 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
270 if (cur_comp
!= NULL
&& prev_comp
!= NULL
)
272 /* We want to discard the rightmost child of PREV_COMP. */
273 *prev_comp
= *d_left (prev_comp
);
274 /* The ten is completely arbitrary; we don't have a good
276 ret
= cp_comp_to_string (ret_comp
, 10);
281 xfree (demangled_name
);
285 /* Return the child of COMP which is the basename of a method,
286 variable, et cetera. All scope qualifiers are discarded, but
287 template arguments will be included. The component tree may be
290 static struct demangle_component
*
291 unqualified_name_from_comp (struct demangle_component
*comp
)
293 struct demangle_component
*ret_comp
= comp
, *last_template
;
297 last_template
= NULL
;
299 switch (ret_comp
->type
)
301 case DEMANGLE_COMPONENT_QUAL_NAME
:
302 case DEMANGLE_COMPONENT_LOCAL_NAME
:
303 ret_comp
= d_right (ret_comp
);
305 case DEMANGLE_COMPONENT_TYPED_NAME
:
306 ret_comp
= d_left (ret_comp
);
308 case DEMANGLE_COMPONENT_TEMPLATE
:
309 gdb_assert (last_template
== NULL
);
310 last_template
= ret_comp
;
311 ret_comp
= d_left (ret_comp
);
313 case DEMANGLE_COMPONENT_CONST
:
314 case DEMANGLE_COMPONENT_RESTRICT
:
315 case DEMANGLE_COMPONENT_VOLATILE
:
316 case DEMANGLE_COMPONENT_CONST_THIS
:
317 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
318 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
319 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
320 ret_comp
= d_left (ret_comp
);
322 case DEMANGLE_COMPONENT_NAME
:
323 case DEMANGLE_COMPONENT_CTOR
:
324 case DEMANGLE_COMPONENT_DTOR
:
325 case DEMANGLE_COMPONENT_OPERATOR
:
326 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR
:
336 d_left (last_template
) = ret_comp
;
337 return last_template
;
343 /* Return the name of the method whose linkage name is PHYSNAME. */
346 method_name_from_physname (const char *physname
)
348 void *storage
= NULL
;
349 char *demangled_name
= NULL
, *ret
;
350 struct demangle_component
*ret_comp
;
352 ret_comp
= mangled_name_to_comp (physname
, DMGL_ANSI
,
353 &storage
, &demangled_name
);
354 if (ret_comp
== NULL
)
357 ret_comp
= unqualified_name_from_comp (ret_comp
);
360 if (ret_comp
!= NULL
)
361 /* The ten is completely arbitrary; we don't have a good
363 ret
= cp_comp_to_string (ret_comp
, 10);
367 xfree (demangled_name
);
371 /* If FULL_NAME is the demangled name of a C++ function (including an
372 arg list, possibly including namespace/class qualifications),
373 return a new string containing only the function name (without the
374 arg list/class qualifications). Otherwise, return NULL. The
375 caller is responsible for freeing the memory in question. */
378 cp_func_name (const char *full_name
)
381 struct demangle_component
*ret_comp
;
383 ret_comp
= cp_demangled_name_to_comp (full_name
, NULL
);
387 ret_comp
= unqualified_name_from_comp (ret_comp
);
390 if (ret_comp
!= NULL
)
391 ret
= cp_comp_to_string (ret_comp
, 10);
396 /* DEMANGLED_NAME is the name of a function, including parameters and
397 (optionally) a return type. Return the name of the function without
398 parameters or return type, or NULL if we can not parse the name. */
401 cp_remove_params (const char *demangled_name
)
404 struct demangle_component
*ret_comp
;
407 if (demangled_name
== NULL
)
410 ret_comp
= cp_demangled_name_to_comp (demangled_name
, NULL
);
411 if (ret_comp
== NULL
)
414 /* First strip off any qualifiers, if we have a function or method. */
416 switch (ret_comp
->type
)
418 case DEMANGLE_COMPONENT_CONST
:
419 case DEMANGLE_COMPONENT_RESTRICT
:
420 case DEMANGLE_COMPONENT_VOLATILE
:
421 case DEMANGLE_COMPONENT_CONST_THIS
:
422 case DEMANGLE_COMPONENT_RESTRICT_THIS
:
423 case DEMANGLE_COMPONENT_VOLATILE_THIS
:
424 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL
:
425 ret_comp
= d_left (ret_comp
);
432 /* What we have now should be a function. Return its name. */
433 if (ret_comp
->type
== DEMANGLE_COMPONENT_TYPED_NAME
)
434 ret
= cp_comp_to_string (d_left (ret_comp
), 10);
439 /* Here are some random pieces of trivia to keep in mind while trying
440 to take apart demangled names:
442 - Names can contain function arguments or templates, so the process
443 has to be, to some extent recursive: maybe keep track of your
444 depth based on encountering <> and ().
446 - Parentheses don't just have to happen at the end of a name: they
447 can occur even if the name in question isn't a function, because
448 a template argument might be a type that's a function.
450 - Conversely, even if you're trying to deal with a function, its
451 demangled name might not end with ')': it could be a const or
452 volatile class method, in which case it ends with "const" or
455 - Parentheses are also used in anonymous namespaces: a variable
456 'foo' in an anonymous namespace gets demangled as "(anonymous
459 - And operator names can contain parentheses or angle brackets. */
461 /* FIXME: carlton/2003-03-13: We have several functions here with
462 overlapping functionality; can we combine them? Also, do they
463 handle all the above considerations correctly? */
466 /* This returns the length of first component of NAME, which should be
467 the demangled name of a C++ variable/function/method/etc.
468 Specifically, it returns the index of the first colon forming the
469 boundary of the first component: so, given 'A::foo' or 'A::B::foo'
470 it returns the 1, and given 'foo', it returns 0. */
472 /* The character in NAME indexed by the return value is guaranteed to
473 always be either ':' or '\0'. */
475 /* NOTE: carlton/2003-03-13: This function is currently only intended
476 for internal use: it's probably not entirely safe when called on
477 user-generated input, because some of the 'index += 2' lines in
478 cp_find_first_component_aux might go past the end of malformed
482 cp_find_first_component (const char *name
)
484 return cp_find_first_component_aux (name
, 0);
487 /* Helper function for cp_find_first_component. Like that function,
488 it returns the length of the first component of NAME, but to make
489 the recursion easier, it also stops if it reaches an unexpected ')'
490 or '>' if the value of PERMISSIVE is nonzero. */
492 /* Let's optimize away calls to strlen("operator"). */
494 #define LENGTH_OF_OPERATOR 8
497 cp_find_first_component_aux (const char *name
, int permissive
)
499 unsigned int index
= 0;
500 /* Operator names can show up in unexpected places. Since these can
501 contain parentheses or angle brackets, they can screw up the
502 recursion. But not every string 'operator' is part of an
503 operater name: e.g. you could have a variable 'cooperator'. So
504 this variable tells us whether or not we should treat the string
505 'operator' as starting an operator. */
506 int operator_possible
= 1;
513 /* Template; eat it up. The calls to cp_first_component
514 should only return (I hope!) when they reach the '>'
515 terminating the component or a '::' between two
516 components. (Hence the '+ 2'.) */
518 for (index
+= cp_find_first_component_aux (name
+ index
, 1);
520 index
+= cp_find_first_component_aux (name
+ index
, 1))
522 if (name
[index
] != ':')
524 demangled_name_complaint (name
);
525 return strlen (name
);
529 operator_possible
= 1;
532 /* Similar comment as to '<'. */
534 for (index
+= cp_find_first_component_aux (name
+ index
, 1);
536 index
+= cp_find_first_component_aux (name
+ index
, 1))
538 if (name
[index
] != ':')
540 demangled_name_complaint (name
);
541 return strlen (name
);
545 operator_possible
= 1;
553 demangled_name_complaint (name
);
554 return strlen (name
);
560 /* Operator names can screw up the recursion. */
561 if (operator_possible
562 && strncmp (name
+ index
, "operator",
563 LENGTH_OF_OPERATOR
) == 0)
565 index
+= LENGTH_OF_OPERATOR
;
566 while (ISSPACE(name
[index
]))
570 /* Skip over one less than the appropriate number of
571 characters: the for loop will skip over the last
574 if (name
[index
+ 1] == '<')
581 if (name
[index
+ 1] == '>')
594 operator_possible
= 0;
601 /* NOTE: carlton/2003-04-18: I'm not sure what the precise
602 set of relevant characters are here: it's necessary to
603 include any character that can show up before 'operator'
604 in a demangled name, and it's safe to include any
605 character that can't be part of an identifier's name. */
606 operator_possible
= 1;
609 operator_possible
= 0;
615 /* Complain about a demangled name that we don't know how to parse.
616 NAME is the demangled name in question. */
619 demangled_name_complaint (const char *name
)
621 complaint (&symfile_complaints
,
622 "unexpected demangled name '%s'", name
);
625 /* If NAME is the fully-qualified name of a C++
626 function/variable/method/etc., this returns the length of its
627 entire prefix: all of the namespaces and classes that make up its
628 name. Given 'A::foo', it returns 1, given 'A::B::foo', it returns
629 4, given 'foo', it returns 0. */
632 cp_entire_prefix_len (const char *name
)
634 unsigned int current_len
= cp_find_first_component (name
);
635 unsigned int previous_len
= 0;
637 while (name
[current_len
] != '\0')
639 gdb_assert (name
[current_len
] == ':');
640 previous_len
= current_len
;
643 current_len
+= cp_find_first_component (name
+ current_len
);
649 /* Overload resolution functions. */
651 /* Test to see if SYM is a symbol that we haven't seen corresponding
652 to a function named OLOAD_NAME. If so, add it to the current
656 overload_list_add_symbol (struct symbol
*sym
,
657 const char *oload_name
)
663 /* If there is no type information, we can't do anything, so
665 if (SYMBOL_TYPE (sym
) == NULL
)
668 /* skip any symbols that we've already considered. */
669 for (i
= 0; i
< sym_return_val_index
; ++i
)
670 if (strcmp (SYMBOL_LINKAGE_NAME (sym
),
671 SYMBOL_LINKAGE_NAME (sym_return_val
[i
])) == 0)
674 /* Get the demangled name without parameters */
675 sym_name
= cp_remove_params (SYMBOL_NATURAL_NAME (sym
));
679 /* skip symbols that cannot match */
680 if (strcmp (sym_name
, oload_name
) != 0)
688 /* We have a match for an overload instance, so add SYM to the
689 current list of overload instances */
690 if (sym_return_val_index
+ 3 > sym_return_val_size
)
692 newsize
= (sym_return_val_size
*= 2) * sizeof (struct symbol
*);
693 sym_return_val
= (struct symbol
**)
694 xrealloc ((char *) sym_return_val
, newsize
);
696 sym_return_val
[sym_return_val_index
++] = sym
;
697 sym_return_val
[sym_return_val_index
] = NULL
;
700 /* Return a null-terminated list of pointers to function symbols that
701 are named FUNC_NAME and are visible within NAMESPACE. */
704 make_symbol_overload_list (const char *func_name
,
705 const char *namespace)
707 struct cleanup
*old_cleanups
;
710 sym_return_val_size
= 100;
711 sym_return_val_index
= 0;
712 sym_return_val
= xmalloc ((sym_return_val_size
+ 1) *
713 sizeof (struct symbol
*));
714 sym_return_val
[0] = NULL
;
716 old_cleanups
= make_cleanup (xfree
, sym_return_val
);
718 make_symbol_overload_list_using (func_name
, namespace);
720 if (namespace[0] == '\0')
724 char *concatenated_name
725 = alloca (strlen (namespace) + 2 + strlen (func_name
) + 1);
726 strcpy (concatenated_name
, namespace);
727 strcat (concatenated_name
, "::");
728 strcat (concatenated_name
, func_name
);
729 name
= concatenated_name
;
732 make_symbol_overload_list_qualified (name
);
734 discard_cleanups (old_cleanups
);
736 return sym_return_val
;
739 /* Add all symbols with a name matching NAME in BLOCK to the overload
743 make_symbol_overload_list_block (const char *name
,
744 const struct block
*block
)
746 struct dict_iterator iter
;
749 const struct dictionary
*dict
= BLOCK_DICT (block
);
751 for (sym
= dict_iter_name_first (dict
, name
, &iter
);
753 sym
= dict_iter_name_next (name
, &iter
))
754 overload_list_add_symbol (sym
, name
);
757 /* Adds the function FUNC_NAME from NAMESPACE to the overload set. */
760 make_symbol_overload_list_namespace (const char *func_name
,
761 const char *namespace)
764 const struct block
*block
= NULL
;
766 if (namespace[0] == '\0')
770 char *concatenated_name
771 = alloca (strlen (namespace) + 2 + strlen (func_name
) + 1);
773 strcpy (concatenated_name
, namespace);
774 strcat (concatenated_name
, "::");
775 strcat (concatenated_name
, func_name
);
776 name
= concatenated_name
;
779 /* Look in the static block. */
780 block
= block_static_block (get_selected_block (0));
782 make_symbol_overload_list_block (name
, block
);
784 /* Look in the global block. */
785 block
= block_global_block (block
);
787 make_symbol_overload_list_block (name
, block
);
791 /* Search the namespace of the given type and namespace of and public
795 make_symbol_overload_list_adl_namespace (struct type
*type
,
796 const char *func_name
)
802 while (TYPE_CODE (type
) == TYPE_CODE_PTR
803 || TYPE_CODE (type
) == TYPE_CODE_REF
804 || TYPE_CODE (type
) == TYPE_CODE_ARRAY
805 || TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
807 if (TYPE_CODE (type
) == TYPE_CODE_TYPEDEF
)
808 type
= check_typedef(type
);
810 type
= TYPE_TARGET_TYPE (type
);
813 type_name
= TYPE_NAME (type
);
815 if (type_name
== NULL
)
818 prefix_len
= cp_entire_prefix_len (type_name
);
822 namespace = alloca (prefix_len
+ 1);
823 strncpy (namespace, type_name
, prefix_len
);
824 namespace[prefix_len
] = '\0';
826 make_symbol_overload_list_namespace (func_name
, namespace);
829 /* Check public base type */
830 if (TYPE_CODE (type
) == TYPE_CODE_CLASS
)
831 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
833 if (BASETYPE_VIA_PUBLIC (type
, i
))
834 make_symbol_overload_list_adl_namespace (TYPE_BASECLASS (type
,
840 /* Adds the overload list overload candidates for FUNC_NAME found
841 through argument dependent lookup. */
844 make_symbol_overload_list_adl (struct type
**arg_types
, int nargs
,
845 const char *func_name
)
849 gdb_assert (sym_return_val_size
!= -1);
851 for (i
= 1; i
<= nargs
; i
++)
852 make_symbol_overload_list_adl_namespace (arg_types
[i
- 1],
855 return sym_return_val
;
858 /* Used for cleanups to reset the "searched" flag in case of an
862 reset_directive_searched (void *data
)
864 struct using_direct
*direct
= data
;
865 direct
->searched
= 0;
868 /* This applies the using directives to add namespaces to search in,
869 and then searches for overloads in all of those namespaces. It
870 adds the symbols found to sym_return_val. Arguments are as in
871 make_symbol_overload_list. */
874 make_symbol_overload_list_using (const char *func_name
,
875 const char *namespace)
877 struct using_direct
*current
;
878 const struct block
*block
;
880 /* First, go through the using directives. If any of them apply,
881 look in the appropriate namespaces for new functions to match
884 for (block
= get_selected_block (0);
886 block
= BLOCK_SUPERBLOCK (block
))
887 for (current
= block_using (block
);
889 current
= current
->next
)
891 /* Prevent recursive calls. */
892 if (current
->searched
)
895 /* If this is a namespace alias or imported declaration ignore
897 if (current
->alias
!= NULL
|| current
->declaration
!= NULL
)
900 if (strcmp (namespace, current
->import_dest
) == 0)
902 /* Mark this import as searched so that the recursive call
903 does not search it again. */
904 struct cleanup
*old_chain
;
905 current
->searched
= 1;
906 old_chain
= make_cleanup (reset_directive_searched
,
909 make_symbol_overload_list_using (func_name
,
910 current
->import_src
);
912 current
->searched
= 0;
913 discard_cleanups (old_chain
);
917 /* Now, add names for this namespace. */
918 make_symbol_overload_list_namespace (func_name
, namespace);
921 /* This does the bulk of the work of finding overloaded symbols.
922 FUNC_NAME is the name of the overloaded function we're looking for
923 (possibly including namespace info). */
926 make_symbol_overload_list_qualified (const char *func_name
)
930 struct objfile
*objfile
;
931 const struct block
*b
, *surrounding_static_block
= 0;
932 struct dict_iterator iter
;
933 const struct dictionary
*dict
;
935 /* Look through the partial symtabs for all symbols which begin by
936 matching FUNC_NAME. Make sure we read that symbol table in. */
938 ALL_OBJFILES (objfile
)
941 objfile
->sf
->qf
->expand_symtabs_for_function (objfile
, func_name
);
944 /* Search upwards from currently selected frame (so that we can
945 complete on local vars. */
947 for (b
= get_selected_block (0); b
!= NULL
; b
= BLOCK_SUPERBLOCK (b
))
948 make_symbol_overload_list_block (func_name
, b
);
950 surrounding_static_block
= block_static_block (get_selected_block (0));
952 /* Go through the symtabs and check the externs and statics for
953 symbols which match. */
955 ALL_PRIMARY_SYMTABS (objfile
, s
)
958 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), GLOBAL_BLOCK
);
959 make_symbol_overload_list_block (func_name
, b
);
962 ALL_PRIMARY_SYMTABS (objfile
, s
)
965 b
= BLOCKVECTOR_BLOCK (BLOCKVECTOR (s
), STATIC_BLOCK
);
966 /* Don't do this block twice. */
967 if (b
== surrounding_static_block
)
969 make_symbol_overload_list_block (func_name
, b
);
973 /* Lookup the rtti type for a class name. */
976 cp_lookup_rtti_type (const char *name
, struct block
*block
)
978 struct symbol
* rtti_sym
;
979 struct type
* rtti_type
;
981 rtti_sym
= lookup_symbol (name
, block
, STRUCT_DOMAIN
, NULL
);
983 if (rtti_sym
== NULL
)
985 warning (_("RTTI symbol not found for class '%s'"), name
);
989 if (SYMBOL_CLASS (rtti_sym
) != LOC_TYPEDEF
)
991 warning (_("RTTI symbol for class '%s' is not a type"), name
);
995 rtti_type
= SYMBOL_TYPE (rtti_sym
);
997 switch (TYPE_CODE (rtti_type
))
999 case TYPE_CODE_CLASS
:
1001 case TYPE_CODE_NAMESPACE
:
1002 /* chastain/2003-11-26: the symbol tables often contain fake
1003 symbols for namespaces with the same name as the struct.
1004 This warning is an indication of a bug in the lookup order
1005 or a bug in the way that the symbol tables are populated. */
1006 warning (_("RTTI symbol for class '%s' is a namespace"), name
);
1009 warning (_("RTTI symbol for class '%s' has bad type"), name
);
1016 /* Don't allow just "maintenance cplus". */
1019 maint_cplus_command (char *arg
, int from_tty
)
1021 printf_unfiltered (_("\"maintenance cplus\" must be followed "
1022 "by the name of a command.\n"));
1023 help_list (maint_cplus_cmd_list
,
1024 "maintenance cplus ",
1028 /* This is a front end for cp_find_first_component, for unit testing.
1029 Be careful when using it: see the NOTE above
1030 cp_find_first_component. */
1033 first_component_command (char *arg
, int from_tty
)
1041 len
= cp_find_first_component (arg
);
1042 prefix
= alloca (len
+ 1);
1044 memcpy (prefix
, arg
, len
);
1047 printf_unfiltered ("%s\n", prefix
);
1050 extern initialize_file_ftype _initialize_cp_support
; /* -Wmissing-prototypes */
1052 #define SKIP_SPACE(P) \
1055 while (*(P) == ' ' || *(P) == '\t') \
1060 /* Returns the length of the operator name or 0 if INPUT does not
1061 point to a valid C++ operator. INPUT should start with
1064 cp_validate_operator (const char *input
)
1069 struct expression
*expr
;
1071 struct gdb_exception except
;
1075 if (strncmp (p
, "operator", 8) == 0)
1082 i
< sizeof (operator_tokens
) / sizeof (operator_tokens
[0]);
1085 int length
= strlen (operator_tokens
[i
]);
1087 /* By using strncmp here, we MUST have operator_tokens
1088 ordered! See additional notes where operator_tokens is
1090 if (strncmp (p
, operator_tokens
[i
], length
) == 0)
1097 if (strncmp (op
, "new", 3) == 0
1098 || strncmp (op
, "delete", 6) == 0)
1101 /* Special case: new[] and delete[]. We must be
1102 careful to swallow whitespace before/in "[]". */
1121 /* Check input for a conversion operator. */
1123 /* Skip past base typename. */
1124 while (*p
!= '*' && *p
!= '&' && *p
!= 0 && *p
!= ' ')
1128 /* Add modifiers '*' / '&'. */
1129 while (*p
== '*' || *p
== '&')
1135 /* Check for valid type. [Remember: input starts with
1137 copy
= savestring (input
+ 8, p
- input
- 8);
1140 TRY_CATCH (except
, RETURN_MASK_ALL
)
1142 expr
= parse_expression (copy
);
1143 val
= evaluate_type (expr
);
1150 if (val
!= NULL
&& value_type (val
) != NULL
)
1158 _initialize_cp_support (void)
1160 add_prefix_cmd ("cplus", class_maintenance
,
1161 maint_cplus_command
,
1162 _("C++ maintenance commands."),
1163 &maint_cplus_cmd_list
,
1164 "maintenance cplus ",
1165 0, &maintenancelist
);
1166 add_alias_cmd ("cp", "cplus",
1167 class_maintenance
, 1,
1170 add_cmd ("first_component",
1172 first_component_command
,
1173 _("Print the first class/namespace component of NAME."),
1174 &maint_cplus_cmd_list
);