* maint.c (print_section_table): Rename SEC_SHARED_LIBRARY to
[deliverable/binutils-gdb.git] / gdb / dwarfread.c
index 688976a35d71b1935ea9d7f9c1e0902dee21a383..15d2988f2969749bdea8232d7dbd37ecc8ebc2f4 100644 (file)
@@ -1,5 +1,5 @@
 /* DWARF debugging format support for GDB.
-   Copyright (C) 1991, 1992 Free Software Foundation, Inc.
+   Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
    Written by Fred Fish at Cygnus Support.  Portions based on dbxread.c,
    mipsread.c, coffread.c, and dwarfread.c from a Data General SVR4 gdb port.
 
@@ -21,10 +21,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 /*
 
-FIXME: Figure out how to get the frame pointer register number in the
-execution environment of the target.  Remove R_FP kludge
-
-FIXME: Add generation of dependencies list to partial symtab code.
+FIXME: Do we need to generate dependencies in partial symtabs?
+(Perhaps we don't need to).
 
 FIXME: Resolve minor differences between what information we put in the
 partial symbol table and what dbxread puts in.  For example, we don't yet
@@ -46,6 +44,8 @@ other things to work on, if you get bored. :-)
 #include "gdbtypes.h"
 #include "symfile.h"
 #include "objfiles.h"
+#include <time.h> /* For time_t in libbfd.h.  */
+#include <sys/types.h> /* For time_t, if not in time.h.  */
 #include "libbfd.h"    /* FIXME Secret Internal BFD stuff (bfd_read) */
 #include "elf/dwarf.h"
 #include "buildsym.h"
@@ -56,7 +56,6 @@ other things to work on, if you get bored. :-)
 
 #include <fcntl.h>
 #include <string.h>
-#include <sys/types.h>
 
 #ifndef        NO_SYS_FILE
 #include <sys/file.h>
@@ -179,10 +178,6 @@ struct complaint not_row_major =
   "DIE @ 0x%x \"%s\", array not row major; not handled correctly", 0, 0
 };
 
-#ifndef R_FP           /* FIXME */
-#define R_FP 14                /* Kludge to get frame pointer register number */
-#endif
-
 typedef unsigned int DIE_REF;  /* Reference to a DIE */
 
 #ifndef GCC_PRODUCER
@@ -197,15 +192,9 @@ typedef unsigned int DIE_REF;      /* Reference to a DIE */
 #define LCC_PRODUCER "NCR C/C++"
 #endif
 
-#ifndef CFRONT_PRODUCER
-#define CFRONT_PRODUCER "CFRONT "      /* A wild a** guess... */
-#endif
-
-/* start-sanitize-chill */
 #ifndef CHILL_PRODUCER
 #define CHILL_PRODUCER "GNU Chill "
 #endif
-/* end-sanitize-chill */
 
 /* Flags to target_to_host() that tell whether or not the data object is
    expected to be signed.  Used, for example, when fetching a signed
@@ -337,10 +326,15 @@ static int dbsize;        /* Size of dwarf info in bytes */
 static int dbroff;     /* Relative offset from start of .debug section */
 static char *lnbase;   /* Base pointer to line section */
 static int isreg;      /* Kludge to identify register variables */
-static int offreg;     /* Kludge to identify basereg references */
+/* Kludge to identify basereg references.  Nonzero if we have an offset
+   relative to a basereg.  */
+static int offreg;
+/* Which base register is it relative to?  */
+static int basereg;
 
 /* This value is added to each symbol value.  FIXME:  Generalize to 
-   the section_offsets structure used by dbxread.  */
+   the section_offsets structure used by dbxread (once this is done,
+   pass the appropriate section number to end_symtab).  */
 static CORE_ADDR baseaddr;     /* Add to each symbol value */
 
 /* The section offsets used in the current psymtab or symtab.  FIXME,
@@ -500,7 +494,7 @@ dwarf_psymtab_to_symtab PARAMS ((struct partial_symtab *));
 static void
 psymtab_to_symtab_1 PARAMS ((struct partial_symtab *));
 
-static struct symtab *
+static void
 read_ofile_symtab PARAMS ((struct partial_symtab *));
 
 static void
@@ -574,10 +568,6 @@ synthesize_typedef PARAMS ((struct dieinfo *, struct objfile *,
 static int
 locval PARAMS ((char *));
 
-static void
-record_minimal_symbol PARAMS ((char *, CORE_ADDR, enum minimal_symbol_type,
-                              struct objfile *));
-
 static void
 set_cu_language PARAMS ((struct dieinfo *));
 
@@ -677,11 +667,9 @@ set_cu_language (dip)
       case LANG_C_PLUS_PLUS:
        cu_language = language_cplus;
        break;
-      /* start-sanitize-chill */
       case LANG_CHILL:
        cu_language = language_chill;
        break;
-      /* end-sanitize-chill */
       case LANG_MODULA2:
        cu_language = language_m2;
        break;
@@ -785,39 +773,6 @@ dwarf_build_psymtabs (objfile, section_offsets, mainline, dbfoff, dbfsize,
   current_objfile = NULL;
 }
 
-
-/*
-
-LOCAL FUNCTION
-
-       record_minimal_symbol -- add entry to gdb's minimal symbol table
-
-SYNOPSIS
-
-       static void record_minimal_symbol (char *name, CORE_ADDR address,
-                                         enum minimal_symbol_type ms_type,
-                                         struct objfile *objfile)
-
-DESCRIPTION
-
-       Given a pointer to the name of a symbol that should be added to the
-       minimal symbol table, and the address associated with that
-       symbol, records this information for later use in building the
-       minimal symbol table.
-
- */
-
-static void
-record_minimal_symbol (name, address, ms_type, objfile)
-     char *name;
-     CORE_ADDR address;
-     enum minimal_symbol_type ms_type;
-     struct objfile *objfile;
-{
-  name = obsavestring (name, strlen (name), &objfile -> symbol_obstack);
-  prim_record_minimal_symbol (name, address, ms_type);
-}
-
 /*
 
 LOCAL FUNCTION
@@ -1032,7 +987,6 @@ struct_type (dip, thisdie, enddie, objfile)
   struct nextfield *new;
   int nfields = 0;
   int n;
-  char *tpart1;
   struct dieinfo mbr;
   char *nextdie;
 #if !BITS_BIG_ENDIAN
@@ -1049,20 +1003,16 @@ struct_type (dip, thisdie, enddie, objfile)
     {
       case TAG_class_type:
         TYPE_CODE (type) = TYPE_CODE_CLASS;
-       tpart1 = "class";
        break;
       case TAG_structure_type:
         TYPE_CODE (type) = TYPE_CODE_STRUCT;
-       tpart1 = "struct";
        break;
       case TAG_union_type:
        TYPE_CODE (type) = TYPE_CODE_UNION;
-       tpart1 = "union";
        break;
       default:
        /* Should never happen */
        TYPE_CODE (type) = TYPE_CODE_UNDEF;
-       tpart1 = "???";
        complain (&missing_tag, DIE_ID, DIE_NAME);
        break;
     }
@@ -1073,8 +1023,8 @@ struct_type (dip, thisdie, enddie, objfile)
       && *dip -> at_name != '~'
       && *dip -> at_name != '.')
     {
-      TYPE_NAME (type) = obconcat (&objfile -> type_obstack,
-                                  tpart1, " ", dip -> at_name);
+      TYPE_TAG_NAME (type) = obconcat (&objfile -> type_obstack,
+                                      "", "", dip -> at_name);
     }
   /* Use whatever size is known.  Zero is a valid size.  We might however
      wish to check has_at_byte_size to make sure that some byte size was
@@ -1553,30 +1503,39 @@ read_tag_string_type (dip)
   unsigned long lowbound = 0;
   unsigned long highbound;
 
-  if ((utype = lookup_utype (dip -> die_ref)) != NULL)
+  if (dip -> has_at_byte_size)
     {
-      /* Ack, someone has stuck a type in the slot we want.  Complain
-        about it. */
-      complain (&dup_user_type_definition, DIE_ID, DIE_NAME);
+      /* A fixed bounds string */
+      highbound = dip -> at_byte_size - 1;
     }
   else
     {
-      if (dip -> has_at_byte_size)
-       {
-         /* A fixed bounds string */
-         highbound = dip -> at_byte_size - 1;
-       }
-      else
+      /* A varying length string.  Stub for now.  (FIXME) */
+      highbound = 1;
+    }
+  indextype = dwarf_fundamental_type (current_objfile, FT_INTEGER);
+  rangetype = create_range_type ((struct type *) NULL, indextype, lowbound,
+                                highbound);
+      
+  utype = lookup_utype (dip -> die_ref);
+  if (utype == NULL)
+    {
+      /* No type defined, go ahead and create a blank one to use. */
+      utype = alloc_utype (dip -> die_ref, (struct type *) NULL);
+    }
+  else
+    {
+      /* Already a type in our slot due to a forward reference. Make sure it
+        is a blank one.  If not, complain and leave it alone. */
+      if (TYPE_CODE (utype) != TYPE_CODE_UNDEF)
        {
-         /* A varying length string.  Stub for now.  (FIXME) */
-         highbound = 1;
+         complain (&dup_user_type_definition, DIE_ID, DIE_NAME);
+         return;
        }
-      indextype = dwarf_fundamental_type (current_objfile, FT_INTEGER);
-      rangetype = create_range_type ((struct type *) NULL, indextype,
-                                    lowbound, highbound);
-      utype = create_string_type ((struct type *) NULL, rangetype);
-      alloc_utype (dip -> die_ref, utype);
     }
+
+  /* Create the string type using the blank type we either found or created. */
+  utype = create_string_type (utype, rangetype);
 }
 
 /*
@@ -1753,8 +1712,8 @@ enum_type (dip, objfile)
       && *dip -> at_name != '~'
       && *dip -> at_name != '.')
     {
-      TYPE_NAME (type) = obconcat (&objfile -> type_obstack, "enum",
-                                  ", dip -> at_name);
+      TYPE_TAG_NAME (type) = obconcat (&objfile -> type_obstack,
+                                      "", "", dip -> at_name);
     }
   if (dip -> at_byte_size != 0)
     {
@@ -1897,9 +1856,7 @@ handle_producer (producer)
 
   processing_gcc_compilation =
     STREQN (producer, GPLUS_PRODUCER, strlen (GPLUS_PRODUCER))
-      /* start-sanitize-chill */
       || STREQN (producer, CHILL_PRODUCER, strlen (CHILL_PRODUCER))
-      /* end-sanitize-chill */
       || STREQN (producer, GCC_PRODUCER, strlen (GCC_PRODUCER));
 
   /* Select a demangling style if we can identify the producer and if
@@ -1907,7 +1864,6 @@ handle_producer (producer)
      is not auto.  We also leave the demangling style alone if we find a
      gcc (cc1) producer, as opposed to a g++ (cc1plus) producer. */
 
-#if 1 /* Works, but is experimental.  -fnf */
   if (AUTO_DEMANGLING)
     {
       if (STREQN (producer, GPLUS_PRODUCER, strlen (GPLUS_PRODUCER)))
@@ -1918,12 +1874,7 @@ handle_producer (producer)
        {
          set_demangling_style (LUCID_DEMANGLING_STYLE_STRING);
        }
-      else if (STREQN (producer, CFRONT_PRODUCER, strlen (CFRONT_PRODUCER)))
-       {
-         set_demangling_style (CFRONT_DEMANGLING_STYLE_STRING);
-       }
     }
-#endif
 }
 
 
@@ -1978,7 +1929,8 @@ read_file_scope (dip, thisdie, enddie, objfile)
   start_symtab (dip -> at_name, dip -> at_comp_dir, dip -> at_low_pc);
   decode_line_numbers (lnbase);
   process_dies (thisdie + dip -> die_length, enddie, objfile);
-  symtab = end_symtab (dip -> at_high_pc, 0, 0, objfile);
+
+  symtab = end_symtab (dip -> at_high_pc, 0, 0, objfile, 0);
   if (symtab != NULL)
     {
       symtab -> language = cu_language;
@@ -2036,10 +1988,21 @@ process_dies (thisdie, enddie, objfile)
            {
              nextdie = thisdie + di.die_length;
            }
+#ifdef SMASH_TEXT_ADDRESS
+         /* I think that these are always text, not data, addresses.  */
+         SMASH_TEXT_ADDRESS (di.at_low_pc);
+         SMASH_TEXT_ADDRESS (di.at_high_pc);
+#endif
          switch (di.die_tag)
            {
            case TAG_compile_unit:
-             read_file_scope (&di, thisdie, nextdie, objfile);
+             /* Skip Tag_compile_unit if we are already inside a compilation
+                unit, we are unable to handle nested compilation units
+                properly (FIXME).  */
+             if (current_subfile == NULL)
+               read_file_scope (&di, thisdie, nextdie, objfile);
+             else
+               nextdie = thisdie + di.die_length;
              break;
            case TAG_global_subroutine:
            case TAG_subroutine:
@@ -2220,7 +2183,6 @@ locval (loc)
   auto long stack[64];
   int stacki;
   char *end;
-  long regno;
   int loc_atom_code;
   int loc_value_size;
   
@@ -2253,21 +2215,13 @@ locval (loc)
            break;
          case OP_BASEREG:
            /* push value of register (number) */
-           /* Actually, we compute the value as if register has 0 */
+           /* Actually, we compute the value as if register has 0, so the
+              value ends up being the offset from that register.  */
            offreg = 1;
-           regno = target_to_host (loc, loc_value_size, GET_UNSIGNED,
-                                   current_objfile);
+           basereg = target_to_host (loc, loc_value_size, GET_UNSIGNED,
+                                     current_objfile);
            loc += loc_value_size;
-           if (regno == R_FP)
-             {
-               stack[++stacki] = 0;
-             }
-           else
-             {
-               stack[++stacki] = 0;
-
-               complain (&basereg_not_handled, DIE_ID, DIE_NAME, regno);
-             }
+           stack[++stacki] = 0;
            break;
          case OP_ADDR:
            /* push address (relocated address) */
@@ -2305,19 +2259,18 @@ LOCAL FUNCTION
 
 SYNOPSIS
 
-       static struct symtab *read_ofile_symtab (struct partial_symtab *pst)
+       static void read_ofile_symtab (struct partial_symtab *pst)
 
 DESCRIPTION
 
        When expanding a partial symbol table entry to a full symbol table
        entry, this is the function that gets called to read in the symbols
-       for the compilation unit.
-
-       Returns a pointer to the newly constructed symtab (which is now
-       the new first one on the objfile's symtab list).
+       for the compilation unit.  A pointer to the newly constructed symtab,
+       which is now the new first one on the objfile's symtab list, is
+       stashed in the partial symbol table entry.
  */
 
-static struct symtab *
+static void
 read_ofile_symtab (pst)
      struct partial_symtab *pst;
 {
@@ -2377,7 +2330,7 @@ read_ofile_symtab (pst)
   process_dies (dbbase, dbbase + dbsize, pst -> objfile);
   do_cleanups (back_to);
   current_objfile = NULL;
-  return (pst -> objfile -> symtabs);
+  pst -> symtab = pst -> objfile -> symtabs;
 }
 
 /*
@@ -2421,14 +2374,14 @@ psymtab_to_symtab_1 (pst)
                  /* Inform about additional files that need to be read in. */
                  if (info_verbose)
                    {
-                     fputs_filtered (" ", stdout);
+                     fputs_filtered (" ", gdb_stdout);
                      wrap_here ("");
-                     fputs_filtered ("and ", stdout);
+                     fputs_filtered ("and ", gdb_stdout);
                      wrap_here ("");
                      printf_filtered ("%s...",
                                       pst -> dependencies[i] -> filename);
                      wrap_here ("");
-                     fflush (stdout);          /* Flush output */
+                     gdb_flush (gdb_stdout);           /* Flush output */
                    }
                  psymtab_to_symtab_1 (pst -> dependencies[i]);
                }
@@ -2437,12 +2390,12 @@ psymtab_to_symtab_1 (pst)
            {
              buildsym_init ();
              old_chain = make_cleanup (really_free_pendings, 0);
-             pst -> symtab = read_ofile_symtab (pst);
+             read_ofile_symtab (pst);
              if (info_verbose)
                {
                  printf_filtered ("%d DIE's, sorting...", diecount);
                  wrap_here ("");
-                 fflush (stdout);
+                 gdb_flush (gdb_stdout);
                }
              sort_symtab_syms (pst -> symtab);
              do_cleanups (old_chain);
@@ -2492,7 +2445,7 @@ dwarf_psymtab_to_symtab (pst)
                {
                  printf_filtered ("Reading in symbols for %s...",
                                   pst -> filename);
-                 fflush (stdout);
+                 gdb_flush (gdb_stdout);
                }
              
              psymtab_to_symtab_1 (pst);
@@ -2510,7 +2463,7 @@ dwarf_psymtab_to_symtab (pst)
              if (info_verbose)
                {
                  printf_filtered ("done.\n");
-                 fflush (stdout);
+                 gdb_flush (gdb_stdout);
                }
            }
        }
@@ -2637,16 +2590,12 @@ add_partial_symbol (dip, objfile)
   switch (dip -> die_tag)
     {
     case TAG_global_subroutine:
-      record_minimal_symbol (dip -> at_name, dip -> at_low_pc, mst_text,
-                           objfile);
       ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
                           VAR_NAMESPACE, LOC_BLOCK,
                           objfile -> global_psymbols,
                           dip -> at_low_pc, cu_language, objfile);
       break;
     case TAG_global_variable:
-      record_minimal_symbol (dip -> at_name, locval (dip -> at_location),
-                           mst_data, objfile);
       ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
                           VAR_NAMESPACE, LOC_STATIC,
                           objfile -> global_psymbols,
@@ -2674,6 +2623,9 @@ add_partial_symbol (dip, objfile)
     case TAG_structure_type:
     case TAG_union_type:
     case TAG_enumeration_type:
+      /* Do not add opaque aggregate definitions to the psymtab.  */
+      if (!dip -> has_at_byte_size)
+       break;
       ADD_PSYMBOL_TO_LIST (dip -> at_name, strlen (dip -> at_name),
                           STRUCT_NAMESPACE, LOC_TYPEDEF,
                           objfile -> static_psymbols,
@@ -3039,7 +2991,8 @@ new_symbol (dip, objfile)
                }
              else if (offreg)
                {
-                 SYMBOL_CLASS (sym) = LOC_LOCAL;
+                 SYMBOL_CLASS (sym) = LOC_BASEREG;
+                 SYMBOL_BASEREG (sym) = basereg;
                }
              else
                {
@@ -3058,6 +3011,11 @@ new_symbol (dip, objfile)
            {
              SYMBOL_CLASS (sym) = LOC_REGPARM;
            }
+         else if (offreg)
+           {
+             SYMBOL_CLASS (sym) = LOC_BASEREG_ARG;
+             SYMBOL_BASEREG (sym) = basereg;
+           }
          else
            {
              SYMBOL_CLASS (sym) = LOC_ARG;
This page took 0.029362 seconds and 4 git commands to generate.