gdb: Don't fault for 'maint print psymbols' when using an index
[deliverable/binutils-gdb.git] / gdb / psymtab.c
index 6f9bf7268f500830917335e18251ba1a93a301ff..031dbd9c1efe74f35f0ce3de771887eeba37578e 100644 (file)
 #include <algorithm>
 #include <set>
 
-static struct partial_symbol *match_partial_symbol (struct objfile *,
-                                                   struct partial_symtab *,
-                                                   int,
-                                                   const char *, domain_enum,
-                                                   symbol_name_match_type,
-                                                   symbol_compare_ftype *);
-
 static struct partial_symbol *lookup_partial_symbol (struct objfile *,
                                                     struct partial_symtab *,
                                                     const char *, int,
@@ -308,14 +301,24 @@ find_pc_sect_psymtab (struct objfile *objfile, CORE_ADDR pc,
                      struct obj_section *section,
                      struct bound_minimal_symbol msymbol)
 {
-  CORE_ADDR baseaddr = ANOFFSET (objfile->section_offsets,
-                                SECT_OFF_TEXT (objfile));
-
-  /* Try just the PSYMTABS_ADDRMAP mapping first as it has better granularity
-     than the later used TEXTLOW/TEXTHIGH one.  */
-
-  if (objfile->partial_symtabs->psymtabs_addrmap != NULL)
+  /* Try just the PSYMTABS_ADDRMAP mapping first as it has better
+     granularity than the later used TEXTLOW/TEXTHIGH one.  However, we need
+     to take care as the PSYMTABS_ADDRMAP can hold things other than partial
+     symtabs in some cases.
+
+     This function should only be called for objfiles that are using partial
+     symtabs, not for objfiles that are using indexes (.gdb_index or
+     .debug_names), however 'maintenance print psymbols' calls this function
+     directly for all objfiles.  If we assume that PSYMTABS_ADDRMAP contains
+     partial symtabs then we will end up returning a pointer to an object
+     that is not a partial_symtab, which doesn't end well.  */
+
+  if (objfile->partial_symtabs->psymtabs != NULL
+      && objfile->partial_symtabs->psymtabs_addrmap != NULL)
     {
+      CORE_ADDR baseaddr = ANOFFSET (objfile->section_offsets,
+                                    SECT_OFF_TEXT (objfile));
+
       struct partial_symtab *pst
        = ((struct partial_symtab *)
           addrmap_find (objfile->partial_symtabs->psymtabs_addrmap,
@@ -479,7 +482,7 @@ find_pc_sect_psymbol (struct objfile *objfile,
 
 static struct compunit_symtab *
 psym_lookup_symbol (struct objfile *objfile,
-                   int block_index, const char *name,
+                   block_enum block_index, const char *name,
                    const domain_enum domain)
 {
   const int psymtab_index = (block_index == GLOBAL_BLOCK ? 1 : 0);
@@ -545,8 +548,7 @@ psymbol_name_matches (partial_symbol *psym,
 static struct partial_symbol *
 match_partial_symbol (struct objfile *objfile,
                      struct partial_symtab *pst, int global,
-                     const char *name, domain_enum domain,
-                     symbol_name_match_type match_type,
+                     const lookup_name_info &name, domain_enum domain,
                      symbol_compare_ftype *ordered_compare)
 {
   struct partial_symbol **start, **psym;
@@ -557,8 +559,6 @@ match_partial_symbol (struct objfile *objfile,
   if (length == 0)
     return NULL;
 
-  lookup_name_info lookup_name (name, match_type);
-
   start = (global ?
           &objfile->partial_symtabs->global_psymbols[pst->globals_offset] :
           &objfile->partial_symtabs->static_psymbols[pst->statics_offset]);
@@ -583,7 +583,7 @@ match_partial_symbol (struct objfile *objfile,
 
          enum language lang = (*center)->ginfo.language;
          const char *lang_ln
-           = lookup_name.language_lookup_name (lang).c_str ();
+           = name.language_lookup_name (lang).c_str ();
 
          if (ordered_compare (symbol_search_name (&(*center)->ginfo),
                               lang_ln) >= 0)
@@ -594,7 +594,7 @@ match_partial_symbol (struct objfile *objfile,
       gdb_assert (top == bottom);
 
       while (top <= real_top
-            && psymbol_name_matches (*top, lookup_name))
+            && psymbol_name_matches (*top, name))
        {
          if (symbol_matches_domain ((*top)->ginfo.language,
                                     (*top)->domain, domain))
@@ -612,7 +612,7 @@ match_partial_symbol (struct objfile *objfile,
        {
          if (symbol_matches_domain ((*psym)->ginfo.language,
                                     (*psym)->domain, domain)
-             && psymbol_name_matches (*psym, lookup_name))
+             && psymbol_name_matches (*psym, name))
            return *psym;
        }
     }
@@ -1168,49 +1168,16 @@ psymtab_to_fullname (struct partial_symtab *ps)
   return ps->fullname;
 }
 
-/* For all symbols, s, in BLOCK that are in DOMAIN and match NAME
-   according to the function MATCH, call CALLBACK(BLOCK, s, DATA).
-   BLOCK is assumed to come from OBJFILE.  Returns 1 iff CALLBACK
-   ever returns non-zero, and otherwise returns 0.  */
-
-static int
-map_block (const char *name, domain_enum domain, struct objfile *objfile,
-          const struct block *block,
-          int (*callback) (const struct block *, struct symbol *, void *),
-          void *data, symbol_name_match_type match)
-{
-  struct block_iterator iter;
-  struct symbol *sym;
-
-  lookup_name_info lookup_name (name, match);
-
-  for (sym = block_iter_match_first (block, lookup_name, &iter);
-       sym != NULL;
-       sym = block_iter_match_next (lookup_name, &iter))
-    {
-      if (symbol_matches_domain (SYMBOL_LANGUAGE (sym),
-                                SYMBOL_DOMAIN (sym), domain))
-       {
-         if (callback (block, sym, data))
-           return 1;
-       }
-    }
-
-  return 0;
-}
-
 /* Psymtab version of map_matching_symbols.  See its definition in
    the definition of quick_symbol_functions in symfile.h.  */
 
 static void
-psym_map_matching_symbols (struct objfile *objfile,
-                          const char *name, domain_enum domain,
-                          int global,
-                          int (*callback) (const struct block *,
-                                           struct symbol *, void *),
-                          void *data,
-                          symbol_name_match_type match,
-                          symbol_compare_ftype *ordered_compare)
+psym_map_matching_symbols
+  (struct objfile *objfile,
+   const lookup_name_info &name, domain_enum domain,
+   int global,
+   gdb::function_view<symbol_found_callback_ftype> callback,
+   symbol_compare_ftype *ordered_compare)
 {
   const int block_kind = global ? GLOBAL_BLOCK : STATIC_BLOCK;
 
@@ -1218,7 +1185,7 @@ psym_map_matching_symbols (struct objfile *objfile,
     {
       QUIT;
       if (ps->readin
-         || match_partial_symbol (objfile, ps, global, name, domain, match,
+         || match_partial_symbol (objfile, ps, global, name, domain,
                                   ordered_compare))
        {
          struct compunit_symtab *cust = psymtab_to_symtab (objfile, ps);
@@ -1227,10 +1194,8 @@ psym_map_matching_symbols (struct objfile *objfile,
          if (cust == NULL)
            continue;
          block = BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust), block_kind);
-         if (map_block (name, domain, objfile, block,
-                        callback, data, match))
-           return;
-         if (callback (block, NULL, data))
+         if (!iterate_over_symbols_terminated (block, name,
+                                               domain, callback))
            return;
        }
     }
@@ -1603,7 +1568,7 @@ psymbol_compare (const void *addr1, const void *addr2, int length)
    different domain (or address) is possible and correct.  */
 
 static struct partial_symbol *
-add_psymbol_to_bcache (const char *name, int namelength, int copy_name,
+add_psymbol_to_bcache (const char *name, int namelength, bool copy_name,
                       domain_enum domain,
                       enum address_class theclass,
                       short section,
@@ -1647,7 +1612,7 @@ append_psymbol_to_list (std::vector<partial_symbol *> *list,
    Return the partial symbol that has been added.  */
 
 void
-add_psymbol_to_list (const char *name, int namelength, int copy_name,
+add_psymbol_to_list (const char *name, int namelength, bool copy_name,
                     domain_enum domain,
                     enum address_class theclass,
                     short section,
This page took 0.028372 seconds and 4 git commands to generate.