* python/py-autoload.c (print_script): Print "Missing" instead of
[deliverable/binutils-gdb.git] / gdb / psymtab.c
index 6a0c563648d38711af6f131387a2be5866f8e502..ea690ef644969f6334314114dd11bc4310b2312a 100644 (file)
@@ -33,6 +33,8 @@
 #include "readline/readline.h"
 #include "gdb_regex.h"
 #include "dictionary.h"
+#include "language.h"
+#include "cp-support.h"
 
 #ifndef DEV_TTY
 #define DEV_TTY "/dev/tty"
@@ -69,6 +71,60 @@ static struct partial_symbol *fixup_psymbol_section (struct partial_symbol
 
 static struct symtab *psymtab_to_symtab (struct partial_symtab *pst);
 
+/* Ensure that the partial symbols for OBJFILE have been loaded.  This
+   function always returns its argument, as a convenience.  */
+
+struct objfile *
+require_partial_symbols (struct objfile *objfile, int verbose)
+{
+  if ((objfile->flags & OBJF_PSYMTABS_READ) == 0)
+    {
+      objfile->flags |= OBJF_PSYMTABS_READ;
+
+      if (objfile->sf->sym_read_psymbols)
+       {
+         if (verbose)
+           {
+             printf_unfiltered (_("Reading symbols from %s..."),
+                                objfile->name);
+             gdb_flush (gdb_stdout);
+           }
+         (*objfile->sf->sym_read_psymbols) (objfile);
+         if (verbose)
+           {
+             if (!objfile_has_symbols (objfile))
+               {
+                 wrap_here ("");
+                 printf_unfiltered (_("(no debugging symbols found)..."));
+                 wrap_here ("");
+               }
+
+             printf_unfiltered (_("done.\n"));
+           }
+       }
+    }
+
+  return objfile;
+}
+
+/* Traverse all psymtabs in one objfile, requiring that the psymtabs
+   be read in.  */
+
+#define ALL_OBJFILE_PSYMTABS_REQUIRED(objfile, p)              \
+    for ((p) = require_partial_symbols (objfile, 1)->psymtabs; \
+        (p) != NULL;                                           \
+        (p) = (p)->next)
+
+/* We want to make sure this file always requires psymtabs.  */
+
+#undef ALL_OBJFILE_PSYMTABS
+
+/* Traverse all psymtabs in all objfiles.  */
+
+#define ALL_PSYMTABS(objfile, p) \
+  ALL_OBJFILES (objfile)        \
+    ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
+
 /* Lookup the partial symbol table of a source file named NAME.
    *If* there is no '/' in the name, a match after a '/'
    in the psymtab filename will also work.  */
@@ -79,7 +135,7 @@ lookup_partial_symtab (struct objfile *objfile, const char *name,
 {
   struct partial_symtab *pst;
 
-  ALL_OBJFILE_PSYMTABS (objfile, pst)
+  ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
   {
     if (FILENAME_CMP (name, pst->filename) == 0)
       {
@@ -117,7 +173,7 @@ lookup_partial_symtab (struct objfile *objfile, const char *name,
   /* Now, search for a matching tail (only if name doesn't have any dirs).  */
 
   if (lbasename (name) == name)
-    ALL_OBJFILE_PSYMTABS (objfile, pst)
+    ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
     {
       if (FILENAME_CMP (lbasename (pst->filename), name) == 0)
        return (pst);
@@ -280,7 +336,7 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
      its CUs may be missing in PSYMTABS_ADDRMAP as they may be varying
      debug info type in single OBJFILE.  */
 
-  ALL_OBJFILE_PSYMTABS (objfile, pst)
+  ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
     if (pc >= pst->textlow && pc < pst->texthigh)
       {
        struct partial_symtab *best_pst;
@@ -423,10 +479,29 @@ lookup_symbol_aux_psymtabs (struct objfile *objfile,
   struct partial_symtab *ps;
   const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
 
-  ALL_OBJFILE_PSYMTABS (objfile, ps)
+  ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
   {
     if (!ps->readin && lookup_partial_symbol (ps, name, psymtab_index, domain))
-      return PSYMTAB_TO_SYMTAB (ps);
+      {
+       struct symbol *sym = NULL;
+       struct symtab *stab = PSYMTAB_TO_SYMTAB (ps);
+
+       /* Some caution must be observed with overloaded functions
+          and methods, since the psymtab will not contain any overload
+          information (but NAME might contain it).  */
+       if (stab->primary)
+         {
+           struct blockvector *bv = BLOCKVECTOR (stab);
+           struct block *block = BLOCKVECTOR_BLOCK (bv, block_index);
+
+           sym = lookup_block_symbol (block, name, domain);
+         }
+
+       if (sym && strcmp_iw (SYMBOL_SEARCH_NAME (sym), name) == 0)
+         return stab;
+
+       /* Keep looking through other psymtabs.  */
+      }
   }
 
   return NULL;
@@ -513,12 +588,46 @@ match_partial_symbol (struct partial_symtab *pst, int global,
 
 static void
 pre_expand_symtabs_matching_psymtabs (struct objfile *objfile,
-                                     int kind, const char *name,
+                                     enum block_enum block_kind,
+                                     const char *name,
                                      domain_enum domain)
 {
   /* Nothing.  */
 }
 
+/* Returns the name used to search psymtabs.  Unlike symtabs, psymtabs do
+   not contain any method/function instance information (since this would
+   force reading type information while reading psymtabs).  Therefore,
+   if NAME contains overload information, it must be stripped before searching
+   psymtabs.
+
+   The caller is responsible for freeing the return result.  */
+
+static char *
+psymtab_search_name (const char *name)
+{
+  switch (current_language->la_language)
+    {
+    case language_cplus:
+    case language_java:
+      {
+       if (strchr (name, '('))
+         {
+           char *ret = cp_remove_params (name);
+
+           if (ret)
+             return ret;
+         }
+      }
+      break;
+
+    default:
+      break;
+    }
+
+  return xstrdup (name);
+}
+
 /* Look, in partial_symtab PST, for symbol whose natural name is NAME.
    Check the global symbols if GLOBAL, the static symbols if not.  */
 
@@ -530,11 +639,16 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name,
   struct partial_symbol **top, **real_top, **bottom, **center;
   int length = (global ? pst->n_global_syms : pst->n_static_syms);
   int do_linear_search = 1;
+  char *search_name;
+  struct cleanup *cleanup;
 
   if (length == 0)
     {
       return (NULL);
     }
+
+  search_name = psymtab_search_name (name);
+  cleanup = make_cleanup (xfree, search_name);
   start = (global ?
           pst->objfile->global_psymbols.list + pst->globals_offset :
           pst->objfile->static_psymbols.list + pst->statics_offset);
@@ -563,7 +677,8 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name,
            {
              do_linear_search = 1;
            }
-         if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center), name) >= 0)
+         if (strcmp_iw_ordered (SYMBOL_SEARCH_NAME (*center),
+                                search_name) >= 0)
            {
              top = center;
            }
@@ -576,12 +691,22 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name,
        internal_error (__FILE__, __LINE__,
                        _("failed internal consistency check"));
 
-      while (top <= real_top
-            && SYMBOL_MATCHES_SEARCH_NAME (*top, name))
+      /* For `case_sensitivity == case_sensitive_off' strcmp_iw_ordered will
+        search more exactly than what matches SYMBOL_MATCHES_SEARCH_NAME.  */
+      while (top >= start && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
+       top--;
+
+      /* Fixup to have a symbol which matches SYMBOL_MATCHES_SEARCH_NAME.  */
+      top++;
+
+      while (top <= real_top && SYMBOL_MATCHES_SEARCH_NAME (*top, search_name))
        {
          if (symbol_matches_domain (SYMBOL_LANGUAGE (*top),
                                     SYMBOL_DOMAIN (*top), domain))
-           return (*top);
+           {
+             do_cleanups (cleanup);
+             return (*top);
+           }
          top++;
        }
     }
@@ -595,11 +720,15 @@ lookup_partial_symbol (struct partial_symtab *pst, const char *name,
        {
          if (symbol_matches_domain (SYMBOL_LANGUAGE (*psym),
                                     SYMBOL_DOMAIN (*psym), domain)
-             && SYMBOL_MATCHES_SEARCH_NAME (*psym, name))
-           return (*psym);
+             && SYMBOL_MATCHES_SEARCH_NAME (*psym, search_name))
+           {
+             do_cleanups (cleanup);
+             return (*psym);
+           }
        }
     }
 
+  do_cleanups (cleanup);
   return (NULL);
 }
 
@@ -635,7 +764,7 @@ relocate_psymtabs (struct objfile *objfile,
   struct partial_symbol **psym;
   struct partial_symtab *p;
 
-  ALL_OBJFILE_PSYMTABS (objfile, p)
+  ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
     {
       p->textlow += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
       p->texthigh += ANOFFSET (delta, SECT_OFF_TEXT (objfile));
@@ -667,7 +796,7 @@ find_last_source_symtab_from_partial (struct objfile *ofp)
   struct partial_symtab *ps;
   struct partial_symtab *cs_pst = 0;
 
-  ALL_OBJFILE_PSYMTABS (ofp, ps)
+  ALL_OBJFILE_PSYMTABS_REQUIRED (ofp, ps)
     {
       const char *name = ps->filename;
       int len = strlen (name);
@@ -696,7 +825,7 @@ forget_cached_source_info_partial (struct objfile *objfile)
 {
   struct partial_symtab *pst;
 
-  ALL_OBJFILE_PSYMTABS (objfile, pst)
+  ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
     {
       if (pst->fullname != NULL)
        {
@@ -873,7 +1002,7 @@ print_psymtab_stats_for_objfile (struct objfile *objfile)
   struct partial_symtab *ps;
 
   i = 0;
-  ALL_OBJFILE_PSYMTABS (objfile, ps)
+  ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
     {
       if (ps->readin == 0)
        i++;
@@ -915,7 +1044,7 @@ read_symtabs_for_function (struct objfile *objfile, const char *func_name)
 {
   struct partial_symtab *ps;
 
-  ALL_OBJFILE_PSYMTABS (objfile, ps)
+  ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
   {
     if (ps->readin)
       continue;
@@ -933,7 +1062,7 @@ expand_partial_symbol_tables (struct objfile *objfile)
 {
   struct partial_symtab *psymtab;
 
-  ALL_OBJFILE_PSYMTABS (objfile, psymtab)
+  ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
     {
       psymtab_to_symtab (psymtab);
     }
@@ -944,49 +1073,13 @@ read_psymtabs_with_filename (struct objfile *objfile, const char *filename)
 {
   struct partial_symtab *p;
 
-  ALL_OBJFILE_PSYMTABS (objfile, p)
+  ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, p)
     {
-      if (strcmp (filename, p->filename) == 0)
+      if (filename_cmp (filename, p->filename) == 0)
        PSYMTAB_TO_SYMTAB (p);
     }
 }
 
-static void
-map_symbol_names_psymtab (struct objfile *objfile,
-                         void (*fun) (const char *, void *), void *data)
-{
-  struct partial_symtab *ps;
-
-  ALL_OBJFILE_PSYMTABS (objfile, ps)
-    {
-      struct partial_symbol **psym;
-
-      /* If the psymtab's been read in we'll get it when we search
-        through the blockvector.  */
-      if (ps->readin)
-       continue;
-
-      for (psym = objfile->global_psymbols.list + ps->globals_offset;
-          psym < (objfile->global_psymbols.list + ps->globals_offset
-                  + ps->n_global_syms);
-          psym++)
-       {
-         /* If interrupted, then quit.  */
-         QUIT;
-         (*fun) (SYMBOL_NATURAL_NAME (*psym), data);
-       }
-
-      for (psym = objfile->static_psymbols.list + ps->statics_offset;
-          psym < (objfile->static_psymbols.list + ps->statics_offset
-                  + ps->n_static_syms);
-          psym++)
-       {
-         QUIT;
-         (*fun) (SYMBOL_NATURAL_NAME (*psym), data);
-       }
-    }
-}
-
 static void
 map_symbol_filenames_psymtab (struct objfile *objfile,
                              void (*fun) (const char *, const char *,
@@ -995,7 +1088,7 @@ map_symbol_filenames_psymtab (struct objfile *objfile,
 {
   struct partial_symtab *ps;
 
-  ALL_OBJFILE_PSYMTABS (objfile, ps)
+  ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
     {
       const char *fullname;
 
@@ -1044,7 +1137,7 @@ find_symbol_file_from_partial (struct objfile *objfile, const char *name)
 {
   struct partial_symtab *pst;
 
-  ALL_OBJFILE_PSYMTABS (objfile, pst)
+  ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, pst)
     {
       if (lookup_partial_symbol (pst, name, 1, VAR_DOMAIN))
        return pst->filename;
@@ -1095,7 +1188,7 @@ map_matching_symbols_psymtab (const char *name, domain_enum namespace,
   const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
   struct partial_symtab *ps;
 
-  ALL_OBJFILE_PSYMTABS (objfile, ps)
+  ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
     {
       QUIT;
       if (ps->readin
@@ -1123,12 +1216,12 @@ expand_symtabs_matching_via_partial (struct objfile *objfile,
                                                          void *),
                                     int (*name_matcher) (const char *,
                                                          void *),
-                                    domain_enum kind,
+                                    enum search_domain kind,
                                     void *data)
 {
   struct partial_symtab *ps;
 
-  ALL_OBJFILE_PSYMTABS (objfile, ps)
+  ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, ps)
     {
       struct partial_symbol **psym;
       struct partial_symbol **bound, **gbound, **sbound;
@@ -1137,7 +1230,7 @@ expand_symtabs_matching_via_partial (struct objfile *objfile,
       if (ps->readin)
        continue;
 
-      if (! (*file_matcher) (ps->filename, data))
+      if (file_matcher && ! (*file_matcher) (ps->filename, data))
        continue;
 
       gbound = objfile->global_psymbols.list
@@ -1166,14 +1259,15 @@ expand_symtabs_matching_via_partial (struct objfile *objfile,
            {
              QUIT;
 
-             if ((*name_matcher) (SYMBOL_NATURAL_NAME (*psym), data)
-                 && ((kind == VARIABLES_DOMAIN
+             if ((kind == ALL_DOMAIN
+                  || (kind == VARIABLES_DOMAIN
                       && SYMBOL_CLASS (*psym) != LOC_TYPEDEF
                       && SYMBOL_CLASS (*psym) != LOC_BLOCK)
-                     || (kind == FUNCTIONS_DOMAIN
-                         && SYMBOL_CLASS (*psym) == LOC_BLOCK)
-                     || (kind == TYPES_DOMAIN
-                         && SYMBOL_CLASS (*psym) == LOC_TYPEDEF)))
+                  || (kind == FUNCTIONS_DOMAIN
+                      && SYMBOL_CLASS (*psym) == LOC_BLOCK)
+                  || (kind == TYPES_DOMAIN
+                      && SYMBOL_CLASS (*psym) == LOC_TYPEDEF))
+                 && (*name_matcher) (SYMBOL_NATURAL_NAME (*psym), data))
                {
                  PSYMTAB_TO_SYMTAB (ps);
                  keep_going = 0;
@@ -1208,7 +1302,6 @@ const struct quick_symbol_functions psym_functions =
   map_matching_symbols_psymtab,
   expand_symtabs_matching_via_partial,
   find_pc_sect_symtab_from_partial,
-  map_symbol_names_psymtab,
   map_symbol_filenames_psymtab
 };
 
@@ -1614,7 +1707,7 @@ print-psymbols takes an output file name and optional symbol file name"));
 
   immediate_quit++;
   ALL_PSYMTABS (objfile, ps)
-    if (symname == NULL || strcmp (symname, ps->filename) == 0)
+    if (symname == NULL || filename_cmp (symname, ps->filename) == 0)
     dump_psymtab (objfile, ps, outfile);
   immediate_quit--;
   do_cleanups (cleanups);
@@ -1640,7 +1733,7 @@ maintenance_info_psymtabs (char *regexp, int from_tty)
          actually find a symtab whose name matches.  */
       int printed_objfile_start = 0;
 
-      ALL_OBJFILE_PSYMTABS (objfile, psymtab)
+      ALL_OBJFILE_PSYMTABS_REQUIRED (objfile, psymtab)
        {
          QUIT;
 
@@ -1811,14 +1904,15 @@ maintenance_check_symtabs (char *ignore, int from_tty)
 \f
 
 void
-map_partial_symbol_names (void (*fun) (const char *, void *), void *data)
+expand_partial_symbol_names (int (*fun) (const char *, void *), void *data)
 {
   struct objfile *objfile;
 
   ALL_OBJFILES (objfile)
   {
     if (objfile->sf)
-      objfile->sf->qf->map_symbol_names (objfile, fun, data);
+      objfile->sf->qf->expand_symtabs_matching (objfile, NULL, fun,
+                                               ALL_DOMAIN, data);
   }
 }
 
This page took 0.031724 seconds and 4 git commands to generate.