Output hex with local_hex_string for Modula-2 support.
[deliverable/binutils-gdb.git] / gdb / dbxread.c
index 619c471b60aa909e9e029bcd1e31b5d298156782..6d138e0030c57a15aa80bbefe9045fe25aef89fb 100644 (file)
@@ -16,17 +16,20 @@ GNU General Public License for more details.
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
-\f
-/* Symbol read-in occurs in two phases:
-   1.  A scan (read_dbx_symtab()) of the entire executable, whose sole
-       purpose is to make a list of symbols (partial symbol table)
-       which will cause symbols
-       to be read in if referenced.  This scan happens when the
-       "symbol-file" command is given (symbol_file_command()).
-   1a. The "add-file" command.  Similar to #1.
-   2.  Full read-in of symbols.  (dbx_psymtab_to_symtab()).  This happens
-       when a symbol in a file for which symbols have not yet been
-       read in is referenced.  */
+
+/* This module provides three functions: dbx_symfile_init,
+   which initializes to read a symbol file; dbx_new_init, which 
+   discards existing cached information when all symbols are being
+   discarded; and dbx_symfile_read, which reads a symbol table
+   from a file.
+
+   dbx_symfile_read only does the minimum work necessary for letting the
+   user "name" things symbolically; it does not read the entire symtab.
+   Instead, it reads the external and static symbols and puts them in partial
+   symbol tables.  When more extensive information is requested of a
+   file, the corresponding partial symbol table is mutated into a full
+   fledged symbol table by going back and reading the symbols
+   for real.  dbx_psymtab_to_symtab() is the function that does this */
 
 #include <stdio.h>
 #include <string.h>
@@ -151,14 +154,14 @@ static void fix_common_block ();
 static void add_undefined_type ();
 static void cleanup_undefined_types ();
 static void scan_file_globals ();
-static void read_ofile_symtab ();
+static struct symtab *read_ofile_symtab ();
 static void dbx_psymtab_to_symtab ();
 
 /* C++ */
 static struct type **read_args ();
 
-static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER };
-static const char vb_name[] =   { '_','v','b',CPLUS_MARKER };
+static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
+static const char vb_name[] =   { '_','v','b',CPLUS_MARKER,'\0' };
 
 /* Macro to determine which symbols to ignore when reading the first symbol
    of a file.  Some machines override this definition. */
@@ -323,6 +326,13 @@ int context_stack_size;
 
 int within_function;
 
+#if 0
+/* The type of the function we are currently reading in.  This is
+   used by define_symbol to record the type of arguments to a function. */
+
+static struct type *in_function_type;
+#endif
+
 /* List of blocks already made (lexical contexts already closed).
    This is used at the end to make the blockvector.  */
 
@@ -384,7 +394,7 @@ struct complaint string_table_offset_complaint =
   {"bad string table offset in symbol %d", 0, 0};
 
 struct complaint unknown_symtype_complaint =
-  {"unknown symbol type 0x%x", 0, 0};
+  {"unknown symbol type %s", 0, 0};
 
 struct complaint lbrac_rbrac_complaint =
   {"block start larger than block end", 0, 0};
@@ -1094,7 +1104,7 @@ start_subfile (name, dirname)
 
    END_ADDR is the address of the end of the file's text.  */
 
-static void
+static struct symtab *
 end_symtab (end_addr)
      CORE_ADDR end_addr;
 {
@@ -1130,11 +1140,11 @@ end_symtab (end_addr)
   current_subfile->line_vector_index = line_vector_index;
 
   /* Now create the symtab objects proper, one for each subfile.  */
-  /* (The main file is one of them.)  */
+  /* (The main file is the last one on the chain.)  */
 
   for (subfile = subfiles; subfile; subfile = nextsub)
     {
-      symtab = (struct symtab *) xmalloc (sizeof (struct symtab));
+      symtab = allocate_symtab (subfile->name);
 
       /* Fill in its components.  */
       symtab->blockvector = blockvector;
@@ -1146,7 +1156,6 @@ end_symtab (end_addr)
       type_vector->length = type_vector_length;
       symtab->typevector = type_vector;
 
-      symtab->filename = subfile->name;
       symtab->dirname = subfile->dirname;
 
       symtab->free_code = free_linetable;
@@ -1154,12 +1163,6 @@ end_symtab (end_addr)
       if (subfile->next == 0)
        symtab->free_ptr = (char *) type_vector;
 
-      symtab->nlines = 0;
-      symtab->line_charpos = 0;
-
-      symtab->language = language_unknown;
-      symtab->fullname = NULL;
-
       /* There should never already be a symtab for this name, since
         any prev dups have been removed when the psymtab was read in.
         FIXME, there ought to be a way to check this here.  */
@@ -1178,6 +1181,8 @@ end_symtab (end_addr)
   line_vector = 0;
   line_vector_length = -1;
   last_source_file = 0;
+
+  return symtab;
 }
 \f
 /* Handle the N_BINCL and N_EINCL symbol types
@@ -1231,14 +1236,18 @@ record_misc_function (name, address, type)
      CORE_ADDR address;
      int type;
 {
-  enum misc_function_type misc_type =
-    (type == (N_TEXT | N_EXT) ? mf_text :
-     (type == (N_DATA | N_EXT)
-      || type == (N_DATA)
-      || type == (N_SETV | N_EXT)
-      ) ? mf_data :
-     type == (N_BSS | N_EXT) ? mf_bss :
-     type == (N_ABS | N_EXT) ? mf_abs : mf_unknown);
+  enum misc_function_type misc_type;
+
+  switch (type &~ N_EXT) {
+    case N_TEXT:  misc_type = mf_text; break;
+    case N_DATA:  misc_type = mf_data; break;
+    case N_BSS:   misc_type = mf_bss;  break;
+    case N_ABS:   misc_type = mf_abs;  break;
+#ifdef N_SETV
+    case N_SETV:  misc_type = mf_data; break;
+#endif
+    default:      misc_type = mf_unknown; break;
+  }
 
   prim_record_misc_function (obsavestring (name, strlen (name)),
                             address, misc_type);
@@ -1315,39 +1324,29 @@ dbx_symfile_read (sf, addr, mainline)
   free (info);
   sf->sym_private = 0;         /* Zap pointer to our (now gone) info struct */
 
-  if (!partial_symtab_list)
-    printf_filtered ("\n(no debugging symbols found)...");
+  if (!partial_symtab_list) {
+    wrap_here ("");
+    printf_filtered ("(no debugging symbols found)...");
+    wrap_here ("");
+  }
 }
 
-/* Discard any information we have cached during the reading of a
-   single symbol file.  This should not toss global information
-   from previous symbol files that have been read.  E.g. we might
-   be discarding info from reading a shared library, and should not
-   throw away the info from the main file.  */
+/* Initialize anything that needs initializing when a completely new
+   symbol file is specified (not just adding some symbols from another
+   file, e.g. a shared library).  */
 
 void
-dbx_symfile_discard ()
+dbx_new_init ()
 {
-
   /* Empty the hash table of global syms looking for values.  */
   bzero (global_sym_chain, sizeof global_sym_chain);
 
   free_pendings = 0;
   file_symbols = 0;
   global_symbols = 0;
-}
 
-/* Initialize anything that needs initializing when a completely new
-   symbol file is specified (not just adding some symbols from another
-   file, e.g. a shared library).  */
-
-void
-dbx_new_init ()
-{
-  dbx_symfile_discard ();
   /* Don't put these on the cleanup chain; they need to stick around
-     until the next call to symbol_file_command.  *Then* we'll free
-     them. */
+     until the next call to dbx_new_init.  *Then* we'll free them. */
   if (symfile_string_table)
     {
       free (symfile_string_table);
@@ -1969,7 +1968,6 @@ read_dbx_symtab (symfile_name, addr,
                               namestring, valu,
                               first_symnum * sizeof (struct nlist),
                               global_psymbols.next, static_psymbols.next);
-
          continue;
        }
 
@@ -2316,6 +2314,7 @@ read_dbx_symtab (symfile_name, addr,
        case N_LBRAC:
        case N_RBRAC:
        case N_NSYMS:           /* Ultrix 4.0: symbol count */
+       case N_DEFD:            /* GNU Modula-2 */
          /* These symbols aren't interesting; don't worry about them */
 
          continue;
@@ -2323,7 +2322,7 @@ read_dbx_symtab (symfile_name, addr,
        default:
          /* If we haven't found it yet, ignore it.  It's probably some
             new type we don't know about yet.  */
-         complain (&unknown_symtype_complaint, bufp->n_type);
+         complain (&unknown_symtype_complaint, local_hex_string(bufp->n_type));
          continue;
        }
     }
@@ -2411,8 +2410,11 @@ compare_psymbols (s1, s2)
     *st1 = SYMBOL_NAME (s1),
     *st2 = SYMBOL_NAME (s2);
 
-  return (st1[0] - st2[0] ? st1[0] - st2[0] :
-         strcmp (st1 + 1, st2 + 1));
+  if (st1[0] - st2[0])
+    return st1[0] - st2[0];
+  if (st1[1] - st2[1])
+    return st1[1] - st2[1];
+  return strcmp (st1 + 1, st2 + 1);
 }
 
 
@@ -2568,11 +2570,12 @@ psymtab_to_symtab_1 (pst, desc, stringtab, stringtab_size, sym_offset)
 
       /* Read in this files symbols */
       lseek (desc, sym_offset, L_SET);
-      read_ofile_symtab (desc, stringtab, stringtab_size,
-                        pst->ldsymoff,
-                        pst->ldsymlen, pst->textlow,
-                        pst->texthigh - pst->textlow, pst->addr);
-      sort_symtab_syms (symtab_list); /* At beginning since just added */
+      pst->symtab =
+       read_ofile_symtab (desc, stringtab, stringtab_size,
+                          pst->ldsymoff,
+                          pst->ldsymlen, pst->textlow,
+                          pst->texthigh - pst->textlow, pst->addr);
+      sort_symtab_syms (pst->symtab);
 
       do_cleanups (old_chain);
     }
@@ -2761,6 +2764,7 @@ scan_file_globals ()
 }
 
 /* Process a pair of symbols.  Currently they must both be N_SO's.  */
+/* ARGSUSED */
 static void
 process_symbol_pair (type1, desc1, value1, name1,
                     type2, desc2, value2, name2)
@@ -2776,7 +2780,7 @@ process_symbol_pair (type1, desc1, value1, name1,
   /* No need to check PCC_SOL_BROKEN, on the assumption that such
      broken PCC's don't put out N_SO pairs.  */
   if (last_source_file)
-    end_symtab (value2);
+    (void)end_symtab (value2);
   start_symtab (name2, name1, value2);
 }
 
@@ -2795,7 +2799,7 @@ process_symbol_pair (type1, desc1, value1, name1,
  * OFFSET is a relocation offset which gets added to each symbol
  */
 
-static void
+static struct symtab *
 read_ofile_symtab (desc, stringtab, stringtab_size, sym_offset,
                   sym_size, text_offset, text_size, offset)
      int desc;
@@ -2929,7 +2933,7 @@ read_ofile_symtab (desc, stringtab, stringtab_size, sym_offset,
        processing_gcc_compilation = 1;
       else if (type & N_EXT || type == (unsigned char)N_TEXT
               || type == (unsigned char)N_NBTEXT
-              )
+              ) {
          /* Global symbol: see if we came across a dbx defintion for
             a corresponding symbol.  If so, store the value.  Remove
             syms from the chain when their values are stored, but
@@ -2940,8 +2944,10 @@ read_ofile_symtab (desc, stringtab, stringtab_size, sym_offset,
             be satisfied in each file as it appears. So we skip this
             section. */
          ;
+        }
     }
-  end_symtab (text_offset + text_size);
+
+  return end_symtab (text_offset + text_size);
 }
 \f
 static int
@@ -3168,7 +3174,7 @@ process_one_symbol (type, desc, valu, name)
        }
 #endif
       if (last_source_file)
-       end_symtab (valu);
+       (void)end_symtab (valu);
       start_symtab (name, NULL, valu);
       break;
 
@@ -3236,6 +3242,7 @@ process_one_symbol (type, desc, valu, name)
 
     case N_ECOML:
     case N_LENG:
+    case N_DEFD:               /* GNU Modula-2 symbol */
       break;
 
     default:
@@ -3275,6 +3282,7 @@ read_type_number (pp, typenums)
    get this name).  */
 static char *type_synonym_name;
 
+/* ARGSUSED */
 static struct symbol *
 define_symbol (valu, string, desc, type)
      unsigned int valu;
@@ -3443,7 +3451,22 @@ define_symbol (valu, string, desc, type)
 
       if ((deftype == 'F' || deftype == 'f')
          && TYPE_CODE (type_read) != TYPE_CODE_FUNC)
+      {
+#if 0
+/* This code doesn't work -- it needs to realloc and can't.  */
+       struct type *new = (struct type *)
+             obstack_alloc (symbol_obstack, sizeof (struct type));
+
+       /* Generate a template for the type of this function.  The 
+          types of the arguments will be added as we read the symbol 
+          table. */
+       *new = *lookup_function_type (type_read);
+       SYMBOL_TYPE(sym) = new;
+       in_function_type = new;
+#else
        SYMBOL_TYPE (sym) = lookup_function_type (type_read);
+#endif
+      }
       else
        SYMBOL_TYPE (sym) = type_read;
     }
@@ -3502,6 +3525,10 @@ define_symbol (valu, string, desc, type)
       SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
       SYMBOL_VALUE (sym) = valu;
       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
+#if 0
+      /* This doesn't work yet.  */
+      add_param_to_type (&in_function_type, sym);
+#endif
       add_symbol_to_list (sym, &local_symbols);
 
       /* If it's gcc-compiled, if it says `short', believe it.  */
@@ -3599,11 +3626,11 @@ define_symbol (valu, string, desc, type)
                 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
                && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
         {
-          int i;
-          for (i = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; i >= 0; i--)
-            if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), i) == 0)
-              TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), i) =
-                type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), i));
+          int j;
+          for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
+            if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
+              TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
+                type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
         }
 
       add_symbol_to_list (sym, &file_symbols);
@@ -4360,6 +4387,9 @@ read_struct_type (pp, type)
              /* This field is unpacked.  */
              list->field.bitsize = 0;
            }
+         /* GNU C++ anonymous type.  */
+         else if (*p == '_')
+           break;
          else
            error ("invalid abbreviation at symtab pos %d.", symnum);
 
@@ -4934,17 +4964,25 @@ read_enum_type (pp, type)
        j = o_nsyms;
       for (; j < syms->nsyms; j++,n++)
        {
-         struct symbol *sym = syms->symbol[j];
-         SYMBOL_TYPE (sym) = type;
-         TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (sym);
+         struct symbol *xsym = syms->symbol[j];
+         SYMBOL_TYPE (xsym) = type;
+         TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
          TYPE_FIELD_VALUE (type, n) = 0;
-         TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (sym);
+         TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
          TYPE_FIELD_BITSIZE (type, n) = 0;
        }
       if (syms == osyms)
        break;
     }
 
+  /* Is this Modula-2's BOOLEAN type?  Flag it as such if so. */
+  if(TYPE_NFIELDS(type) == 2 &&
+     ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
+       !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
+      (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
+       !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
+     TYPE_CODE(type) = TYPE_CODE_BOOL;
+
   return type;
 }
 
@@ -5061,8 +5099,8 @@ read_huge_number (pp, end, valu, bits)
     }
 }
 
-#define        MAX_OF_TYPE(t)  ((1 << (sizeof (t)*8 - 1)) - 1)
-#define MIN_OF_TYPE(t) (-(1 << (sizeof (t)*8 - 1)))
+#define        MAX_OF_C_TYPE(t)        ((1 << (sizeof (t)*8 - 1)) - 1)
+#define MIN_OF_C_TYPE(t)       (-(1 << (sizeof (t)*8 - 1)))
 
 static struct type *
 read_range_type (pp, typenums)
@@ -5222,34 +5260,39 @@ read_range_type (pp, typenums)
                                               sizeof (struct type));
   bzero (result_type, sizeof (struct type));
 
-  TYPE_TARGET_TYPE (result_type) = (self_subrange ?
-                                   builtin_type_int :
-                                   *dbx_lookup_type(rangenums));
+  TYPE_CODE (result_type) = TYPE_CODE_RANGE;
 
+  TYPE_TARGET_TYPE (result_type) = *dbx_lookup_type(rangenums);
+
+  TYPE_NFIELDS (result_type) = 2;
+  TYPE_FIELDS (result_type) =
+     (struct field *) obstack_alloc (symbol_obstack,
+                                    2 * sizeof (struct field));
+  bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field));
+  TYPE_FIELD_BITPOS (result_type, 0) = n2;
+  TYPE_FIELD_BITPOS (result_type, 1) = n3;
+
+#if 0
+/* Note that TYPE_LENGTH (result_type) is just overridden a few
+   statements down.  What do we really need here?  */
   /* We have to figure out how many bytes it takes to hold this
      range type.  I'm going to assume that anything that is pushing
      the bounds of a long was taken care of above.  */
-  if (n2 >= MIN_OF_TYPE(char) && n3 <= MAX_OF_TYPE(char))
+  if (n2 >= MIN_OF_C_TYPE(char) && n3 <= MAX_OF_C_TYPE(char))
     TYPE_LENGTH (result_type) = 1;
-  else if (n2 >= MIN_OF_TYPE(short) && n3 <= MAX_OF_TYPE(short))
+  else if (n2 >= MIN_OF_C_TYPE(short) && n3 <= MAX_OF_C_TYPE(short))
     TYPE_LENGTH (result_type) = sizeof (short);
-  else if (n2 >= MIN_OF_TYPE(int) && n3 <= MAX_OF_TYPE(int))
+  else if (n2 >= MIN_OF_C_TYPE(int) && n3 <= MAX_OF_C_TYPE(int))
     TYPE_LENGTH (result_type) = sizeof (int);
-  else if (n2 >= MIN_OF_TYPE(long) && n3 <= MAX_OF_TYPE(long))
+  else if (n2 >= MIN_OF_C_TYPE(long) && n3 <= MAX_OF_C_TYPE(long))
     TYPE_LENGTH (result_type) = sizeof (long);
   else
     /* Ranged type doesn't fit within known sizes.  */
+    /* FIXME -- use "long long" here.  */
     return error_type (pp);
+#endif
 
   TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
-  TYPE_CODE (result_type) = TYPE_CODE_RANGE;
-  TYPE_NFIELDS (result_type) = 2;
-  TYPE_FIELDS (result_type) =
-    (struct field *) obstack_alloc (symbol_obstack,
-                                   2 * sizeof (struct field));
-  bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field));
-  TYPE_FIELD_BITPOS (result_type, 0) = n2;
-  TYPE_FIELD_BITPOS (result_type, 1) = n3;
 
   return result_type;
 }
@@ -5382,16 +5425,13 @@ fix_common_block (sym, valu)
 /* Register our willingness to decode symbols for SunOS and a.out and
    b.out files handled by BFD... */
 static struct sym_fns sunos_sym_fns = {"sunOs", 6,
-              dbx_new_init, dbx_symfile_init,
-              dbx_symfile_read, dbx_symfile_discard};
+              dbx_new_init, dbx_symfile_init, dbx_symfile_read};
 
 static struct sym_fns aout_sym_fns = {"a.out", 5,
-              dbx_new_init, dbx_symfile_init,
-              dbx_symfile_read, dbx_symfile_discard};
+              dbx_new_init, dbx_symfile_init, dbx_symfile_read};
 
 static struct sym_fns bout_sym_fns = {"b.out", 5,
-              dbx_new_init, dbx_symfile_init,
-              dbx_symfile_read, dbx_symfile_discard};
+              dbx_new_init, dbx_symfile_init, dbx_symfile_read};
 
 void
 _initialize_dbxread ()
@@ -5404,6 +5444,4 @@ _initialize_dbxread ()
   undef_types_length = 0;
   undef_types = (struct type **) xmalloc (undef_types_allocated *
                                          sizeof (struct type *));
-
-  dbx_new_init ();
 }
This page took 0.036351 seconds and 4 git commands to generate.