spelling fix.
[deliverable/binutils-gdb.git] / gdb / symtab.c
index 61bbe28b50cfcf09c447b291eb7428babe81411f..b54c9f66bb825f0a3ecf9e4a23e85c25ad3cdbdf 100644 (file)
@@ -1,5 +1,5 @@
 /* Symbol table lookup for the GNU debugger, GDB.
-   Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 1997
+   Copyright 1986, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 1998
              Free Software Foundation, Inc.
 
 This file is part of GDB.
@@ -33,6 +33,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "expression.h"
 #include "language.h"
 #include "demangle.h"
+#include "inferior.h"
 
 #include "obstack.h"
 
@@ -44,53 +45,65 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
 /* Prototypes for local functions */
 
-extern int
-find_methods PARAMS ((struct type *, char *, struct symbol **));
+static int find_methods PARAMS ((struct type *, char *, struct symbol **));
 
-static void
-completion_list_add_name PARAMS ((char *, char *, int, char *, char *));
+static void completion_list_add_name PARAMS ((char *, char *, int, char *, 
+                                              char *));
 
-static void
-build_canonical_line_spec PARAMS ((struct symtab_and_line *, char *, char ***));
+static void build_canonical_line_spec PARAMS ((struct symtab_and_line *, 
+                                               char *, char ***));
 
-static struct symtabs_and_lines
-decode_line_2 PARAMS ((struct symbol *[], int, int, char ***));
+static struct symtabs_and_lines decode_line_2 PARAMS ((struct symbol *[], 
+                                                       int, int, char ***));
 
-static void
-rbreak_command PARAMS ((char *, int));
+static void rbreak_command PARAMS ((char *, int));
 
-static void
-types_info PARAMS ((char *, int));
+static void types_info PARAMS ((char *, int));
 
-static void
-functions_info PARAMS ((char *, int));
-
-static void
-variables_info PARAMS ((char *, int));
+static void functions_info PARAMS ((char *, int));
 
-static void
-sources_info PARAMS ((char *, int));
+static void variables_info PARAMS ((char *, int));
 
-static void
-list_symbols PARAMS ((char *, int, int, int));
+static void sources_info PARAMS ((char *, int));
 
-static void
-output_source_filename PARAMS ((char *, int *));
+static void output_source_filename PARAMS ((char *, int *));
 
-char *
-operator_chars PARAMS ((char *, char **));
+char *operator_chars PARAMS ((char *, char **));
 
 static int find_line_common PARAMS ((struct linetable *, int, int *));
 
-static struct partial_symbol *
-lookup_partial_symbol PARAMS ((struct partial_symtab *, const char *,
-                              int, namespace_enum));
+static struct partial_symbol *lookup_partial_symbol PARAMS 
+                                  ((struct partial_symtab *, const char *,
+                                   int, namespace_enum));
 
-static struct symtab *
-lookup_symtab_1 PARAMS ((char *));
+static struct partial_symbol *fixup_psymbol_section PARAMS ((struct 
+                                        partial_symbol *, struct objfile *));
 
-static void
-cplusplus_hint PARAMS ((char *));
+static struct symtab *lookup_symtab_1 PARAMS ((char *));
+
+static void cplusplus_hint PARAMS ((char *));
+
+static struct symbol *find_active_alias PARAMS ((struct symbol *sym, 
+                                                 CORE_ADDR addr));
+
+/* This flag is used in hppa-tdep.c, and set in hp-symtab-read.c */
+/* Signals the presence of objects compiled by HP compilers */
+int hp_som_som_object_present = 0;
+
+static void fixup_section PARAMS ((struct general_symbol_info *, 
+                                   struct objfile *));
+
+static int file_matches PARAMS ((char *, char **, int));
+
+static void print_symbol_info PARAMS ((namespace_enum, 
+                                       struct symtab *, struct symbol *, 
+                                       int, char *));
+
+static void print_msymbol_info PARAMS ((struct minimal_symbol *));
+
+static void symtab_symbol_info PARAMS ((char *, namespace_enum, int));
+
+void _initialize_symtab PARAMS ((void));
 
 /* */
 
@@ -256,20 +269,22 @@ char *name;
   return (NULL);
 }
 \f
-/* Demangle a GDB method stub type.
-   Note that this function is g++ specific. */
+/* Mangle a GDB method stub type.  This actually reassembles the pieces of the
+   full method name, which consist of the class name (from T), the unadorned
+   method name from METHOD_ID, and the signature for the specific overload,
+   specified by SIGNATURE_ID.  Note that this function is g++ specific. */
 
 char *
-gdb_mangle_name (type, i, j)
+gdb_mangle_name (type, method_id, signature_id)
      struct type *type;
-     int i, j;
+     int method_id, signature_id;
 {
   int mangled_name_len;
   char *mangled_name;
-  struct fn_field *f = TYPE_FN_FIELDLIST1 (type, i);
-  struct fn_field *method = &f[j];
-  char *field_name = TYPE_FN_FIELDLIST_NAME (type, i);
-  char *physname = TYPE_FN_FIELD_PHYSNAME (f, j);
+  struct fn_field *f = TYPE_FN_FIELDLIST1 (type, method_id);
+  struct fn_field *method = &f[signature_id];
+  char *field_name = TYPE_FN_FIELDLIST_NAME (type, method_id);
+  char *physname = TYPE_FN_FIELD_PHYSNAME (f, signature_id);
   char *newname = type_name_no_tag (type);
 
   /* Does the form of physname indicate that it is the full mangled name
@@ -305,12 +320,11 @@ gdb_mangle_name (type, i, j)
   if (len == 0)
     {
       sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
-      if (strcmp(buf, "__") == 0)
-       buf[0] = '\0';
     }
-  else if (newname != NULL && strchr (newname, '<') != NULL)
+  else if (physname[0] == 't' || physname[0] == 'Q')
     {
-      /* Template methods are fully mangled.  */
+      /* The physname for template and qualified methods already includes
+        the class name.  */
       sprintf (buf, "__%s%s", const_prefix, volatile_prefix);
       newname = NULL;
       len = 0;
@@ -359,12 +373,6 @@ gdb_mangle_name (type, i, j)
 
 \f
 
-struct symbol         * fixup_symbol_section  PARAMS ((struct symbol  *,
-                                                      struct objfile *));
-struct partial_symbol * fixup_psymbol_section PARAMS ((struct partial_symbol *,
-                                                      struct objfile *));
-
-
 /* Find which partial symtab on contains PC and SECTION.  Return 0 if none.  */
 
 struct partial_symtab *
@@ -440,7 +448,8 @@ find_pc_sect_psymbol (psymtab, pc, section)
   if (!psymtab)
     return 0;
 
-  best_pc = psymtab->textlow - 1;
+  /* Cope with programs that start at address 0 */
+  best_pc = (psymtab->textlow != 0) ? psymtab->textlow - 1 : 0;
 
   /* Search the global symbols as well as the static symbols, so that
      find_pc_partial_function doesn't use a minimal symbol and thus
@@ -454,7 +463,9 @@ find_pc_sect_psymbol (psymtab, pc, section)
       if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
          && SYMBOL_CLASS (p) == LOC_BLOCK
          && pc >= SYMBOL_VALUE_ADDRESS (p)
-         && SYMBOL_VALUE_ADDRESS (p) > best_pc)
+         && (SYMBOL_VALUE_ADDRESS (p) > best_pc
+             || (psymtab->textlow == 0
+                 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
        {
          if (section)  /* match on a specific section */
            {
@@ -466,6 +477,7 @@ find_pc_sect_psymbol (psymtab, pc, section)
          best = p;
        }
     }
+
   for (pp = psymtab->objfile->static_psymbols.list + psymtab->statics_offset;
        (pp - (psymtab->objfile->static_psymbols.list + psymtab->statics_offset)
        < psymtab->n_static_syms);
@@ -475,7 +487,9 @@ find_pc_sect_psymbol (psymtab, pc, section)
       if (SYMBOL_NAMESPACE (p) == VAR_NAMESPACE
          && SYMBOL_CLASS (p) == LOC_BLOCK
          && pc >= SYMBOL_VALUE_ADDRESS (p)
-         && SYMBOL_VALUE_ADDRESS (p) > best_pc)
+         && (SYMBOL_VALUE_ADDRESS (p) > best_pc
+             || (psymtab->textlow == 0 
+                 && best_pc == 0 && SYMBOL_VALUE_ADDRESS (p) == 0)))
        {
          if (section)  /* match on a specific section */
            {
@@ -487,8 +501,7 @@ find_pc_sect_psymbol (psymtab, pc, section)
          best = p;
        }
     }
-  if (best_pc == psymtab->textlow - 1)
-    return 0;
+
   return best;
 }
 
@@ -523,8 +536,6 @@ fixup_symbol_section (sym, objfile)
      struct symbol *sym;
      struct objfile *objfile;
 {
-  struct minimal_symbol *msym;
-
   if (!sym)
     return NULL;
 
@@ -536,13 +547,11 @@ fixup_symbol_section (sym, objfile)
   return sym;
 }
 
-struct partial_symbol *
+static struct partial_symbol *
 fixup_psymbol_section (psym, objfile)
      struct partial_symbol *psym;
      struct objfile *objfile;
 {
-  struct minimal_symbol *msym;
-
   if (!psym)
     return NULL;
 
@@ -837,7 +846,12 @@ lookup_partial_symbol (pst, name, global, namespace)
          center = bottom + (top - bottom) / 2;
          if (!(center < top))
            abort ();
-         if (!do_linear_search && SYMBOL_LANGUAGE (*center) == language_cplus)
+         if (!do_linear_search
+             && (SYMBOL_LANGUAGE (*center) == language_cplus
+/* start-sanitize-java */
+                 || SYMBOL_LANGUAGE (*center) == language_java
+/* end-sanitize-java */
+                 ))
            {
              do_linear_search = 1;
            }
@@ -882,6 +896,120 @@ lookup_partial_symbol (pst, name, global, namespace)
   return (NULL);
 }
 
+/* Look up a type named NAME in the struct_namespace.  The type returned
+   must not be opaque -- i.e., must have at least one field defined
+
+   This code was modelled on lookup_symbol -- the parts not relevant to looking
+   up types were just left out.  In particular it's assumed here that types
+   are available in struct_namespace and only at file-static or global blocks. */
+
+
+struct type *
+lookup_transparent_type (name)
+     const char *name;
+{
+  register struct symbol *sym;
+  register struct symtab *s = NULL;
+  register struct partial_symtab *ps;
+  struct blockvector *bv;
+  register struct objfile *objfile;
+  register struct block *block;
+  register struct minimal_symbol *msymbol;
+
+  /* Now search all the global symbols.  Do the symtab's first, then
+     check the psymtab's. If a psymtab indicates the existence
+     of the desired name as a global, then do psymtab-to-symtab
+     conversion on the fly and return the found symbol.  */
+  
+  ALL_SYMTABS (objfile, s)
+    {
+      bv = BLOCKVECTOR (s);
+      block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
+      sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
+      if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
+       {
+         return SYMBOL_TYPE (sym);
+       }
+    }
+
+  ALL_PSYMTABS (objfile, ps)
+    {
+      if (!ps->readin && lookup_partial_symbol (ps, name, 1, STRUCT_NAMESPACE))
+       {
+         s = PSYMTAB_TO_SYMTAB(ps);
+         bv = BLOCKVECTOR (s);
+         block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
+         sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
+         if (!sym) 
+            {
+              /* This shouldn't be necessary, but as a last resort
+               * try looking in the statics even though the psymtab
+               * claimed the symbol was global. It's possible that
+               * the psymtab gets it wrong in some cases.
+               */
+             block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
+             sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
+              if (!sym)
+                error ("Internal: global symbol `%s' found in %s psymtab but not in symtab.\n\
+%s may be an inlined function, or may be a template function\n\
+(if a template, try specifying an instantiation: %s<type>).",
+                       name, ps->filename, name, name);
+            }
+          if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
+            return SYMBOL_TYPE (sym);
+       }
+    }
+
+  /* Now search the static file-level symbols.
+     Not strictly correct, but more useful than an error.
+     Do the symtab's first, then
+     check the psymtab's. If a psymtab indicates the existence
+     of the desired name as a file-level static, then do psymtab-to-symtab
+     conversion on the fly and return the found symbol.
+   */
+
+  ALL_SYMTABS (objfile, s)
+    {
+      bv = BLOCKVECTOR (s);
+      block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
+      sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
+      if (sym && !TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
+       {
+         return SYMBOL_TYPE (sym);
+       }
+    }
+
+  ALL_PSYMTABS (objfile, ps)
+    {
+      if (!ps->readin && lookup_partial_symbol (ps, name, 0, STRUCT_NAMESPACE))
+       {
+         s = PSYMTAB_TO_SYMTAB(ps);
+         bv = BLOCKVECTOR (s);
+         block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK);
+         sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
+         if (!sym)
+            {
+              /* This shouldn't be necessary, but as a last resort
+               * try looking in the globals even though the psymtab
+               * claimed the symbol was static. It's possible that
+               * the psymtab gets it wrong in some cases.
+               */
+             block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK);
+             sym = lookup_block_symbol (block, name, STRUCT_NAMESPACE);
+              if (!sym)
+               error ("Internal: static symbol `%s' found in %s psymtab but not in symtab.\n\
+%s may be an inlined function, or may be a template function\n\
+(if a template, try specifying an instantiation: %s<type>).",
+                       name, ps->filename, name, name);
+            }
+          if (!TYPE_IS_OPAQUE (SYMBOL_TYPE (sym)))
+            return SYMBOL_TYPE (sym);
+       }
+    }
+  return (struct type *) 0;
+}
+
+
 /* Find the psymtab containing main(). */
 /* FIXME:  What about languages without main() or specially linked
    executables that have no main() ? */
@@ -950,7 +1078,12 @@ lookup_block_symbol (block, name, namespace)
            }
          inc = (inc >> 1) + bot;
          sym = BLOCK_SYM (block, inc);
-         if (!do_linear_search && SYMBOL_LANGUAGE (sym) == language_cplus)
+         if (!do_linear_search
+             && (SYMBOL_LANGUAGE (sym) == language_cplus
+/* start-sanitize-java */
+                 || SYMBOL_LANGUAGE (sym) == language_java
+/* end-sanitize-java */
+                 ))
            {
              do_linear_search = 1;
            }
@@ -1024,6 +1157,15 @@ lookup_block_symbol (block, name, namespace)
          if (SYMBOL_NAMESPACE (sym) == namespace &&
              SYMBOL_MATCHES_NAME (sym, name))
            {
+             /* If SYM has aliases, then use any alias that is active
+                at the current PC.  If no alias is active at the current
+                PC, then use the main symbol.
+
+                ?!? Is checking the current pc correct?  Is this routine
+                ever called to look up a symbol from another context?  */
+              if (SYMBOL_ALIASES (sym))
+                sym = find_active_alias (sym, read_pc ());
+
              sym_found = sym;
              if (SYMBOL_CLASS (sym) != LOC_ARG &&
                  SYMBOL_CLASS (sym) != LOC_LOCAL_ARG &&
@@ -1041,6 +1183,39 @@ lookup_block_symbol (block, name, namespace)
   return (sym_found);          /* Will be NULL if not found. */
 }
 
+/* Given a main symbol SYM and ADDR, search through the alias
+   list to determine if an alias is active at ADDR and return
+   the active alias.
+
+   If no alias is active, then return SYM.  */
+
+static struct symbol *
+find_active_alias (sym, addr)
+  struct symbol *sym;
+  CORE_ADDR addr;
+{
+  struct range_list *r;
+  struct alias_list *aliases;
+
+  /* If we have aliases, check them first.  */
+  aliases = SYMBOL_ALIASES (sym);
+
+  while (aliases)
+    {
+      if (!SYMBOL_RANGES (aliases->sym))
+        return aliases->sym;
+      for (r = SYMBOL_RANGES (aliases->sym); r; r = r->next)
+       {
+         if (r->start <= addr && r->end > addr)
+           return aliases->sym;
+       }
+      aliases = aliases->next;
+    }
+
+  /* Nothing found, return the main symbol.  */
+  return sym;
+}
+
 \f
 /* Return the symbol for the function which contains a specified
    lexical block, described by a struct block BL.  */
@@ -1069,7 +1244,7 @@ find_pc_sect_symtab (pc, section)
   register struct symtab *best_s = NULL;
   register struct partial_symtab *ps;
   register struct objfile *objfile;
-  int distance = 0;
+  CORE_ADDR distance = 0;
 
   /* Search all symtabs for the one whose file contains our address, and which
      is the smallest of all the ones containing the address.  This is designed
@@ -1299,6 +1474,9 @@ find_pc_sect_line (pc, section, notcurrent)
   s = find_pc_sect_symtab (pc, section);
   if (!s)
     {
+      /* if no symbol information, return previous pc */
+      if (notcurrent)
+       pc++;
       val.pc = pc;
       return val;
     }
@@ -1416,24 +1594,23 @@ find_pc_line (pc, notcurrent)
 }
 
 \f
-static int find_line_symtab PARAMS ((struct symtab *, int, struct linetable **,
-                                    int *, int *));
+static struct symtab* find_line_symtab PARAMS ((struct symtab *, int,
+                                               int *, int *));
 
 /* Find line number LINE in any symtab whose name is the same as
    SYMTAB.
 
-   If found, return 1, set *LINETABLE to the linetable in which it was
+   If found, return the symtab that contains the linetable in which it was
    found, set *INDEX to the index in the linetable of the best entry
    found, and set *EXACT_MATCH nonzero if the value returned is an
    exact match.
 
-   If not found, return 0.  */
+   If not found, return NULL.  */
 
-static int
-find_line_symtab (symtab, line, linetable, index, exact_match)
+static struct symtab*
+find_line_symtab (symtab, line, index, exact_match)
      struct symtab *symtab;
      int line;
-     struct linetable **linetable;
      int *index;
      int *exact_match;
 {
@@ -1444,9 +1621,11 @@ find_line_symtab (symtab, line, linetable, index, exact_match)
 
   int best_index;
   struct linetable *best_linetable;
+  struct symtab *best_symtab;
 
   /* First try looking it up in the given symtab.  */
   best_linetable = LINETABLE (symtab);
+  best_symtab = symtab;
   best_index = find_line_common (best_linetable, line, &exact);
   if (best_index < 0 || !exact)
     {
@@ -1485,6 +1664,7 @@ find_line_symtab (symtab, line, linetable, index, exact_match)
                {
                  best_index = ind;
                  best_linetable = l;
+                 best_symtab = s;
                  goto done;
                }
              if (best == 0 || l->item[ind].line < best)
@@ -1492,39 +1672,47 @@ find_line_symtab (symtab, line, linetable, index, exact_match)
                  best = l->item[ind].line;
                  best_index = ind;
                  best_linetable = l;
+                 best_symtab = s;
                }
            }
        }
     }
  done:
   if (best_index < 0)
-    return 0;
+    return NULL;
 
   if (index)
     *index = best_index;
-  if (linetable)
-    *linetable = best_linetable;
   if (exact_match)
     *exact_match = exact;
-  return 1;
+
+  return best_symtab;
 }
 \f
-/* Find the PC value for a given source file and line number.
-   Returns zero for invalid line number.
+/* Set the PC value for a given source file and line number and return true.
+   Returns zero for invalid line number (and sets the PC to 0).
    The source file is specified with a struct symtab.  */
 
-CORE_ADDR
-find_line_pc (symtab, line)
+int
+find_line_pc (symtab, line, pc)
      struct symtab *symtab;
      int line;
+     CORE_ADDR *pc;
 {
   struct linetable *l;
   int ind;
 
+  *pc = 0;
   if (symtab == 0)
     return 0;
-  if (find_line_symtab (symtab, line, &l, &ind, NULL))
-    return l->item[ind].pc;
+
+  symtab = find_line_symtab (symtab, line, &ind, NULL);
+  if (symtab != NULL)
+    {
+      l = LINETABLE (symtab);
+      *pc = l->item[ind].pc;
+      return 1;
+    }
   else
     return 0;
 }
@@ -1544,11 +1732,7 @@ find_line_pc_range (sal, startptr, endptr)
   struct symtab_and_line found_sal;
 
   startaddr = sal.pc;
-  if (startaddr == 0)
-    {
-      startaddr = find_line_pc (sal.symtab, sal.line);
-    }
-  if (startaddr == 0)
+  if (startaddr==0 && !find_line_pc (sal.symtab, sal.line, &startaddr))
     return 0;
 
   /* This whole function is based on address.  For example, if line 10 has
@@ -1810,7 +1994,7 @@ total_number_of_methods (type)
    a size of total_number_of_methods (T) * sizeof (struct symbol *).
    Note that this function is g++ specific.  */
 
-int
+static int
 find_methods (t, name, sym_arr)
      struct type *t;
      char *name;
@@ -1820,6 +2004,7 @@ find_methods (t, name, sym_arr)
   int ibase;
   struct symbol *sym_class;
   char *class_name = type_name_no_tag (t);
+
   /* Ignore this class if it doesn't have a name.  This is ugly, but
      unless we figure out how to get the physname without the name of
      the class, then the loop can't do any good.  */
@@ -1831,36 +2016,57 @@ find_methods (t, name, sym_arr)
                                     (struct symtab **)NULL)))
     {
       int method_counter;
+
       /* FIXME: Shouldn't this just be CHECK_TYPEDEF (t)?  */
       t = SYMBOL_TYPE (sym_class);
+
+      /* Loop over each method name.  At this level, all overloads of a name
+        are counted as a single name.  There is an inner loop which loops over
+        each overload.  */
+
       for (method_counter = TYPE_NFN_FIELDS (t) - 1;
           method_counter >= 0;
           --method_counter)
        {
          int field_counter;
-         struct fn_field *f = TYPE_FN_FIELDLIST1 (t, method_counter);
          char *method_name = TYPE_FN_FIELDLIST_NAME (t, method_counter);
          char dem_opname[64];
 
-          if (strncmp(method_name, "__", 2)==0 ||
-           strncmp(method_name, "op", 2)==0 ||
-           strncmp(method_name, "type", 4)==0 )
-           {
-             if (cplus_demangle_opname(method_name, dem_opname, DMGL_ANSI))
+          if (strncmp (method_name, "__", 2) == 0 ||
+             strncmp (method_name, "op", 2) == 0 ||
+             strncmp (method_name, "type", 4) == 0)
+            {
+             if (cplus_demangle_opname (method_name, dem_opname, DMGL_ANSI))
                method_name = dem_opname;
-             else if (cplus_demangle_opname(method_name, dem_opname, 0))
+             else if (cplus_demangle_opname (method_name, dem_opname, 0))
                method_name = dem_opname; 
-           }
+            }
+
          if (STREQ (name, method_name))
-           /* Find all the fields with that name.  */
+           /* Find all the overloaded methods with that name.  */
            for (field_counter = TYPE_FN_FIELDLIST_LENGTH (t, method_counter) - 1;
                 field_counter >= 0;
                 --field_counter)
              {
+               struct fn_field *f;
                char *phys_name;
+
+               f = TYPE_FN_FIELDLIST1 (t, method_counter);
+
                if (TYPE_FN_FIELD_STUB (f, field_counter))
-                 check_stub_method (t, method_counter, field_counter);
-               phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
+                 {
+                   char *tmp_name;
+
+                   tmp_name = gdb_mangle_name (t,
+                                                method_counter,
+                                                field_counter);
+                   phys_name = alloca (strlen (tmp_name) + 1);
+                   strcpy (phys_name, tmp_name);
+                   free (tmp_name);
+                 }
+               else
+                 phys_name = TYPE_FN_FIELD_PHYSNAME (f, field_counter);
+
                /* Destructor is handled by caller, dont add it to the list */
                if (DESTRUCTOR_PREFIX_P (phys_name))
                  continue;
@@ -1873,11 +2079,14 @@ find_methods (t, name, sym_arr)
                  i1++;
                else
                  {
-                   fputs_filtered("(Cannot find method ", gdb_stdout);
-                   fprintf_symbol_filtered (gdb_stdout, phys_name,
-                                            language_cplus,
-                                            DMGL_PARAMS | DMGL_ANSI);
-                   fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
+                   /* This error message gets printed, but the method
+                      still seems to be found
+                      fputs_filtered("(Cannot find method ", gdb_stdout);
+                      fprintf_symbol_filtered (gdb_stdout, phys_name,
+                      language_cplus,
+                      DMGL_PARAMS | DMGL_ANSI);
+                      fputs_filtered(" - possibly inlined.)\n", gdb_stdout);
+                      */
                  }
              }
        }
@@ -1894,11 +2103,10 @@ find_methods (t, name, sym_arr)
      rather than hiding without any problem, and gcc 2.4.5 does overload
      rather than hiding in this case).  */
 
-  if (i1)
-    return i1;
-  for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
-    i1 += find_methods(TYPE_BASECLASS(t, ibase), name,
-                      sym_arr + i1);
+  if (i1 == 0)
+    for (ibase = 0; ibase < TYPE_N_BASECLASSES (t); ibase++)
+      i1 += find_methods (TYPE_BASECLASS (t, ibase), name, sym_arr + i1);
+
   return i1;
 }
 
@@ -2023,9 +2231,6 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
 #endif
   register char *p, *p1;
   char *q, *pp;
-#if 0
-  char *q1;
-#endif
   register struct symtab *s;
 
   register struct symbol *sym;
@@ -2035,11 +2240,7 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
   register CORE_ADDR pc;
   register struct minimal_symbol *msymbol;
   char *copy;
-  struct symbol *sym_class;
-  int i1;
   int is_quoted, has_parens;
-  struct symbol **sym_arr;
-  struct type *t;
   char *saved_arg = *argptr;
   extern char *gdb_completer_quote_characters;
   
@@ -2059,10 +2260,15 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
     {
       (*argptr)++;
       pc = parse_and_eval_address_1 (argptr);
+
       values.sals = (struct symtab_and_line *)
        xmalloc (sizeof (struct symtab_and_line));
+
       values.nelts = 1;
       values.sals[0] = find_pc_line (pc, 0);
+      values.sals[0].pc = pc;
+      values.sals[0].section = find_pc_overlay (pc);
+
       return values;
     }
 
@@ -2086,16 +2292,32 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
        }
       if (p[0] == ':' || p[0] == ' ' || p[0] == '\t')
        break;
+      /* start-sanitize-java */
+      if (p[0] == '.' && strchr (p, ':') == NULL) /* Java qualified method. */
+       {
+         /* Find the *last* '.', since the others are package qualifiers. */
+         for (p1 = p;  *p1;  p1++)
+           {
+             if (*p1 == '.')
+               p = p1;
+           }
+         break;
+       }
+      /* end-sanitize-java */
     }
   while (p[0] == ' ' || p[0] == '\t') p++;
 
-  if ((p[0] == ':') && !has_parens)
+  if ((p[0] == ':' || p[0] == '.') && !has_parens)
     {
-
-      /*  C++  */
+      /*  C++ */
+      /* start-sanitize-java */
+      /*  ... or Java */
+      /* end-sanitize-java */
       if (is_quoted) *argptr = *argptr+1;
-      if (p[1] ==':')
+      if (p[0] == '.' || p[1] ==':')
        {
+         struct symbol *sym_class;
+
          /* Extract the class name.  */
          p1 = p;
          while (p != *argptr && p[-1] == ' ') --p;
@@ -2104,7 +2326,7 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
          copy[p - *argptr] = 0;
 
          /* Discard the class name from the arg.  */
-         p = p1 + 2;
+         p = p1 + (p1[0] == ':' ? 2 : 1);
          while (*p == ' ' || *p == '\t') p++;
          *argptr = p;
 
@@ -2112,10 +2334,15 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
                                     (struct symtab **)NULL);
        
          if (sym_class &&
-             (t = check_typedef (SYMBOL_TYPE (sym_class)),
-              (TYPE_CODE (t) == TYPE_CODE_STRUCT
-               || TYPE_CODE (t) == TYPE_CODE_UNION)))
+             (TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_STRUCT
+              || TYPE_CODE (SYMBOL_TYPE (sym_class)) == TYPE_CODE_UNION))
            {
+             struct symbol **sym_arr;
+             struct type *t;
+             int i1;
+
+             t = check_typedef (SYMBOL_TYPE (sym_class));
+
              /* Arg token is not digits => try it as a function name
                 Find the next token(everything up to end or next blank). */
              if (**argptr
@@ -2334,7 +2561,14 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
       *argptr = q;
       if (s == 0)
        s = default_symtab;
-      val.symtab = s;
+
+      /* It is possible that this source file has more than one symtab, 
+        and that the new line number specification has moved us from the
+        default (in s) to a new one.  */
+      val.symtab = find_line_symtab (s, val.line, NULL, NULL);
+      if (val.symtab == 0)
+       val.symtab = s;
+     
       val.pc = 0;
       values.sals = (struct symtab_and_line *)
        xmalloc (sizeof (struct symtab_and_line));
@@ -2466,16 +2700,16 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
   msymbol = lookup_minimal_symbol (copy, NULL, NULL);
   if (msymbol != NULL)
     {
-      val.pc      = SYMBOL_VALUE_ADDRESS (msymbol);
-      val.section = SYMBOL_BFD_SECTION (msymbol);
+      values.sals = (struct symtab_and_line *)
+       xmalloc (sizeof (struct symtab_and_line));
+      values.sals[0] = find_pc_sect_line ( SYMBOL_VALUE_ADDRESS (msymbol), 
+                                          (struct sec *)0,0 );
+      values.sals[0].section = SYMBOL_BFD_SECTION (msymbol);
       if (funfirstline)
        {
-         val.pc += FUNCTION_START_OFFSET;
-         SKIP_PROLOGUE (val.pc);
+         values.sals[0].pc += FUNCTION_START_OFFSET;
+         SKIP_PROLOGUE (values.sals[0].pc);
        }
-      values.sals = (struct symtab_and_line *)
-       xmalloc (sizeof (struct symtab_and_line));
-      values.sals[0] = val;
       values.nelts = 1;
       return values;
     }
@@ -2560,12 +2794,9 @@ decode_line_2 (sym_arr, nelts, funfirstline, canonical)
   
   if ((prompt = getenv ("PS2")) == NULL)
     {
-      prompt = ">";
+      prompt = "> ";
     }
-  printf_unfiltered("%s ",prompt);
-  gdb_flush(gdb_stdout);
-
-  args = command_line_input ((char *) NULL, 0, "overload-choice");
+  args = command_line_input (prompt, 0, "overload-choice");
   
   if (args == 0 || *args == 0)
     error_no_arg ("one or more choice numbers");
@@ -2733,37 +2964,75 @@ sources_info (ignore, from_tty)
   printf_filtered ("\n");
 }
 
-/* List all symbols (if REGEXP is NULL) or all symbols matching REGEXP.
-   If CLASS is zero, list all symbols except functions, type names, and
-                    constants (enums).
-   If CLASS is 1, list only functions.
-   If CLASS is 2, list only type names.
-   If CLASS is 3, list only method names.
+static int
+file_matches (file, files, nfiles)
+     char *file;
+     char *files[];
+     int nfiles;
+{
+  int i;
+
+  if (file != NULL && nfiles != 0)
+    {
+      for (i = 0; i < nfiles; i++)
+        {
+          if (strcmp (files[i], basename (file)) == 0)
+            return 1;
+        }
+    }
+  else if (nfiles == 0)
+    return 1;
+  return 0;
+}
+
+/* Free any memory associated with a search. */
+void
+free_search_symbols (symbols)
+     struct symbol_search *symbols;
+{
+  struct symbol_search *p;
+  struct symbol_search *next;
 
-   BPT is non-zero if we should set a breakpoint at the functions
-   we find.  */
+  for (p = symbols; p != NULL; p = next)
+    {
+      next = p->next;
+      free (p);
+    }
+}
 
-static void
-list_symbols (regexp, class, bpt, from_tty)
+/* Search the symbol table for matches to the regular expression REGEXP,
+   returning the results in *MATCHES.
+
+   Only symbols of KIND are searched:
+     FUNCTIONS_NAMESPACE - search all functions
+     TYPES_NAMESPACE     - search all type names
+     METHODS_NAMESPACE   - search all methods NOT IMPLEMENTED
+     VARIABLES_NAMESPACE - search all symbols, excluding functions, type names,
+                         and constants (enums)
+
+   free_search_symbols should be called when *MATCHES is no longer needed.
+*/
+void
+search_symbols (regexp, kind, nfiles, files, matches)
      char *regexp;
-     int class;
-     int bpt;
-     int from_tty;
+     namespace_enum kind;
+     int nfiles;
+     char *files[];
+     struct symbol_search **matches;
+     
 {
   register struct symtab *s;
   register struct partial_symtab *ps;
   register struct blockvector *bv;
   struct blockvector *prev_bv = 0;
   register struct block *b;
-  register int i, j;
+  register int i = 0;
+  register int j;
   register struct symbol *sym;
   struct partial_symbol **psym;
   struct objfile *objfile;
   struct minimal_symbol *msymbol;
   char *val;
-  static char *classnames[]
-    = {"variable", "function", "type", "method"};
-  int found_in_file = 0;
   int found_misc = 0;
   static enum minimal_symbol_type types[]
     = {mst_data, mst_text, mst_abs, mst_unknown};
@@ -2773,45 +3042,60 @@ list_symbols (regexp, class, bpt, from_tty)
     = {mst_file_data,  mst_solib_trampoline, mst_abs, mst_unknown};
   static enum minimal_symbol_type types4[]
     = {mst_file_bss,   mst_text, mst_abs, mst_unknown};
-  enum minimal_symbol_type ourtype = types[class];
-  enum minimal_symbol_type ourtype2 = types2[class];
-  enum minimal_symbol_type ourtype3 = types3[class];
-  enum minimal_symbol_type ourtype4 = types4[class];
+  enum minimal_symbol_type ourtype;
+  enum minimal_symbol_type ourtype2;
+  enum minimal_symbol_type ourtype3;
+  enum minimal_symbol_type ourtype4;
+  struct symbol_search *sr;
+  struct symbol_search *psr;
+  struct symbol_search *tail;
+  struct cleanup *old_chain = NULL;
+
+  if (kind < LABEL_NAMESPACE)
+    error ("must search on specific namespace");
+
+  ourtype = types[(int) (kind - LABEL_NAMESPACE)];
+  ourtype2 = types2[(int) (kind - LABEL_NAMESPACE)];
+  ourtype3 = types3[(int) (kind - LABEL_NAMESPACE)];
+  ourtype4 = types4[(int) (kind - LABEL_NAMESPACE)];
+
+  sr = *matches = NULL;
+  tail = NULL;
 
   if (regexp != NULL)
     {
       /* Make sure spacing is right for C++ operators.
-        This is just a courtesy to make the matching less sensitive
-        to how many spaces the user leaves between 'operator'
-        and <TYPENAME> or <OPERATOR>. */
+         This is just a courtesy to make the matching less sensitive
+         to how many spaces the user leaves between 'operator'
+         and <TYPENAME> or <OPERATOR>. */
       char *opend;
       char *opname = operator_chars (regexp, &opend);
       if (*opname)
-       {
+        {
           int fix = -1; /* -1 means ok; otherwise number of spaces needed. */
-         if (isalpha(*opname) || *opname == '_' || *opname == '$')
-           {
-             /* There should 1 space between 'operator' and 'TYPENAME'. */
-             if (opname[-1] != ' ' || opname[-2] == ' ')
-               fix = 1;
-           }
-         else
-           {
-             /* There should 0 spaces between 'operator' and 'OPERATOR'. */
-             if (opname[-1] == ' ')
-               fix = 0;
-           }
-         /* If wrong number of spaces, fix it. */
-         if (fix >= 0)
-           {
-             char *tmp = (char*) alloca(opend-opname+10);
-             sprintf(tmp, "operator%.*s%s", fix, " ", opname);
-             regexp = tmp;
-           }
+          if (isalpha(*opname) || *opname == '_' || *opname == '$')
+            {
+              /* There should 1 space between 'operator' and 'TYPENAME'. */
+              if (opname[-1] != ' ' || opname[-2] == ' ')
+                fix = 1;
+            }
+          else
+            {
+              /* There should 0 spaces between 'operator' and 'OPERATOR'. */
+              if (opname[-1] == ' ')
+                fix = 0;
+            }
+          /* If wrong number of spaces, fix it. */
+          if (fix >= 0)
+            {
+              char *tmp = (char*) alloca(opend-opname+10);
+              sprintf(tmp, "operator%.*s%s", fix, " ", opname);
+              regexp = tmp;
+            }
         }
       
       if (0 != (val = re_comp (regexp)))
-       error ("Invalid regexp (%s): %s", val, regexp);
+        error ("Invalid regexp (%s): %s", val, regexp);
     }
 
   /* Search through the partial symtabs *first* for all symbols
@@ -2822,48 +3106,49 @@ list_symbols (regexp, class, bpt, from_tty)
     {
       struct partial_symbol **bound, **gbound, **sbound;
       int keep_going = 1;
-      
+
       if (ps->readin) continue;
-      
+
       gbound = objfile->global_psymbols.list + ps->globals_offset + ps->n_global_syms;
       sbound = objfile->static_psymbols.list + ps->statics_offset + ps->n_static_syms;
       bound = gbound;
       
       /* Go through all of the symbols stored in a partial
-        symtab in one loop. */
+         symtab in one loop. */
       psym = objfile->global_psymbols.list + ps->globals_offset;
       while (keep_going)
-       {
-         if (psym >= bound)
-           {
-             if (bound == gbound && ps->n_static_syms != 0)
-               {
-                 psym = objfile->static_psymbols.list + ps->statics_offset;
-                 bound = sbound;
-               }
-             else
-               keep_going = 0;
-             continue;
-           }
-         else
-           {
-             QUIT;
-
-             /* If it would match (logic taken from loop below)
-                load the file and go on to the next one */
-             if ((regexp == NULL || SYMBOL_MATCHES_REGEXP (*psym))
-                 && ((class == 0 && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
-                      && 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)))
-               {
-                 PSYMTAB_TO_SYMTAB(ps);
-                 keep_going = 0;
-               }
-           }
-         psym++;
-       }
+        {
+          if (psym >= bound)
+            {
+              if (bound == gbound && ps->n_static_syms != 0)
+                {
+                  psym = objfile->static_psymbols.list + ps->statics_offset;
+                  bound = sbound;
+                }
+              else
+                keep_going = 0;
+              continue;
+            }
+          else
+            {
+              QUIT;
+
+              /* If it would match (logic taken from loop below)
+                 load the file and go on to the next one */
+              if (file_matches (ps->filename, files, nfiles)
+                  && ((regexp == NULL || SYMBOL_MATCHES_REGEXP (*psym))
+                      && ((kind == VARIABLES_NAMESPACE && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
+                           && SYMBOL_CLASS (*psym) != LOC_BLOCK)
+                          || (kind == FUNCTIONS_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_BLOCK)
+                          || (kind == TYPES_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_TYPEDEF)
+                          || (kind == METHODS_NAMESPACE && SYMBOL_CLASS (*psym) == LOC_BLOCK))))
+                {
+                  PSYMTAB_TO_SYMTAB(ps);
+                  keep_going = 0;
+                }
+            }
+          psym++;
+        }
     }
 
   /* Here, we search through the minimal symbol tables for functions
@@ -2879,194 +3164,261 @@ list_symbols (regexp, class, bpt, from_tty)
      any matching symbols without debug info.
   */
 
-  if (class == 0 || class == 1)
+  if (nfiles == 0 && (kind == VARIABLES_NAMESPACE || kind == FUNCTIONS_NAMESPACE))
     {
       ALL_MSYMBOLS (objfile, msymbol)
-       {
-         if (MSYMBOL_TYPE (msymbol) == ourtype ||
-             MSYMBOL_TYPE (msymbol) == ourtype2 ||
-             MSYMBOL_TYPE (msymbol) == ourtype3 ||
-             MSYMBOL_TYPE (msymbol) == ourtype4)
-           {
-             if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
-               {
-                 if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)))
-                   {
-                     if (class == 1
-                         || lookup_symbol (SYMBOL_NAME (msymbol), 
-                                           (struct block *) NULL,
-                                           VAR_NAMESPACE,
-                                           0, (struct symtab **) NULL) == NULL)
-                       found_misc = 1;
-                   }
-               }
-           }
-       }
+        {
+          if (MSYMBOL_TYPE (msymbol) == ourtype ||
+              MSYMBOL_TYPE (msymbol) == ourtype2 ||
+              MSYMBOL_TYPE (msymbol) == ourtype3 ||
+              MSYMBOL_TYPE (msymbol) == ourtype4)
+            {
+              if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
+                {
+                  if (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol)))
+                    {
+                      if (kind == FUNCTIONS_NAMESPACE
+                          || lookup_symbol (SYMBOL_NAME (msymbol), 
+                                            (struct block *) NULL,
+                                            VAR_NAMESPACE,
+                                            0, (struct symtab **) NULL) == NULL)
+                        found_misc = 1;
+                    }
+                }
+            }
+        }
     }
 
-  /* Printout here so as to get after the "Reading in symbols"
-     messages which will be generated above.  */
-  if (!bpt)
-    printf_filtered (regexp
-         ? "All %ss matching regular expression \"%s\":\n"
-         : "All defined %ss:\n",
-         classnames[class],
-         regexp);
-
   ALL_SYMTABS (objfile, s)
     {
-      found_in_file = 0;
       bv = BLOCKVECTOR (s);
       /* Often many files share a blockvector.
-        Scan each blockvector only once so that
-        we don't get every symbol many times.
-        It happens that the first symtab in the list
-        for any given blockvector is the main file.  */
+         Scan each blockvector only once so that
+         we don't get every symbol many times.
+         It happens that the first symtab in the list
+         for any given blockvector is the main file.  */
       if (bv != prev_bv)
-       for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
-         {
-           b = BLOCKVECTOR_BLOCK (bv, i);
-           /* Skip the sort if this block is always sorted.  */
-           if (!BLOCK_SHOULD_SORT (b))
-             sort_block_syms (b);
-           for (j = 0; j < BLOCK_NSYMS (b); j++)
-             {
-               QUIT;
-               sym = BLOCK_SYM (b, j);
-               if ((regexp == NULL || SYMBOL_MATCHES_REGEXP (sym))
-                   && ((class == 0 && SYMBOL_CLASS (sym) != LOC_TYPEDEF
-                        && SYMBOL_CLASS (sym) != LOC_BLOCK
-                        && SYMBOL_CLASS (sym) != LOC_CONST)
-                       || (class == 1 && SYMBOL_CLASS (sym) == LOC_BLOCK)
-                       || (class == 2 && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
-                       || (class == 3 && SYMBOL_CLASS (sym) == LOC_BLOCK)))
-                 {
-                   if (bpt)
-                     {
-                       /* Set a breakpoint here, if it's a function */
-                       if (class == 1)
-                         {
-                           /* There may be more than one function with the
-                              same name but in different files.  In order to
-                              set breakpoints on all of them, we must give
-                              both the file name and the function name to
-                              break_command.
-                              Quoting the symbol name gets rid of problems
-                              with mangled symbol names that contain
-                              CPLUS_MARKER characters.  */
-                           char *string =
-                             (char *) alloca (strlen (s->filename)
-                                              + strlen (SYMBOL_NAME(sym))
-                                              + 4);
-                           strcpy (string, s->filename);
-                           strcat (string, ":'");
-                           strcat (string, SYMBOL_NAME(sym));
-                           strcat (string, "'");
-                           break_command (string, from_tty);
-                         }
-                     }
-                   else if (!found_in_file)
-                     {
-                       fputs_filtered ("\nFile ", gdb_stdout);
-                       fputs_filtered (s->filename, gdb_stdout);
-                       fputs_filtered (":\n", gdb_stdout);
-                     }
-                   found_in_file = 1;
-                   
-                   if (class != 2 && i == STATIC_BLOCK)
-                     printf_filtered ("static ");
-                   
-                   /* Typedef that is not a C++ class */
-                   if (class == 2
-                       && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
-                     c_typedef_print (SYMBOL_TYPE(sym), sym, gdb_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_SOURCE_NAME (sym)),
-                                   gdb_stdout, 0);
-                       
-                       printf_filtered (";\n");
-                     }
-                   else
-                     {
-# if 0
-/* Tiemann says: "info methods was never implemented."  */
-                       char *demangled_name;
-                       c_type_print_base (TYPE_FN_FIELD_TYPE(t, i),
-                                          gdb_stdout, 0, 0); 
-                       c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, i),
-                                                    gdb_stdout, 0); 
-                       if (TYPE_FN_FIELD_STUB (t, i))
-                         check_stub_method (TYPE_DOMAIN_TYPE (type), j, i);
-                       demangled_name =
-                         cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t, i),
-                                         DMGL_ANSI | DMGL_PARAMS);
-                       if (demangled_name == NULL)
-                         fprintf_filtered (stream, "<badly mangled name %s>",
-                                           TYPE_FN_FIELD_PHYSNAME (t, i));
-                       else
-                         {
-                           fputs_filtered (demangled_name, stream);
-                           free (demangled_name);
-                         }
-# endif
-                     }
-                 }
-             }
-         }
+        for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
+          {
+            b = BLOCKVECTOR_BLOCK (bv, i);
+            /* Skip the sort if this block is always sorted.  */
+            if (!BLOCK_SHOULD_SORT (b))
+              sort_block_syms (b);
+            for (j = 0; j < BLOCK_NSYMS (b); j++)
+              {
+                QUIT;
+                sym = BLOCK_SYM (b, j);
+                if (file_matches (s->filename, files, nfiles)
+                    && ((regexp == NULL || SYMBOL_MATCHES_REGEXP (sym))
+                        && ((kind == VARIABLES_NAMESPACE && SYMBOL_CLASS (sym) != LOC_TYPEDEF
+                             && SYMBOL_CLASS (sym) != LOC_BLOCK
+                             && SYMBOL_CLASS (sym) != LOC_CONST)
+                            || (kind == FUNCTIONS_NAMESPACE && SYMBOL_CLASS (sym) == LOC_BLOCK)
+                            || (kind == TYPES_NAMESPACE && SYMBOL_CLASS (sym) == LOC_TYPEDEF)
+                            || (kind == METHODS_NAMESPACE && SYMBOL_CLASS (sym) == LOC_BLOCK))))
+                  {
+                    /* match */
+                    psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search));
+                    psr->block = i;
+                    psr->symtab = s;
+                    psr->symbol = sym;
+                    psr->msymbol = NULL;
+                    psr->next = NULL;
+                    if (tail == NULL)
+                      {
+                        sr = psr;
+                        old_chain = make_cleanup ((make_cleanup_func) 
+                                                  free_search_symbols, sr);
+                      }
+                    else
+                      tail->next = psr;
+                    tail = psr;
+                  }
+              }
+          }
       prev_bv = bv;
     }
 
   /* If there are no eyes, avoid all contact.  I mean, if there are
      no debug symbols, then print directly from the msymbol_vector.  */
 
-  if (found_misc || class != 1)
+  if (found_misc || kind != FUNCTIONS_NAMESPACE)
     {
-      found_in_file = 0;
       ALL_MSYMBOLS (objfile, msymbol)
-       {
-         if (MSYMBOL_TYPE (msymbol) == ourtype ||
-             MSYMBOL_TYPE (msymbol) == ourtype2 ||
-             MSYMBOL_TYPE (msymbol) == ourtype3 ||
-             MSYMBOL_TYPE (msymbol) == ourtype4)
-           {
-             if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
-               {
-                 /* Functions:  Look up by address. */
-                 if (class != 1 ||
-                     (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol))))
-                   {
-                     /* Variables/Absolutes:  Look up by name */
-                     if (lookup_symbol (SYMBOL_NAME (msymbol), 
-                                        (struct block *) NULL, VAR_NAMESPACE,
-                                        0, (struct symtab **) NULL) == NULL)
-                       {
-                          if (bpt)
+        {
+          if (MSYMBOL_TYPE (msymbol) == ourtype ||
+              MSYMBOL_TYPE (msymbol) == ourtype2 ||
+              MSYMBOL_TYPE (msymbol) == ourtype3 ||
+              MSYMBOL_TYPE (msymbol) == ourtype4)
+            {
+              if (regexp == NULL || SYMBOL_MATCHES_REGEXP (msymbol))
+                {
+                  /* Functions:  Look up by address. */
+                  if (kind != FUNCTIONS_NAMESPACE ||
+                      (0 == find_pc_symtab (SYMBOL_VALUE_ADDRESS (msymbol))))
+                    {
+                      /* Variables/Absolutes:  Look up by name */
+                      if (lookup_symbol (SYMBOL_NAME (msymbol), 
+                                         (struct block *) NULL, VAR_NAMESPACE,
+                                         0, (struct symtab **) NULL) == NULL)
+                        {
+                          /* match */
+                          psr = (struct symbol_search *) xmalloc (sizeof (struct symbol_search));
+                          psr->block = i;
+                          psr->msymbol = msymbol;
+                          psr->symtab  = NULL;
+                          psr->symbol  = NULL;
+                          psr->next = NULL;
+                          if (tail == NULL)
                             {
-                              break_command (SYMBOL_NAME (msymbol), from_tty);
-                              printf_filtered ("<function, no debug info> %s;\n",
-                                               SYMBOL_SOURCE_NAME (msymbol));
-                              continue;
+                              sr = psr;
+                              old_chain = make_cleanup ((make_cleanup_func) 
+                                                      free_search_symbols, &sr);
                             }
-                         if (!found_in_file)
-                           {
-                             printf_filtered ("\nNon-debugging symbols:\n");
-                             found_in_file = 1;
-                           }
-                         printf_filtered ("    %08lx  %s\n",
-                                          (unsigned long) SYMBOL_VALUE_ADDRESS (msymbol),
-                                          SYMBOL_SOURCE_NAME (msymbol));
-                       }
-                   }
-               }
-           }
-       }
+                          else
+                            tail->next = psr;
+                          tail = psr;
+                        }
+                    }
+                }
+            }
+        }
     }
+
+  *matches = sr;
+  if (sr != NULL)
+    discard_cleanups (old_chain);
+}
+
+/* Helper function for symtab_symbol_info, this function uses
+   the data returned from search_symbols() to print information
+   regarding the match to gdb_stdout.
+*/
+static void
+print_symbol_info (kind, s, sym, block, last)
+     namespace_enum kind;
+     struct symtab *s;
+     struct symbol *sym;
+     int block;
+     char *last;
+{
+  if (last == NULL || strcmp (last, s->filename) != 0)
+    {
+      fputs_filtered ("\nFile ", gdb_stdout);
+      fputs_filtered (s->filename, gdb_stdout);
+      fputs_filtered (":\n", gdb_stdout);
+    }
+
+  if (kind != TYPES_NAMESPACE && block == STATIC_BLOCK)
+    printf_filtered ("static ");
+           
+  /* Typedef that is not a C++ class */
+  if (kind == TYPES_NAMESPACE
+      && SYMBOL_NAMESPACE (sym) != STRUCT_NAMESPACE)
+    c_typedef_print (SYMBOL_TYPE(sym), sym, gdb_stdout);
+  /* variable, func, or typedef-that-is-c++-class */
+  else if (kind < TYPES_NAMESPACE || 
+           (kind == TYPES_NAMESPACE && 
+            SYMBOL_NAMESPACE(sym) == STRUCT_NAMESPACE))
+    {
+      type_print (SYMBOL_TYPE (sym),
+                  (SYMBOL_CLASS (sym) == LOC_TYPEDEF
+                   ? "" : SYMBOL_SOURCE_NAME (sym)),
+                  gdb_stdout, 0);
+
+      printf_filtered (";\n");
+    }
+  else
+    {
+# if 0
+      /* Tiemann says: "info methods was never implemented."  */
+      char *demangled_name;
+      c_type_print_base (TYPE_FN_FIELD_TYPE(t, block),
+                         gdb_stdout, 0, 0); 
+      c_type_print_varspec_prefix (TYPE_FN_FIELD_TYPE(t, block),
+                                   gdb_stdout, 0); 
+      if (TYPE_FN_FIELD_STUB (t, block))
+        check_stub_method (TYPE_DOMAIN_TYPE (type), j, block);
+      demangled_name =
+        cplus_demangle (TYPE_FN_FIELD_PHYSNAME (t, block),
+                        DMGL_ANSI | DMGL_PARAMS);
+      if (demangled_name == NULL)
+        fprintf_filtered (stream, "<badly mangled name %s>",
+                          TYPE_FN_FIELD_PHYSNAME (t, block));
+      else
+        {
+          fputs_filtered (demangled_name, stream);
+          free (demangled_name);
+        }
+# endif
+    }
+}
+
+/* This help function for symtab_symbol_info() prints information
+   for non-debugging symbols to gdb_stdout.
+*/
+static void
+print_msymbol_info (msymbol)
+     struct minimal_symbol *msymbol;
+{
+  printf_filtered ("   %08lx  %s\n",
+                   (unsigned long) SYMBOL_VALUE_ADDRESS (msymbol),
+                   SYMBOL_SOURCE_NAME (msymbol));
+}
+
+/* This is the guts of the commands "info functions", "info types", and
+   "info variables". It calls search_symbols to find all matches and then
+   print_[m]symbol_info to print out some useful information about the
+   matches.
+*/
+static void
+symtab_symbol_info (regexp, kind, from_tty)
+     char *regexp;
+     namespace_enum kind;
+     int   from_tty;
+{
+  static char *classnames[]
+    = {"variable", "function", "type", "method"};
+  struct symbol_search *symbols;
+  struct symbol_search *p;
+  struct cleanup *old_chain;
+  char *last_filename = NULL;
+  int first = 1;
+
+  /* must make sure that if we're interrupted, symbols gets freed */
+  search_symbols (regexp, kind, 0, (char **) NULL, &symbols);
+  old_chain = make_cleanup ((make_cleanup_func) free_search_symbols, symbols);
+
+  printf_filtered (regexp
+                   ? "All %ss matching regular expression \"%s\":\n"
+                   : "All defined %ss:\n",
+                   classnames[(int) (kind - LABEL_NAMESPACE - 1)], regexp);
+
+  for (p = symbols; p != NULL; p = p->next)
+    {
+      QUIT;
+
+      if (p->msymbol != NULL)
+        {
+          if (first)
+            {
+              printf_filtered ("\nNon-debugging symbols:\n");
+              first = 0;
+            }
+          print_msymbol_info (p->msymbol);
+        }
+      else
+        {
+          print_symbol_info (kind,
+                             p->symtab,
+                             p->symbol,
+                             p->block,
+                             last_filename);
+          last_filename = p->symtab->filename;
+        }
+    }
+
+  do_cleanups (old_chain);
 }
 
 static void
@@ -3074,7 +3426,7 @@ variables_info (regexp, from_tty)
      char *regexp;
      int from_tty;
 {
-  list_symbols (regexp, 0, 0, from_tty);
+  symtab_symbol_info (regexp, VARIABLES_NAMESPACE, from_tty);
 }
 
 static void
@@ -3082,7 +3434,7 @@ functions_info (regexp, from_tty)
      char *regexp;
      int from_tty;
 {
-  list_symbols (regexp, 1, 0, from_tty);
+  symtab_symbol_info (regexp, FUNCTIONS_NAMESPACE, from_tty);
 }
 
 static void
@@ -3090,7 +3442,7 @@ types_info (regexp, from_tty)
      char *regexp;
      int from_tty;
 {
-  list_symbols (regexp, 2, 0, from_tty);
+  symtab_symbol_info (regexp, TYPES_NAMESPACE, from_tty);
 }
 
 #if 0
@@ -3099,7 +3451,7 @@ static void
 methods_info (regexp)
      char *regexp;
 {
-  list_symbols (regexp, 3, 0, from_tty);
+  symtab_symbol_info (regexp, METHODS_NAMESPACE, 0, from_tty);
 }
 #endif /* 0 */
 
@@ -3109,10 +3461,43 @@ rbreak_command (regexp, from_tty)
      char *regexp;
      int from_tty;
 {
-  list_symbols (regexp, 1, 1, from_tty);
+  struct symbol_search *ss;
+  struct symbol_search *p;
+  struct cleanup *old_chain;
+
+  search_symbols (regexp, FUNCTIONS_NAMESPACE, 0, (char **) NULL, &ss);
+  old_chain = make_cleanup ((make_cleanup_func) free_search_symbols, ss);
+
+  for (p = ss; p != NULL; p = p->next)
+    {
+      if (p->msymbol == NULL)
+        {
+          char *string = (char *) alloca (strlen (p->symtab->filename)
+                                          + strlen (SYMBOL_NAME (p->symbol))
+                                          + 4);
+          strcpy (string, p->symtab->filename);
+          strcat (string, ":'");
+          strcat (string, SYMBOL_NAME (p->symbol));
+          strcat (string, "'");
+          break_command (string, from_tty);
+          print_symbol_info (FUNCTIONS_NAMESPACE,
+                             p->symtab,
+                             p->symbol,
+                             p->block,
+                             p->symtab->filename);
+        }
+      else
+        {
+          break_command (SYMBOL_NAME (p->msymbol), from_tty);
+          printf_filtered ("<function, no debug info> %s;\n",
+                           SYMBOL_SOURCE_NAME (p->msymbol));
+        }
+    }
+
+  do_cleanups (old_chain);
 }
-\f
 
+\f
 /* Return Nonzero if block a is lexically nested within block b,
    or if a and b have the same pc range.
    Return zero otherwise. */
@@ -3498,7 +3883,7 @@ are listed.");
   add_info ("sources", sources_info,
            "Source files in the program.");
 
-  add_com ("rbreak", no_class, rbreak_command,
+  add_com ("rbreak", class_breakpoint, rbreak_command,
            "Set a breakpoint for all functions matching REGEXP.");
 
   /* Initialize the one built-in type that isn't language dependent... */
This page took 0.043148 seconds and 4 git commands to generate.