* doc/gdb.texinfo (appendix "Installing GDB"): changes in configure.
[deliverable/binutils-gdb.git] / gdb / symtab.c
index 6ebea5ee16abebacfb71a5483a69f3c9a15f2446..2d6cd05d755df162494bc806b238a849a6abcec4 100644 (file)
@@ -1,21 +1,21 @@
 /* Symbol table lookup for the GNU debugger, GDB.
-   Copyright (C) 1986, 1987, 1988, 1989, 1990 Free Software Foundation, Inc.
+   Copyright 1986, 1987, 1988, 1989, 1990, 1991 Free Software Foundation, Inc.
 
 This file is part of GDB.
 
-GDB is free software; you can redistribute it and/or modify
+This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 1, or (at your option)
-any later version.
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
 
-GDB is distributed in the hope that it will be useful,
+This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with GDB; see the file COPYING.  If not, write to
-the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
 
 #include <stdio.h>
 #include "defs.h"
@@ -28,6 +28,7 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include "symfile.h"
 #include "gdbcmd.h"
 #include "regex.h"
+#include "language.h"
 
 #include <obstack.h>
 #include <assert.h>
@@ -37,8 +38,6 @@ the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
 #include <string.h>
 #include <sys/stat.h>
 
-extern int close ();
-extern void qsort ();
 extern char *getenv ();
 
 extern char *cplus_demangle ();
@@ -53,22 +52,7 @@ static struct partial_symbol *lookup_partial_symbol ();
 static struct partial_symbol *lookup_demangled_partial_symbol ();
 static struct symbol *lookup_demangled_block_symbol ();
 
-/* These variables point to the objects
-   representing the predefined C data types.  */
-
-struct type *builtin_type_void;
-struct type *builtin_type_char;
-struct type *builtin_type_short;
-struct type *builtin_type_int;
-struct type *builtin_type_long;
-struct type *builtin_type_long_long;
-struct type *builtin_type_unsigned_char;
-struct type *builtin_type_unsigned_short;
-struct type *builtin_type_unsigned_int;
-struct type *builtin_type_unsigned_long;
-struct type *builtin_type_unsigned_long_long;
-struct type *builtin_type_float;
-struct type *builtin_type_double;
+/* The single non-language-specific builtin type */
 struct type *builtin_type_error;
 
 /* Block in which the most recently searched-for symbol was found.
@@ -208,7 +192,8 @@ type_name_no_tag (type)
    If this is a stubbed struct (i.e. declared as struct foo *), see if
    we can find a full definition in some other file. If so, copy this
    definition, so we can use it in future.  If not, set a flag so we 
-   don't waste too much time in future.
+   don't waste too much time in future.  (FIXME, this doesn't seem
+   to be happening...)
 
    This used to be coded as a macro, but I don't think it is called 
    often enough to merit such treatment.
@@ -273,21 +258,12 @@ struct type *
 lookup_primitive_typename (name)
      char *name;
 {
-  if (!strcmp (name, "int"))
-    return builtin_type_int;
-  if (!strcmp (name, "long"))
-    return builtin_type_long;
-  if (!strcmp (name, "short"))
-    return builtin_type_short;
-  if (!strcmp (name, "char"))
-    return builtin_type_char;
-  if (!strcmp (name, "float"))
-    return builtin_type_float;
-  if (!strcmp (name, "double"))
-    return builtin_type_double;
-  if (!strcmp (name, "void"))
-    return builtin_type_void;
-  return 0;
+   struct type ** const *p;
+
+   for (p = current_language->la_builtin_type_vector; *p; p++)
+      if(!strcmp((**p)->name, name))
+        return **p;
+   return 0; 
 }
 
 /* Lookup a typedef or primitive type named NAME,
@@ -306,9 +282,12 @@ lookup_typename (name, block, noerr)
     {
       struct type *tmp;
       tmp = lookup_primitive_typename (name);
-      if (!tmp && noerr)
+      if(tmp)
+        return tmp;
+      else if (!tmp && noerr)
        return 0;
-      error ("No type named %s.", name);
+      else
+        error ("No type named %s.", name);
     }
   return SYMBOL_TYPE (sym);
 }
@@ -317,16 +296,11 @@ struct type *
 lookup_unsigned_typename (name)
      char *name;
 {
-  if (!strcmp (name, "int"))
-    return builtin_type_unsigned_int;
-  if (!strcmp (name, "long"))
-    return builtin_type_unsigned_long;
-  if (!strcmp (name, "short"))
-    return builtin_type_unsigned_short;
-  if (!strcmp (name, "char"))
-    return builtin_type_unsigned_char;
-  error ("No type named unsigned %s.", name);
-  return (struct type *)-1;  /* for lint */
+  char *uns = alloca (strlen(name) + 10);
+
+  strcpy (uns, "unsigned ");
+  strcpy (uns+9, name);
+  return lookup_typename (uns, (struct block *)0, 0);
 }
 
 /* Lookup a structure type named "struct NAME",
@@ -463,6 +437,8 @@ lookup_pointer_type (type)
   if (TYPE_FLAGS (type) & TYPE_FLAG_PERM)
     TYPE_FLAGS (ptype) |= TYPE_FLAG_PERM;
   /* We assume the machine has only one representation for pointers!  */
+  /* FIXME:  This confuses host<->target data representations, and is a
+     poor assumption besides. */
   TYPE_LENGTH (ptype) = sizeof (char *);
   TYPE_CODE (ptype) = TYPE_CODE_PTR;
   return ptype;
@@ -574,13 +550,13 @@ allocate_stub_method (type)
   return mtype;
 }
 
-/* Lookup a method type returning type TYPE, belonging
-   to class DOMAIN, and taking a list of arguments ARGS.
+/* Lookup a method type belonging to class DOMAIN, returning type TYPE,
+   and taking a list of arguments ARGS.
    If one is not found, allocate a new one.  */
 
 struct type *
-lookup_method_type (type, domain, args)
-     struct type *type, *domain, **args;
+lookup_method_type (domain, type, args)
+     struct type *domain, *type, **args;
 {
   register struct type *mtype = TYPE_MAIN_VARIANT (type);
   struct type *main_type;
@@ -754,6 +730,7 @@ create_array_type (element_type, number)
 {
   struct type *result_type = (struct type *)
     obstack_alloc (symbol_obstack, sizeof (struct type));
+  struct type *range_type;
 
   bzero (result_type, sizeof (struct type));
 
@@ -763,7 +740,27 @@ create_array_type (element_type, number)
   TYPE_NFIELDS (result_type) = 1;
   TYPE_FIELDS (result_type) =
     (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field));
-  TYPE_FIELD_TYPE (result_type, 0) = builtin_type_int;
+
+  {
+    /* Create range type.  */
+    range_type = (struct type *) obstack_alloc (symbol_obstack,
+                                               sizeof (struct type));
+    TYPE_CODE (range_type) = TYPE_CODE_RANGE;
+    TYPE_TARGET_TYPE (range_type) = builtin_type_int;  /* FIXME */
+
+    /* This should never be needed.  */
+    TYPE_LENGTH (range_type) = sizeof (int);
+
+    TYPE_NFIELDS (range_type) = 2;
+    TYPE_FIELDS (range_type) =
+      (struct field *) obstack_alloc (symbol_obstack,
+                                     2 * sizeof (struct field));
+    TYPE_FIELD_BITPOS (range_type, 0) = 0; /* FIXME */
+    TYPE_FIELD_BITPOS (range_type, 1) = number-1; /* FIXME */
+    TYPE_FIELD_TYPE (range_type, 0) = builtin_type_int; /* FIXME */
+    TYPE_FIELD_TYPE (range_type, 1) = builtin_type_int; /* FIXME */
+  }
+  TYPE_FIELD_TYPE(result_type,0)=range_type;
   TYPE_VPTR_FIELDNO (result_type) = -1;
 
   return result_type;
@@ -1006,6 +1003,8 @@ lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
       if (ind != -1)
        {
          s = find_pc_symtab (misc_function_vector[ind].address);
+         /* If S is zero, there are no debug symbols for this file.
+            Skip this stuff and check for matching static symbols below. */
          if (s)
            {
              bv = BLOCKVECTOR (s);
@@ -1383,7 +1382,8 @@ find_pc_symtab (pc)
     {
       ps = find_pc_psymtab (pc);
       if (ps && ps->readin)
-       fatal ("Internal error: pc in read in psymtab, but not in symtab.");
+       printf_filtered (
+         "(Internal error: pc in read in psymtab, but not in symtab.)\n");
 
       if (ps)
        s = PSYMTAB_TO_SYMTAB (ps);
@@ -2083,8 +2083,6 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line)
 
       if (s == 0 && default_symtab == 0)
        {
-         if (symtab_list == 0 && partial_symtab_list == 0)
-           error (no_symtab_msg);
          select_source_symtab (0);
          default_symtab = current_source_symtab;
          default_line = current_source_line;
@@ -2190,9 +2188,6 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line)
        error ("Line number not known for symbol \"%s\"", copy);
     }
 
-  if (symtab_list == 0 && partial_symtab_list == 0)
-    error (no_symtab_msg);
-
   if ((i = lookup_misc_func (copy)) >= 0)
     {
       val.symtab = 0;
@@ -2206,6 +2201,9 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line)
       return values;
     }
 
+  if (symtab_list == 0 && partial_symtab_list == 0 && misc_function_count == 0)
+    error (no_symtab_msg);
+
   error ("Function %s not defined.", copy);
   return values;       /* for lint */
 }
@@ -2234,7 +2232,6 @@ decode_line_2 (sym_arr, nelts, funfirstline)
      int nelts;
      int funfirstline;
 {
-  char *getenv();
   struct symtabs_and_lines values, return_values;
   register CORE_ADDR pc;
   char *args, *arg1, *command_line_input ();
@@ -2442,6 +2439,7 @@ sources_info ()
    If CLASS is zero, list all symbols except functions and type names.
    If CLASS is 1, list only functions.
    If CLASS is 2, list only type names.
+   If CLASS is 3, list only method names.
 
    BPT is non-zero if we should set a breakpoint at the functions
    we find.  */
@@ -2464,9 +2462,16 @@ list_symbols (regexp, class, bpt)
   static char *classnames[]
     = {"variable", "function", "type", "method"};
   int found_in_file = 0;
+  int found_misc = 0;
+  static enum misc_function_type types[]
+    = {mf_data, mf_text, mf_abs, mf_unknown};
+  static enum misc_function_type types2[]
+    = {mf_bss,  mf_text, mf_abs, mf_unknown};
+  enum misc_function_type ourtype = types[class];
+  enum misc_function_type ourtype2 = types2[class];
 
   if (regexp)
-    if (0 != (val = (char *) re_comp (regexp)))
+    if (0 != (val = re_comp (regexp)))
       error ("Invalid regexp (%s): %s", val, regexp);
 
   /* Search through the partial_symtab_list *first* for all symbols
@@ -2507,7 +2512,7 @@ list_symbols (regexp, class, bpt)
                 load the file and go on to the next one */
              if ((regexp == 0 || re_exec (SYMBOL_NAME (psym)))
                  && ((class == 0 && SYMBOL_CLASS (psym) != LOC_TYPEDEF
-                      && SYMBOL_CLASS (psym) != LOC_BLOCK)
+                                 && SYMBOL_CLASS (psym) != LOC_BLOCK)
                      || (class == 1 && SYMBOL_CLASS (psym) == LOC_BLOCK)
                      || (class == 2 && SYMBOL_CLASS (psym) == LOC_TYPEDEF)
                      || (class == 3 && SYMBOL_CLASS (psym) == LOC_BLOCK)))
@@ -2520,20 +2525,23 @@ list_symbols (regexp, class, bpt)
        }
     }
 
-  /* Here, *if* the class is correct (function only, right now), we
-     search through the misc function vector for symbols that
+  /* Here, we search through the misc function vector for functions that
      match, and call find_pc_symtab on them to force their symbols to
      be read.  The symbol will then be found during the scan of symtabs
-     below.  */
-
-  if (class == 1)
-    {
-      for (i = 0; i < misc_function_count; i++)
-       if (regexp == 0 || re_exec (misc_function_vector[i].name))
-         {
-           (void) find_pc_symtab (misc_function_vector[i].address);
-         }
+     below.  If find_pc_symtab fails, set found_misc so that we will
+     rescan to print any matching symbols without debug info.  */
+
+  if (class == 1) {
+    for (i = 0; i < misc_function_count; i++) {
+      if (misc_function_vector[i].type != ourtype
+       && misc_function_vector[i].type != ourtype2)
+       continue;
+      if (regexp == 0 || re_exec (misc_function_vector[i].name)) {
+         if (0 == find_pc_symtab (misc_function_vector[i].address))
+           found_misc = 1;
+      }
     }
+  }
 
   /* Printout here so as to get after the "Reading in symbols"
      messages which will be generated above.  */
@@ -2566,7 +2574,7 @@ list_symbols (regexp, class, bpt)
                sym = BLOCK_SYM (b, j);
                if ((regexp == 0 || re_exec (SYMBOL_NAME (sym)))
                    && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
-                        && SYMBOL_CLASS (sym) != LOC_BLOCK)
+                                   && SYMBOL_CLASS (sym) != LOC_BLOCK)
                        || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
                        || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
                        || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))
@@ -2587,28 +2595,22 @@ list_symbols (regexp, class, bpt)
 
                    if (class != 2 && i == STATIC_BLOCK)
                      printf_filtered ("static ");
+
+                   /* Typedef that is not a C++ class */
                    if (class == 2
                        && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
-                     printf_filtered ("typedef ");
-
-                   if (class < 3)
+                      typedef_print (SYMBOL_TYPE(sym), sym, stdout);
+                   /* variable, func, or typedef-that-is-c++-class */
+                   else if (class < 2 || 
+                            (class == 2 && 
+                               SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE))
                      {
-                       type_print (SYMBOL_TYPE (sym),
-                                   (SYMBOL_CLASS (sym) == LOC_TYPEDEF
-                                    ? "" : SYMBOL_NAME (sym)),
-                                   stdout, 0);
-
-                       if (class == 2
-                           && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE
-                           && (TYPE_NAME ((SYMBOL_TYPE (sym))) == 0
-                               || 0 != strcmp (TYPE_NAME ((SYMBOL_TYPE (sym))),
-                                               SYMBOL_NAME (sym))))
-                         {
-                           fputs_filtered (" ", stdout);
-                           fprint_symbol (stdout, SYMBOL_NAME (sym));
-                         }
-
-                       printf_filtered (";\n");
+                        type_print (SYMBOL_TYPE (sym),
+                                    (SYMBOL_CLASS (sym) == LOC_TYPEDEF
+                                     ? "" : SYMBOL_NAME (sym)),
+                                    stdout, 0);
+                        
+                        printf_filtered (";\n");
                      }
                    else
                      {
@@ -2625,6 +2627,36 @@ list_symbols (regexp, class, bpt)
          }
       prev_bv = bv;
     }
+
+
+  /* If there are no eyes, avoid all contact.  I mean, if there are
+     no debug symbols, then print directly from the misc_function_vector.  */
+
+  if (found_misc || class != 1) {
+    found_in_file = 0;
+    for (i = 0; i < misc_function_count; i++) {
+      if (misc_function_vector[i].type != ourtype
+       && misc_function_vector[i].type != ourtype2)
+       continue;
+      if (regexp == 0 || re_exec (misc_function_vector[i].name)) {
+       /* Functions:  Look up by address. */
+       if (class == 1)
+         if (0 != find_pc_symtab (misc_function_vector[i].address))
+           continue;
+       /* Variables/Absolutes:  Look up by name */
+       if (0 != lookup_symbol (misc_function_vector[i].name, 
+               (struct block *)0, VAR_NAMESPACE, 0, (struct symtab **)0))
+         continue;
+       if (!found_in_file) {
+         printf_filtered ("\nNon-debugging symbols:\n");
+         found_in_file = 1;
+       }
+       printf_filtered ("      %08x  %s\n",
+             misc_function_vector[i].address,
+             misc_function_vector[i].name);
+      }
+    }
+  }
 }
 
 static void
@@ -2666,9 +2698,8 @@ rbreak_command (regexp)
   list_symbols (regexp, 1, 1);
 }
 \f
-/* Initialize the standard C scalar types.  */
+/* Helper function to initialize the standard scalar types.  */
 
-static
 struct type *
 init_type (code, length, uns, name)
      enum type_code code;
@@ -2852,6 +2883,51 @@ make_symbol_completion_list (text)
   return (return_val);
 }
 \f
+#if 0
+/* Add the type of the symbol sym to the type of the current
+   function whose block we are in (assumed).  The type of
+   this current function is contained in *TYPE.
+   
+   This basically works as follows:  When we find a function
+   symbol (N_FUNC with a 'f' or 'F' in the symbol name), we record
+   a pointer to its type in the global in_function_type.  Every 
+   time we come across a parameter symbol ('p' in its name), then
+   this procedure adds the name and type of that parameter
+   to the function type pointed to by *TYPE.  (Which should correspond
+   to in_function_type if it was called correctly).
+
+   Note that since we are modifying a type, the result of 
+   lookup_function_type() should be bcopy()ed before calling
+   this.  When not in strict typing mode, the expression
+   evaluator can choose to ignore this.
+
+   Assumption:  All of a function's parameter symbols will
+   appear before another function symbol is found.  The parameters 
+   appear in the same order in the argument list as they do in the
+   symbol table. */
+
+void
+add_param_to_type (type,sym)
+   struct type **type;
+   struct symbol *sym;
+{
+   int num = ++(TYPE_NFIELDS(*type));
+
+   if(TYPE_NFIELDS(*type)-1)
+      TYPE_FIELDS(*type) = 
+        (struct field *)xrealloc((char *)(TYPE_FIELDS(*type)),
+                                 num*sizeof(struct field));
+   else
+      TYPE_FIELDS(*type) =
+        (struct field *)xmalloc(num*sizeof(struct field));
+   
+   TYPE_FIELD_BITPOS(*type,num-1) = num-1;
+   TYPE_FIELD_BITSIZE(*type,num-1) = 0;
+   TYPE_FIELD_TYPE(*type,num-1) = SYMBOL_TYPE(sym);
+   TYPE_FIELD_NAME(*type,num-1) = SYMBOL_NAME(sym);
+}
+#endif 
+\f
 void
 _initialize_symtab ()
 {
@@ -2884,31 +2960,6 @@ are listed.");
   add_com ("rbreak", no_class, rbreak_command,
            "Set a breakpoint for all functions matching REGEXP.");
 
-  /* FIXME:  The code below assumes that the sizes of the basic data
-     types are the same on the host and target machines!!!  */
-
-  builtin_type_void = init_type (TYPE_CODE_VOID, 1, 0, "void");
-
-  builtin_type_float = init_type (TYPE_CODE_FLT, sizeof (float), 0, "float");
-  builtin_type_double = init_type (TYPE_CODE_FLT, sizeof (double), 0, "double");
-
-  builtin_type_char = init_type (TYPE_CODE_INT, sizeof (char), 0, "char");
-  builtin_type_short = init_type (TYPE_CODE_INT, sizeof (short), 0, "short");
-  builtin_type_long = init_type (TYPE_CODE_INT, sizeof (long), 0, "long");
-  builtin_type_int = init_type (TYPE_CODE_INT, sizeof (int), 0, "int");
-
-  builtin_type_unsigned_char = init_type (TYPE_CODE_INT, sizeof (char), 1, "unsigned char");
-  builtin_type_unsigned_short = init_type (TYPE_CODE_INT, sizeof (short), 1, "unsigned short");
-  builtin_type_unsigned_long = init_type (TYPE_CODE_INT, sizeof (long), 1, "unsigned long");
-  builtin_type_unsigned_int = init_type (TYPE_CODE_INT, sizeof (int), 1, "unsigned int");
-
-  builtin_type_long_long =
-    init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
-              0, "long long");
-  builtin_type_unsigned_long_long = 
-    init_type (TYPE_CODE_INT, TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT,
-              1, "unsigned long long");
-
+  /* Initialize the one built-in type that isn't language dependent... */
   builtin_type_error = init_type (TYPE_CODE_ERROR, 0, 0, "<unknown type>");
 }
-
This page took 0.033989 seconds and 4 git commands to generate.