* exec.c (bfdsec_to_vmap): Use strcmp instead of DEPRECATED_STREQ.
[deliverable/binutils-gdb.git] / gdb / cp-support.c
... / ...
CommitLineData
1/* Helper routines for C++ support in GDB.
2 Copyright 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
3
4 Contributed by MontaVista Software.
5
6 This file is part of GDB.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
22
23#include "defs.h"
24#include <ctype.h>
25#include "cp-support.h"
26#include "gdb_string.h"
27#include "demangle.h"
28#include "gdb_assert.h"
29#include "gdbcmd.h"
30#include "dictionary.h"
31#include "objfiles.h"
32#include "frame.h"
33#include "symtab.h"
34#include "block.h"
35#include "complaints.h"
36#include "gdbtypes.h"
37
38#define d_left(dc) (dc)->u.s_binary.left
39#define d_right(dc) (dc)->u.s_binary.right
40
41/* Functions related to demangled name parsing. */
42
43static unsigned int cp_find_first_component_aux (const char *name,
44 int permissive);
45
46static void demangled_name_complaint (const char *name);
47
48/* Functions/variables related to overload resolution. */
49
50static int sym_return_val_size;
51static int sym_return_val_index;
52static struct symbol **sym_return_val;
53
54static char *remove_params (const char *demangled_name);
55
56static void overload_list_add_symbol (struct symbol *sym,
57 const char *oload_name);
58
59static void make_symbol_overload_list_using (const char *func_name,
60 const char *namespace);
61
62static void make_symbol_overload_list_qualified (const char *func_name);
63
64static void read_in_psymtabs (const char *oload_name);
65
66/* The list of "maint cplus" commands. */
67
68struct cmd_list_element *maint_cplus_cmd_list = NULL;
69
70/* The actual commands. */
71
72static void maint_cplus_command (char *arg, int from_tty);
73static void first_component_command (char *arg, int from_tty);
74
75/* Return the canonicalized form of STRING, or NULL if STRING can not be
76 parsed. The return value is allocated via xmalloc.
77
78 drow/2005-03-07: Should we also return NULL for things that trivially do
79 not require any change? e.g. simple identifiers. This could be more
80 efficient. */
81
82char *
83cp_canonicalize_string (const char *string)
84{
85 void *storage;
86 struct demangle_component *ret_comp;
87 char *ret;
88 int len = strlen (string);
89
90 len = len + len / 8;
91
92 ret_comp = cp_demangled_name_to_comp (string, &storage, NULL);
93 if (ret_comp == NULL)
94 return NULL;
95
96 ret = cp_comp_to_string (ret_comp, len);
97
98 xfree (storage);
99
100 return ret;
101}
102
103/* Convert a mangled name to a demangle_component tree. *MEMORY is set to the
104 block of used memory that should be freed when finished with the tree.
105 DEMANGLED_P is set to the char * that should be freed when finished with
106 the tree, or NULL if none was needed. OPTIONS will be passed to the
107 demangler. */
108
109static struct demangle_component *
110mangled_name_to_comp (const char *mangled_name, int options,
111 void **memory, char **demangled_p)
112{
113 struct demangle_component *ret;
114 char *demangled_name;
115 int len;
116
117 /* If it looks like a v3 mangled name, then try to go directly
118 to trees. */
119 if (mangled_name[0] == '_' && mangled_name[1] == 'Z')
120 {
121 ret = cplus_demangle_v3_components (mangled_name, options, memory);
122 if (ret)
123 {
124 *demangled_p = NULL;
125 return ret;
126 }
127 }
128
129 /* If it doesn't, or if that failed, then try to demangle the name. */
130 demangled_name = cplus_demangle (mangled_name, options);
131 if (demangled_name == NULL)
132 return NULL;
133
134 /* If we could demangle the name, parse it to build the component tree. */
135 ret = cp_demangled_name_to_comp (demangled_name, memory, NULL);
136
137 if (ret == NULL)
138 {
139 free (demangled_name);
140 return NULL;
141 }
142
143 *demangled_p = demangled_name;
144 return ret;
145}
146
147/* Return the name of the class containing method PHYSNAME. */
148
149char *
150cp_class_name_from_physname (const char *physname)
151{
152 void *storage;
153 char *demangled_name = NULL, *ret;
154 struct demangle_component *ret_comp, *prev_comp;
155 int done;
156
157 ret_comp = mangled_name_to_comp (physname, DMGL_ANSI, &storage,
158 &demangled_name);
159 if (ret_comp == NULL)
160 return NULL;
161
162 done = 0;
163 prev_comp = NULL;
164 while (!done)
165 switch (ret_comp->type)
166 {
167 case DEMANGLE_COMPONENT_TYPED_NAME:
168 prev_comp = NULL;
169 ret_comp = d_right (ret_comp);
170 break;
171 case DEMANGLE_COMPONENT_QUAL_NAME:
172 case DEMANGLE_COMPONENT_LOCAL_NAME:
173 prev_comp = ret_comp;
174 ret_comp = d_right (ret_comp);
175 break;
176 case DEMANGLE_COMPONENT_CONST:
177 case DEMANGLE_COMPONENT_RESTRICT:
178 case DEMANGLE_COMPONENT_VOLATILE:
179 case DEMANGLE_COMPONENT_CONST_THIS:
180 case DEMANGLE_COMPONENT_RESTRICT_THIS:
181 case DEMANGLE_COMPONENT_VOLATILE_THIS:
182 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
183 prev_comp = NULL;
184 ret_comp = d_left (ret_comp);
185 break;
186 case DEMANGLE_COMPONENT_NAME:
187 case DEMANGLE_COMPONENT_TEMPLATE:
188 case DEMANGLE_COMPONENT_CTOR:
189 case DEMANGLE_COMPONENT_DTOR:
190 case DEMANGLE_COMPONENT_OPERATOR:
191 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
192 done = 1;
193 break;
194 default:
195 done = 1;
196 prev_comp = NULL;
197 ret_comp = NULL;
198 break;
199 }
200
201 ret = NULL;
202 if (prev_comp != NULL)
203 {
204 *prev_comp = *d_left (prev_comp);
205 /* The ten is completely arbitrary; we don't have a good estimate. */
206 ret = cp_comp_to_string (prev_comp, 10);
207 }
208
209 xfree (storage);
210 if (demangled_name)
211 xfree (demangled_name);
212 return ret;
213}
214
215/* Return the name of the method whose linkage name is PHYSNAME. */
216
217char *
218method_name_from_physname (const char *physname)
219{
220 void *storage;
221 char *demangled_name = NULL, *ret;
222 struct demangle_component *ret_comp;
223 int done;
224
225 ret_comp = mangled_name_to_comp (physname, DMGL_ANSI, &storage,
226 &demangled_name);
227 if (ret_comp == NULL)
228 return NULL;
229
230 done = 0;
231 while (!done)
232 switch (ret_comp->type)
233 {
234 case DEMANGLE_COMPONENT_QUAL_NAME:
235 case DEMANGLE_COMPONENT_LOCAL_NAME:
236 case DEMANGLE_COMPONENT_TYPED_NAME:
237 ret_comp = d_right (ret_comp);
238 break;
239 case DEMANGLE_COMPONENT_CONST:
240 case DEMANGLE_COMPONENT_RESTRICT:
241 case DEMANGLE_COMPONENT_VOLATILE:
242 case DEMANGLE_COMPONENT_CONST_THIS:
243 case DEMANGLE_COMPONENT_RESTRICT_THIS:
244 case DEMANGLE_COMPONENT_VOLATILE_THIS:
245 case DEMANGLE_COMPONENT_VENDOR_TYPE_QUAL:
246 ret_comp = d_left (ret_comp);
247 break;
248 case DEMANGLE_COMPONENT_NAME:
249 case DEMANGLE_COMPONENT_TEMPLATE:
250 case DEMANGLE_COMPONENT_CTOR:
251 case DEMANGLE_COMPONENT_DTOR:
252 case DEMANGLE_COMPONENT_OPERATOR:
253 case DEMANGLE_COMPONENT_EXTENDED_OPERATOR:
254 done = 1;
255 break;
256 default:
257 done = 1;
258 ret_comp = NULL;
259 break;
260 }
261
262 ret = NULL;
263 if (ret_comp != NULL)
264 /* The ten is completely arbitrary; we don't have a good estimate. */
265 ret = cp_comp_to_string (ret_comp, 10);
266
267 xfree (storage);
268 if (demangled_name)
269 xfree (demangled_name);
270 return ret;
271}
272
273/* Here are some random pieces of trivia to keep in mind while trying
274 to take apart demangled names:
275
276 - Names can contain function arguments or templates, so the process
277 has to be, to some extent recursive: maybe keep track of your
278 depth based on encountering <> and ().
279
280 - Parentheses don't just have to happen at the end of a name: they
281 can occur even if the name in question isn't a function, because
282 a template argument might be a type that's a function.
283
284 - Conversely, even if you're trying to deal with a function, its
285 demangled name might not end with ')': it could be a const or
286 volatile class method, in which case it ends with "const" or
287 "volatile".
288
289 - Parentheses are also used in anonymous namespaces: a variable
290 'foo' in an anonymous namespace gets demangled as "(anonymous
291 namespace)::foo".
292
293 - And operator names can contain parentheses or angle brackets. */
294
295/* FIXME: carlton/2003-03-13: We have several functions here with
296 overlapping functionality; can we combine them? Also, do they
297 handle all the above considerations correctly? */
298
299
300/* This returns the length of first component of NAME, which should be
301 the demangled name of a C++ variable/function/method/etc.
302 Specifically, it returns the index of the first colon forming the
303 boundary of the first component: so, given 'A::foo' or 'A::B::foo'
304 it returns the 1, and given 'foo', it returns 0. */
305
306/* The character in NAME indexed by the return value is guaranteed to
307 always be either ':' or '\0'. */
308
309/* NOTE: carlton/2003-03-13: This function is currently only intended
310 for internal use: it's probably not entirely safe when called on
311 user-generated input, because some of the 'index += 2' lines in
312 cp_find_first_component_aux might go past the end of malformed
313 input. */
314
315unsigned int
316cp_find_first_component (const char *name)
317{
318 return cp_find_first_component_aux (name, 0);
319}
320
321/* Helper function for cp_find_first_component. Like that function,
322 it returns the length of the first component of NAME, but to make
323 the recursion easier, it also stops if it reaches an unexpected ')'
324 or '>' if the value of PERMISSIVE is nonzero. */
325
326/* Let's optimize away calls to strlen("operator"). */
327
328#define LENGTH_OF_OPERATOR 8
329
330static unsigned int
331cp_find_first_component_aux (const char *name, int permissive)
332{
333 unsigned int index = 0;
334 /* Operator names can show up in unexpected places. Since these can
335 contain parentheses or angle brackets, they can screw up the
336 recursion. But not every string 'operator' is part of an
337 operater name: e.g. you could have a variable 'cooperator'. So
338 this variable tells us whether or not we should treat the string
339 'operator' as starting an operator. */
340 int operator_possible = 1;
341
342 for (;; ++index)
343 {
344 switch (name[index])
345 {
346 case '<':
347 /* Template; eat it up. The calls to cp_first_component
348 should only return (I hope!) when they reach the '>'
349 terminating the component or a '::' between two
350 components. (Hence the '+ 2'.) */
351 index += 1;
352 for (index += cp_find_first_component_aux (name + index, 1);
353 name[index] != '>';
354 index += cp_find_first_component_aux (name + index, 1))
355 {
356 if (name[index] != ':')
357 {
358 demangled_name_complaint (name);
359 return strlen (name);
360 }
361 index += 2;
362 }
363 operator_possible = 1;
364 break;
365 case '(':
366 /* Similar comment as to '<'. */
367 index += 1;
368 for (index += cp_find_first_component_aux (name + index, 1);
369 name[index] != ')';
370 index += cp_find_first_component_aux (name + index, 1))
371 {
372 if (name[index] != ':')
373 {
374 demangled_name_complaint (name);
375 return strlen (name);
376 }
377 index += 2;
378 }
379 operator_possible = 1;
380 break;
381 case '>':
382 case ')':
383 if (permissive)
384 return index;
385 else
386 {
387 demangled_name_complaint (name);
388 return strlen (name);
389 }
390 case '\0':
391 case ':':
392 return index;
393 case 'o':
394 /* Operator names can screw up the recursion. */
395 if (operator_possible
396 && strncmp (name + index, "operator", LENGTH_OF_OPERATOR) == 0)
397 {
398 index += LENGTH_OF_OPERATOR;
399 while (isspace(name[index]))
400 ++index;
401 switch (name[index])
402 {
403 /* Skip over one less than the appropriate number of
404 characters: the for loop will skip over the last
405 one. */
406 case '<':
407 if (name[index + 1] == '<')
408 index += 1;
409 else
410 index += 0;
411 break;
412 case '>':
413 case '-':
414 if (name[index + 1] == '>')
415 index += 1;
416 else
417 index += 0;
418 break;
419 case '(':
420 index += 1;
421 break;
422 default:
423 index += 0;
424 break;
425 }
426 }
427 operator_possible = 0;
428 break;
429 case ' ':
430 case ',':
431 case '.':
432 case '&':
433 case '*':
434 /* NOTE: carlton/2003-04-18: I'm not sure what the precise
435 set of relevant characters are here: it's necessary to
436 include any character that can show up before 'operator'
437 in a demangled name, and it's safe to include any
438 character that can't be part of an identifier's name. */
439 operator_possible = 1;
440 break;
441 default:
442 operator_possible = 0;
443 break;
444 }
445 }
446}
447
448/* Complain about a demangled name that we don't know how to parse.
449 NAME is the demangled name in question. */
450
451static void
452demangled_name_complaint (const char *name)
453{
454 complaint (&symfile_complaints,
455 "unexpected demangled name '%s'", name);
456}
457
458/* If NAME is the fully-qualified name of a C++
459 function/variable/method/etc., this returns the length of its
460 entire prefix: all of the namespaces and classes that make up its
461 name. Given 'A::foo', it returns 1, given 'A::B::foo', it returns
462 4, given 'foo', it returns 0. */
463
464unsigned int
465cp_entire_prefix_len (const char *name)
466{
467 unsigned int current_len = cp_find_first_component (name);
468 unsigned int previous_len = 0;
469
470 while (name[current_len] != '\0')
471 {
472 gdb_assert (name[current_len] == ':');
473 previous_len = current_len;
474 /* Skip the '::'. */
475 current_len += 2;
476 current_len += cp_find_first_component (name + current_len);
477 }
478
479 return previous_len;
480}
481
482/* If FULL_NAME is the demangled name of a C++ function (including an
483 arg list, possibly including namespace/class qualifications),
484 return a new string containing only the function name (without the
485 arg list/class qualifications). Otherwise, return NULL. The
486 caller is responsible for freeing the memory in question. */
487
488char *
489cp_func_name (const char *full_name)
490{
491 const char *previous_component = full_name;
492 const char *next_component;
493
494 if (!full_name)
495 return NULL;
496
497 for (next_component = (previous_component
498 + cp_find_first_component (previous_component));
499 *next_component == ':';
500 next_component = (previous_component
501 + cp_find_first_component (previous_component)))
502 {
503 /* Skip '::'. */
504 previous_component = next_component + 2;
505 }
506
507 return remove_params (previous_component);
508}
509
510/* Overload resolution functions. */
511
512static char *
513remove_params (const char *demangled_name)
514{
515 const char *argp;
516 char *new_name;
517 int depth;
518
519 if (demangled_name == NULL)
520 return NULL;
521
522 /* First find the end of the arg list. */
523 argp = strrchr (demangled_name, ')');
524 if (argp == NULL)
525 return NULL;
526
527 /* Back up to the beginning. */
528 depth = 1;
529
530 while (argp-- > demangled_name)
531 {
532 if (*argp == ')')
533 depth ++;
534 else if (*argp == '(')
535 {
536 depth --;
537
538 if (depth == 0)
539 break;
540 }
541 }
542 if (depth != 0)
543 internal_error (__FILE__, __LINE__,
544 _("bad demangled name %s\n"), demangled_name);
545 while (argp[-1] == ' ' && argp > demangled_name)
546 argp --;
547
548 new_name = xmalloc (argp - demangled_name + 1);
549 memcpy (new_name, demangled_name, argp - demangled_name);
550 new_name[argp - demangled_name] = '\0';
551 return new_name;
552}
553
554/* Test to see if SYM is a symbol that we haven't seen corresponding
555 to a function named OLOAD_NAME. If so, add it to the current
556 completion list. */
557
558static void
559overload_list_add_symbol (struct symbol *sym, const char *oload_name)
560{
561 int newsize;
562 int i;
563 char *sym_name;
564
565 /* If there is no type information, we can't do anything, so skip */
566 if (SYMBOL_TYPE (sym) == NULL)
567 return;
568
569 /* skip any symbols that we've already considered. */
570 for (i = 0; i < sym_return_val_index; ++i)
571 if (strcmp (SYMBOL_LINKAGE_NAME (sym),
572 SYMBOL_LINKAGE_NAME (sym_return_val[i])) == 0)
573 return;
574
575 /* Get the demangled name without parameters */
576 sym_name = remove_params (SYMBOL_NATURAL_NAME (sym));
577 if (!sym_name)
578 return;
579
580 /* skip symbols that cannot match */
581 if (strcmp (sym_name, oload_name) != 0)
582 {
583 xfree (sym_name);
584 return;
585 }
586
587 xfree (sym_name);
588
589 /* We have a match for an overload instance, so add SYM to the current list
590 * of overload instances */
591 if (sym_return_val_index + 3 > sym_return_val_size)
592 {
593 newsize = (sym_return_val_size *= 2) * sizeof (struct symbol *);
594 sym_return_val = (struct symbol **) xrealloc ((char *) sym_return_val, newsize);
595 }
596 sym_return_val[sym_return_val_index++] = sym;
597 sym_return_val[sym_return_val_index] = NULL;
598}
599
600/* Return a null-terminated list of pointers to function symbols that
601 are named FUNC_NAME and are visible within NAMESPACE. */
602
603struct symbol **
604make_symbol_overload_list (const char *func_name,
605 const char *namespace)
606{
607 struct cleanup *old_cleanups;
608
609 sym_return_val_size = 100;
610 sym_return_val_index = 0;
611 sym_return_val = xmalloc ((sym_return_val_size + 1) *
612 sizeof (struct symbol *));
613 sym_return_val[0] = NULL;
614
615 old_cleanups = make_cleanup (xfree, sym_return_val);
616
617 make_symbol_overload_list_using (func_name, namespace);
618
619 discard_cleanups (old_cleanups);
620
621 return sym_return_val;
622}
623
624/* This applies the using directives to add namespaces to search in,
625 and then searches for overloads in all of those namespaces. It
626 adds the symbols found to sym_return_val. Arguments are as in
627 make_symbol_overload_list. */
628
629static void
630make_symbol_overload_list_using (const char *func_name,
631 const char *namespace)
632{
633 const struct using_direct *current;
634
635 /* First, go through the using directives. If any of them apply,
636 look in the appropriate namespaces for new functions to match
637 on. */
638
639 for (current = block_using (get_selected_block (0));
640 current != NULL;
641 current = current->next)
642 {
643 if (strcmp (namespace, current->outer) == 0)
644 {
645 make_symbol_overload_list_using (func_name,
646 current->inner);
647 }
648 }
649
650 /* Now, add names for this namespace. */
651
652 if (namespace[0] == '\0')
653 {
654 make_symbol_overload_list_qualified (func_name);
655 }
656 else
657 {
658 char *concatenated_name
659 = alloca (strlen (namespace) + 2 + strlen (func_name) + 1);
660 strcpy (concatenated_name, namespace);
661 strcat (concatenated_name, "::");
662 strcat (concatenated_name, func_name);
663 make_symbol_overload_list_qualified (concatenated_name);
664 }
665}
666
667/* This does the bulk of the work of finding overloaded symbols.
668 FUNC_NAME is the name of the overloaded function we're looking for
669 (possibly including namespace info). */
670
671static void
672make_symbol_overload_list_qualified (const char *func_name)
673{
674 struct symbol *sym;
675 struct symtab *s;
676 struct objfile *objfile;
677 const struct block *b, *surrounding_static_block = 0;
678 struct dict_iterator iter;
679 const struct dictionary *dict;
680
681 /* Look through the partial symtabs for all symbols which begin
682 by matching FUNC_NAME. Make sure we read that symbol table in. */
683
684 read_in_psymtabs (func_name);
685
686 /* Search upwards from currently selected frame (so that we can
687 complete on local vars. */
688
689 for (b = get_selected_block (0); b != NULL; b = BLOCK_SUPERBLOCK (b))
690 {
691 dict = BLOCK_DICT (b);
692
693 for (sym = dict_iter_name_first (dict, func_name, &iter);
694 sym;
695 sym = dict_iter_name_next (func_name, &iter))
696 {
697 overload_list_add_symbol (sym, func_name);
698 }
699 }
700
701 surrounding_static_block = block_static_block (get_selected_block (0));
702
703 /* Go through the symtabs and check the externs and statics for
704 symbols which match. */
705
706 ALL_SYMTABS (objfile, s)
707 {
708 QUIT;
709 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), GLOBAL_BLOCK);
710 dict = BLOCK_DICT (b);
711
712 for (sym = dict_iter_name_first (dict, func_name, &iter);
713 sym;
714 sym = dict_iter_name_next (func_name, &iter))
715 {
716 overload_list_add_symbol (sym, func_name);
717 }
718 }
719
720 ALL_SYMTABS (objfile, s)
721 {
722 QUIT;
723 b = BLOCKVECTOR_BLOCK (BLOCKVECTOR (s), STATIC_BLOCK);
724 /* Don't do this block twice. */
725 if (b == surrounding_static_block)
726 continue;
727 dict = BLOCK_DICT (b);
728
729 for (sym = dict_iter_name_first (dict, func_name, &iter);
730 sym;
731 sym = dict_iter_name_next (func_name, &iter))
732 {
733 overload_list_add_symbol (sym, func_name);
734 }
735 }
736}
737
738/* Look through the partial symtabs for all symbols which begin
739 by matching FUNC_NAME. Make sure we read that symbol table in. */
740
741static void
742read_in_psymtabs (const char *func_name)
743{
744 struct partial_symtab *ps;
745 struct objfile *objfile;
746
747 ALL_PSYMTABS (objfile, ps)
748 {
749 if (ps->readin)
750 continue;
751
752 if ((lookup_partial_symbol (ps, func_name, NULL, 1, VAR_DOMAIN)
753 != NULL)
754 || (lookup_partial_symbol (ps, func_name, NULL, 0, VAR_DOMAIN)
755 != NULL))
756 psymtab_to_symtab (ps);
757 }
758}
759
760/* Lookup the rtti type for a class name. */
761
762struct type *
763cp_lookup_rtti_type (const char *name, struct block *block)
764{
765 struct symbol * rtti_sym;
766 struct type * rtti_type;
767
768 rtti_sym = lookup_symbol (name, block, STRUCT_DOMAIN, NULL, NULL);
769
770 if (rtti_sym == NULL)
771 {
772 warning (_("RTTI symbol not found for class '%s'"), name);
773 return NULL;
774 }
775
776 if (SYMBOL_CLASS (rtti_sym) != LOC_TYPEDEF)
777 {
778 warning (_("RTTI symbol for class '%s' is not a type"), name);
779 return NULL;
780 }
781
782 rtti_type = SYMBOL_TYPE (rtti_sym);
783
784 switch (TYPE_CODE (rtti_type))
785 {
786 case TYPE_CODE_CLASS:
787 break;
788 case TYPE_CODE_NAMESPACE:
789 /* chastain/2003-11-26: the symbol tables often contain fake
790 symbols for namespaces with the same name as the struct.
791 This warning is an indication of a bug in the lookup order
792 or a bug in the way that the symbol tables are populated. */
793 warning (_("RTTI symbol for class '%s' is a namespace"), name);
794 return NULL;
795 default:
796 warning (_("RTTI symbol for class '%s' has bad type"), name);
797 return NULL;
798 }
799
800 return rtti_type;
801}
802
803/* Don't allow just "maintenance cplus". */
804
805static void
806maint_cplus_command (char *arg, int from_tty)
807{
808 printf_unfiltered (_("\"maintenance cplus\" must be followed by the name of a command.\n"));
809 help_list (maint_cplus_cmd_list, "maintenance cplus ", -1, gdb_stdout);
810}
811
812/* This is a front end for cp_find_first_component, for unit testing.
813 Be careful when using it: see the NOTE above
814 cp_find_first_component. */
815
816static void
817first_component_command (char *arg, int from_tty)
818{
819 int len = cp_find_first_component (arg);
820 char *prefix = alloca (len + 1);
821
822 memcpy (prefix, arg, len);
823 prefix[len] = '\0';
824
825 printf_unfiltered ("%s\n", prefix);
826}
827
828extern initialize_file_ftype _initialize_cp_support; /* -Wmissing-prototypes */
829
830void
831_initialize_cp_support (void)
832{
833 add_prefix_cmd ("cplus", class_maintenance, maint_cplus_command,
834 _("C++ maintenance commands."), &maint_cplus_cmd_list,
835 "maintenance cplus ", 0, &maintenancelist);
836 add_alias_cmd ("cp", "cplus", class_maintenance, 1, &maintenancelist);
837
838 add_cmd ("first_component", class_maintenance, first_component_command,
839 _("Print the first class/namespace component of NAME."),
840 &maint_cplus_cmd_list);
841
842}
This page took 0.026018 seconds and 4 git commands to generate.