]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
2002-11-21 David Carlton <carlton@math.stanford.edu>
authorDavid Carlton <carlton@bactrian.org>
Fri, 22 Nov 2002 01:16:14 +0000 (01:16 +0000)
committerDavid Carlton <carlton@bactrian.org>
Fri, 22 Nov 2002 01:16:14 +0000 (01:16 +0000)
* cp-support.c (get_namespace_objfile): Set
namespace_objfile->name.
* dwarf2read.c (scan_partial_symbols): Allow empty pdi.name if
we're reading a namespace.
* Makefile.in (dwarf2read.o): Depend on cp_support_h.
* dwarf2read.c (scan_partial_symbols): Add 'namespace' arg.
(dwarf2_build_psymtabs_hard): Update call to
scan_partial_symbols.
(add_partial_namespace): New function.
(scan_partial_symbols): Call add_partial_namespace.
#include "cp-support.h"
* cp-support.c: Add me to contributors.
* cp-support.h: Ditto.
* buildsym.c (scan_for_anonymous_namespaces): Convert for loop
into a clearer while loop.
(finish_block): Ditto.

gdb/ChangeLog
gdb/Makefile.in
gdb/buildsym.c
gdb/cp-support.c
gdb/cp-support.h
gdb/dwarf2read.c
gdb/testsuite/ChangeLog
gdb/testsuite/carlton_runnamespace

index 8b3908f4c917ab53c400e03e3de9a7fb98c9aeb5..1fd22cf9e8a6226e2c13fe6e588177434bdad03b 100644 (file)
@@ -1,3 +1,22 @@
+2002-11-21  David Carlton  <carlton@math.stanford.edu>
+
+       * cp-support.c (get_namespace_objfile): Set
+       namespace_objfile->name.
+       * dwarf2read.c (scan_partial_symbols): Allow empty pdi.name if
+       we're reading a namespace.
+       * Makefile.in (dwarf2read.o): Depend on cp_support_h.
+       * dwarf2read.c (scan_partial_symbols): Add 'namespace' arg.
+       (dwarf2_build_psymtabs_hard): Update call to
+       scan_partial_symbols.
+       (add_partial_namespace): New function.
+       (scan_partial_symbols): Call add_partial_namespace.
+       #include "cp-support.h"
+       * cp-support.c: Add me to contributors.
+       * cp-support.h: Ditto.
+       * buildsym.c (scan_for_anonymous_namespaces): Convert for loop
+       into a clearer while loop.
+       (finish_block): Ditto.
+
 2002-11-20  David Carlton  <carlton@math.stanford.edu>
 
        * dwarf2read.c (scan_partial_symbols): Move lowpc, highpc initial
index 625fc1b46c6beefa6849966a2d338a2fc4920719..7d3f96c56180b4b65d3d6caa6cd27ff47f7f8cd0 100644 (file)
@@ -1657,7 +1657,7 @@ dwarf2read.o: dwarf2read.c $(defs_h) $(bfd_h) $(symtab_h) $(gdbtypes_h) \
        $(symfile_h) $(objfiles_h) $(elf_dwarf2_h) $(buildsym_h) \
        $(demangle_h) $(expression_h) $(filenames_h) $(macrotab_h) \
        $(language_h) $(complaints_h) $(bcache_h) $(gdb_string_h) \
-       $(gdb_assert_h)
+       $(gdb_assert_h) $(cp_support_h)
 dwarfread.o: dwarfread.c $(defs_h) $(symtab_h) $(gdbtypes_h) $(symfile_h) \
        $(objfiles_h) $(elf_dwarf_h) $(buildsym_h) $(demangle_h) \
        $(expression_h) $(language_h) $(complaints_h) $(gdb_string_h)
index 311bc96b0f7ad1821d63243ae8aed31a844536dd..7d5009baa1b203a44995b102f0f5a21d186dad45 100644 (file)
@@ -179,23 +179,26 @@ static void
 scan_for_anonymous_namespaces (struct symbol *symbol)
 {
   const char *name = SYMBOL_CPLUS_DEMANGLED_NAME (symbol);
-  const char *beginning, *end;
+  const char *beginning = name;
+  const char *end = cp_find_first_component (beginning);
 
-  for (beginning = name, end = cp_find_first_component (name);
-       *end == ':';
-       /* The "+ 2" is for the "::"-.  */
-       beginning = end + 2, end = cp_find_first_component (beginning))
+  while (*end == ':')
     {
       if ((end - beginning) == ANONYMOUS_NAMESPACE_LEN
          && strncmp (beginning, "(anonymous namespace)",
                      ANONYMOUS_NAMESPACE_LEN) == 0)
-       /* We've found a component of the name that's an anonymous
-          namespace.  So add symbols in it to the namespace given by
-          the previous component if there is one, or to the global
-          namespace if there isn't.  */
-       add_using_directive (name,
-                            beginning == name ? 0 : beginning - name - 2,
-                            end - name);
+       {
+         /* We've found a component of the name that's an anonymous
+            namespace.  So add symbols in it to the namespace given
+            by the previous component if there is one, or to the
+            global namespace if there isn't.  */
+         add_using_directive (name,
+                              beginning == name ? 0 : beginning - name - 2,
+                              end - name);
+       }
+      /* The "+ 2" is for the "::".  */
+       beginning = end + 2;
+       end = cp_find_first_component (beginning);
     }
 }
 
@@ -458,13 +461,15 @@ finish_block (struct symbol *symbol, struct pending **listhead,
              /* FIXME: carlton/2002-11-14: For members of classes,
                 with this include the class name as well?  I don't
                 think that's a problem yet, but it will be.  */
-             
-             for (current = name, next = cp_find_first_component (current);
-                  *next == ':';
-                  /* The '+ 2' is to skip the '::'.  */
-                  current = next,
-                    next = cp_find_first_component (current + 2))
-               ;
+
+             current = name;
+             next = cp_find_first_component (current);
+             while (*next == ':')
+               {
+                 current = next;
+                 /* The '+ 2' is to skip the '::'.  */
+                 next = cp_find_first_component (current + 2);
+               }
              if (current == name)
                block_set_scope (block, "", &objfile->symbol_obstack);
              else
index 0efb1d855491c5c8f16d5261e8403c38cda15c6a..dc56d88c17b9cd7b76c0d37cb8ece2369b7cb626 100644 (file)
@@ -1,7 +1,8 @@
 /* Helper routines for C++ support in GDB.
    Copyright 2002 Free Software Foundation, Inc.
 
-   Contributed by MontaVista Software.
+   Contributed by MontaVista Software and by David Carlton, Stanford
+   University.
 
    This file is part of GDB.
 
@@ -440,6 +441,7 @@ get_namespace_objfile (void)
   if (namespace_objfile == NULL)
     {
       namespace_objfile = allocate_objfile (NULL, 0);
+      namespace_objfile->name = "<C++-namespaces>";
     }
 
   return namespace_objfile;
index 5d7b4af8ea512a9f4770832957805d2ab73175f5..324728722111d17eb709aa68681977ef81056367 100644 (file)
@@ -1,7 +1,8 @@
 /* Helper routines for C++ support in GDB.
    Copyright 2002 Free Software Foundation, Inc.
 
-   Contributed by MontaVista Software.
+   Contributed by MontaVista Software and by David Carlton, Stanford
+   University.
 
    This file is part of GDB.
 
index 281e2e996c2df6b83b397112f5e6e7c5ae81871f..07375390cfa5b4425e2a57dd6778432cd8c94346 100644 (file)
@@ -46,6 +46,7 @@
 #include "gdb_string.h"
 #include "gdb_assert.h"
 #include <sys/types.h>
+#include "cp-support.h"
 
 #ifndef DWARF2_REG_TO_REGNUM
 #define DWARF2_REG_TO_REGNUM(REG) (REG)
@@ -706,11 +707,19 @@ static void dwarf2_build_psymtabs_hard (struct objfile *, int);
 
 static char *scan_partial_symbols (char *, struct objfile *,
                                   CORE_ADDR *, CORE_ADDR *,
-                                  const struct comp_unit_head *);
+                                  const struct comp_unit_head *,
+                                  const char *namespace);
 
 static void add_partial_symbol (struct partial_die_info *, struct objfile *,
                                const struct comp_unit_head *);
 
+static char *add_partial_namespace (struct partial_die_info *pdi,
+                                   char *info_ptr,
+                                   struct objfile *objfile,
+                                   CORE_ADDR *lowpc, CORE_ADDR *highpc,
+                                   const struct comp_unit_head *cu_header,
+                                   const char *namespace);
+
 static void dwarf2_psymtab_to_symtab (struct partial_symtab *);
 
 static void psymtab_to_symtab_1 (struct partial_symtab *);
@@ -1300,7 +1309,7 @@ dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
          highpc = ((CORE_ADDR) 0);
 
          info_ptr = scan_partial_symbols (info_ptr, objfile, &lowpc, &highpc,
-                                          &cu_header);
+                                          &cu_header, NULL);
 
          /* If we didn't find a lowpc, set it to highpc to avoid
             complaints from `maint check'.  */
@@ -1336,12 +1345,17 @@ dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
 }
 
 /* Read in all interesting dies to the end of the compilation unit or
-   to the end of the current namespace.  */
+   to the end of the current namespace.  NAMESPACE is NULL if we
+   haven't yet encountered any DW_TAG_namespace entries; otherwise,
+   it's the name of the current namespace.  (In particular, it's the
+   empty string if we're currently in the global namespace but have
+   previously encountered a DW_TAG_namespace.)  */
 
 static char *
 scan_partial_symbols (char *info_ptr, struct objfile *objfile,
                      CORE_ADDR *lowpc, CORE_ADDR *highpc,
-                     const struct comp_unit_head *cu_header)
+                     const struct comp_unit_head *cu_header,
+                     const char *namespace)
 {
   bfd *abfd = objfile->obfd;
   struct partial_die_info pdi;
@@ -1358,7 +1372,9 @@ scan_partial_symbols (char *info_ptr, struct objfile *objfile,
     {
       info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu_header);
 
-      if (pdi.name)
+      /* Anonymous namespaces have no name but are interesting.  */
+
+      if (pdi.name != NULL || pdi.tag == DW_TAG_namespace)
        {
          switch (pdi.tag)
            {
@@ -1407,10 +1423,14 @@ scan_partial_symbols (char *info_ptr, struct objfile *objfile,
                add_partial_symbol (&pdi, objfile, cu_header);
              break;
            case DW_TAG_namespace:
-             if (pdi.has_children)
-               info_ptr = scan_partial_symbols (info_ptr, objfile,
-                                                lowpc, highpc,
-                                                cu_header);
+             /* We've hit a DW_TAG_namespace entry, so we know this
+                file has been compiled using a compiler that
+                generates them; update NAMESPACE to reflect that.  */
+             if (namespace == NULL)
+               namespace = "";
+             info_ptr = add_partial_namespace (&pdi, info_ptr, objfile,
+                                               lowpc, highpc, cu_header,
+                                               namespace);
            default:
              break;
            }
@@ -1418,7 +1438,7 @@ scan_partial_symbols (char *info_ptr, struct objfile *objfile,
 
       /* If the die has a sibling, skip to the sibling.  Do not skip
          enumeration types, we want to record their enumerators.  Do
-         not skip namespaces, the scan_partial_symbols call has
+         not skip namespaces, the add_partial_namespace call has
          already updated info_ptr for us.  */
       if (pdi.sibling
          && pdi.tag != DW_TAG_enumeration_type
@@ -1426,7 +1446,7 @@ scan_partial_symbols (char *info_ptr, struct objfile *objfile,
        {
          info_ptr = pdi.sibling;
        }
-      else if (pdi.has_children)
+      else if (pdi.has_children && pdi.tag != DW_TAG_namespace)
        {
          /* Die has children, but either the optional DW_AT_sibling
             attribute is missing or we want to look at them.  */
@@ -1548,6 +1568,43 @@ add_partial_symbol (struct partial_die_info *pdi, struct objfile *objfile,
     }
 }
 
+/* Read a partial die corresponding to a namespace; also, add a symbol
+   corresponding to that namespace to the symbol table.  NAMESPACE is
+   the name of the enclosing namespace.  */
+
+static char *
+add_partial_namespace (struct partial_die_info *pdi, char *info_ptr,
+                      struct objfile *objfile,
+                      CORE_ADDR *lowpc, CORE_ADDR *highpc,
+                      const struct comp_unit_head *cu_header,
+                      const char *namespace)
+{
+  /* Calculate the full name of the namespace that we just entered.  */
+
+  const char *new_name = pdi->name;
+  if (new_name == NULL)
+    new_name = "(anonymous namespace)";
+  char *full_name = alloca (strlen (namespace) + 2 + strlen (new_name) + 1);
+  strcpy (full_name, namespace);
+  if (*namespace != '\0')
+    strcat (full_name, "::");
+  strcat (full_name, new_name);
+
+  /* Make sure that there's a symbol associated to that namespace.  */
+
+  cp_check_namespace_symbol (full_name, strlen (full_name));
+
+  /* Now scan partial symbols in that namespace.  */
+
+  if (pdi->has_children)
+    info_ptr = scan_partial_symbols (info_ptr, objfile,
+                                    lowpc, highpc,
+                                    cu_header, full_name);
+
+  return info_ptr;
+}
+
+
 /* Expand this partial symbol table into a full symbol table.  */
 
 static void
index d6c1f8258a5ba4e5d6ff90d828045ea081cf20f7..bb061d20d01a62e075d6bf0b752cecce8c7f1d85 100644 (file)
@@ -1,3 +1,7 @@
+2002-11-21  David Carlton  <carlton@math.stanford.edu>
+
+       * carlton_runnamespace: Run using multiple compilers.
+
 2002-11-19  David Carlton  <carlton@math.stanford.edu>
 
        * gdb.c++/namespace.exp: Delete FIXME comment.
index fb3714942e156f1eb05ff724eacba9ffd1bf2175..37a836422f37b1ad6217e7384966bfbda7eb7e50 100755 (executable)
@@ -1,6 +1,17 @@
 #!/bin/bash
 
-# Just run the namespace test.
+# Just run the namespace test.  But run it using multiple compilers:
+# the regular one, and one which generates more namespace debugging
+# info.  Maybe eventually I should run this on one which generates
+# stabs info, too?
 
+EXTRACOMPPATH=/usr/local/testbed/gcc3/bin
+
+echo "Running tests using regular compiler."
 runtest namespace.exp 2>&1 | grep -v "^Test Run By" > /tmp/namespaceout
 diff -u {carlton_,/tmp/}namespaceout
+echo "Running tests using compiler with extra debug info."
+PATH=${EXTRACOMPPATH}:${PATH} runtest namespace.exp 2>&1 | grep -v "^Test Run By" > /tmp/namespaceout
+diff -u {carlton_,/tmp/}namespaceout
+
+echo "Done."