]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
2002-11-29 David Carlton <carlton@bactrian.org>
authorDavid Carlton <carlton@bactrian.org>
Sun, 1 Dec 2002 22:07:56 +0000 (22:07 +0000)
committerDavid Carlton <carlton@bactrian.org>
Sun, 1 Dec 2002 22:07:56 +0000 (22:07 +0000)
* dwarf2read.c (add_partial_symbol): Add partial symbols
corresponding to classes, etc. to global list.
(new_symbol): Ditto, mutatis mutandem.

2002-11-29  David Carlton  <carlton@bactrian.org>

* gdb.c++/namespace.exp: Add OtherFileClass tests.
* gdb.c++/namespace1.cc (C): New file.

gdb/ChangeLog
gdb/dwarf2read.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.c++/namespace.exp
gdb/testsuite/gdb.c++/namespace1.cc [new file with mode: 0644]

index a925f6322f13eddfaf5a8013631eff68faf894a3..a93161af25f8956bac2e82002dc7f14dce1d5a98 100644 (file)
@@ -1,3 +1,9 @@
+2002-11-29  David Carlton  <carlton@bactrian.org>
+
+       * dwarf2read.c (add_partial_symbol): Add partial symbols
+       corresponding to classes, etc. to global list.
+       (new_symbol): Ditto, mutatis mutandem.
+
 2002-11-27  David Carlton  <carlton@math.stanford.edu>
 
        * dwarf2read.c (add_partial_enumeration): New function.
index 0c5bb17f22dc582859f1702d11c4ec7a8905656e..2c64f59a821902b4ec846a41e440c8adcc62e8a6 100644 (file)
@@ -1553,11 +1553,13 @@ add_partial_symbol (struct partial_die_info *pdi, struct objfile *objfile,
     case DW_TAG_enumeration_type:
       /* Skip aggregate types without children, these are external
          references.  */
+      /* NOTE: carlton/2002-11-29: See comment in new_symbol about
+        static vs. global.  */
       if (pdi->has_children == 0)
        return;
       add_psymbol_to_list (actual_name, strlen (actual_name),
                           STRUCT_NAMESPACE, LOC_TYPEDEF,
-                          &objfile->static_psymbols,
+                          &objfile->global_psymbols,
                           0, (CORE_ADDR) 0, cu_language, objfile);
 
       if (cu_language == language_cplus)
@@ -1565,14 +1567,14 @@ add_partial_symbol (struct partial_die_info *pdi, struct objfile *objfile,
          /* For C++, these implicitly act as typedefs as well. */
          add_psymbol_to_list (actual_name, strlen (actual_name),
                               VAR_NAMESPACE, LOC_TYPEDEF,
-                              &objfile->static_psymbols,
+                              &objfile->global_psymbols,
                               0, (CORE_ADDR) 0, cu_language, objfile);
        }
       break;
     case DW_TAG_enumerator:
       add_psymbol_to_list (actual_name, strlen (actual_name),
                           VAR_NAMESPACE, LOC_CONST,
-                          &objfile->static_psymbols,
+                          &objfile->global_psymbols,
                           0, (CORE_ADDR) 0, cu_language, objfile);
       break;
     default:
@@ -5239,26 +5241,43 @@ new_symbol (struct die_info *die, struct type *type, struct objfile *objfile,
                  gdb_assert (SYMBOL_DEMANGLED_NAME (sym) == NULL);
                }
            }
-         
-         add_symbol_to_list (sym, list_in_scope);
 
-         /* The semantics of C++ state that "struct foo { ... }" also
-            defines a typedef for "foo". Synthesize a typedef symbol so
-            that "ptype foo" works as expected.  */
-         if (cu_language == language_cplus)
-           {
-             struct symbol *typedef_sym = (struct symbol *)
-             obstack_alloc (&objfile->symbol_obstack,
-                            sizeof (struct symbol));
-             *typedef_sym = *sym;
-             SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
-             if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
-               TYPE_NAME (SYMBOL_TYPE (sym)) =
-                 obsavestring (SYMBOL_NAME (sym),
-                               strlen (SYMBOL_NAME (sym)),
-                               &objfile->type_obstack);
-             add_symbol_to_list (typedef_sym, list_in_scope);
-           }
+         {
+           /* NOTE: carlton/2002-11-29: Class symbols shouldn't
+              really ever be static objects: otherwise, if you try
+              to, say, break of a class's method and you're in a file
+              which doesn't mention that class, it won't work unless
+              the check for all static symbols in lookup_symbol_aux
+              saves you.  Though perhaps C allows different files to
+              define different structs with the same name; if so,
+              this should be conditional on C++.  See the
+              OtherFileClass tests in gdb.c++/namespace.exp.  */
+
+           struct pending **list_to_add;
+
+           list_to_add = (list_in_scope == &file_symbols
+                          ? &global_symbols : list_in_scope);
+         
+           add_symbol_to_list (sym, list_to_add);
+
+           /* The semantics of C++ state that "struct foo { ... }" also
+              defines a typedef for "foo". Synthesize a typedef symbol so
+              that "ptype foo" works as expected.  */
+           if (cu_language == language_cplus)
+             {
+               struct symbol *typedef_sym = (struct symbol *)
+                 obstack_alloc (&objfile->symbol_obstack,
+                                sizeof (struct symbol));
+               *typedef_sym = *sym;
+               SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
+               if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
+                 TYPE_NAME (SYMBOL_TYPE (sym)) =
+                   obsavestring (SYMBOL_NAME (sym),
+                                 strlen (SYMBOL_NAME (sym)),
+                                 &objfile->type_obstack);
+               add_symbol_to_list (typedef_sym, list_to_add);
+             }
+         }
          break;
        case DW_TAG_typedef:
          if (processing_has_namespace_info
@@ -5292,7 +5311,17 @@ new_symbol (struct die_info *die, struct type *type, struct objfile *objfile,
            {
              dwarf2_const_value (attr, sym, objfile, cu_header);
            }
-         add_symbol_to_list (sym, list_in_scope);
+         {
+           /* NOTE: carlton/2002-11-29: See comment above in the
+              DW_TAG_class_type, etc. block.  */
+
+           struct pending **list_to_add;
+
+           list_to_add = (list_in_scope == &file_symbols
+                          ? &global_symbols : list_in_scope);
+         
+           add_symbol_to_list (sym, list_to_add);
+         }
          break;
        default:
          /* Not a tag we recognize.  Hopefully we aren't processing
index 6fa5e95d9aa59f1e918adbae874805cb6408c881..0886e86ece4b4bbaf97f2e2be5a8c40721cd0de8 100644 (file)
@@ -1,3 +1,8 @@
+2002-11-29  David Carlton  <carlton@bactrian.org>
+
+       * gdb.c++/namespace.exp: Add OtherFileClass tests.
+       * gdb.c++/namespace1.cc (C): New file.
+
 2002-11-27  David Carlton  <carlton@math.stanford.edu>
 
        * gdb.c++/m-data.cc (main): Add marker comment.
index d8fa93839c3d23d91c4da425398ec2f93289fe7d..fa38f2e58a3addb64f03743fa776d547202ebe7a 100644 (file)
@@ -39,6 +39,7 @@ if { [skip_cplus_tests] } { continue }
 
 set testfile "namespace"
 set srcfile ${testfile}.cc
+set srcfile1 ${testfile}1.cc
 set binfile ${objdir}/${subdir}/${testfile}
 
 if [get_compiler_info ${binfile}] {
@@ -47,7 +48,7 @@ if [get_compiler_info ${binfile}] {
 
 
 
-if  { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug c++}] != "" } {
+if  { [gdb_compile "${srcdir}/${subdir}/${srcfile} ${srcdir}/${subdir}/${srcfile1}" "${binfile}" executable {debug c++}] != "" } {
      gdb_suppress_entire_file "Testcase compile failed, so all tests in this file will a
 utomatically fail."
 }
@@ -251,13 +252,19 @@ gdb_test "ptype E" "type = namespace C::D::E" "ptype C::D::E"
 gdb_test "ptype CClass" "type = class C::CClass \{\r\n  public:\r\n    int x;\r\n\}" "ptype CClass"
 gdb_test "ptype CClass::NestedClass" "type = class C::CClass::NestedClass \{\r\n  public:\r\n    int y;\r\n\}" "ptype CClass::NestedClass"
 gdb_test "ptype NestedClass" "No symbol \"NestedClass\" in current context." "ptype NestedClass"
-gdb_test "ptype ::C::CClass" "type = class C::CClass \{\r\n  public:\r\n    inty;\r\n\}" "ptype ::C::CClass"
+gdb_test "ptype ::C::CClass" "type = class C::CClass \{\r\n  public:\r\n    int x;\r\n\}" "ptype ::C::CClass"
 gdb_test "ptype ::C::CClass::NestedClass" "type = class C::CClass::NestedClass \{\r\n  public:\r\n    int y;\r\n\}" "ptype ::C::CClass::NestedClass"
 gdb_test "ptype ::C::NestedClass" "No symbol \"NestedClass\" in namespace \"C\"." "ptype ::C::NestedClass"
 gdb_test "ptype C::CClass" "No symbol \"Class\" in namespace \"C::C\"" "ptype C::CClass"
 gdb_test "ptype C::CClass::NestedClass" "No symbol \"Class\" in namespace \"C::C\"" "ptype C::CClass::NestedClass"
 gdb_test "ptype C::NestedClass" "No symbol \"NestedClass\" in namespace \"C::C\"." "ptype C::NestedClass"
 
+# Tests involving multiple files
+
+gdb_test "ptype OtherFileClass" "type = class C::OtherFileClass \{\r\n  public:\r\n    int z;\r\n\}" "ptype OtherFileClass"
+gdb_test "ptype ::C::OtherFileClass" "type = class C::OtherFileClass \{\r\n  public:\r\n    int z;\r\n\}" "ptype ::C::OtherFileClass"
+gdb_test "ptype C::OtherFileClass" "No symbol \"Class\" in namespace \"C::C\"" "ptype C::OtherFileClass"
+
 # Some anonymous namespace tests.
 
 gdb_test "print cX" "\\$\[0-9\].* = 6" "print cX"
diff --git a/gdb/testsuite/gdb.c++/namespace1.cc b/gdb/testsuite/gdb.c++/namespace1.cc
new file mode 100644 (file)
index 0000000..ac4703c
--- /dev/null
@@ -0,0 +1,7 @@
+namespace C
+{
+  class OtherFileClass {
+  public:
+    int z;
+  };
+}