]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
2003-01-10 David Carlton <carlton@math.stanford.edu>
authorDavid Carlton <carlton@bactrian.org>
Sat, 11 Jan 2003 01:11:03 +0000 (01:11 +0000)
committerDavid Carlton <carlton@bactrian.org>
Sat, 11 Jan 2003 01:11:03 +0000 (01:11 +0000)
* objfiles.c (allocate_objfile): Always set name.
* dwarf2read.c (scan_partial_symbols): Don't call
add_partial_structure on unions.
(add_partial_structure): Look for enclosing namespace names.
(read_structure_scope): Look enclosing namespace/class names.
(new_symbol): For C++ structures, always grab the name from the
type's name.

2003-01-10  David Carlton  <carlton@math.stanford.edu>

* gdb.c++/templates.exp (do_tests): Update some of the regexps to
be a bit more generous.

gdb/ChangeLog
gdb/dwarf2read.c
gdb/objfiles.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.c++/templates.exp

index a885af266dcfe7c1f190c1910f5f7a27fb8b89b7..f932e7c90ffd62d2027c2541dab8ff04532e83b2 100644 (file)
@@ -1,3 +1,13 @@
+2003-01-10  David Carlton  <carlton@math.stanford.edu>
+
+       * objfiles.c (allocate_objfile): Always set name.
+       * dwarf2read.c (scan_partial_symbols): Don't call
+       add_partial_structure on unions.
+       (add_partial_structure): Look for enclosing namespace names.
+       (read_structure_scope): Look enclosing namespace/class names.
+       (new_symbol): For C++ structures, always grab the name from the
+       type's name.
+
 2003-01-07  David Carlton  <carlton@math.stanford.edu>
 
        * dwarf2read.c (add_partial_structure): New function.
index 0302563ce404325cf4ce3fc5c0d02b1fb9f46df8..fd7483a9a4e3e3336be235adf229c5aa631c5862 100644 (file)
@@ -1344,6 +1344,7 @@ scan_partial_symbols (char *info_ptr, struct objfile *objfile,
              break;
            case DW_TAG_variable:
            case DW_TAG_typedef:
+           case DW_TAG_union_type:
              if (!pdi.is_declaration)
                {
                  add_partial_symbol (&pdi, objfile, cu_header, namespace);
@@ -1351,7 +1352,6 @@ scan_partial_symbols (char *info_ptr, struct objfile *objfile,
              break;
            case DW_TAG_class_type:
            case DW_TAG_structure_type:
-           case DW_TAG_union_type:
              if (!pdi.is_declaration)
                {
                  info_ptr = add_partial_structure (&pdi, info_ptr,
@@ -1605,8 +1605,7 @@ add_partial_namespace (struct partial_die_info *pdi, char *info_ptr,
   return info_ptr;
 }
 
-/* Read a partial die corresponding to a non-enumeration compound data
-   structure type.  */
+/* Read a partial die corresponding to a class or structure.  */
 
 static char *
 add_partial_structure (struct partial_die_info *struct_pdi, char *info_ptr,
@@ -1615,8 +1614,39 @@ add_partial_structure (struct partial_die_info *struct_pdi, char *info_ptr,
                       const char *namespace)
 {
   bfd *abfd = objfile->obfd;
+  char *actual_class_name = NULL;
+
+  if (cu_language == language_cplus
+      && namespace == NULL
+      && struct_pdi->name != NULL
+      && struct_pdi->has_children)
+    {
+      /* We don't have namespace debugging information, so see if we
+        can figure out if this structure lives in a namespace.  Look
+        for a member function; its demangled name will contain
+        namespace info, if there is any.  */
+      char *next_child = info_ptr;
+
+      while (1)
+       {
+         struct partial_die_info child_pdi;
+
+         next_child = read_partial_die (&child_pdi, abfd, next_child,
+                                        cu_header);
+         if (!child_pdi.tag)
+           break;
+         if (child_pdi.tag == DW_TAG_subprogram)
+           {
+             actual_class_name = class_name_from_physname (child_pdi.name);
+             if (actual_class_name != NULL)
+               struct_pdi->name = actual_class_name;
+             break;
+           }
+       }
+    }
 
   add_partial_symbol (struct_pdi, objfile, cu_header, namespace);
+  xfree(actual_class_name);
 
   return locate_pdi_sibling (struct_pdi, info_ptr, abfd, cu_header);
 }
@@ -2681,6 +2711,10 @@ read_structure_scope (struct die_info *die, struct objfile *objfile,
   struct attribute *attr;
   char *name;
   const char *previous_prefix = processing_current_prefix;
+  /* This says whether or not we want to try to update the structure's
+     name to include enclosing namespace/class information, if
+     any.  */
+  int need_to_update_name = 0;
 
   type = alloc_type (objfile);
 
@@ -2707,6 +2741,7 @@ read_structure_scope (struct die_info *die, struct objfile *objfile,
        {
          TYPE_TAG_NAME (type) = obsavestring (name, strlen (name),
                                               &objfile->type_obstack);
+         need_to_update_name = (cu_language == language_cplus);
        }
     }
 
@@ -2767,6 +2802,29 @@ read_structure_scope (struct die_info *die, struct objfile *objfile,
              /* C++ member function. */
              process_die (child_die, objfile, cu_header);
              dwarf2_add_member_fn (&fi, child_die, type, objfile, cu_header);
+             if (need_to_update_name)
+               {
+                 /* The demangled names of member functions contain
+                    information about enclosing namespaces/classes,
+                    if any.  */
+
+                 /* FIXME: carlton/2003-01-10: The excessive
+                    demangling here is a bit wasteful, as is the
+                    memory usage for names.  */
+                 char *actual_class_name
+                   = class_name_from_physname (dwarf2_linkage_name
+                                               (child_die));
+                 if (actual_class_name != NULL
+                     && strcmp (actual_class_name, name) != 0)
+                   {
+                     TYPE_TAG_NAME (type)
+                       = obsavestring (actual_class_name,
+                                       strlen (actual_class_name),
+                                       &objfile->type_obstack);
+                   }
+                 xfree (actual_class_name);
+                 need_to_update_name = 0;
+               }
            }
          else if (child_die->tag == DW_TAG_inheritance)
            {
@@ -5225,15 +5283,19 @@ new_symbol (struct die_info *die, struct type *type, struct objfile *objfile,
          SYMBOL_CLASS (sym) = LOC_TYPEDEF;
          SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
 
-         /* Make sure that the symbol includes appropriate
-            namespaces in its name.  */
+         /* Make sure that the symbol includes appropriate enclosing
+            classes/namespaces in its name.  These are calculated in
+            read_structure_scope, and the correct name is saved in
+            the type.  */
 
-         if (processing_has_namespace_info)
+         if (cu_language == language_cplus)
            {
              struct type *type = SYMBOL_TYPE (sym);
              
              if (TYPE_TAG_NAME (type) != NULL)
                {
+                 /* FIXME: carlton/2003-01-10: We're being a bit
+                    profligate with memory names here.  */
                  SYMBOL_NAME (sym)
                    = obsavestring (TYPE_TAG_NAME (type),
                                    strlen (TYPE_TAG_NAME (type)),
index 8f36f8af655f4ab991f70f71f242c84ff411202f..c333f4cfd97d7d38865c6d0e52ad2daf260b48c4 100644 (file)
@@ -307,6 +307,10 @@ allocate_objfile (bfd *abfd, int flags)
                 objfile->name, bfd_errmsg (bfd_get_error ()));
        }
     }
+  else
+    {
+      objfile->name = "<<anonymous objfile>>";
+    }
 
   /* Initialize the section indexes for this objfile, so that we can
      later detect if they are used w/o being properly assigned to. */
index d5e3fc8beb9ad281f3454da87842b0981e880e82..c25c49913364a0bb5754a7b747132cac76f73ff8 100644 (file)
@@ -1,3 +1,8 @@
+2003-01-10  David Carlton  <carlton@math.stanford.edu>
+
+       * gdb.c++/templates.exp (do_tests): Update some of the regexps to
+       be a bit more generous.
+
 2003-01-06  David Carlton  <carlton@math.stanford.edu>
 
        * gdb.c++/namespace.exp: Test anonymous namespaces and multiple
index a6d35fcb116b2d770c71f714d9d57dc94cc2a7ef..b0260bec11d386c5b9e00715abb0ed644a5dbec6 100644 (file)
@@ -288,6 +288,7 @@ gdb_expect {
 send_gdb "ptype fvpchar\n"   
 gdb_expect {   
    -re "type = (class |)Foo<volatile char ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*.*char.*\\*t;\r\n\r\n\[ \t\]*.*char \\* foo\\(int,.*char.*\\*\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype fvpchar" }
+   -re "type = class Foo<char volatile\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*.*char.*\\*t;\r\n\r\n\[ \t\]*.*char \\* foo\\(int,.*char.*\\*\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype fvpchar" }
    -re "$gdb_prompt $"                     { fail "ptype fvpchar" }
    timeout                             { fail "(timeout) ptype fvpchar" }
 }
@@ -319,7 +320,7 @@ gdb_expect {
 
 send_gdb "ptype bint\n"   
 gdb_expect {   
-   -re "type = (class |)Bar<int,(\\(int\\)|)33> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int bar\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bint" }
+   -re "type = (class |)Bar<int, ?(\\(int\\)|)33> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int bar\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bint" }
    -re "$gdb_prompt $"                     { fail "ptype bint" }
    timeout                             { fail "(timeout) ptype bint" }
 }
@@ -328,7 +329,7 @@ gdb_expect {
 
 send_gdb "ptype bint2\n"   
 gdb_expect {   
-   -re "type = (class |)Bar<int,(\\(int\\)|)1> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int bar\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bint2" }
+   -re "type = (class |)Bar<int, ?(\\(int\\)|)1> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int bar\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bint2" }
    -re "$gdb_prompt $"                     { fail "ptype bint2" }
    timeout                             { fail "(timeout) ptype bint2" }
 }
@@ -351,7 +352,7 @@ gdb_expect {
 
 send_gdb "ptype bazint\n"   
 gdb_expect {   
-   -re "type = (class |)Baz<int,(\\(char\\)|)(115|\\'s\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int baz\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bazint" }
+   -re "type = (class |)Baz<int, ?(\\(char\\)|)(115|\\'s\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int baz\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bazint" }
    -re "$gdb_prompt $"                     { fail "ptype bazint" }
    timeout                             { fail "(timeout) ptype bazint" }
 }
@@ -360,7 +361,7 @@ gdb_expect {
 
 send_gdb "ptype bazint2\n"   
 gdb_expect {   
-   -re "type = (class |)Baz<char,(\\(char\\)|)(97|\\'a\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*.*char baz\\(int, char\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bazint2" }
+   -re "type = (class |)Baz<char, ?(\\(char\\)|)(97|\\'a\\')> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*char t;\r\n\r\n\[ \t\]*.*char baz\\(int, char\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype bazint2" }
    -re "$gdb_prompt $"                     { fail "ptype bazint2" }
    timeout                             { fail "(timeout) ptype bazint2" }
 }
@@ -380,7 +381,7 @@ gdb_expect {
 
 send_gdb "ptype quxint\n"   
 gdb_expect {   
-   -re "type = class Qux<int,&string> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int qux\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype quxint" }
+   -re "type = class Qux<int, ?&\\(?string\\)?> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\[ \t\]*int t;\r\n\r\n\[ \t\]*.*int qux\\(int, int\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype quxint" }
    -re "$gdb_prompt $"                     { fail "ptype quxint" }
    timeout                             { fail "(timeout) ptype quxint" }
 }
@@ -413,7 +414,7 @@ gdb_expect {
 
 send_gdb "ptype siip\n"   
 gdb_expect {   
-   -re "type = class Spec<int,int ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\r\n\[ \t\]*.*int spec\\(int ?\\*\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype siip" }
+   -re "type = class Spec<int, ?int ?\\*> \\{\r\n\[ \t\]*public:\r\n\[ \t\]*int x;\r\n\r\n\[ \t\]*.*int spec\\(int ?\\*\\);\r\n\\}\r\n$gdb_prompt $" { pass "ptype siip" }
    -re "$gdb_prompt $"                     { fail "ptype siip" }
    timeout                             { fail "(timeout) ptype siip" }
 }