2004-02-17 Elena Zannoni <ezannoni@redhat.com>
[deliverable/binutils-gdb.git] / gdb / dwarf2read.c
index 94d210c3f424f38e35dd38195c59929e95641a2d..e09c3c15f6c30b08f3886ff18b8fe729c4a8c788 100644 (file)
@@ -31,7 +31,6 @@
 #include "bfd.h"
 #include "symtab.h"
 #include "gdbtypes.h"
 #include "bfd.h"
 #include "symtab.h"
 #include "gdbtypes.h"
-#include "symfile.h"
 #include "objfiles.h"
 #include "elf/dwarf2.h"
 #include "buildsym.h"
 #include "objfiles.h"
 #include "elf/dwarf2.h"
 #include "buildsym.h"
@@ -446,7 +445,7 @@ static int isreg;           /* Object lives in register.
 /* We put a pointer to this structure in the read_symtab_private field
    of the psymtab.
    The complete dwarf information for an objfile is kept in the
 /* We put a pointer to this structure in the read_symtab_private field
    of the psymtab.
    The complete dwarf information for an objfile is kept in the
-   psymbol_obstack, so that absolute die references can be handled.
+   objfile_obstack, so that absolute die references can be handled.
    Most of the information in this structure is related to an entire
    object file and could be passed via the sym_private field of the objfile.
    It is however conceivable that dwarf2 might not be the only type
    Most of the information in this structure is related to an entire
    object file and could be passed via the sym_private field of the objfile.
    It is however conceivable that dwarf2 might not be the only type
@@ -1256,7 +1255,7 @@ dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline)
                                  objfile->static_psymbols.next);
 
       pst->read_symtab_private = (char *)
                                  objfile->static_psymbols.next);
 
       pst->read_symtab_private = (char *)
-       obstack_alloc (&objfile->psymbol_obstack, sizeof (struct dwarf2_pinfo));
+       obstack_alloc (&objfile->objfile_obstack, sizeof (struct dwarf2_pinfo));
       DWARF_INFO_BUFFER (pst) = dwarf_info_buffer;
       DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf_info_buffer;
       DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer;
       DWARF_INFO_BUFFER (pst) = dwarf_info_buffer;
       DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf_info_buffer;
       DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer;
@@ -1661,12 +1660,12 @@ add_partial_structure (struct partial_die_info *struct_pdi, char *info_ptr,
   char *actual_class_name = NULL;
 
   if (cu->language == language_cplus
   char *actual_class_name = NULL;
 
   if (cu->language == language_cplus
-      && namespace == NULL
+      && (namespace == NULL || namespace[0] == '\0')
       && struct_pdi->name != NULL
       && struct_pdi->has_children)
     {
       && 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
+      /* See if we can figure out if the class lives in a namespace
+        (or is nested within another class.)  We do this by looking
         for a member function; its demangled name will contain
         namespace info, if there is any.  */
 
         for a member function; its demangled name will contain
         namespace info, if there is any.  */
 
@@ -1676,6 +1675,21 @@ add_partial_structure (struct partial_die_info *struct_pdi, char *info_ptr,
         could fix this by only using the demangled name to get the
         prefix (but see comment in read_structure_scope).  */
 
         could fix this by only using the demangled name to get the
         prefix (but see comment in read_structure_scope).  */
 
+      /* FIXME: carlton/2004-01-23: If NAMESPACE equals "", we have
+        the appropriate debug information, so it would be nice to be
+        able to avoid this hack.  But NAMESPACE may not be the
+        namespace where this class was defined: NAMESPACE reflects
+        where STRUCT_PDI occurs in the tree of dies, but because of
+        DW_AT_specification, that may not actually tell us where the
+        class is defined.  (See the comment in read_func_scope for an
+        example of how this could occur.)
+
+         Unfortunately, our current partial symtab data structures are
+         completely unable to deal with DW_AT_specification.  So, for
+         now, the best thing to do is to get nesting information from
+         places other than the tree structure of dies if there's any
+         chance that a DW_AT_specification is involved. :-( */
+
       char *next_child = info_ptr;
 
       while (1)
       char *next_child = info_ptr;
 
       while (1)
@@ -2173,27 +2187,27 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu)
     {
       struct die_info *spec_die = die_specification (die, cu);
 
     {
       struct die_info *spec_die = die_specification (die, cu);
 
-         /* NOTE: carlton/2004-01-23: We have to be careful in the
-            presence of DW_AT_specification.  For example, with GCC
-            3.4, given the code
+      /* NOTE: carlton/2004-01-23: We have to be careful in the
+         presence of DW_AT_specification.  For example, with GCC 3.4,
+         given the code
 
 
-               namespace N {
-                void foo() {
-                  // Definition of N::foo.
-                }
-              }
+           namespace N {
+             void foo() {
+               // Definition of N::foo.
+             }
+           }
 
 
-            then we'll have a tree of DIEs like this:
+         then we'll have a tree of DIEs like this:
 
 
-            1: DW_TAG_compile_unit
-               2: DW_TAG_namespace        // N
-                 3: DW_TAG_subprogram     // declaration of N::foo
-               4: DW_TAG_subprogram       // definition of N::foo
-                    DW_AT_specification   // refers to die #3
+         1: DW_TAG_compile_unit
+           2: DW_TAG_namespace        // N
+             3: DW_TAG_subprogram     // declaration of N::foo
+           4: DW_TAG_subprogram       // definition of N::foo
+                DW_AT_specification   // refers to die #3
 
 
-             Thus, when processing die #4, we have to pretend that
-             we're in the context of its DW_AT_specification, namely
-             the contex of die #3.  */
+         Thus, when processing die #4, we have to pretend that we're
+         in the context of its DW_AT_specification, namely the contex
+         of die #3.  */
        
       if (spec_die != NULL)
        {
        
       if (spec_die != NULL)
        {
@@ -2651,7 +2665,7 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       if (attr && DW_STRING (attr))
        fieldname = DW_STRING (attr);
       fp->name = obsavestring (fieldname, strlen (fieldname),
       if (attr && DW_STRING (attr))
        fieldname = DW_STRING (attr);
       fp->name = obsavestring (fieldname, strlen (fieldname),
-                              &objfile->type_obstack);
+                              &objfile->objfile_obstack);
 
       /* Change accessibility for artificial fields (e.g. virtual table
          pointer or virtual base class pointer) to private.  */
 
       /* Change accessibility for artificial fields (e.g. virtual table
          pointer or virtual base class pointer) to private.  */
@@ -2683,10 +2697,10 @@ dwarf2_add_field (struct field_info *fip, struct die_info *die,
       physname = dwarf2_linkage_name (die, cu);
 
       SET_FIELD_PHYSNAME (*fp, obsavestring (physname, strlen (physname),
       physname = dwarf2_linkage_name (die, cu);
 
       SET_FIELD_PHYSNAME (*fp, obsavestring (physname, strlen (physname),
-                                            &objfile->type_obstack));
+                                            &objfile->objfile_obstack));
       FIELD_TYPE (*fp) = die_type (die, cu);
       FIELD_NAME (*fp) = obsavestring (fieldname, strlen (fieldname),
       FIELD_TYPE (*fp) = die_type (die, cu);
       FIELD_NAME (*fp) = obsavestring (fieldname, strlen (fieldname),
-                                      &objfile->type_obstack);
+                                      &objfile->objfile_obstack);
     }
   else if (die->tag == DW_TAG_inheritance)
     {
     }
   else if (die->tag == DW_TAG_inheritance)
     {
@@ -2855,7 +2869,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die,
   /* Fill in the member function field info.  */
   fnp = &new_fnfield->fnfield;
   fnp->physname = obsavestring (physname, strlen (physname),
   /* Fill in the member function field info.  */
   fnp = &new_fnfield->fnfield;
   fnp->physname = obsavestring (physname, strlen (physname),
-                               &objfile->type_obstack);
+                               &objfile->objfile_obstack);
   fnp->type = alloc_type (objfile);
   if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC)
     {
   fnp->type = alloc_type (objfile);
   if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC)
     {
@@ -3021,7 +3035,7 @@ read_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
             TYPE_TAG_NAME to be a const char *, I ran into a cascade
             of changes which would have forced decode_line_1 to take
             a const char **.  */
             TYPE_TAG_NAME to be a const char *, I ran into a cascade
             of changes which would have forced decode_line_1 to take
             a const char **.  */
-         char *new_prefix = obconcat (&objfile->type_obstack,
+         char *new_prefix = obconcat (&objfile->objfile_obstack,
                                       processing_current_prefix,
                                       processing_current_prefix[0] == '\0'
                                       ? "" : "::",
                                       processing_current_prefix,
                                       processing_current_prefix[0] == '\0'
                                       ? "" : "::",
@@ -3032,7 +3046,7 @@ read_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
       else
        {
          TYPE_TAG_NAME (type) = obsavestring (name, strlen (name),
       else
        {
          TYPE_TAG_NAME (type) = obsavestring (name, strlen (name),
-                                              &objfile->type_obstack);
+                                              &objfile->objfile_obstack);
          need_to_update_name = (cu->language == language_cplus);
        }
     }
          need_to_update_name = (cu->language == language_cplus);
        }
     }
@@ -3124,7 +3138,7 @@ read_structure_scope (struct die_info *die, struct dwarf2_cu *cu)
                      TYPE_TAG_NAME (type)
                        = obsavestring (actual_class_name,
                                        strlen (actual_class_name),
                      TYPE_TAG_NAME (type)
                        = obsavestring (actual_class_name,
                                        strlen (actual_class_name),
-                                       &objfile->type_obstack);
+                                       &objfile->objfile_obstack);
                    }
                  xfree (actual_class_name);
                  need_to_update_name = 0;
                    }
                  xfree (actual_class_name);
                  need_to_update_name = 0;
@@ -3241,7 +3255,7 @@ read_enumeration (struct die_info *die, struct dwarf2_cu *cu)
 
       if (processing_has_namespace_info)
        {
 
       if (processing_has_namespace_info)
        {
-         TYPE_TAG_NAME (type) = obconcat (&objfile->type_obstack,
+         TYPE_TAG_NAME (type) = obconcat (&objfile->objfile_obstack,
                                           processing_current_prefix,
                                           processing_current_prefix[0] == '\0'
                                           ? "" : "::",
                                           processing_current_prefix,
                                           processing_current_prefix[0] == '\0'
                                           ? "" : "::",
@@ -3250,7 +3264,7 @@ read_enumeration (struct die_info *die, struct dwarf2_cu *cu)
       else
        {
          TYPE_TAG_NAME (type) = obsavestring (name, strlen (name),
       else
        {
          TYPE_TAG_NAME (type) = obsavestring (name, strlen (name),
-                                              &objfile->type_obstack);
+                                              &objfile->objfile_obstack);
        }
     }
 
        }
     }
 
@@ -4117,7 +4131,7 @@ make_cleanup_free_die_list (struct die_info *dies)
 
 
 /* Read the contents of the section at OFFSET and of size SIZE from the
 
 
 /* Read the contents of the section at OFFSET and of size SIZE from the
-   object file specified by OBJFILE into the psymbol_obstack and return it.  */
+   object file specified by OBJFILE into the objfile_obstack and return it.  */
 
 char *
 dwarf2_read_section (struct objfile *objfile, asection *sectp)
 
 char *
 dwarf2_read_section (struct objfile *objfile, asection *sectp)
@@ -4129,7 +4143,7 @@ dwarf2_read_section (struct objfile *objfile, asection *sectp)
   if (size == 0)
     return NULL;
 
   if (size == 0)
     return NULL;
 
-  buf = (char *) obstack_alloc (&objfile->psymbol_obstack, size);
+  buf = (char *) obstack_alloc (&objfile->objfile_obstack, size);
   retbuf
     = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf);
   if (retbuf != NULL)
   retbuf
     = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf);
   if (retbuf != NULL)
@@ -5529,7 +5543,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
 
   if (name)
     {
 
   if (name)
     {
-      sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack,
+      sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack,
                                             sizeof (struct symbol));
       OBJSTAT (objfile, n_syms++);
       memset (sym, 0, sizeof (struct symbol));
                                             sizeof (struct symbol));
       OBJSTAT (objfile, n_syms++);
       memset (sym, 0, sizeof (struct symbol));
@@ -5667,7 +5681,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
                  SYMBOL_LINKAGE_NAME (sym)
                    = obsavestring (TYPE_TAG_NAME (type),
                                    strlen (TYPE_TAG_NAME (type)),
                  SYMBOL_LINKAGE_NAME (sym)
                    = obsavestring (TYPE_TAG_NAME (type),
                                    strlen (TYPE_TAG_NAME (type)),
-                                   &objfile->symbol_obstack);
+                                   &objfile->objfile_obstack);
                }
            }
 
                }
            }
 
@@ -5694,7 +5708,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
            if (cu->language == language_cplus)
              {
                struct symbol *typedef_sym = (struct symbol *)
            if (cu->language == language_cplus)
              {
                struct symbol *typedef_sym = (struct symbol *)
-                 obstack_alloc (&objfile->symbol_obstack,
+                 obstack_alloc (&objfile->objfile_obstack,
                                 sizeof (struct symbol));
                *typedef_sym = *sym;
                SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
                                 sizeof (struct symbol));
                *typedef_sym = *sym;
                SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN;
@@ -5702,7 +5716,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
                  TYPE_NAME (SYMBOL_TYPE (sym)) =
                    obsavestring (SYMBOL_NATURAL_NAME (sym),
                                  strlen (SYMBOL_NATURAL_NAME (sym)),
                  TYPE_NAME (SYMBOL_TYPE (sym)) =
                    obsavestring (SYMBOL_NATURAL_NAME (sym),
                                  strlen (SYMBOL_NATURAL_NAME (sym)),
-                                 &objfile->type_obstack);
+                                 &objfile->objfile_obstack);
                add_symbol_to_list (typedef_sym, list_to_add);
              }
          }
                add_symbol_to_list (typedef_sym, list_to_add);
              }
          }
@@ -5711,7 +5725,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
          if (processing_has_namespace_info
              && processing_current_prefix[0] != '\0')
            {
          if (processing_has_namespace_info
              && processing_current_prefix[0] != '\0')
            {
-             SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->symbol_obstack,
+             SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack,
                                                    processing_current_prefix,
                                                    "::",
                                                    name);
                                                    processing_current_prefix,
                                                    "::",
                                                    name);
@@ -5730,7 +5744,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu)
          if (processing_has_namespace_info
              && processing_current_prefix[0] != '\0')
            {
          if (processing_has_namespace_info
              && processing_current_prefix[0] != '\0')
            {
-             SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->symbol_obstack,
+             SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack,
                                                    processing_current_prefix,
                                                    "::",
                                                    name);
                                                    processing_current_prefix,
                                                    "::",
                                                    name);
@@ -5789,7 +5803,7 @@ dwarf2_const_value (struct attribute *attr, struct symbol *sym,
                                                      TYPE_LENGTH (SYMBOL_TYPE
                                                                   (sym)));
       SYMBOL_VALUE_BYTES (sym) = (char *)
                                                      TYPE_LENGTH (SYMBOL_TYPE
                                                                   (sym)));
       SYMBOL_VALUE_BYTES (sym) = (char *)
-       obstack_alloc (&objfile->symbol_obstack, cu_header->addr_size);
+       obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size);
       /* NOTE: cagney/2003-05-09: In-lined store_address call with
          it's body - store_unsigned_integer.  */
       store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
       /* NOTE: cagney/2003-05-09: In-lined store_address call with
          it's body - store_unsigned_integer.  */
       store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size,
@@ -5807,7 +5821,7 @@ dwarf2_const_value (struct attribute *attr, struct symbol *sym,
                                                      TYPE_LENGTH (SYMBOL_TYPE
                                                                   (sym)));
       SYMBOL_VALUE_BYTES (sym) = (char *)
                                                      TYPE_LENGTH (SYMBOL_TYPE
                                                                   (sym)));
       SYMBOL_VALUE_BYTES (sym) = (char *)
-       obstack_alloc (&objfile->symbol_obstack, blk->size);
+       obstack_alloc (&objfile->objfile_obstack, blk->size);
       memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
       SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
       break;
       memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size);
       SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
       break;
@@ -7643,7 +7657,7 @@ macro_start_file (int file, int line,
   /* We don't create a macro table for this compilation unit
      at all until we actually get a filename.  */
   if (! pending_macros)
   /* We don't create a macro table for this compilation unit
      at all until we actually get a filename.  */
   if (! pending_macros)
-    pending_macros = new_macro_table (&objfile->symbol_obstack,
+    pending_macros = new_macro_table (&objfile->objfile_obstack,
                                       objfile->macro_cache);
 
   if (! current_file)
                                       objfile->macro_cache);
 
   if (! current_file)
@@ -7986,7 +8000,7 @@ dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
     {
       struct dwarf2_loclist_baton *baton;
 
     {
       struct dwarf2_loclist_baton *baton;
 
-      baton = obstack_alloc (&cu->objfile->symbol_obstack,
+      baton = obstack_alloc (&cu->objfile->objfile_obstack,
                             sizeof (struct dwarf2_loclist_baton));
       baton->objfile = cu->objfile;
 
                             sizeof (struct dwarf2_loclist_baton));
       baton->objfile = cu->objfile;
 
@@ -8006,7 +8020,7 @@ dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym,
     {
       struct dwarf2_locexpr_baton *baton;
 
     {
       struct dwarf2_locexpr_baton *baton;
 
-      baton = obstack_alloc (&cu->objfile->symbol_obstack,
+      baton = obstack_alloc (&cu->objfile->objfile_obstack,
                             sizeof (struct dwarf2_locexpr_baton));
       baton->objfile = cu->objfile;
 
                             sizeof (struct dwarf2_locexpr_baton));
       baton->objfile = cu->objfile;
 
This page took 0.031079 seconds and 4 git commands to generate.