PR24427, bfd/doc/chew.c reads uninitialized memory and subtracts from function pointer
[deliverable/binutils-gdb.git] / gdb / symtab.c
index 29b24328fbed417490846af0587d90684a5fbfbf..d25f560f084a23089154605e3631ce1a0d7aac66 100644 (file)
@@ -41,6 +41,7 @@
 #include "p-lang.h"
 #include "addrmap.h"
 #include "cli/cli-utils.h"
+#include "cli/cli-style.h"
 #include "fnmatch.h"
 #include "hashtab.h"
 #include "typeprint.h"
@@ -94,9 +95,6 @@ static struct block_symbol
   lookup_symbol_in_objfile (struct objfile *objfile, int block_index,
                            const char *name, const domain_enum domain);
 
-/* See symtab.h.  */
-const struct block_symbol null_block_symbol = { NULL, NULL };
-
 /* Program space key for finding name and language of "main".  */
 
 static const struct program_space_data *main_progspace_key;
@@ -311,6 +309,31 @@ compunit_language (const struct compunit_symtab *cust)
   return SYMTAB_LANGUAGE (symtab);
 }
 
+/* See symtab.h.  */
+
+bool
+minimal_symbol::data_p () const
+{
+  return type == mst_data
+    || type == mst_bss
+    || type == mst_abs
+    || type == mst_file_data
+    || type == mst_file_bss;
+}
+
+/* See symtab.h.  */
+
+bool
+minimal_symbol::text_p () const
+{
+  return type == mst_text
+    || type == mst_text_gnu_ifunc
+    || type == mst_data_gnu_ifunc
+    || type == mst_slot_got_plt
+    || type == mst_solib_trampoline
+    || type == mst_file_text;
+}
+
 /* See whether FILENAME matches SEARCH_NAME using the rule that we
    advertise to the user.  (The manual's description of linespecs
    describes what we advertise).  Returns true if they match, false
@@ -473,7 +496,7 @@ iterate_over_symtabs (const char *name,
       gdb_assert (IS_ABSOLUTE_PATH (real_path.get ()));
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->objfiles ())
     {
       if (iterate_over_some_symtabs (name, real_path.get (),
                                     objfile->compunit_symtabs, NULL,
@@ -484,7 +507,7 @@ iterate_over_symtabs (const char *name,
   /* Same search rules as above apply here, but now we look thru the
      psymtabs.  */
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->objfiles ())
     {
       if (objfile->sf
          && objfile->sf->qf->map_symtabs_matching_filename (objfile,
@@ -714,9 +737,9 @@ create_demangled_names_hash (struct objfile_per_bfd_storage *per_bfd)
      Choosing a much larger table size wastes memory, and saves only about
      1% in symbol reading.  */
 
-  per_bfd->demangled_names_hash = htab_create_alloc
+  per_bfd->demangled_names_hash.reset (htab_create_alloc
     (256, hash_demangled_name_entry, eq_demangled_name_entry,
-     NULL, xcalloc, xfree);
+     NULL, xcalloc, xfree));
 }
 
 /* Try to determine the demangled name for a symbol, based on the
@@ -822,7 +845,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
 
   entry.mangled = linkage_name_copy;
   slot = ((struct demangled_name_entry **)
-         htab_find_slot (per_bfd->demangled_names_hash,
+         htab_find_slot (per_bfd->demangled_names_hash.get (),
                          &entry, INSERT));
 
   /* If this name is not in the hash table, add it.  */
@@ -1010,7 +1033,7 @@ matching_obj_sections (struct obj_section *obj_first,
   /* Otherwise check that they are in corresponding objfiles.  */
 
   struct objfile *obj = NULL;
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->objfiles ())
     if (objfile->obfd == first->owner)
       {
        obj = objfile;
@@ -1039,15 +1062,10 @@ expand_symtab_containing_pc (CORE_ADDR pc, struct obj_section *section)
      necessary because we loop based on texthigh and textlow, which do
      not include the data ranges.  */
   msymbol = lookup_minimal_symbol_by_pc_section (pc, section);
-  if (msymbol.minsym
-      && (MSYMBOL_TYPE (msymbol.minsym) == mst_data
-         || MSYMBOL_TYPE (msymbol.minsym) == mst_bss
-         || MSYMBOL_TYPE (msymbol.minsym) == mst_abs
-         || MSYMBOL_TYPE (msymbol.minsym) == mst_file_data
-         || MSYMBOL_TYPE (msymbol.minsym) == mst_file_bss))
+  if (msymbol.minsym && msymbol.minsym->data_p ())
     return;
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->objfiles ())
     {
       struct compunit_symtab *cust = NULL;
 
@@ -1318,7 +1336,7 @@ symbol_cache_lookup (struct symbol_cache *cache,
     {
       *bsc_ptr = NULL;
       *slot_ptr = NULL;
-      return (struct block_symbol) {NULL, NULL};
+      return {};
     }
 
   hash = hash_symbol_entry (objfile_context, name, domain);
@@ -1352,7 +1370,7 @@ symbol_cache_lookup (struct symbol_cache *cache,
                          name, domain_name (domain));
     }
   ++bsc->misses;
-  return (struct block_symbol) {NULL, NULL};
+  return {};
 }
 
 /* Clear out SLOT.  */
@@ -1917,7 +1935,7 @@ lookup_language_this (const struct language_defn *lang,
                      const struct block *block)
 {
   if (lang->la_name_of_this == NULL || block == NULL)
-    return (struct block_symbol) {NULL, NULL};
+    return {};
 
   if (symbol_lookup_debug > 1)
     {
@@ -1954,7 +1972,7 @@ lookup_language_this (const struct language_defn *lang,
 
   if (symbol_lookup_debug > 1)
     fprintf_unfiltered (gdb_stdlog, " = NULL\n");
-  return (struct block_symbol) {NULL, NULL};
+  return {};
 }
 
 /* Given TYPE, a structure/union,
@@ -2081,7 +2099,7 @@ lookup_symbol_aux (const char *name, symbol_name_match_type match_type,
                  fprintf_unfiltered (gdb_stdlog,
                                      "lookup_symbol_aux (...) = NULL\n");
                }
-             return (struct block_symbol) {NULL, NULL};
+             return {};
            }
        }
     }
@@ -2131,7 +2149,7 @@ lookup_local_symbol (const char *name,
   /* Check if either no block is specified or it's a global block.  */
 
   if (static_block == NULL)
-    return (struct block_symbol) {NULL, NULL};
+    return {};
 
   while (block != static_block)
     {
@@ -2156,7 +2174,7 @@ lookup_local_symbol (const char *name,
 
   /* We've reached the end of the function without finding a result.  */
 
-  return (struct block_symbol) {NULL, NULL};
+  return {};
 }
 
 /* See symtab.h.  */
@@ -2169,9 +2187,9 @@ lookup_objfile_from_block (const struct block *block)
 
   block = block_global_block (block);
   /* Look through all blockvectors.  */
-  for (objfile *obj : all_objfiles (current_program_space))
+  for (objfile *obj : current_program_space->objfiles ())
     {
-      for (compunit_symtab *cust : objfile_compunits (obj))
+      for (compunit_symtab *cust : obj->compunits ())
        if (block == BLOCKVECTOR_BLOCK (COMPUNIT_BLOCKVECTOR (cust),
                                        GLOBAL_BLOCK))
          {
@@ -2241,7 +2259,7 @@ lookup_global_symbol_from_objfile (struct objfile *main_objfile,
        return result;
     }
 
-  return (struct block_symbol) {NULL, NULL};
+  return {};
 }
 
 /* Check to see if the symbol is defined in one of the OBJFILE's
@@ -2265,7 +2283,7 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile, int block_index,
                          name, domain_name (domain));
     }
 
-  for (compunit_symtab *cust : objfile_compunits (objfile))
+  for (compunit_symtab *cust : objfile->compunits ())
     {
       const struct blockvector *bv;
       const struct block *block;
@@ -2291,7 +2309,7 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile, int block_index,
 
   if (symbol_lookup_debug > 1)
     fprintf_unfiltered (gdb_stdlog, " = NULL\n");
-  return (struct block_symbol) {NULL, NULL};
+  return {};
 }
 
 /* Wrapper around lookup_symbol_in_objfile_symtabs for search_symbols.
@@ -2301,7 +2319,7 @@ lookup_symbol_in_objfile_symtabs (struct objfile *objfile, int block_index,
    Normally we only look in OBJFILE, and not any separate debug objfiles
    because the outer loop will cause them to be searched too.  This case is
    different.  Here we're called from search_symbols where it will only
-   call us for the the objfile that contains a matching minsym.  */
+   call us for the objfile that contains a matching minsym.  */
 
 static struct block_symbol
 lookup_symbol_in_objfile_from_linkage_name (struct objfile *objfile,
@@ -2334,7 +2352,7 @@ lookup_symbol_in_objfile_from_linkage_name (struct objfile *objfile,
        return result;
     }
 
-  return (struct block_symbol) {NULL, NULL};
+  return {};
 }
 
 /* A helper function that throws an exception when a symbol was found
@@ -2367,7 +2385,7 @@ lookup_symbol_via_quick_fns (struct objfile *objfile, int block_index,
   struct block_symbol result;
 
   if (!objfile->sf)
-    return (struct block_symbol) {NULL, NULL};
+    return {};
 
   if (symbol_lookup_debug > 1)
     {
@@ -2387,7 +2405,7 @@ lookup_symbol_via_quick_fns (struct objfile *objfile, int block_index,
          fprintf_unfiltered (gdb_stdlog,
                              "lookup_symbol_via_quick_fns (...) = NULL\n");
        }
-      return (struct block_symbol) {NULL, NULL};
+      return {};
     }
 
   bv = COMPUNIT_BLOCKVECTOR (cust);
@@ -2491,7 +2509,7 @@ lookup_symbol_in_static_block (const char *name,
   struct symbol *sym;
 
   if (static_block == NULL)
-    return (struct block_symbol) {NULL, NULL};
+    return {};
 
   if (symbol_lookup_debug)
     {
@@ -2584,11 +2602,11 @@ lookup_static_symbol (const char *name, const domain_enum domain)
   if (result.symbol != NULL)
     {
       if (SYMBOL_LOOKUP_FAILED_P (result))
-       return (struct block_symbol) {NULL, NULL};
+       return {};
       return result;
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->objfiles ())
     {
       result = lookup_symbol_in_objfile (objfile, STATIC_BLOCK, name, domain);
       if (result.symbol != NULL)
@@ -2602,7 +2620,7 @@ lookup_static_symbol (const char *name, const domain_enum domain)
 
   /* Still pass NULL for OBJFILE_CONTEXT here.  */
   symbol_cache_mark_not_found (bsc, slot, NULL, name, domain);
-  return (struct block_symbol) {NULL, NULL};
+  return {};
 }
 
 /* Private data to be used with lookup_symbol_global_iterator_cb.  */
@@ -2666,7 +2684,7 @@ lookup_global_symbol (const char *name,
   if (result.symbol != NULL)
     {
       if (SYMBOL_LOOKUP_FAILED_P (result))
-       return (struct block_symbol) {NULL, NULL};
+       return {};
       return result;
     }
 
@@ -2731,7 +2749,7 @@ basic_lookup_transparent_type_quick (struct objfile *objfile, int block_index,
 {
   struct compunit_symtab *cust;
   const struct blockvector *bv;
-  struct block *block;
+  const struct block *block;
   struct symbol *sym;
 
   if (!objfile->sf)
@@ -2763,7 +2781,7 @@ basic_lookup_transparent_type_1 (struct objfile *objfile, int block_index,
   const struct block *block;
   const struct symbol *sym;
 
-  for (compunit_symtab *cust : objfile_compunits (objfile))
+  for (compunit_symtab *cust : objfile->compunits ())
     {
       bv = COMPUNIT_BLOCKVECTOR (cust);
       block = BLOCKVECTOR_BLOCK (bv, block_index);
@@ -2795,14 +2813,14 @@ basic_lookup_transparent_type (const char *name)
      of the desired name as a global, then do psymtab-to-symtab
      conversion on the fly and return the found symbol.  */
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->objfiles ())
     {
       t = basic_lookup_transparent_type_1 (objfile, GLOBAL_BLOCK, name);
       if (t)
        return t;
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->objfiles ())
     {
       t = basic_lookup_transparent_type_quick (objfile, GLOBAL_BLOCK, name);
       if (t)
@@ -2816,14 +2834,14 @@ basic_lookup_transparent_type (const char *name)
      of the desired name as a file-level static, then do psymtab-to-symtab
      conversion on the fly and return the found symbol.  */
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->objfiles ())
     {
       t = basic_lookup_transparent_type_1 (objfile, STATIC_BLOCK, name);
       if (t)
        return t;
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->objfiles ())
     {
       t = basic_lookup_transparent_type_quick (objfile, STATIC_BLOCK, name);
       if (t)
@@ -2879,12 +2897,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
      we call find_pc_sect_psymtab which has a similar restriction based
      on the partial_symtab's texthigh and textlow.  */
   msymbol = lookup_minimal_symbol_by_pc_section (pc, section);
-  if (msymbol.minsym
-      && (MSYMBOL_TYPE (msymbol.minsym) == mst_data
-         || MSYMBOL_TYPE (msymbol.minsym) == mst_bss
-         || MSYMBOL_TYPE (msymbol.minsym) == mst_abs
-         || MSYMBOL_TYPE (msymbol.minsym) == mst_file_data
-         || MSYMBOL_TYPE (msymbol.minsym) == mst_file_bss))
+  if (msymbol.minsym && msymbol.minsym->data_p ())
     return NULL;
 
   /* Search all symtabs for the one whose file contains our address, and which
@@ -2902,11 +2915,11 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
      It also happens for objfiles that have their functions reordered.
      For these, the symtab we are looking for is not necessarily read in.  */
 
-  for (objfile *obj_file : all_objfiles (current_program_space))
+  for (objfile *obj_file : current_program_space->objfiles ())
     {
-      for (compunit_symtab *cust : objfile_compunits (obj_file))
+      for (compunit_symtab *cust : obj_file->compunits ())
        {
-         struct block *b;
+         const struct block *b;
          const struct blockvector *bv;
 
          bv = COMPUNIT_BLOCKVECTOR (cust);
@@ -2964,7 +2977,7 @@ find_pc_sect_compunit_symtab (CORE_ADDR pc, struct obj_section *section)
 
   /* Not found in symtabs, search the "quick" symtabs (e.g. psymtabs).  */
 
-  for (objfile *objf : all_objfiles (current_program_space))
+  for (objfile *objf : current_program_space->objfiles ())
     {
       struct compunit_symtab *result;
 
@@ -2996,7 +3009,7 @@ find_pc_compunit_symtab (CORE_ADDR pc)
 struct symbol *
 find_symbol_at_address (CORE_ADDR address)
 {
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->objfiles ())
     {
       if (objfile->sf == NULL
          || objfile->sf->qf->find_compunit_symtab_by_address == NULL)
@@ -3010,7 +3023,7 @@ find_symbol_at_address (CORE_ADDR address)
 
          for (int i = GLOBAL_BLOCK; i <= STATIC_BLOCK; ++i)
            {
-             struct block *b = BLOCKVECTOR_BLOCK (bv, i);
+             const struct block *b = BLOCKVECTOR_BLOCK (bv, i);
              struct block_iterator iter;
              struct symbol *sym;
 
@@ -3351,16 +3364,16 @@ find_line_symtab (struct symtab *sym_tab, int line,
       else
        best = 0;
 
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->objfiles ())
        {
          if (objfile->sf)
            objfile->sf->qf->expand_symtabs_with_fullname
              (objfile, symtab_to_fullname (sym_tab));
        }
 
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->objfiles ())
        {
-         for (compunit_symtab *cu : objfile_compunits (objfile))
+         for (compunit_symtab *cu : objfile->compunits ())
            {
              for (symtab *s : compunit_filetabs (cu))
                {
@@ -4168,7 +4181,7 @@ output_source_filename (const char *name,
   data->first = 0;
 
   wrap_here ("");
-  fputs_filtered (name, gdb_stdout);
+  fputs_styled (name, file_name_style.style (), gdb_stdout);
 }
 
 /* A callback for map_partial_symbol_filenames.  */
@@ -4198,9 +4211,9 @@ info_sources_command (const char *ignore, int from_tty)
   printf_filtered ("Source files for which symbols have been read in:\n\n");
 
   data.first = 1;
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->objfiles ())
     {
-      for (compunit_symtab *cu : objfile_compunits (objfile))
+      for (compunit_symtab *cu : objfile->compunits ())
        {
          for (symtab *s : compunit_filetabs (cu))
            {
@@ -4341,7 +4354,7 @@ search_symbols (const char *regexp, enum search_domain kind,
                int nfiles, const char *files[])
 {
   const struct blockvector *bv;
-  struct block *b;
+  const struct block *b;
   int i = 0;
   struct block_iterator iter;
   struct symbol *sym;
@@ -4453,9 +4466,9 @@ search_symbols (const char *regexp, enum search_domain kind,
 
   if (nfiles == 0 && (kind == VARIABLES_DOMAIN || kind == FUNCTIONS_DOMAIN))
     {
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->objfiles ())
        {
-         for (minimal_symbol *msymbol : objfile_msymbols (objfile))
+         for (minimal_symbol *msymbol : objfile->msymbols ())
            {
              QUIT;
 
@@ -4490,9 +4503,9 @@ search_symbols (const char *regexp, enum search_domain kind,
        }
     }
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->objfiles ())
     {
-      for (compunit_symtab *cust : objfile_compunits (objfile))
+      for (compunit_symtab *cust : objfile->compunits ())
        {
          bv = COMPUNIT_BLOCKVECTOR (cust);
          for (i = GLOBAL_BLOCK; i <= STATIC_BLOCK; i++)
@@ -4556,9 +4569,9 @@ search_symbols (const char *regexp, enum search_domain kind,
   if ((found_misc || (nfiles == 0 && kind != FUNCTIONS_DOMAIN))
       && !treg.has_value ())
     {
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->objfiles ())
        {
-         for (minimal_symbol *msymbol : objfile_msymbols (objfile))
+         for (minimal_symbol *msymbol : objfile->msymbols ())
            {
              QUIT;
 
@@ -4620,7 +4633,7 @@ print_symbol_info (enum search_domain kind,
       if (filename_cmp (last, s_filename) != 0)
        {
          fputs_filtered ("\nFile ", gdb_stdout);
-         fputs_filtered (s_filename, gdb_stdout);
+         fputs_styled (s_filename, file_name_style.style (), gdb_stdout);
          fputs_filtered (":\n", gdb_stdout);
        }
 
@@ -4667,8 +4680,15 @@ print_msymbol_info (struct bound_minimal_symbol msymbol)
   else
     tmp = hex_string_custom (BMSYMBOL_VALUE_ADDRESS (msymbol),
                             16);
-  printf_filtered ("%s  %s\n",
-                  tmp, MSYMBOL_PRINT_NAME (msymbol.minsym));
+  fputs_styled (tmp, address_style.style (), gdb_stdout);
+  fputs_filtered ("  ", gdb_stdout);
+  if (msymbol.minsym->text_p ())
+    fputs_styled (MSYMBOL_PRINT_NAME (msymbol.minsym),
+                 function_name_style.style (),
+                 gdb_stdout);
+  else
+    fputs_filtered (MSYMBOL_PRINT_NAME (msymbol.minsym), gdb_stdout);
+  fputs_filtered ("\n", gdb_stdout);
 }
 
 /* This is the guts of the commands "info functions", "info types", and
@@ -4699,7 +4719,7 @@ symtab_symbol_info (bool quiet,
          if (t_regexp != NULL)
            printf_filtered
              (_("All %ss matching regular expression \"%s\""
-                " with type matching regulation expression \"%s\":\n"),
+                " with type matching regular expression \"%s\":\n"),
               classnames[kind], regexp, t_regexp);
          else
            printf_filtered (_("All %ss matching regular expression \"%s\":\n"),
@@ -4710,7 +4730,7 @@ symtab_symbol_info (bool quiet,
          if (t_regexp != NULL)
            printf_filtered
              (_("All defined %ss"
-                " with type matching regulation expression \"%s\" :\n"),
+                " with type matching regular expression \"%s\" :\n"),
               classnames[kind], t_regexp);
          else
            printf_filtered (_("All defined %ss:\n"), classnames[kind]);
@@ -5272,9 +5292,9 @@ default_collect_symbol_completion_matches_break_on
 
   if (code == TYPE_CODE_UNDEF)
     {
-      for (objfile *objfile : all_objfiles (current_program_space))
+      for (objfile *objfile : current_program_space->objfiles ())
        {
-         for (minimal_symbol *msymbol : objfile_msymbols (objfile))
+         for (minimal_symbol *msymbol : objfile->msymbols ())
            {
              QUIT;
 
@@ -5291,9 +5311,9 @@ default_collect_symbol_completion_matches_break_on
     }
 
   /* Add completions for all currently loaded symbol tables.  */
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->objfiles ())
     {
-      for (compunit_symtab *cust : objfile_compunits (objfile))
+      for (compunit_symtab *cust : objfile->compunits ())
        add_symtab_completions (cust, tracker, mode, lookup_name,
                                sym_text, word, code);
     }
@@ -5600,9 +5620,9 @@ make_source_files_completion_list (const char *text, const char *word)
 
   filename_seen_cache filenames_seen;
 
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->objfiles ())
     {
-      for (compunit_symtab *cu : objfile_compunits (objfile))
+      for (compunit_symtab *cu : objfile->compunits ())
        {
          for (symtab *s : compunit_filetabs (cu))
            {
@@ -5717,7 +5737,7 @@ find_main_name (void)
      relies on the order of objfile creation -- which still isn't
      guaranteed to get the correct answer, but is just probably more
      accurate.  */
-  for (objfile *objfile : all_objfiles (current_program_space))
+  for (objfile *objfile : current_program_space->objfiles ())
     {
       if (objfile->per_bfd->name_of_main != NULL)
        {
This page took 0.037482 seconds and 4 git commands to generate.