diff options
author | David Carlton <carlton@bactrian.org> | 2003-01-07 01:28:24 +0000 |
---|---|---|
committer | David Carlton <carlton@bactrian.org> | 2003-01-07 01:28:24 +0000 |
commit | 57852209eee94fadacb1e68710446540bbea4780 (patch) | |
tree | cb3051cdb3093d424fd4202a85bc35f0a69c9cd9 /gdb | |
parent | de4bdf83a9693d35178e5e0680b4a5b0c3f23e0d (diff) | |
download | gdb-57852209eee94fadacb1e68710446540bbea4780.zip gdb-57852209eee94fadacb1e68710446540bbea4780.tar.gz gdb-57852209eee94fadacb1e68710446540bbea4780.tar.bz2 |
2003-01-06 David Carlton <carlton@math.stanford.edu>
* config/djgpp/fnchange.lst: Mention
testsuite/gdb.c++/namespace1.cc.
* cp-support.h: Declare cp_lookup_namespace_symbol.
* cp-support.c (cp_lookup_namespace_symbol): New function.
(cp_check_namespace_symbol): Call cp_lookup_namespace_symbol.
(cp_lookup_possible_namespace_symbol): Update comment.
* symtab.c (lookup_symbol_aux_file): Add 'anonymous_namespace'
argument.
(lookup_symbol_namespace): Call lookup_symbol_aux_file with new
argument.
* cp-support.h: Declare cp_is_anonymous.
* cp-support.c (cp_is_anonymous): New function.
* buildsym.c (add_symbol_to_list): Don't test for anonymous
namespace mention here.
(scan_for_anonymous_namespaces): Test for it here, instead.
* symtab.c (lookup_symbol_aux_minsyms): Delete.
(lookup_symbol_aux_nonlocal): Don't call
lookup_symbol_aux_minsyms.
2003-01-06 David Carlton <carlton@math.stanford.edu>
* gdb.c++/namespace.exp: Test anonymous namespaces and multiple
files.
* gdb.c++/namespace1.cc: Add anonymous namespaces.
Diffstat (limited to 'gdb')
-rw-r--r-- | gdb/ChangeLog | 21 | ||||
-rw-r--r-- | gdb/buildsym.c | 17 | ||||
-rw-r--r-- | gdb/config/djgpp/fnchange.lst | 1 | ||||
-rw-r--r-- | gdb/cp-support.c | 38 | ||||
-rw-r--r-- | gdb/cp-support.h | 4 | ||||
-rw-r--r-- | gdb/symtab.c | 201 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/testsuite/gdb.c++/namespace.exp | 2 | ||||
-rw-r--r-- | gdb/testsuite/gdb.c++/namespace1.cc | 8 |
9 files changed, 124 insertions, 174 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index fc443c0..654bf4b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,24 @@ +2003-01-06 David Carlton <carlton@math.stanford.edu> + + * config/djgpp/fnchange.lst: Mention + testsuite/gdb.c++/namespace1.cc. + * cp-support.h: Declare cp_lookup_namespace_symbol. + * cp-support.c (cp_lookup_namespace_symbol): New function. + (cp_check_namespace_symbol): Call cp_lookup_namespace_symbol. + (cp_lookup_possible_namespace_symbol): Update comment. + * symtab.c (lookup_symbol_aux_file): Add 'anonymous_namespace' + argument. + (lookup_symbol_namespace): Call lookup_symbol_aux_file with new + argument. + * cp-support.h: Declare cp_is_anonymous. + * cp-support.c (cp_is_anonymous): New function. + * buildsym.c (add_symbol_to_list): Don't test for anonymous + namespace mention here. + (scan_for_anonymous_namespaces): Test for it here, instead. + * symtab.c (lookup_symbol_aux_minsyms): Delete. + (lookup_symbol_aux_nonlocal): Don't call + lookup_symbol_aux_minsyms. + 2002-12-24 David Carlton <carlton@math.stanford.edu> * MAINTAINERS: Delete OBSOLETE targets. diff --git a/gdb/buildsym.c b/gdb/buildsym.c index 66650bd..065e078 100644 --- a/gdb/buildsym.c +++ b/gdb/buildsym.c @@ -146,9 +146,7 @@ add_symbol_to_list (struct symbol *symbol, struct pending **listhead) if (SYMBOL_LANGUAGE (symbol) == language_cplus && !processing_has_namespace_info - && SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL - && strstr (SYMBOL_CPLUS_DEMANGLED_NAME (symbol), - "(anonymous namespace)") != NULL) + && SYMBOL_CPLUS_DEMANGLED_NAME (symbol) != NULL) scan_for_anonymous_namespaces (symbol); } @@ -163,8 +161,17 @@ static void scan_for_anonymous_namespaces (struct symbol *symbol) { const char *name = SYMBOL_CPLUS_DEMANGLED_NAME (symbol); - const char *beginning = name; - const char *end = cp_find_first_component (beginning); + const char *beginning; + const char *end; + + /* Start with a quick-and-dirty check for mention of "(anonymous + namespace)". */ + + if (!cp_is_anonymous (name, -1)) + return; + + beginning = name; + end = cp_find_first_component (beginning); while (*end == ':') { diff --git a/gdb/config/djgpp/fnchange.lst b/gdb/config/djgpp/fnchange.lst index 046b065..7c6ab43 100644 --- a/gdb/config/djgpp/fnchange.lst +++ b/gdb/config/djgpp/fnchange.lst @@ -234,6 +234,7 @@ @V@/gdb/testsuite/gdb.c++/misc.cc @V@/gdb/testsuite/gdb.cxx/misc.cc @V@/gdb/testsuite/gdb.c++/misc.exp @V@/gdb/testsuite/gdb.cxx/misc.exp @V@/gdb/testsuite/gdb.c++/namespace.cc @V@/gdb/testsuite/gdb.cxx/namespace.cc +@V@/gdb/testsuite/gdb.c++/namespace1.cc @V@/gdb/testsuite/gdb.cxx/namesp1.cc @V@/gdb/testsuite/gdb.c++/namespace.exp @V@/gdb/testsuite/gdb.cxx/namespace.exp @V@/gdb/testsuite/gdb.c++/overload.cc @V@/gdb/testsuite/gdb.cxx/overload.cc @V@/gdb/testsuite/gdb.c++/overload.exp @V@/gdb/testsuite/gdb.cxx/overload.exp diff --git a/gdb/cp-support.c b/gdb/cp-support.c index c37819b..d910705 100644 --- a/gdb/cp-support.c +++ b/gdb/cp-support.c @@ -494,9 +494,7 @@ cp_check_namespace_symbol (const char *name, int len) { struct objfile *objfile = get_namespace_objfile (); char *name_copy = obsavestring (name, len, &objfile->symbol_obstack); - const struct block *block = get_namespace_block (); - struct symbol *sym = lookup_block_symbol (block, name_copy, - NULL, VAR_NAMESPACE); + struct symbol *sym = cp_lookup_namespace_symbol (name_copy); if (sym == NULL) { @@ -512,7 +510,7 @@ cp_check_namespace_symbol (const char *name, int len) SYMBOL_TYPE (sym) = type; SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE; - dict_add_symbol (BLOCK_DICT (block), sym); + dict_add_symbol (BLOCK_DICT (get_namespace_block ()), sym); } else { @@ -522,6 +520,15 @@ cp_check_namespace_symbol (const char *name, int len) return sym; } +/* Look for a symbol in namespace_block named NAME. */ + +struct symbol * +cp_lookup_namespace_symbol (const char *name) +{ + return lookup_block_symbol (get_namespace_block (), name, NULL, + VAR_NAMESPACE); +} + /* The next few functions deal with "possible namespace symbols". These are symbols that claim to be associated to namespaces, whereas in fact we don't know if the object of that name is a @@ -609,10 +616,7 @@ cp_check_possible_namespace_symbols (const char *name) - name); } -/* Look up a symbol in possible_namespace_block named NAME. Note that - there's no corresponding function for regular namespace symbols: - those get searched via the normal search of all global blocks in - lookup_symbol. */ +/* Look for a symbol in possible_namespace_block named NAME. */ struct symbol * cp_lookup_possible_namespace_symbol (const char *name) @@ -642,6 +646,24 @@ maintenance_print_namespace (char *args, int from_tty) } } +/* Test whether or not the initial substring of NAMESPACE_NAME of + length NAMESPACE_LEN mentions an anonymous namespace. + NAMESPACE_NAME must be a NULL-terminated string. If NAMESPACE_LEN + is -1, search the entire string. */ + +int +cp_is_anonymous (const char *namespace_name, int namespace_len) +{ + const char *location = strstr (namespace_name, "(anonymous namespace)"); + + if (location == NULL) + return 0; + else if (namespace_len == -1) + return 1; + else + return (location - namespace_name) < namespace_len; +} + void _initialize_cp_support (void) { diff --git a/gdb/cp-support.h b/gdb/cp-support.h index 09fdd5e..f14cf99 100644 --- a/gdb/cp-support.h +++ b/gdb/cp-support.h @@ -101,6 +101,10 @@ extern void cp_free_usings (struct using_direct_node *using); extern struct symbol *cp_check_namespace_symbol (const char *name, int len); +extern struct symbol *cp_lookup_namespace_symbol (const char *name); + extern void cp_check_possible_namespace_symbols (const char *name); extern struct symbol *cp_lookup_possible_namespace_symbol (const char *name); + +extern int cp_is_anonymous (const char *namespace_name, int namespace_len); diff --git a/gdb/symtab.c b/gdb/symtab.c index d92a696..33baa65 100644 --- a/gdb/symtab.c +++ b/gdb/symtab.c @@ -114,7 +114,8 @@ struct symbol *lookup_symbol_aux_file (const char *name, const char *linkage_name, const struct block *block, const namespace_enum namespace, - struct symtab **symtab); + struct symtab **symtab, + int anonymous_namespace); static struct symbol *lookup_symbol_aux_symtabs (int block_index, @@ -146,13 +147,6 @@ struct symbol *lookup_symbol_aux_using_loop (const char *name, const char *scope, int scope_len); -static -struct symbol *lookup_symbol_aux_minsyms (int block_index, - const char *name, - const char *linkage_name, - const namespace_enum namespace, - struct symtab **symtab); - static struct symbol *find_active_alias (struct symbol *sym, CORE_ADDR addr); /* This flag is used in hppa-tdep.c, and set in hp-symtab-read.c */ @@ -1005,75 +999,27 @@ lookup_symbol_aux_nonlocal (int block_index, if (sym != NULL) return sym; -#ifndef HPUXHPPA - sym = lookup_symbol_aux_minsyms (block_index, name, linkage_name, - namespace, symtab); - if (sym != NULL) - return sym; -#endif - sym = lookup_symbol_aux_psymtabs (block_index, name, linkage_name, namespace, symtab); if (sym != NULL) return sym; -#ifdef HPUXHPPA - - /* FIXME: carlton/2002-10-28: The following comment was present in - lookup_symbol_aux before I broke it up: at that time, the HP - search order for nonlocal stuff was global symtab, global - psymtab, static symtab, static psymtab, global and static - minsyms. (The minsyms are stored so that it's just as easy to do - global and static searches of them at the same time.) Now it's - global symtab, global psymtab, global minsyms, static symtab, - static psymtab, static minsyms. Also, it's now impossible for a - global minsym search to cause a NULL return by itself: if a - minsym search returns NULL, then the next search after that is - still performed. - - Given that that's the case, I'm pretty sure that my search order - is safe; indeed, given that the comment below warns against - premature NULL returns, it even seems plausible to me that we can - treat HP symbol tables the same as non-HP symbol tables. It - would be great if somebody who has access to HP machines (or, - even better, who understands the reason behind the HP special - case in the first place) could check on this. - - But there's still the comment about "foo_" symbols in - lookup_symbol_aux_minsyms which I really don't understand, sigh. - _Should_ a minsym lookup sometimes be able to force a NULL return - from lookup_symbol? */ - - /* RT: I moved this check to last, after the complete search of the - global (p)symtab's and static (p)symtab's. For HP-generated - symbol tables, this check was causing a premature exit from - lookup_symbol with NULL return, and thus messing up symbol - lookups of things like "c::f". It seems to me a check of the - minimal symbol table ought to be a last resort in any case. I'm - vaguely worried about the comment within - lookup_symbol_aux_minsyms which talks about FORTRAN routines - "foo_" though... is it saying we need to do the "minsym" check - before the static check in this case? */ - - sym = lookup_symbol_aux_minsyms (block_index, name, linkage_name, - namespace, symtab); - if (sym != NULL) - return sym; -#endif - return NULL; } -/* Look up NAME in BLOCK's static block and in global blocks. */ +/* Look up NAME in BLOCK's static block and in global blocks. If + ANONYMOUS_NAMESPACE is nonzero, don't look in other files' global + blocks, just in the one belonging to this file. */ static struct symbol * lookup_symbol_aux_file (const char *name, const char *linkage_name, const struct block *block, const namespace_enum namespace, - struct symtab **symtab) + struct symtab **symtab, + int anonymous_namespace) { - struct symbol *sym; + struct symbol *sym = NULL; const struct block *static_block = block_static_block (block); if (static_block != NULL) @@ -1084,8 +1030,26 @@ lookup_symbol_aux_file (const char *name, return sym; } - sym = lookup_symbol_aux_nonlocal (GLOBAL_BLOCK, name, linkage_name, - namespace, symtab); + if (anonymous_namespace) + { + const struct block *global_block = NULL; + if (static_block != NULL) + global_block = BLOCK_SUPERBLOCK (static_block); + else if (block != NULL) + global_block = block; + + if (global_block != NULL) + sym = lookup_symbol_aux_block (name, linkage_name, global_block, + namespace, symtab); + + if (sym == NULL || global_block == NULL) + sym = cp_lookup_namespace_symbol (name); + } + else + { + sym = lookup_symbol_aux_nonlocal (GLOBAL_BLOCK, name, linkage_name, + namespace, symtab); + } if (sym != NULL) return sym; @@ -1100,6 +1064,13 @@ lookup_symbol_aux_file (const char *name, /* FIXME: carlton/2002-12-18: This is a hack and should eventually be deleted: see cp-support.c. */ + /* FIXME: carlton/2003-01-06: Searching this seems a bit fishy if + anonymous_namespace is nonzero, since we might return a namespace + that's really a class that doesn't happen to be mentioned in the + current file. Sigh. Still, I don't think anything catastrophic + should happen in that case. Probably the right thing to do is to + move anonymous namespace symbols to files' static blocks. */ + if (namespace == VAR_NAMESPACE) { sym = cp_lookup_possible_namespace_symbol (name); @@ -1314,7 +1285,8 @@ lookup_symbol_namespace (const char *namespace_name, if (namespace_len == 0) { return lookup_symbol_aux_file (name, linkage_name, block, - name_space, symtab); + name_space, symtab, + 0); } else { @@ -1324,108 +1296,15 @@ lookup_symbol_namespace (const char *namespace_name, strcpy (concatenated_name + namespace_len, "::"); strcpy (concatenated_name + namespace_len + 2, name); sym = lookup_symbol_aux_file (concatenated_name, linkage_name, - block, name_space, symtab); + block, name_space, symtab, + cp_is_anonymous (namespace_name, + namespace_len)); xfree (concatenated_name); return sym; } } -/* Check for the possibility of the symbol being a function that is - stored in one of the minimal symbol tables. */ - -static struct symbol * -lookup_symbol_aux_minsyms (int block_index, const char *name, - const char *linkage_name, - const namespace_enum namespace, - struct symtab **symtab) -{ - struct symbol *sym; - struct blockvector *bv; - const struct block *block; - struct minimal_symbol *msymbol; - struct symtab *s; - - if (namespace == VAR_NAMESPACE) - { - msymbol = lookup_minimal_symbol (name, NULL, NULL); - if (msymbol != NULL) - { - /* OK, we found a minimal symbol in spite of not finding any - symbol. There are various possible explanations for - this. One possibility is the symbol exists in code not - compiled -g. Another possibility is that the 'psymtab' - isn't doing its job. A third possibility, related to #2, - is that we were confused by name-mangling. For instance, - maybe the psymtab isn't doing its job because it only - know about demangled names, but we were given a mangled - name... */ - - /* First, check to see that the symbol looks like it's - global or static (depending on what we were asked to look - for). */ - - /* NOTE: carlton/2002-10-28: lookup_minimal_symbol gives - preference to global symbols over static symbols, so if - block_index is STATIC_BLOCK then this might well miss - static symbols that are shadowed by global symbols. But - that's okay: this is only called with block_index equal - to STATIC_BLOCK if a global search has failed. */ - - if (minsym_static (msymbol)) - { - if (block_index == GLOBAL_BLOCK) - return NULL; - } - else - { - if (block_index == STATIC_BLOCK) - return NULL; - } - - /* We next use the address in the msymbol to try to locate - the appropriate symtab. Note that find_pc_sect_symtab() - has a side-effect of doing psymtab-to-symtab expansion, - for the found symtab. */ - s = find_pc_sect_symtab (SYMBOL_VALUE_ADDRESS (msymbol), - SYMBOL_BFD_SECTION (msymbol)); - if (s != NULL) - { - /* This is a function which has a symtab for its address. */ - bv = BLOCKVECTOR (s); - block = BLOCKVECTOR_BLOCK (bv, block_index); - - /* This call used to pass `SYMBOL_NAME (msymbol)' as the - `name' argument to lookup_block_symbol. But the name - of a minimal symbol is always mangled, so that seems - to be clearly the wrong thing to pass as the - unmangled name. */ - sym = - lookup_block_symbol (block, name, linkage_name, namespace); - - /* sym == 0 if symbol was found in the minimal symbol table - but not in the symtab. - Return 0 to use the msymbol definition of "foo_". - - This happens for Fortran "foo_" symbols, - which are "foo" in the symtab. - - This can also happen if "asm" is used to make a - regular symbol but not a debugging symbol, e.g. - asm(".globl _main"); - asm("_main:"); - */ - - if (symtab != NULL) - *symtab = s; - return fixup_symbol_section (sym, s->objfile); - } - } - } - - return NULL; -} - /* Lookup the symbol associated to a minimal symbol, if there is one. */ struct symbol * diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index c3372c7..d5e3fc8 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,9 @@ +2003-01-06 David Carlton <carlton@math.stanford.edu> + + * gdb.c++/namespace.exp: Test anonymous namespaces and multiple + files. + * gdb.c++/namespace1.cc: Add anonymous namespaces. + 2002-12-23 David Carlton <carlton@math.stanford.edu> * gdb.base/selftest.exp (do_steps_and_nexts): Allow initial brace diff --git a/gdb/testsuite/gdb.c++/namespace.exp b/gdb/testsuite/gdb.c++/namespace.exp index 78775b1..57b7f32 100644 --- a/gdb/testsuite/gdb.c++/namespace.exp +++ b/gdb/testsuite/gdb.c++/namespace.exp @@ -274,6 +274,8 @@ gdb_test "print X" "\\$\[0-9\].* = 9" gdb_test "print 'G::Xg'" "\\$\[0-9\].* = 10" gdb_test "print G::Xg" "\\$\[0-9\].* = 10" gdb_test "print G::XgX" "\\$\[0-9\].* = 11" +gdb_test "print cXOtherFile" "No symbol \"cXOtherFile\" in current context." +gdb_test "print XOtherFile" "No symbol \"XOtherFile\" in current context." # Test namespace renaming. diff --git a/gdb/testsuite/gdb.c++/namespace1.cc b/gdb/testsuite/gdb.c++/namespace1.cc index ac4703c..6d9a0e0 100644 --- a/gdb/testsuite/gdb.c++/namespace1.cc +++ b/gdb/testsuite/gdb.c++/namespace1.cc @@ -4,4 +4,12 @@ namespace C public: int z; }; + + namespace { + int cXOtherFile = 29; + }; +} + +namespace { + int XOtherFile = 317; } |