2000-10-12 Elena Zannoni <ezannoni@kwikemart.cygnus.com>
[deliverable/binutils-gdb.git] / gdb / symtab.c
index 36a40519416d58ee74697597af7099a787748c7f..3a97e10281b8d72cbf0339ed9735a9e7071afa24 100644 (file)
@@ -30,7 +30,7 @@
 #include "objfiles.h"
 #include "gdbcmd.h"
 #include "call-cmds.h"
-#include "gnu-regex.h"
+#include "gdb_regex.h"
 #include "expression.h"
 #include "language.h"
 #include "demangle.h"
 /* Prototype for one function in parser-defs.h,
    instead of including that entire file. */
 
-extern char *find_template_name_end PARAMS ((char *));
+extern char *find_template_name_end (char *);
 
 /* Prototypes for local functions */
 
-static int find_methods PARAMS ((struct type *, char *, struct symbol **));
+static int find_methods (struct type *, char *, struct symbol **);
 
-static void completion_list_add_name PARAMS ((char *, char *, int, char *,
-                                             char *));
+static void completion_list_add_name (char *, char *, int, char *, char *);
 
-static void build_canonical_line_spec PARAMS ((struct symtab_and_line *,
-                                              char *, char ***));
+static void build_canonical_line_spec (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 (struct symbol *[],
+                                              int, int, char ***);
 
-static void rbreak_command PARAMS ((char *, int));
+static void rbreak_command (char *, int);
 
-static void types_info PARAMS ((char *, int));
+static void types_info (char *, int);
 
-static void functions_info PARAMS ((char *, int));
+static void functions_info (char *, int);
 
-static void variables_info PARAMS ((char *, int));
+static void variables_info (char *, int);
 
-static void sources_info PARAMS ((char *, int));
+static void sources_info (char *, int);
 
-static void output_source_filename PARAMS ((char *, int *));
+static void output_source_filename (char *, int *);
 
-char *operator_chars PARAMS ((char *, char **));
+char *operator_chars (char *, char **);
 
-static int find_line_common PARAMS ((struct linetable *, int, int *));
+static int find_line_common (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 (struct partial_symtab *,
+                                                    const char *, int,
+                                                    namespace_enum);
 
-static struct partial_symbol *fixup_psymbol_section PARAMS ((struct
-                                      partial_symbol *, struct objfile *));
+static struct symtab *lookup_symtab_1 (char *);
 
-static struct symtab *lookup_symtab_1 PARAMS ((char *));
+static struct symbol *lookup_symbol_aux (const char *name, const
+                                        struct block *block, const
+                                        namespace_enum namespace, int
+                                        *is_a_field_of_this, struct
+                                        symtab **symtab);
 
-static void cplusplus_hint PARAMS ((char *));
 
-static struct symbol *find_active_alias PARAMS ((struct symbol * sym,
-                                                CORE_ADDR addr));
+static void cplusplus_hint (char *);
+
+static struct symbol *find_active_alias (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 void fixup_section (struct general_symbol_info *, struct objfile *);
 
-static int file_matches PARAMS ((char *, char **, int));
+static int file_matches (char *, char **, int);
 
-static void print_symbol_info PARAMS ((namespace_enum,
-                                      struct symtab *, struct symbol *,
-                                      int, char *));
+static void print_symbol_info (namespace_enum,
+                              struct symtab *, struct symbol *, int, char *);
 
-static void print_msymbol_info PARAMS ((struct minimal_symbol *));
+static void print_msymbol_info (struct minimal_symbol *);
 
-static void symtab_symbol_info PARAMS ((char *, namespace_enum, int));
+static void symtab_symbol_info (char *, namespace_enum, int);
 
-static void overload_list_add_symbol PARAMS ((struct symbol * sym,
-                                             char *oload_name));
+static void overload_list_add_symbol (struct symbol *sym, char *oload_name);
 
-void _initialize_symtab PARAMS ((void));
+void _initialize_symtab (void);
 
 /* */
 
@@ -132,8 +131,7 @@ char no_symtab_msg[] = "No symbol table is loaded.  Use the \"file\" command.";
    symbols.  Remove when loose ends are cleaned up.   FIXME -fnf */
 
 static void
-cplusplus_hint (name)
-     char *name;
+cplusplus_hint (char *name)
 {
   while (*name == '\'')
     name++;
@@ -146,8 +144,7 @@ cplusplus_hint (name)
    in the symtab filename will also work.  */
 
 static struct symtab *
-lookup_symtab_1 (name)
-     char *name;
+lookup_symtab_1 (char *name)
 {
   register struct symtab *s;
   register struct partial_symtab *ps;
@@ -210,8 +207,7 @@ got_symtab:
    of variations if the first lookup doesn't work.  */
 
 struct symtab *
-lookup_symtab (name)
-     char *name;
+lookup_symtab (char *name)
 {
   register struct symtab *s;
 #if 0
@@ -248,8 +244,7 @@ lookup_symtab (name)
    in the psymtab filename will also work.  */
 
 struct partial_symtab *
-lookup_partial_symtab (name)
-     char *name;
+lookup_partial_symtab (char *name)
 {
   register struct partial_symtab *pst;
   register struct objfile *objfile;
@@ -286,9 +281,7 @@ lookup_partial_symtab (name)
    specified by SIGNATURE_ID.  Note that this function is g++ specific. */
 
 char *
-gdb_mangle_name (type, method_id, signature_id)
-     struct type *type;
-     int method_id, signature_id;
+gdb_mangle_name (struct type *type, int method_id, int signature_id)
 {
   int mangled_name_len;
   char *mangled_name;
@@ -387,9 +380,7 @@ gdb_mangle_name (type, method_id, signature_id)
 /* Find which partial symtab on contains PC and SECTION.  Return 0 if none.  */
 
 struct partial_symtab *
-find_pc_sect_psymtab (pc, section)
-     CORE_ADDR pc;
-     asection *section;
+find_pc_sect_psymtab (CORE_ADDR pc, asection *section)
 {
   register struct partial_symtab *pst;
   register struct objfile *objfile;
@@ -436,8 +427,7 @@ find_pc_sect_psymtab (pc, section)
    Backward compatibility, no section */
 
 struct partial_symtab *
-find_pc_psymtab (pc)
-     CORE_ADDR pc;
+find_pc_psymtab (CORE_ADDR pc)
 {
   return find_pc_sect_psymtab (pc, find_pc_mapped_section (pc));
 }
@@ -446,10 +436,8 @@ find_pc_psymtab (pc)
    Return 0 if none.  Check all psymtabs if PSYMTAB is 0.  */
 
 struct partial_symbol *
-find_pc_sect_psymbol (psymtab, pc, section)
-     struct partial_symtab *psymtab;
-     CORE_ADDR pc;
-     asection *section;
+find_pc_sect_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc,
+                     asection *section)
 {
   struct partial_symbol *best = NULL, *p, **pp;
   CORE_ADDR best_pc;
@@ -520,9 +508,7 @@ find_pc_sect_psymbol (psymtab, pc, section)
    Check all psymtabs if PSYMTAB is 0.  Backwards compatibility, no section. */
 
 struct partial_symbol *
-find_pc_psymbol (psymtab, pc)
-     struct partial_symtab *psymtab;
-     CORE_ADDR pc;
+find_pc_psymbol (struct partial_symtab *psymtab, CORE_ADDR pc)
 {
   return find_pc_sect_psymbol (psymtab, pc, find_pc_mapped_section (pc));
 }
@@ -531,21 +517,20 @@ find_pc_psymbol (psymtab, pc)
    out of the minimal symbols and stash that in the debug symbol.  */
 
 static void
-fixup_section (ginfo, objfile)
-     struct general_symbol_info *ginfo;
-     struct objfile *objfile;
+fixup_section (struct general_symbol_info *ginfo, struct objfile *objfile)
 {
   struct minimal_symbol *msym;
   msym = lookup_minimal_symbol (ginfo->name, NULL, objfile);
 
   if (msym)
-    ginfo->bfd_section = SYMBOL_BFD_SECTION (msym);
+    {
+      ginfo->bfd_section = SYMBOL_BFD_SECTION (msym);
+      ginfo->section = SYMBOL_SECTION (msym);
+    }
 }
 
 struct symbol *
-fixup_symbol_section (sym, objfile)
-     struct symbol *sym;
-     struct objfile *objfile;
+fixup_symbol_section (struct symbol *sym, struct objfile *objfile)
 {
   if (!sym)
     return NULL;
@@ -558,10 +543,8 @@ fixup_symbol_section (sym, objfile)
   return sym;
 }
 
-static struct partial_symbol *
-fixup_psymbol_section (psym, objfile)
-     struct partial_symbol *psym;
-     struct objfile *objfile;
+struct partial_symbol *
+fixup_psymbol_section (struct partial_symbol *psym, struct objfile *objfile)
 {
   if (!psym)
     return NULL;
@@ -596,21 +579,64 @@ fixup_psymbol_section (psym, objfile)
    can probably assume it will never hit the C++ code).  */
 
 struct symbol *
-lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
-     const char *name;
-     register const struct block *block;
-     const namespace_enum namespace;
-     int *is_a_field_of_this;
-     struct symtab **symtab;
+lookup_symbol (const char *name, const struct block *block,
+              const namespace_enum namespace, int *is_a_field_of_this,
+              struct symtab **symtab)
+{
+  char *modified_name = NULL;
+  char *modified_name2 = NULL;
+  int needtofreename = 0;
+  struct symbol *returnval;
+
+  if (case_sensitivity == case_sensitive_off)
+    {
+      char *copy;
+      int len, i;
+
+      len = strlen (name);
+      copy = (char *) alloca (len + 1);
+      for (i= 0; i < len; i++)
+        copy[i] = tolower (name[i]);
+      copy[len] = 0;
+      modified_name = copy;
+    }
+  else 
+      modified_name = (char *) name;
+
+  /* If we are using C++ language, demangle the name before doing a lookup, so
+     we can always binary search. */
+  if (current_language->la_language == language_cplus)
+    {
+      modified_name2 = cplus_demangle (modified_name, DMGL_ANSI | DMGL_PARAMS);
+      if (modified_name2)
+       {
+         modified_name = modified_name2;
+         needtofreename = 1;
+       }
+    }
+
+  returnval = lookup_symbol_aux (modified_name, block, namespace,
+                                is_a_field_of_this, symtab);
+  if (needtofreename)
+    free (modified_name2);
+
+  return returnval;     
+}
+
+static struct symbol *
+lookup_symbol_aux (const char *name, const struct block *block,
+              const namespace_enum namespace, int *is_a_field_of_this,
+              struct symtab **symtab)
 {
   register struct symbol *sym;
   register struct symtab *s = NULL;
   register struct partial_symtab *ps;
-  struct blockvector *bv;
+  register struct blockvector *bv;
   register struct objfile *objfile = NULL;
   register struct block *b;
   register struct minimal_symbol *msymbol;
 
+
   /* Search specified block and its superiors.  */
 
   while (block != 0)
@@ -958,31 +984,28 @@ lookup_symbol (name, block, namespace, is_a_field_of_this, symtab)
     *symtab = NULL;
   return 0;
 }
-
+                                                               
 /* Look, in partial_symtab PST, for symbol NAME.  Check the global
    symbols if GLOBAL, the static symbols if not */
 
 static struct partial_symbol *
-lookup_partial_symbol (pst, name, global, namespace)
-     struct partial_symtab *pst;
-     const char *name;
-     int global;
-     namespace_enum namespace;
+lookup_partial_symbol (struct partial_symtab *pst, const char *name, int global,
+                      namespace_enum namespace)
 {
+  struct partial_symbol *temp;
   struct partial_symbol **start, **psym;
   struct partial_symbol **top, **bottom, **center;
   int length = (global ? pst->n_global_syms : pst->n_static_syms);
   int do_linear_search = 1;
-
+  
   if (length == 0)
     {
       return (NULL);
     }
-
   start = (global ?
           pst->objfile->global_psymbols.list + pst->globals_offset :
           pst->objfile->static_psymbols.list + pst->statics_offset);
-
+  
   if (global)                  /* This means we can use a binary search. */
     {
       do_linear_search = 0;
@@ -1000,13 +1023,11 @@ lookup_partial_symbol (pst, name, global, namespace)
          if (!(center < top))
            abort ();
          if (!do_linear_search
-             && (SYMBOL_LANGUAGE (*center) == language_cplus
-                 || SYMBOL_LANGUAGE (*center) == language_java
-             ))
+             && (SYMBOL_LANGUAGE (*center) == language_java))
            {
              do_linear_search = 1;
            }
-         if (STRCMP (SYMBOL_NAME (*center), name) >= 0)
+         if (STRCMP (SYMBOL_SOURCE_NAME (*center), name) >= 0)
            {
              top = center;
            }
@@ -1017,11 +1038,15 @@ lookup_partial_symbol (pst, name, global, namespace)
        }
       if (!(top == bottom))
        abort ();
-      while (STREQ (SYMBOL_NAME (*top), name))
+
+      /* djb - 2000-06-03 - Use SYMBOL_MATCHES_NAME, not a strcmp, so
+        we don't have to force a linear search on C++. Probably holds true
+        for JAVA as well, no way to check.*/
+      while (SYMBOL_MATCHES_NAME (*top,name))
        {
          if (SYMBOL_NAMESPACE (*top) == namespace)
            {
-             return (*top);
+                 return (*top);
            }
          top++;
        }
@@ -1031,7 +1056,7 @@ lookup_partial_symbol (pst, name, global, namespace)
      we should also do a linear search. */
 
   if (do_linear_search)
-    {
+    {                  
       for (psym = start; psym < start + length; psym++)
        {
          if (namespace == SYMBOL_NAMESPACE (*psym))
@@ -1056,8 +1081,7 @@ lookup_partial_symbol (pst, name, global, namespace)
 
 
 struct type *
-lookup_transparent_type (name)
-     const char *name;
+lookup_transparent_type (const char *name)
 {
   register struct symbol *sym;
   register struct symtab *s = NULL;
@@ -1165,7 +1189,7 @@ lookup_transparent_type (name)
    executables that have no main() ? */
 
 struct partial_symtab *
-find_main_psymtab ()
+find_main_psymtab (void)
 {
   register struct partial_symtab *pst;
   register struct objfile *objfile;
@@ -1192,10 +1216,8 @@ find_main_psymtab ()
    tested for a match. */
 
 struct symbol *
-lookup_block_symbol (block, name, namespace)
-     register const struct block *block;
-     const char *name;
-     const namespace_enum namespace;
+lookup_block_symbol (register const struct block *block, const char *name,
+                    const namespace_enum namespace)
 {
   register int bot, top, inc;
   register struct symbol *sym;
@@ -1208,9 +1230,7 @@ lookup_block_symbol (block, name, namespace)
     {
       /* Reset the linear search flag so if the binary search fails, we
          won't do the linear search once unless we find some reason to
-         do so, such as finding a C++ symbol during the binary search.
-         Note that for C++ modules, ALL the symbols in a block should
-         end up marked as C++ symbols. */
+         do so */
 
       do_linear_search = 0;
       top = BLOCK_NSYMS (block);
@@ -1228,22 +1248,19 @@ lookup_block_symbol (block, name, namespace)
            }
          inc = (inc >> 1) + bot;
          sym = BLOCK_SYM (block, inc);
-         if (!do_linear_search
-             && (SYMBOL_LANGUAGE (sym) == language_cplus
-                 || SYMBOL_LANGUAGE (sym) == language_java
-             ))
+         if (!do_linear_search && (SYMBOL_LANGUAGE (sym) == language_java))
            {
              do_linear_search = 1;
            }
-         if (SYMBOL_NAME (sym)[0] < name[0])
+         if (SYMBOL_SOURCE_NAME (sym)[0] < name[0])
            {
              bot = inc;
            }
-         else if (SYMBOL_NAME (sym)[0] > name[0])
+         else if (SYMBOL_SOURCE_NAME (sym)[0] > name[0])
            {
              top = inc;
            }
-         else if (STRCMP (SYMBOL_NAME (sym), name) < 0)
+         else if (STRCMP (SYMBOL_SOURCE_NAME (sym), name) < 0)
            {
              bot = inc;
            }
@@ -1265,19 +1282,8 @@ lookup_block_symbol (block, name, namespace)
       while (bot < top)
        {
          sym = BLOCK_SYM (block, bot);
-         inc = SYMBOL_NAME (sym)[0] - name[0];
-         if (inc == 0)
-           {
-             inc = STRCMP (SYMBOL_NAME (sym), name);
-           }
-         if (inc == 0 && SYMBOL_NAMESPACE (sym) == namespace)
-           {
-             return (sym);
-           }
-         if (inc > 0)
-           {
-             break;
-           }
+         if (SYMBOL_MATCHES_NAME (sym, name))
+           return sym;
          bot++;
        }
     }
@@ -1352,9 +1358,7 @@ lookup_block_symbol (block, name, namespace)
    If no alias is active, then return SYM.  */
 
 static struct symbol *
-find_active_alias (sym, addr)
-     struct symbol *sym;
-     CORE_ADDR addr;
+find_active_alias (struct symbol *sym, CORE_ADDR addr)
 {
   struct range_list *r;
   struct alias_list *aliases;
@@ -1383,8 +1387,7 @@ find_active_alias (sym, addr)
    lexical block, described by a struct block BL.  */
 
 struct symbol *
-block_function (bl)
-     struct block *bl;
+block_function (struct block *bl)
 {
   while (BLOCK_FUNCTION (bl) == 0 && BLOCK_SUPERBLOCK (bl) != 0)
     bl = BLOCK_SUPERBLOCK (bl);
@@ -1396,9 +1399,7 @@ block_function (bl)
    psymtabs and read in another symtab if necessary. */
 
 struct symtab *
-find_pc_sect_symtab (pc, section)
-     CORE_ADDR pc;
-     asection *section;
+find_pc_sect_symtab (CORE_ADDR pc, asection *section)
 {
   register struct block *b;
   struct blockvector *bv;
@@ -1474,10 +1475,9 @@ find_pc_sect_symtab (pc, section)
        /* Might want to error() here (in case symtab is corrupt and
           will cause a core dump), but maybe we can successfully
           continue, so let's not.  */
-       /* FIXME-32x64: assumes pc fits in a long */
        warning ("\
-(Internal error: pc 0x%lx in read in psymtab, but not in symtab.)\n",
-                (unsigned long) pc);
+(Internal error: pc 0x%s in read in psymtab, but not in symtab.)\n",
+                paddr_nz (pc));
       s = PSYMTAB_TO_SYMTAB (ps);
     }
   return (s);
@@ -1487,8 +1487,7 @@ find_pc_sect_symtab (pc, section)
    read in another symtab if necessary.  Backward compatibility, no section */
 
 struct symtab *
-find_pc_symtab (pc)
-     CORE_ADDR pc;
+find_pc_symtab (CORE_ADDR pc)
 {
   return find_pc_sect_symtab (pc, find_pc_mapped_section (pc));
 }
@@ -1504,10 +1503,7 @@ find_pc_symtab (pc)
    line *0x2345" cause psymtabs to be converted to symtabs).  */
 
 struct symbol *
-find_addr_symbol (addr, symtabp, symaddrp)
-     CORE_ADDR addr;
-     struct symtab **symtabp;
-     CORE_ADDR *symaddrp;
+find_addr_symbol (CORE_ADDR addr, struct symtab **symtabp, CORE_ADDR *symaddrp)
 {
   struct symtab *symtab, *best_symtab;
   struct objfile *objfile;
@@ -1605,10 +1601,7 @@ done:
 /* If it's worth the effort, we could be using a binary search.  */
 
 struct symtab_and_line
-find_pc_sect_line (pc, section, notcurrent)
-     CORE_ADDR pc;
-     struct sec *section;
-     int notcurrent;
+find_pc_sect_line (CORE_ADDR pc, struct sec *section, int notcurrent)
 {
   struct symtab *s;
   register struct linetable *l;
@@ -1831,9 +1824,7 @@ find_pc_sect_line (pc, section, notcurrent)
 /* Backward compatibility (no section) */
 
 struct symtab_and_line
-find_pc_line (pc, notcurrent)
-     CORE_ADDR pc;
-     int notcurrent;
+find_pc_line (CORE_ADDR pc, int notcurrent)
 {
   asection *section;
 
@@ -1844,8 +1835,7 @@ find_pc_line (pc, notcurrent)
 }
 \f
 
-static struct symtab *find_line_symtab PARAMS ((struct symtab *, int,
-                                               int *, int *));
+static struct symtab *find_line_symtab (struct symtab *, int, int *, int *);
 
 /* Find line number LINE in any symtab whose name is the same as
    SYMTAB.
@@ -1858,11 +1848,7 @@ static struct symtab *find_line_symtab PARAMS ((struct symtab *, int,
    If not found, return NULL.  */
 
 static struct symtab *
-find_line_symtab (symtab, line, index, exact_match)
-     struct symtab *symtab;
-     int line;
-     int *index;
-     int *exact_match;
+find_line_symtab (struct symtab *symtab, int line, int *index, int *exact_match)
 {
   int exact;
 
@@ -1944,10 +1930,7 @@ done:
    The source file is specified with a struct symtab.  */
 
 int
-find_line_pc (symtab, line, pc)
-     struct symtab *symtab;
-     int line;
-     CORE_ADDR *pc;
+find_line_pc (struct symtab *symtab, int line, CORE_ADDR *pc)
 {
   struct linetable *l;
   int ind;
@@ -1974,9 +1957,8 @@ find_line_pc (symtab, line, pc)
    Returns 0 if could not find the specified line.  */
 
 int
-find_line_pc_range (sal, startptr, endptr)
-     struct symtab_and_line sal;
-     CORE_ADDR *startptr, *endptr;
+find_line_pc_range (struct symtab_and_line sal, CORE_ADDR *startptr,
+                   CORE_ADDR *endptr)
 {
   CORE_ADDR startaddr;
   struct symtab_and_line found_sal;
@@ -2014,10 +1996,8 @@ find_line_pc_range (sal, startptr, endptr)
    Set *EXACT_MATCH nonzero if the value returned is an exact match.  */
 
 static int
-find_line_common (l, lineno, exact_match)
-     register struct linetable *l;
-     register int lineno;
-     int *exact_match;
+find_line_common (register struct linetable *l, register int lineno,
+                 int *exact_match)
 {
   register int i;
   register int len;
@@ -2060,9 +2040,7 @@ find_line_common (l, lineno, exact_match)
 }
 
 int
-find_pc_line_pc_range (pc, startptr, endptr)
-     CORE_ADDR pc;
-     CORE_ADDR *startptr, *endptr;
+find_pc_line_pc_range (CORE_ADDR pc, CORE_ADDR *startptr, CORE_ADDR *endptr)
 {
   struct symtab_and_line sal;
   sal = find_pc_line (pc, 0);
@@ -2077,12 +2055,10 @@ find_pc_line_pc_range (pc, startptr, endptr)
    of real code inside the function.  */
 
 static struct symtab_and_line
-find_function_start_sal PARAMS ((struct symbol * sym, int));
+find_function_start_sal (struct symbol *sym, int);
 
 static struct symtab_and_line
-find_function_start_sal (sym, funfirstline)
-     struct symbol *sym;
-     int funfirstline;
+find_function_start_sal (struct symbol *sym, int funfirstline)
 {
   CORE_ADDR pc;
   struct symtab_and_line sal;
@@ -2132,9 +2108,7 @@ find_function_start_sal (sym, funfirstline)
    beginning of the substring of the operator text.
    Otherwise, return "".  */
 char *
-operator_chars (p, end)
-     char *p;
-     char **end;
+operator_chars (char *p, char **end)
 {
   *end = "";
   if (strncmp (p, "operator", 8))
@@ -2217,11 +2191,10 @@ operator_chars (p, end)
    reader because the type of the baseclass might still be stubbed
    when the definition of the derived class is parsed.  */
 
-static int total_number_of_methods PARAMS ((struct type * type));
+static int total_number_of_methods (struct type *type);
 
 static int
-total_number_of_methods (type)
-     struct type *type;
+total_number_of_methods (struct type *type)
 {
   int n;
   int count;
@@ -2245,10 +2218,7 @@ total_number_of_methods (type)
    Note that this function is g++ specific.  */
 
 static int
-find_methods (t, name, sym_arr)
-     struct type *t;
-     char *name;
-     struct symbol **sym_arr;
+find_methods (struct type *t, char *name, struct symbol **sym_arr)
 {
   int i1 = 0;
   int ibase;
@@ -2368,10 +2338,8 @@ find_methods (t, name, sym_arr)
    line spec is `filename:linenum'.  */
 
 static void
-build_canonical_line_spec (sal, symname, canonical)
-     struct symtab_and_line *sal;
-     char *symname;
-     char ***canonical;
+build_canonical_line_spec (struct symtab_and_line *sal, char *symname,
+                          char ***canonical)
 {
   char **canonical_arr;
   char *canonical_name;
@@ -2400,6 +2368,43 @@ build_canonical_line_spec (sal, symname, canonical)
   canonical_arr[0] = canonical_name;
 }
 
+
+
+/* Find an instance of the character C in the string S that is outside
+   of all parenthesis pairs, single-quoted strings, and double-quoted
+   strings.  */
+static char *
+find_toplevel_char (char *s, char c)
+{
+  int quoted = 0;              /* zero if we're not in quotes;
+                                  '"' if we're in a double-quoted string;
+                                  '\'' if we're in a single-quoted string.  */
+  int depth = 0;               /* number of unclosed parens we've seen */
+  char *scan;
+
+  for (scan = s; *scan; scan++)
+    {
+      if (quoted)
+       {
+         if (*scan == quoted)
+           quoted = 0;
+         else if (*scan == '\\' && *(scan + 1))
+           scan++;
+       }
+      else if (*scan == c && ! quoted && depth == 0)
+       return scan;
+      else if (*scan == '"' || *scan == '\'')
+       quoted = *scan;
+      else if (*scan == '(')
+       depth++;
+      else if (*scan == ')' && depth > 0)
+       depth--;
+    }
+
+  return 0;
+}
+
+
 /* Parse a string that specifies a line number.
    Pass the address of a char * variable; that variable will be
    advanced over the characters actually parsed.
@@ -2443,12 +2448,8 @@ build_canonical_line_spec (sal, symname, canonical)
    can use as appropriate instead of make_symbol_completion_list.  */
 
 struct symtabs_and_lines
-decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
-     char **argptr;
-     int funfirstline;
-     struct symtab *default_symtab;
-     int default_line;
-     char ***canonical;
+decode_line_1 (char **argptr, int funfirstline, struct symtab *default_symtab,
+              int default_line, char ***canonical)
 {
   struct symtabs_and_lines values;
 #ifdef HPPA_COMPILER_BUG
@@ -2576,9 +2577,14 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
 
   /* Maybe we were called with a line range FILENAME:LINENUM,FILENAME:LINENUM
      and we must isolate the first half.  Outer layers will call again later
-     for the second half */
-  if ((ii = strchr (*argptr, ',')) != NULL)
-    has_comma = 1;
+     for the second half.
+
+     Don't count commas that appear in argument lists of overloaded
+     functions, or in quoted strings.  It's stupid to go to this much
+     trouble when the rest of the function is such an obvious roach hotel.  */
+  ii = find_toplevel_char (*argptr, ',');
+  has_comma = (ii != 0);
+
   /* Temporarily zap out second half to not
    * confuse the code below.
    * This is undone below. Do not change ii!!
@@ -2632,10 +2638,14 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
     }
   while (p[0] == ' ' || p[0] == '\t')
     p++;
+
   /* if the closing double quote was left at the end, remove it */
-  if (is_quote_enclosed && ((pp = strchr (p, '"')) != NULL))
-    if (!*(pp + 1))
-      *pp = '\0';
+  if (is_quote_enclosed)
+    {
+      char *closing_quote = strchr (p, '"');
+      if (closing_quote && closing_quote[1] == '\0')
+       *closing_quote = '\0';
+    }
 
   /* Now that we've safely parsed the first half,
    * put back ',' so outer layers can see it 
@@ -2656,7 +2666,8 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
          /* First check for "global" namespace specification,
             of the form "::foo". If found, skip over the colons
             and jump to normal symbol processing */
-         if ((*argptr == p) || (p[-1] == ' ') || (p[-1] == '\t'))
+         if (p[0] == ':' 
+             && ((*argptr == p) || (p[-1] == ' ') || (p[-1] == '\t')))
            saved_arg2 += 2;
 
          /* We have what looks like a class or namespace
@@ -3068,6 +3079,9 @@ decode_line_1 (argptr, funfirstline, default_symtab, default_line, canonical)
       p = skip_quoted (*argptr);
     }
 
+  if (is_quote_enclosed && **argptr == '"')
+    (*argptr)++;
+
   copy = (char *) alloca (p - *argptr + 1);
   memcpy (copy, *argptr, p - *argptr);
   copy[p - *argptr] = '\0';
@@ -3241,9 +3255,7 @@ minimal_symbol_found:             /* We also jump here from the case for variables
 }
 
 struct symtabs_and_lines
-decode_line_spec (string, funfirstline)
-     char *string;
-     int funfirstline;
+decode_line_spec (char *string, int funfirstline)
 {
   struct symtabs_and_lines sals;
   if (string == 0)
@@ -3392,9 +3404,7 @@ decode_line_2 (sym_arr, nelts, funfirstline, canonical)
    NAME is the name to print and *FIRST is nonzero if this is the first
    name printed.  Set *FIRST to zero.  */
 static void
-output_source_filename (name, first)
-     char *name;
-     int *first;
+output_source_filename (char *name, int *first)
 {
   /* Table of files printed so far.  Since a single source file can
      result in several partial symbol tables, we need to avoid printing
@@ -3448,9 +3458,7 @@ output_source_filename (name, first)
 }
 
 static void
-sources_info (ignore, from_tty)
-     char *ignore;
-     int from_tty;
+sources_info (char *ignore, int from_tty)
 {
   register struct symtab *s;
   register struct partial_symtab *ps;
@@ -3507,8 +3515,7 @@ file_matches (file, files, nfiles)
 
 /* Free any memory associated with a search. */
 void
-free_search_symbols (symbols)
-     struct symbol_search *symbols;
+free_search_symbols (struct symbol_search *symbols)
 {
   struct symbol_search *p;
   struct symbol_search *next;
@@ -3520,6 +3527,19 @@ free_search_symbols (symbols)
     }
 }
 
+static void
+do_free_search_symbols_cleanup (void *symbols)
+{
+  free_search_symbols (symbols);
+}
+
+struct cleanup *
+make_cleanup_free_search_symbols (struct symbol_search *symbols)
+{
+  return make_cleanup (do_free_search_symbols_cleanup, symbols);
+}
+
+
 /* Search the symbol table for matches to the regular expression REGEXP,
    returning the results in *MATCHES.
 
@@ -3578,10 +3598,10 @@ search_symbols (regexp, kind, nfiles, files, matches)
   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)];
+  ourtype = types[(int) (kind - VARIABLES_NAMESPACE)];
+  ourtype2 = types2[(int) (kind - VARIABLES_NAMESPACE)];
+  ourtype3 = types3[(int) (kind - VARIABLES_NAMESPACE)];
+  ourtype4 = types4[(int) (kind - VARIABLES_NAMESPACE)];
 
   sr = *matches = NULL;
   tail = NULL;
@@ -3752,8 +3772,7 @@ search_symbols (regexp, kind, nfiles, files, matches)
                  if (tail == NULL)
                    {
                      sr = psr;
-                     old_chain = make_cleanup ((make_cleanup_func)
-                                               free_search_symbols, sr);
+                     old_chain = make_cleanup_free_search_symbols (sr);
                    }
                  else
                    tail->next = psr;
@@ -3797,8 +3816,7 @@ search_symbols (regexp, kind, nfiles, files, matches)
                        if (tail == NULL)
                          {
                            sr = psr;
-                           old_chain = make_cleanup ((make_cleanup_func)
-                                                 free_search_symbols, &sr);
+                           old_chain = make_cleanup_free_search_symbols (sr);
                          }
                        else
                          tail->next = psr;
@@ -3820,12 +3838,8 @@ search_symbols (regexp, kind, nfiles, files, matches)
    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;
+print_symbol_info (namespace_enum kind, struct symtab *s, struct symbol *sym,
+                  int block, char *last)
 {
   if (last == NULL || strcmp (last, s->filename) != 0)
     {
@@ -3840,7 +3854,7 @@ print_symbol_info (kind, s, sym, block, last)
   /* 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);
+    typedef_print (SYMBOL_TYPE (sym), sym, gdb_stdout);
   /* variable, func, or typedef-that-is-c++-class */
   else if (kind < TYPES_NAMESPACE ||
           (kind == TYPES_NAMESPACE &&
@@ -3883,8 +3897,7 @@ print_symbol_info (kind, s, sym, block, last)
    for non-debugging symbols to gdb_stdout.
  */
 static void
-print_msymbol_info (msymbol)
-     struct minimal_symbol *msymbol;
+print_msymbol_info (struct minimal_symbol *msymbol)
 {
   printf_filtered ("   %08lx  %s\n",
                   (unsigned long) SYMBOL_VALUE_ADDRESS (msymbol),
@@ -3897,10 +3910,7 @@ print_msymbol_info (msymbol)
    matches.
  */
 static void
-symtab_symbol_info (regexp, kind, from_tty)
-     char *regexp;
-     namespace_enum kind;
-     int from_tty;
+symtab_symbol_info (char *regexp, namespace_enum kind, int from_tty)
 {
   static char *classnames[]
   =
@@ -3913,12 +3923,12 @@ symtab_symbol_info (regexp, kind, from_tty)
 
   /* 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);
+  old_chain = make_cleanup_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);
+                  classnames[(int) (kind - VARIABLES_NAMESPACE)], regexp);
 
   for (p = symbols; p != NULL; p = p->next)
     {
@@ -3948,25 +3958,20 @@ symtab_symbol_info (regexp, kind, from_tty)
 }
 
 static void
-variables_info (regexp, from_tty)
-     char *regexp;
-     int from_tty;
+variables_info (char *regexp, int from_tty)
 {
   symtab_symbol_info (regexp, VARIABLES_NAMESPACE, from_tty);
 }
 
 static void
-functions_info (regexp, from_tty)
-     char *regexp;
-     int from_tty;
+functions_info (char *regexp, int from_tty)
 {
   symtab_symbol_info (regexp, FUNCTIONS_NAMESPACE, from_tty);
 }
 
+
 static void
-types_info (regexp, from_tty)
-     char *regexp;
-     int from_tty;
+types_info (char *regexp, int from_tty)
 {
   symtab_symbol_info (regexp, TYPES_NAMESPACE, from_tty);
 }
@@ -3974,25 +3979,29 @@ types_info (regexp, from_tty)
 #if 0
 /* Tiemann says: "info methods was never implemented."  */
 static void
-methods_info (regexp)
-     char *regexp;
+methods_info (char *regexp)
 {
   symtab_symbol_info (regexp, METHODS_NAMESPACE, 0, from_tty);
 }
 #endif /* 0 */
 
 /* Breakpoint all functions matching regular expression. */
+#ifdef UI_OUT
+void
+rbreak_command_wrapper (char *regexp, int from_tty)
+{
+  rbreak_command (regexp, from_tty);
+}
+#endif
 static void
-rbreak_command (regexp, from_tty)
-     char *regexp;
-     int from_tty;
+rbreak_command (char *regexp, int 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);
+  old_chain = make_cleanup_free_search_symbols (ss);
 
   for (p = ss; p != NULL; p = p->next)
     {
@@ -4028,8 +4037,7 @@ rbreak_command (regexp, from_tty)
    or if a and b have the same pc range.
    Return zero otherwise. */
 int
-contained_in (a, b)
-     struct block *a, *b;
+contained_in (struct block *a, struct block *b)
 {
   if (!a || !b)
     return 0;
@@ -4062,12 +4070,8 @@ static char **return_val;
    characters.  If so, add it to the current completion list. */
 
 static void
-completion_list_add_name (symname, sym_text, sym_text_len, text, word)
-     char *symname;
-     char *sym_text;
-     int sym_text_len;
-     char *text;
-     char *word;
+completion_list_add_name (char *symname, char *sym_text, int sym_text_len,
+                         char *text, char *word)
 {
   int newsize;
   int i;
@@ -4146,9 +4150,7 @@ completion_list_add_name (symname, sym_text, sym_text_len, text, word)
    I'm not going to worry about this; hopefully there won't be that many.  */
 
 char **
-make_symbol_completion_list (text, word)
-     char *text;
-     char *word;
+make_symbol_completion_list (char *text, char *word)
 {
   register struct symbol *sym;
   register struct symtab *s;
@@ -4337,50 +4339,69 @@ make_symbol_completion_list (text, word)
  */
 
 int
-in_prologue (pc, func_start)
-     CORE_ADDR pc;
-     CORE_ADDR func_start;
+in_prologue (CORE_ADDR pc, CORE_ADDR func_start)
 {
   struct symtab_and_line sal;
   CORE_ADDR func_addr, func_end;
 
-  if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
-    goto nosyms;               /* Might be in prologue */
-
-  sal = find_pc_line (func_addr, 0);
-
-  if (sal.line == 0)
-    goto nosyms;
-
-  /* sal.end is the address of the first instruction past sal.line. */
-  if (sal.end > func_addr
-      && sal.end <= func_end)  /* Is prologue in function? */
-    return pc < sal.end;       /* Yes, is pc in prologue? */
-
-  /* The line after the prologue seems to be outside the function.  In this
-     case, tell the caller to find the prologue the hard way.  */
-
-  return 1;
+  /* We have several sources of information we can consult to figure
+     this out.
+     - Compilers usually emit line number info that marks the prologue
+       as its own "source line".  So the ending address of that "line"
+       is the end of the prologue.  If available, this is the most
+       reliable method.
+     - The minimal symbols and partial symbols, which can usually tell
+       us the starting and ending addresses of a function.
+     - If we know the function's start address, we can call the
+       architecture-defined SKIP_PROLOGUE function to analyze the
+       instruction stream and guess where the prologue ends.
+     - Our `func_start' argument; if non-zero, this is the caller's
+       best guess as to the function's entry point.  At the time of
+       this writing, handle_inferior_event doesn't get this right, so
+       it should be our last resort.  */
+
+  /* Consult the partial symbol table, to find which function
+     the PC is in.  */
+  if (! find_pc_partial_function (pc, NULL, &func_addr, &func_end))
+    {
+      CORE_ADDR prologue_end;
 
-/* Come here when symtabs don't contain line # info.  In this case, it is
-   likely that the user has stepped into a library function w/o symbols, or
-   is doing a stepi/nexti through code without symbols.  */
+      /* We don't even have minsym information, so fall back to using
+         func_start, if given.  */
+      if (! func_start)
+       return 1;               /* We *might* be in a prologue.  */
 
-nosyms:
+      prologue_end = SKIP_PROLOGUE (func_start);
 
-/* If func_start is zero (meaning unknown) then we don't know whether pc is
-   in the prologue or not.  I.E. it might be. */
+      return func_start <= pc && pc < prologue_end;
+    }
 
-  if (!func_start)
-    return 1;
+  /* If we have line number information for the function, that's
+     usually pretty reliable.  */
+  sal = find_pc_line (func_addr, 0);
 
-/* We need to call the target-specific prologue skipping functions with the
-   function's start address because PC may be pointing at an instruction that
-   could be mistakenly considered part of the prologue.  */
+  /* Now sal describes the source line at the function's entry point,
+     which (by convention) is the prologue.  The end of that "line",
+     sal.end, is the end of the prologue.
+
+     Note that, for functions whose source code is all on a single
+     line, the line number information doesn't always end up this way.
+     So we must verify that our purported end-of-prologue address is
+     *within* the function, not at its start or end.  */
+  if (sal.line == 0
+      || sal.end <= func_addr
+      || func_end <= sal.end)
+    {
+      /* We don't have any good line number info, so use the minsym
+        information, together with the architecture-specific prologue
+        scanning code.  */
+      CORE_ADDR prologue_end = SKIP_PROLOGUE (func_addr);
 
-  func_start = SKIP_PROLOGUE (func_start);
+      return func_addr <= pc && pc < prologue_end;
+    }
 
-  return pc < func_start;
+  /* We have line number info, and it looks good.  */
+  return func_addr <= pc && pc < sal.end;
 }
 
 
@@ -4396,9 +4417,7 @@ static struct symbol **sym_return_val;
    characters.  If so, add it to the current completion list. */
 
 static void
-overload_list_add_symbol (sym, oload_name)
-     struct symbol *sym;
-     char *oload_name;
+overload_list_add_symbol (struct symbol *sym, char *oload_name)
 {
   int newsize;
   int i;
@@ -4413,7 +4432,10 @@ overload_list_add_symbol (sym, oload_name)
 
   /* skip symbols that cannot match */
   if (strcmp (sym_name, oload_name) != 0)
-    return;
+    {
+      free (sym_name);
+      return;
+    }
 
   /* If there is no type information, we can't do anything, so skip */
   if (SYMBOL_TYPE (sym) == NULL)
@@ -4444,14 +4466,12 @@ overload_list_add_symbol (sym, oload_name)
 
 
 struct symbol **
-make_symbol_overload_list (fsym)
-     struct symbol *fsym;
+make_symbol_overload_list (struct symbol *fsym)
 {
   register struct symbol *sym;
   register struct symtab *s;
   register struct partial_symtab *ps;
   register struct objfile *objfile;
-  register struct minimal_symbol *msymbol;
   register struct block *b, *surrounding_static_block = 0;
   register int i;
   /* The name we are completing on. */
@@ -4475,18 +4495,8 @@ make_symbol_overload_list (fsym)
   sym_return_val = (struct symbol **) xmalloc ((sym_return_val_size + 1) * sizeof (struct symbol *));
   sym_return_val[0] = NULL;
 
-  /* Comment and #if 0 from Rajiv Mirani <mirani@cup.hp.com>.
-     However, leaving #if 0's around is uncool.  We need to figure out
-     what this is really trying to do, decide whether we want that,
-     and either fix it or delete it.  --- Jim Blandy, Mar 1999 */
-
-  /* ??? RM: What in hell is this? overload_list_add_symbol expects a symbol,
-   * not a partial_symbol or a minimal_symbol. And it looks at the type field
-   * of the symbol, and we don't know the type of minimal and partial symbols
-   */
-#if 0
   /* Look through the partial symtabs for all symbols which begin
-     by matching OLOAD_NAME.  Add each one that you find to the list.  */
+     by matching OLOAD_NAME.  Make sure we read that symbol table in. */
 
   ALL_PSYMTABS (objfile, ps)
   {
@@ -4504,7 +4514,8 @@ make_symbol_overload_list (fsym)
       {
        /* If interrupted, then quit. */
        QUIT;
-       overload_list_add_symbol (*psym, oload_name);
+        /* This will cause the symbol table to be read if it has not yet been */
+        s = PSYMTAB_TO_SYMTAB (ps);
       }
 
     for (psym = objfile->static_psymbols.list + ps->statics_offset;
@@ -4513,22 +4524,11 @@ make_symbol_overload_list (fsym)
         psym++)
       {
        QUIT;
-       overload_list_add_symbol (*psym, oload_name);
+        /* This will cause the symbol table to be read if it has not yet been */
+        s = PSYMTAB_TO_SYMTAB (ps);
       }
   }
 
-  /* At this point scan through the misc symbol vectors and add each
-     symbol you find to the list.  Eventually we want to ignore
-     anything that isn't a text symbol (everything else will be
-     handled by the psymtab code above).  */
-
-  ALL_MSYMBOLS (objfile, msymbol)
-  {
-    QUIT;
-    overload_list_add_symbol (msymbol, oload_name);
-  }
-#endif
-
   /* Search upwards from currently selected frame (so that we can
      complete on local vars.  */
 
@@ -4586,7 +4586,7 @@ make_symbol_overload_list (fsym)
 \f
 
 void
-_initialize_symtab ()
+_initialize_symtab (void)
 {
   add_info ("variables", variables_info,
         "All global and static variable names, or those matching REGEXP.");
@@ -4597,6 +4597,7 @@ _initialize_symtab ()
   add_info ("functions", functions_info,
            "All function names, or those matching REGEXP.");
 
+  
   /* FIXME:  This command has at least the following problems:
      1.  It prints builtin types (in a very strange and confusing fashion).
      2.  It doesn't print right, e.g. with
This page took 0.039514 seconds and 4 git commands to generate.