]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/cp-namespace.c
* lib/java.exp (java_init): Import target_alias before using it.
[thirdparty/binutils-gdb.git] / gdb / cp-namespace.c
CommitLineData
9219021c
DC
1/* Helper routines for C++ support in GDB.
2 Copyright 2003 Free Software Foundation, Inc.
3
1fcb5155 4 Contributed by David Carlton and by Kealia, Inc.
9219021c
DC
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 "cp-support.h"
25#include "gdb_obstack.h"
26#include "symtab.h"
27#include "symfile.h"
28#include "gdb_assert.h"
29#include "block.h"
5c4e30ca
DC
30#include "objfiles.h"
31#include "gdbtypes.h"
32#include "dictionary.h"
33#include "command.h"
9219021c
DC
34
35/* When set, the file that we're processing seems to have debugging
36 info for C++ namespaces, so cp-namespace.c shouldn't try to guess
37 namespace info itself. */
38
39unsigned char processing_has_namespace_info;
40
41/* If processing_has_namespace_info is nonzero, this string should
42 contain the name of the current namespace. The string is
43 temporary; copy it if you need it. */
44
0fc9922a
DC
45/* FIXME: carlton/2003-06-12: This isn't entirely reliable: currently,
46 we get mislead by DW_AT_specification. */
47
9219021c
DC
48const char *processing_current_namespace;
49
50/* List of using directives that are active in the current file. */
51
52static struct using_direct *using_list;
53
54static struct using_direct *cp_add_using (const char *name,
55 unsigned int inner_len,
56 unsigned int outer_len,
57 struct using_direct *next);
58
59static struct using_direct *cp_copy_usings (struct using_direct *using,
60 struct obstack *obstack);
61
1fcb5155
DC
62static struct symbol *lookup_namespace_scope (const char *name,
63 const char *linkage_name,
64 const struct block *block,
65 const domain_enum domain,
66 struct symtab **symtab,
67 const char *scope,
68 int scope_len);
69
70static struct symbol *lookup_symbol_file (const char *name,
71 const char *linkage_name,
72 const struct block *block,
73 const domain_enum domain,
74 struct symtab **symtab,
75 int anonymous_namespace);
76
5c4e30ca
DC
77static void initialize_namespace_symtab (struct objfile *objfile);
78
79static struct block *get_possible_namespace_block (struct objfile *objfile);
80
81static void free_namespace_block (struct symtab *symtab);
82
83static int check_possible_namespace_symbols_loop (const char *name,
84 int len,
85 struct objfile *objfile);
86
87static int check_one_possible_namespace_symbol (const char *name,
88 int len,
89 struct objfile *objfile);
90
91static
92struct symbol *lookup_possible_namespace_symbol (const char *name,
93 struct symtab **symtab);
94
95static void maintenance_cplus_namespace (char *args, int from_tty);
96
9219021c
DC
97/* Set up support for dealing with C++ namespace info in the current
98 symtab. */
99
100void cp_initialize_namespace ()
101{
102 processing_has_namespace_info = 0;
103 using_list = NULL;
104}
105
106/* Add all the using directives we've gathered to the current symtab.
107 STATIC_BLOCK should be the symtab's static block; OBSTACK is used
108 for allocation. */
109
110void
111cp_finalize_namespace (struct block *static_block,
112 struct obstack *obstack)
113{
114 if (using_list != NULL)
115 {
116 block_set_using (static_block,
117 cp_copy_usings (using_list, obstack),
118 obstack);
119 using_list = NULL;
120 }
121}
122
123/* Check to see if SYMBOL refers to an object contained within an
124 anonymous namespace; if so, add an appropriate using directive. */
125
126/* Optimize away strlen ("(anonymous namespace)"). */
127
128#define ANONYMOUS_NAMESPACE_LEN 21
129
130void
131cp_scan_for_anonymous_namespaces (const struct symbol *symbol)
132{
133 if (!processing_has_namespace_info
134 && SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL)
135 {
136 const char *name = SYMBOL_CPLUS_DEMANGLED_NAME (symbol);
137 unsigned int previous_component;
138 unsigned int next_component;
139 const char *len;
140
141 /* Start with a quick-and-dirty check for mention of "(anonymous
142 namespace)". */
143
144 if (!cp_is_anonymous (name))
145 return;
146
147 previous_component = 0;
148 next_component = cp_find_first_component (name + previous_component);
149
150 while (name[next_component] == ':')
151 {
152 if ((next_component - previous_component) == ANONYMOUS_NAMESPACE_LEN
153 && strncmp (name + previous_component,
154 "(anonymous namespace)",
155 ANONYMOUS_NAMESPACE_LEN) == 0)
156 {
157 /* We've found a component of the name that's an
158 anonymous namespace. So add symbols in it to the
159 namespace given by the previous component if there is
160 one, or to the global namespace if there isn't. */
161 cp_add_using_directive (name,
162 previous_component == 0
163 ? 0 : previous_component - 2,
164 next_component);
165 }
166 /* The "+ 2" is for the "::". */
167 previous_component = next_component + 2;
168 next_component = (previous_component
169 + cp_find_first_component (name
170 + previous_component));
171 }
172 }
173}
174
175/* Add a using directive to using_list. NAME is the start of a string
176 that should contain the namespaces we want to add as initial
177 substrings, OUTER_LENGTH is the end of the outer namespace, and
178 INNER_LENGTH is the end of the inner namespace. If the using
179 directive in question has already been added, don't add it
180 twice. */
181
182void
183cp_add_using_directive (const char *name, unsigned int outer_length,
184 unsigned int inner_length)
185{
186 struct using_direct *current;
187 struct using_direct *new;
188
189 /* Has it already been added? */
190
191 for (current = using_list; current != NULL; current = current->next)
192 {
193 if ((strncmp (current->inner, name, inner_length) == 0)
194 && (strlen (current->inner) == inner_length)
195 && (strlen (current->outer) == outer_length))
196 return;
197 }
198
199 using_list = cp_add_using (name, inner_length, outer_length,
200 using_list);
201}
202
203/* Record the namespace that the function defined by SYMBOL was
204 defined in, if necessary. BLOCK is the associated block; use
205 OBSTACK for allocation. */
206
207void
208cp_set_block_scope (const struct symbol *symbol,
209 struct block *block,
210 struct obstack *obstack)
211{
212 /* Make sure that the name was originally mangled: if not, there
213 certainly isn't any namespace information to worry about! */
214
215 if (SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL)
216 {
0fc9922a
DC
217#if 0
218 /* FIXME: carlton/2003-06-12: As mentioned above,
219 'processing_has_namespace_info' currently isn't entirely
220 reliable, so let's always use demangled names to get this
221 information for now. */
222
9219021c
DC
223 if (processing_has_namespace_info)
224 {
225 block_set_scope
226 (block, obsavestring (processing_current_namespace,
227 strlen (processing_current_namespace),
228 obstack),
229 obstack);
230 }
231 else
0fc9922a 232#endif
9219021c
DC
233 {
234 /* Try to figure out the appropriate namespace from the
235 demangled name. */
236
237 /* FIXME: carlton/2003-04-15: If the function in question is
238 a method of a class, the name will actually include the
239 name of the class as well. This should be harmless, but
240 is a little unfortunate. */
241
242 const char *name = SYMBOL_CPLUS_DEMANGLED_NAME (symbol);
243 unsigned int prefix_len = cp_entire_prefix_len (name);
244
245 block_set_scope (block,
246 obsavestring (name, prefix_len, obstack),
247 obstack);
248 }
249 }
250}
251
252/* Test whether or not NAMESPACE looks like it mentions an anonymous
253 namespace; return nonzero if so. */
254
255int
256cp_is_anonymous (const char *namespace)
257{
258 return (strstr (namespace, "(anonymous namespace)")
259 != NULL);
260}
261
262/* Create a new struct using direct whose inner namespace is the
263 initial substring of NAME of leng INNER_LEN and whose outer
264 namespace is the initial substring of NAME of length OUTER_LENGTH.
265 Set its next member in the linked list to NEXT; allocate all memory
266 using xmalloc. It copies the strings, so NAME can be a temporary
267 string. */
268
269static struct using_direct *
270cp_add_using (const char *name,
271 unsigned int inner_len,
272 unsigned int outer_len,
273 struct using_direct *next)
274{
275 struct using_direct *retval;
276
277 gdb_assert (outer_len < inner_len);
278
279 retval = xmalloc (sizeof (struct using_direct));
280 retval->inner = savestring (name, inner_len);
281 retval->outer = savestring (name, outer_len);
282 retval->next = next;
283
284 return retval;
285}
286
287/* Make a copy of the using directives in the list pointed to by
288 USING, using OBSTACK to allocate memory. Free all memory pointed
289 to by USING via xfree. */
290
291static struct using_direct *
292cp_copy_usings (struct using_direct *using,
293 struct obstack *obstack)
294{
295 if (using == NULL)
296 {
297 return NULL;
298 }
299 else
300 {
301 struct using_direct *retval
302 = obstack_alloc (obstack, sizeof (struct using_direct));
303 retval->inner = obsavestring (using->inner, strlen (using->inner),
304 obstack);
305 retval->outer = obsavestring (using->outer, strlen (using->outer),
306 obstack);
307 retval->next = cp_copy_usings (using->next, obstack);
308
309 xfree (using->inner);
310 xfree (using->outer);
311 xfree (using);
312
313 return retval;
314 }
315}
1fcb5155
DC
316
317/* The C++-specific version of name lookup for static and global
318 names. This makes sure that names get looked for in all namespaces
319 that are in scope. NAME is the natural name of the symbol that
320 we're looking for, LINKAGE_NAME (which is optional) is its linkage
321 name, BLOCK is the block that we're searching within, DOMAIN says
322 what kind of symbols we're looking for, and if SYMTAB is non-NULL,
323 we should store the symtab where we found the symbol in it. */
324
325struct symbol *
326cp_lookup_symbol_nonlocal (const char *name,
327 const char *linkage_name,
328 const struct block *block,
329 const domain_enum domain,
330 struct symtab **symtab)
331{
332 return lookup_namespace_scope (name, linkage_name, block, domain,
333 symtab, block_scope (block), 0);
334}
335
336/* Lookup NAME at namespace scope (or, in C terms, in static and
337 global variables). SCOPE is the namespace that the current
338 function is defined within; only consider namespaces whose length
339 is at least SCOPE_LEN. Other arguments are as in
340 cp_lookup_symbol_nonlocal.
341
342 For example, if we're within a function A::B::f and looking for a
343 symbol f, this will get called with NAME = "f", SCOPE = "A::B", and
344 SCOPE_LEN = 0. It then calls itself with NAME and SCOPE the same,
345 but with SCOPE_LEN = 1. And then it calls itself with NAME and
346 SCOPE the same, but with SCOPE_LEN = 4. This third call looks for
347 "A::B::x"; if it doesn't find it, then the second call looks for
348 "A::x", and if that call fails, then the first call looks for
349 "x". */
350
351static struct symbol *
352lookup_namespace_scope (const char *name,
353 const char *linkage_name,
354 const struct block *block,
355 const domain_enum domain,
356 struct symtab **symtab,
357 const char *scope,
358 int scope_len)
359{
360 char *namespace;
361
362 if (scope[scope_len] != '\0')
363 {
364 /* Recursively search for names in child namespaces first. */
365
366 struct symbol *sym;
367 int new_scope_len = scope_len;
368
369 /* If the current scope is followed by "::", skip past that. */
370 if (new_scope_len != 0)
371 {
372 gdb_assert (scope[new_scope_len] == ':');
373 new_scope_len += 2;
374 }
375 new_scope_len += cp_find_first_component (scope + new_scope_len);
376 sym = lookup_namespace_scope (name, linkage_name, block,
377 domain, symtab,
378 scope, new_scope_len);
379 if (sym != NULL)
380 return sym;
381 }
382
383 /* Okay, we didn't find a match in our children, so look for the
384 name in the current namespace. */
385
386 namespace = alloca (scope_len + 1);
387 strncpy (namespace, scope, scope_len);
388 namespace[scope_len] = '\0';
389 return cp_lookup_symbol_namespace (namespace, name, linkage_name,
390 block, domain, symtab);
391}
392
393/* Look up NAME in the C++ namespace NAMESPACE, applying the using
394 directives that are active in BLOCK. Other arguments are as in
395 cp_lookup_symbol_nonlocal. */
396
397struct symbol *
398cp_lookup_symbol_namespace (const char *namespace,
399 const char *name,
400 const char *linkage_name,
401 const struct block *block,
402 const domain_enum domain,
403 struct symtab **symtab)
404{
405 const struct using_direct *current;
406 struct symbol *sym;
407
408 /* First, go through the using directives. If any of them add new
409 names to the namespace we're searching in, see if we can find a
410 match by applying them. */
411
412 for (current = block_using (block);
413 current != NULL;
414 current = current->next)
415 {
416 if (strcmp (namespace, current->outer) == 0)
417 {
418 sym = cp_lookup_symbol_namespace (current->inner,
419 name,
420 linkage_name,
421 block,
422 domain,
423 symtab);
424 if (sym != NULL)
425 return sym;
426 }
427 }
428
429 /* We didn't find anything by applying any of the using directives
430 that are still applicable; so let's see if we've got a match
431 using the current namespace. */
432
433 if (namespace[0] == '\0')
434 {
435 return lookup_symbol_file (name, linkage_name, block,
436 domain, symtab, 0);
437 }
438 else
439 {
440 char *concatenated_name
441 = alloca (strlen (namespace) + 2 + strlen (name) + 1);
442 strcpy (concatenated_name, namespace);
443 strcat (concatenated_name, "::");
444 strcat (concatenated_name, name);
445 sym = lookup_symbol_file (concatenated_name, linkage_name,
446 block, domain, symtab,
447 cp_is_anonymous (namespace));
448 return sym;
449 }
450}
451
452/* Look up NAME in BLOCK's static block and in global blocks. If
453 ANONYMOUS_NAMESPACE is nonzero, the symbol in question is located
454 within an anonymous namespace. Other arguments are as in
455 cp_lookup_symbol_nonlocal. */
456
457static struct symbol *
458lookup_symbol_file (const char *name,
459 const char *linkage_name,
460 const struct block *block,
461 const domain_enum domain,
462 struct symtab **symtab,
463 int anonymous_namespace)
464{
465 struct symbol *sym = NULL;
466
467 sym = lookup_symbol_static (name, linkage_name, block, domain, symtab);
468 if (sym != NULL)
469 return sym;
470
471 if (anonymous_namespace)
472 {
473 /* Symbols defined in anonymous namespaces have external linkage
474 but should be treated as local to a single file nonetheless.
475 So we only search the current file's global block. */
476
477 const struct block *global_block = block_global_block (block);
478
479 if (global_block != NULL)
5c4e30ca
DC
480 sym = lookup_symbol_aux_block (name, linkage_name, global_block,
481 domain, symtab);
1fcb5155
DC
482 }
483 else
484 {
5c4e30ca
DC
485 sym = lookup_symbol_global (name, linkage_name, domain, symtab);
486 }
487
488 if (sym != NULL)
489 return sym;
490
491 /* Now call "lookup_possible_namespace_symbol". Symbols in here
492 claim to be associated to namespaces, but this claim might be
493 incorrect: the names in question might actually correspond to
494 classes instead of namespaces. But if they correspond to
495 classes, then we should have found a match for them above. So if
496 we find them now, they should be genuine. */
497
498 /* FIXME: carlton/2003-06-12: This is a hack and should eventually
499 be deleted: see comments below. */
500
501 if (domain == VAR_DOMAIN)
502 {
503 sym = lookup_possible_namespace_symbol (name, symtab);
504 if (sym != NULL)
505 return sym;
506 }
507
508 return NULL;
509}
510
511/* Now come functions for dealing with symbols associated to
512 namespaces. (They're used to store the namespaces themselves, not
513 objects that live in the namespaces.) These symbols come in two
514 varieties: if we run into a DW_TAG_namespace DIE, then we know that
515 we have a namespace, so dwarf2read.c creates a symbol for it just
516 like normal. But, unfortunately, versions of GCC through at least
517 3.3 don't generate those DIE's. Our solution is to try to guess
518 their existence by looking at demangled names. This might cause us
519 to misidentify classes as namespaces, however. So we put those
520 symbols in a special block (one per objfile), and we only search
521 that block as a last resort. */
522
523/* FIXME: carlton/2003-06-12: Once versions of GCC that generate
524 DW_TAG_namespace have been out for a year or two, we should get rid
525 of all of this "possible namespace" nonsense. */
526
527/* Allocate everything necessary for the possible namespace block
528 associated to OBJFILE. */
529
530static void
531initialize_namespace_symtab (struct objfile *objfile)
532{
533 struct symtab *namespace_symtab;
534 struct blockvector *bv;
535 struct block *bl;
536
537 namespace_symtab = allocate_symtab ("<<C++-namespaces>>", objfile);
538 namespace_symtab->language = language_cplus;
539 namespace_symtab->free_code = free_nothing;
540 namespace_symtab->dirname = NULL;
541
542 bv = obstack_alloc (&objfile->symbol_obstack,
543 sizeof (struct blockvector)
544 + FIRST_LOCAL_BLOCK * sizeof (struct block *));
545 BLOCKVECTOR_NBLOCKS (bv) = FIRST_LOCAL_BLOCK + 1;
546 BLOCKVECTOR (namespace_symtab) = bv;
547
548 /* Allocate empty GLOBAL_BLOCK and STATIC_BLOCK. */
549
550 bl = allocate_block (&objfile->symbol_obstack);
551 BLOCK_DICT (bl) = dict_create_linear (&objfile->symbol_obstack,
552 NULL);
553 BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK) = bl;
554 bl = allocate_block (&objfile->symbol_obstack);
555 BLOCK_DICT (bl) = dict_create_linear (&objfile->symbol_obstack,
556 NULL);
557 BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK) = bl;
558
559 /* Allocate the possible namespace block; we put it where the first
560 local block will live, though I don't think there's any need to
561 pretend that it's actually a local block (e.g. by setting
562 BLOCK_SUPERBLOCK appropriately). We don't use the global or
563 static block because we don't want it searched during the normal
564 search of all global/static blocks in lookup_symbol: we only want
565 it used as a last resort. */
566
567 /* NOTE: carlton/2003-09-11: I considered not associating the fake
568 symbols to a block/symtab at all. But that would cause problems
569 with lookup_symbol's SYMTAB argument and with block_found, so
570 having a symtab/block for this purpose seems like the best
571 solution for now. */
572
573 bl = allocate_block (&objfile->symbol_obstack);
574 BLOCK_DICT (bl) = dict_create_hashed_expandable ();
575 BLOCKVECTOR_BLOCK (bv, FIRST_LOCAL_BLOCK) = bl;
576
577 namespace_symtab->free_func = free_namespace_block;
578
579 objfile->cp_namespace_symtab = namespace_symtab;
580}
581
582/* Locate the possible namespace block associated to OBJFILE,
583 allocating it if necessary. */
584
585static struct block *
586get_possible_namespace_block (struct objfile *objfile)
587{
588 if (objfile->cp_namespace_symtab == NULL)
589 initialize_namespace_symtab (objfile);
590
591 return BLOCKVECTOR_BLOCK (BLOCKVECTOR (objfile->cp_namespace_symtab),
592 FIRST_LOCAL_BLOCK);
593}
594
595/* Free the dictionary associated to the possible namespace block. */
596
597static void
598free_namespace_block (struct symtab *symtab)
599{
600 struct block *possible_namespace_block;
601
602 possible_namespace_block = BLOCKVECTOR_BLOCK (BLOCKVECTOR (symtab),
603 FIRST_LOCAL_BLOCK);
604 gdb_assert (possible_namespace_block != NULL);
605 dict_free (BLOCK_DICT (possible_namespace_block));
606}
607
608/* Ensure that there are symbols in the possible namespace block
609 associated to OBJFILE for all initial substrings of NAME that look
610 like namespaces or classes. NAME should end in a member variable:
611 it shouldn't consist solely of namespaces. */
612
613void
614cp_check_possible_namespace_symbols (const char *name, struct objfile *objfile)
615{
616 check_possible_namespace_symbols_loop (name,
617 cp_find_first_component (name),
618 objfile);
619}
620
621/* This is a helper loop for cp_check_possible_namespace_symbols; it
622 ensures that there are symbols in the possible namespace block
623 associated to OBJFILE for all namespaces that are initial
624 substrings of NAME of length at least LEN. It returns 1 if a
625 previous loop had already created the shortest such symbol and 0
626 otherwise.
627
628 This function assumes that if there is already a symbol associated
629 to a substring of NAME of a given length, then there are already
630 symbols associated to all substrings of NAME whose length is less
631 than that length. So if cp_check_possible_namespace_symbols has
632 been called once with argument "A::B::C::member", then that will
633 create symbols "A", "A::B", and "A::B::C". If it is then later
634 called with argument "A::B::D::member", then the new call will
635 generate a new symbol for "A::B::D", but once it sees that "A::B"
636 has already been created, it doesn't bother checking to see if "A"
637 has also been created. */
638
639static int
640check_possible_namespace_symbols_loop (const char *name, int len,
641 struct objfile *objfile)
642{
643 if (name[len] == ':')
644 {
645 int done;
646 int next_len = len + 2;
647
648 next_len += cp_find_first_component (name + next_len);
649 done = check_possible_namespace_symbols_loop (name, next_len,
650 objfile);
651
652 if (!done)
653 done = check_one_possible_namespace_symbol (name, len, objfile);
654
655 return done;
1fcb5155 656 }
5c4e30ca
DC
657 else
658 return 0;
659}
660
661/* Check to see if there's already a possible namespace symbol in
662 OBJFILE whose name is the initial substring of NAME of length LEN.
663 If not, create one and return 0; otherwise, return 1. */
664
665static int
666check_one_possible_namespace_symbol (const char *name, int len,
667 struct objfile *objfile)
668{
669 struct block *block = get_possible_namespace_block (objfile);
670 char *name_copy = obsavestring (name, len, &objfile->symbol_obstack);
671 struct symbol *sym = lookup_block_symbol (block, name_copy, NULL,
672 VAR_DOMAIN);
673
674 if (sym == NULL)
675 {
676 struct type *type = init_type (TYPE_CODE_NAMESPACE, 0, 0,
677 name_copy, objfile);
678 TYPE_TAG_NAME (type) = TYPE_NAME (type);
679
680 sym = obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
681 memset (sym, 0, sizeof (struct symbol));
682 SYMBOL_LANGUAGE (sym) = language_cplus;
683 SYMBOL_SET_NAMES (sym, name_copy, len, objfile);
684 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
685 SYMBOL_TYPE (sym) = type;
686 SYMBOL_DOMAIN (sym) = VAR_DOMAIN;
687
688 dict_add_symbol (BLOCK_DICT (block), sym);
689
690 return 0;
691 }
692 else
693 {
694 obstack_free (&objfile->symbol_obstack, name_copy);
695
696 return 1;
697 }
698}
699
700/* Look for a symbol named NAME in all the possible namespace blocks.
701 If one is found, return it; if SYMTAB is non-NULL, set *SYMTAB to
702 equal the symtab where it was found. */
703
704static struct symbol *
705lookup_possible_namespace_symbol (const char *name, struct symtab **symtab)
706{
707 struct objfile *objfile;
708
709 ALL_OBJFILES (objfile)
710 {
711 struct symbol *sym;
712
713 sym = lookup_block_symbol (get_possible_namespace_block (objfile),
714 name, NULL, VAR_DOMAIN);
715
716 if (sym != NULL)
717 {
718 if (symtab != NULL)
719 *symtab = objfile->cp_namespace_symtab;
720
721 return sym;
722 }
723 }
724
725 return NULL;
726}
727
728/* Print out all the possible namespace symbols. */
729
730static void
731maintenance_cplus_namespace (char *args, int from_tty)
732{
733 struct objfile *objfile;
734 printf_unfiltered ("Possible namespaces:\n");
735 ALL_OBJFILES (objfile)
736 {
737 struct dict_iterator iter;
738 struct symbol *sym;
739
740 ALL_BLOCK_SYMBOLS (get_possible_namespace_block (objfile), iter, sym)
741 {
742 printf_unfiltered ("%s\n", SYMBOL_PRINT_NAME (sym));
743 }
744 }
745}
746
747void
748_initialize_cp_namespace (void)
749{
750 add_cmd ("namespace", class_maintenance, maintenance_cplus_namespace,
751 "Print the list of possible C++ namespaces.",
752 &maint_cplus_cmd_list);
1fcb5155 753}