]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
2003-01-06 David Carlton <carlton@math.stanford.edu>
authorDavid Carlton <carlton@bactrian.org>
Tue, 7 Jan 2003 01:28:24 +0000 (01:28 +0000)
committerDavid Carlton <carlton@bactrian.org>
Tue, 7 Jan 2003 01:28:24 +0000 (01:28 +0000)
* 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.

gdb/ChangeLog
gdb/buildsym.c
gdb/config/djgpp/fnchange.lst
gdb/cp-support.c
gdb/cp-support.h
gdb/symtab.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.c++/namespace.exp
gdb/testsuite/gdb.c++/namespace1.cc

index fc443c05bb4dc3e34287d8b9da6b7f61f0d990e0..654bf4bfb04cf7278df2851f7282b4be17118771 100644 (file)
@@ -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.
index 66650bd9bb98917cef5a351406ca28ebb791221c..065e078f892f6ad9c72bc4631eb53a5cce72215b 100644 (file)
@@ -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 == ':')
     {
index 046b0651cad8b77c23631e014dcb99b03de2525e..7c6ab439e6427ae4f11ec5920d51fe9adc5f6376 100644 (file)
 @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
index c37819b796f83133c7cf8644cc9dbced7655f824..d91070515c8b6bad99ed1631c368db66a8546335 100644 (file)
@@ -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)
 {
index 09fdd5ef69a65e0300243d849b416af0894fe64a..f14cf994e3cd231cc04c829eae0bb00ea6c2e059 100644 (file)
@@ -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);
index d92a696840bfd3432ff05ae893c46b75d32f7b30..33baa65b8a3fc292b87237b46e0c8fd231f0deec 100644 (file)
@@ -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 *
index c3372c7ebebae66f9220d42c8bd57660eb15ae15..d5e3fc8beb9ad281f3454da87842b0981e880e82 100644 (file)
@@ -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
index 78775b185717dae6722a838a8cd3dcb796b2b585..57b7f32050284c916e69aec429e4b3b598d9cf95 100644 (file)
@@ -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.
 
index ac4703cd4050dc9cc7c0511cf80092f4b9f4af48..6d9a0e0151ddfc6a92cfae5b07bada87adb3f72e 100644 (file)
@@ -4,4 +4,12 @@ namespace C
   public:
     int z;
   };
+
+  namespace {
+    int cXOtherFile = 29;
+  };
+}
+
+namespace {
+  int XOtherFile = 317;
 }