make language_of_main static
[deliverable/binutils-gdb.git] / gdb / symtab.c
index 8076fe5bb30e87e107989f630cae576067acf5af..a8073b8ef7e8027566949952b9115631e33a5f5f 100644 (file)
@@ -1,6 +1,6 @@
 /* Symbol table lookup for the GNU debugger, GDB.
 
-   Copyright (C) 1986-2013 Free Software Foundation, Inc.
+   Copyright (C) 1986-2014 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
@@ -50,8 +50,8 @@
 
 #include <sys/types.h>
 #include <fcntl.h>
-#include "gdb_string.h"
-#include "gdb_stat.h"
+#include <string.h>
+#include <sys/stat.h>
 #include <ctype.h>
 #include "cp-abi.h"
 #include "cp-support.h"
@@ -61,7 +61,6 @@
 #include "macrotab.h"
 #include "macroscope.h"
 
-#include "psymtab.h"
 #include "parser-defs.h"
 
 /* Prototypes for local functions */
@@ -106,7 +105,7 @@ void _initialize_symtab (void);
 /* */
 
 /* When non-zero, print debugging messages related to symtab creation.  */
-int symtab_create_debug = 0;
+unsigned int symtab_create_debug = 0;
 
 /* Non-zero if a file may be known by two different basenames.
    This is the uncommon case, and significantly slows down gdb.
@@ -143,6 +142,53 @@ multiple_symbols_select_mode (void)
 
 const struct block *block_found;
 
+/* Return the name of a domain_enum.  */
+
+const char *
+domain_name (domain_enum e)
+{
+  switch (e)
+    {
+    case UNDEF_DOMAIN: return "UNDEF_DOMAIN";
+    case VAR_DOMAIN: return "VAR_DOMAIN";
+    case STRUCT_DOMAIN: return "STRUCT_DOMAIN";
+    case LABEL_DOMAIN: return "LABEL_DOMAIN";
+    case COMMON_BLOCK_DOMAIN: return "COMMON_BLOCK_DOMAIN";
+    default: gdb_assert_not_reached ("bad domain_enum");
+    }
+}
+
+/* Return the name of a search_domain .  */
+
+const char *
+search_domain_name (enum search_domain e)
+{
+  switch (e)
+    {
+    case VARIABLES_DOMAIN: return "VARIABLES_DOMAIN";
+    case FUNCTIONS_DOMAIN: return "FUNCTIONS_DOMAIN";
+    case TYPES_DOMAIN: return "TYPES_DOMAIN";
+    case ALL_DOMAIN: return "ALL_DOMAIN";
+    default: gdb_assert_not_reached ("bad search_domain");
+    }
+}
+
+/* Set the primary field in SYMTAB.  */
+
+void
+set_symtab_primary (struct symtab *symtab, int primary)
+{
+  symtab->primary = primary;
+
+  if (symtab_create_debug && primary)
+    {
+      fprintf_unfiltered (gdb_stdlog,
+                         "Created primary symtab %s for %s.\n",
+                         host_address_to_string (symtab),
+                         symtab_to_filename_for_display (symtab));
+    }
+}
+
 /* 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
@@ -561,7 +607,7 @@ create_demangled_names_hash (struct objfile *objfile)
      Choosing a much larger table size wastes memory, and saves only about
      1% in symbol reading.  */
 
-  objfile->demangled_names_hash = htab_create_alloc
+  objfile->per_bfd->demangled_names_hash = htab_create_alloc
     (256, hash_demangled_name_entry, eq_demangled_name_entry,
      NULL, xcalloc, xfree);
 }
@@ -645,6 +691,42 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
      symbols).  Just the mangling standard is not standardized across compilers
      and there is no DW_AT_producer available for inferiors with only the ELF
      symbols to check the mangling kind.  */
+
+  /* Check for Ada symbols last.  See comment below explaining why.  */
+
+  if (gsymbol->language == language_auto)
+   {
+     const char *demangled = ada_decode (mangled);
+
+     if (demangled != mangled && demangled != NULL && demangled[0] != '<')
+       {
+        /* Set the gsymbol language to Ada, but still return NULL.
+           Two reasons for that:
+
+             1. For Ada, we prefer computing the symbol's decoded name
+                on the fly rather than pre-compute it, in order to save
+                memory (Ada projects are typically very large).
+
+             2. There are some areas in the definition of the GNAT
+                encoding where, with a bit of bad luck, we might be able
+                to decode a non-Ada symbol, generating an incorrect
+                demangled name (Eg: names ending with "TB" for instance
+                are identified as task bodies and so stripped from
+                the decoded name returned).
+
+                Returning NULL, here, helps us get a little bit of
+                the best of both worlds.  Because we're last, we should
+                not affect any of the other languages that were able to
+                demangle the symbol before us; we get to correctly tag
+                Ada symbols as such; and even if we incorrectly tagged
+                a non-Ada symbol, which should be rare, any routing
+                through the Ada language should be transparent (Ada
+                tries to behave much like C/C++ with non-Ada symbols).  */
+        gsymbol->language = language_ada;
+        return NULL;
+       }
+   }
+
   return NULL;
 }
 
@@ -656,7 +738,7 @@ symbol_find_demangled_name (struct general_symbol_info *gsymbol,
    objfile), and it will not be copied.
 
    The hash table corresponding to OBJFILE is used, and the memory
-   comes from that objfile's objfile_obstack.  LINKAGE_NAME is copied,
+   comes from the per-BFD storage_obstack.  LINKAGE_NAME is copied,
    so the pointer can be discarded after calling this function.  */
 
 /* We have to be careful when dealing with Java names: when we run
@@ -692,6 +774,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
   /* The length of lookup_name.  */
   int lookup_len;
   struct demangled_name_entry entry;
+  struct objfile_per_bfd_storage *per_bfd = objfile->per_bfd;
 
   if (gsymbol->language == language_ada)
     {
@@ -707,18 +790,18 @@ symbol_set_names (struct general_symbol_info *gsymbol,
        gsymbol->name = linkage_name;
       else
        {
-         char *name = obstack_alloc (&objfile->objfile_obstack, len + 1);
+         char *name = obstack_alloc (&per_bfd->storage_obstack, len + 1);
 
          memcpy (name, linkage_name, len);
          name[len] = '\0';
          gsymbol->name = name;
        }
-      symbol_set_demangled_name (gsymbol, NULL, &objfile->objfile_obstack);
+      symbol_set_demangled_name (gsymbol, NULL, &per_bfd->storage_obstack);
 
       return;
     }
 
-  if (objfile->demangled_names_hash == NULL)
+  if (per_bfd->demangled_names_hash == NULL)
     create_demangled_names_hash (objfile);
 
   /* The stabs reader generally provides names that are not
@@ -758,7 +841,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
 
   entry.mangled = lookup_name;
   slot = ((struct demangled_name_entry **)
-         htab_find_slot (objfile->demangled_names_hash,
+         htab_find_slot (per_bfd->demangled_names_hash,
                          &entry, INSERT));
 
   /* If this name is not in the hash table, add it.  */
@@ -783,7 +866,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
         us better bcache hit rates for partial symbols.  */
       if (!copy_name && lookup_name == linkage_name)
        {
-         *slot = obstack_alloc (&objfile->objfile_obstack,
+         *slot = obstack_alloc (&per_bfd->storage_obstack,
                                 offsetof (struct demangled_name_entry,
                                           demangled)
                                 + demangled_len + 1);
@@ -796,7 +879,7 @@ symbol_set_names (struct general_symbol_info *gsymbol,
          /* If we must copy the mangled name, put it directly after
             the demangled name so we can have a single
             allocation.  */
-         *slot = obstack_alloc (&objfile->objfile_obstack,
+         *slot = obstack_alloc (&per_bfd->storage_obstack,
                                 offsetof (struct demangled_name_entry,
                                           demangled)
                                 + lookup_len + demangled_len + 2);
@@ -817,9 +900,9 @@ symbol_set_names (struct general_symbol_info *gsymbol,
   gsymbol->name = (*slot)->mangled + lookup_len - len;
   if ((*slot)->demangled[0] != '\0')
     symbol_set_demangled_name (gsymbol, (*slot)->demangled,
-                              &objfile->objfile_obstack);
+                              &per_bfd->storage_obstack);
   else
-    symbol_set_demangled_name (gsymbol, NULL, &objfile->objfile_obstack);
+    symbol_set_demangled_name (gsymbol, NULL, &per_bfd->storage_obstack);
 }
 
 /* Return the source code name of a symbol.  In languages where
@@ -1949,29 +2032,6 @@ basic_lookup_transparent_type (const char *name)
   return (struct type *) 0;
 }
 
-/* Find the name of the file containing main().  */
-/* FIXME:  What about languages without main() or specially linked
-   executables that have no main() ?   */
-
-const char *
-find_main_filename (void)
-{
-  struct objfile *objfile;
-  char *name = main_name ();
-
-  ALL_OBJFILES (objfile)
-  {
-    const char *result;
-
-    if (!objfile->sf)
-      continue;
-    result = objfile->sf->qf->find_symbol_file (objfile, name);
-    if (result)
-      return result;
-  }
-  return (NULL);
-}
-
 /* Search BLOCK for symbol NAME in DOMAIN.
 
    Note that if NAME is the demangled form of a C++ symbol, we will fail
@@ -3259,8 +3319,8 @@ sources_info (char *ignore, int from_tty)
 
   clear_filename_seen_cache (data.filename_seen_cache);
   data.first = 1;
-  map_partial_symbol_filenames (output_partial_symbol_filename, &data,
-                               1 /*need_fullname*/);
+  map_symbol_filenames (output_partial_symbol_filename, &data,
+                       1 /*need_fullname*/);
   printf_filtered ("\n");
 
   do_cleanups (cleanups);
@@ -3328,7 +3388,7 @@ compare_search_syms (const void *sa, const void *sb)
   struct symbol_search *sym_b = *(struct symbol_search **) sb;
   int c;
 
-  c = strcmp (sym_a->symtab->filename, sym_b->symtab->filename);
+  c = FILENAME_CMP (sym_a->symtab->filename, sym_b->symtab->filename);
   if (c != 0)
     return c;
 
@@ -3339,19 +3399,6 @@ compare_search_syms (const void *sa, const void *sb)
                 SYMBOL_PRINT_NAME (sym_b->symbol));
 }
 
-/* Helper function for sort_search_symbols_remove_dups.
-   Return TRUE if symbols A, B are equal.  */
-
-static int
-search_symbols_equal (const struct symbol_search *a,
-                     const struct symbol_search *b)
-{
-  return (strcmp (a->symtab->filename, b->symtab->filename) == 0
-         && a->block == b->block
-         && strcmp (SYMBOL_PRINT_NAME (a->symbol),
-                    SYMBOL_PRINT_NAME (b->symbol)) == 0);
-}
-
 /* Sort the NFOUND symbols in list FOUND and remove duplicates.
    The duplicates are freed, and the new list is returned in
    *NEW_HEAD, *NEW_TAIL.  */
@@ -3385,7 +3432,7 @@ sort_search_symbols_remove_dups (struct symbol_search *found, int nfound,
   /* Collapse out the dups.  */
   for (i = 1, j = 1; i < nfound; ++i)
     {
-      if (! search_symbols_equal (symbols[j - 1], symbols[i]))
+      if (compare_search_syms (&symbols[j - 1], &symbols[i]) != 0)
        symbols[j++] = symbols[i];
       else
        xfree (symbols[i]);
@@ -3555,17 +3602,11 @@ search_symbols (char *regexp, enum search_domain kind,
 
   datum.nfiles = nfiles;
   datum.files = files;
-  ALL_OBJFILES (objfile)
-  {
-    if (objfile->sf)
-      objfile->sf->qf->expand_symtabs_matching (objfile,
-                                               (nfiles == 0
-                                                ? NULL
-                                                : search_symbols_file_matches),
-                                               search_symbols_name_matches,
-                                               kind,
-                                               &datum);
-  }
+  expand_symtabs_matching ((nfiles == 0
+                           ? NULL
+                           : search_symbols_file_matches),
+                          search_symbols_name_matches,
+                          kind, &datum);
 
   /* Here, we search through the minimal symbol tables for functions
      and variables that match, and force their symbols to be read.
@@ -4206,7 +4247,7 @@ completion_list_add_fields (struct symbol *sym, const char *sym_text,
 }
 
 /* Type of the user_data argument passed to add_macro_name or
-   expand_partial_symbol_name.  The contents are simply whatever is
+   symbol_completion_matcher.  The contents are simply whatever is
    needed by completion_list_add_name.  */
 struct add_name_data
 {
@@ -4231,10 +4272,10 @@ add_macro_name (const char *name, const struct macro_definition *ignore,
                            datum->text, datum->word);
 }
 
-/* A callback for expand_partial_symbol_names.  */
+/* A callback for expand_symtabs_matching.  */
 
 static int
-expand_partial_symbol_name (const char *name, void *user_data)
+symbol_completion_matcher (const char *name, void *user_data)
 {
   struct add_name_data *datum = (struct add_name_data *) user_data;
 
@@ -4345,7 +4386,8 @@ default_make_symbol_completion_list_break_on (const char *text,
   /* Look through the partial symtabs for all symbols which begin
      by matching SYM_TEXT.  Expand all CUs that you find to the list.
      The real names will get added by COMPLETION_LIST_ADD_SYMBOL below.  */
-  expand_partial_symbol_names (expand_partial_symbol_name, &datum);
+  expand_symtabs_matching (NULL, symbol_completion_matcher, ALL_DOMAIN,
+                          &datum);
 
   /* At this point scan through the misc symbol vectors and add each
      symbol you find to the list.  Eventually we want to ignore
@@ -4759,8 +4801,8 @@ make_source_files_completion_list (const char *text, const char *word)
   datum.word = word;
   datum.text_len = text_len;
   datum.list = &list;
-  map_partial_symbol_filenames (maybe_add_partial_symtab_filename, &datum,
-                               0 /*need_fullname*/);
+  map_symbol_filenames (maybe_add_partial_symtab_filename, &datum,
+                       0 /*need_fullname*/);
 
   do_cleanups (cache_cleanup);
   discard_cleanups (back_to);
@@ -4957,10 +4999,10 @@ skip_prologue_using_sal (struct gdbarch *gdbarch, CORE_ADDR func_addr)
 \f
 /* Track MAIN */
 static char *name_of_main;
-enum language language_of_main = language_unknown;
+static enum language language_of_main = language_unknown;
 
 void
-set_main_name (const char *name)
+set_main_name (const char *name, enum language lang)
 {
   if (name_of_main != NULL)
     {
@@ -4971,7 +5013,7 @@ set_main_name (const char *name)
   if (name != NULL)
     {
       name_of_main = xstrdup (name);
-      language_of_main = language_unknown;
+      language_of_main = lang;
     }
 }
 
@@ -5002,27 +5044,27 @@ find_main_name (void)
   new_main_name = ada_main_name ();
   if (new_main_name != NULL)
     {
-      set_main_name (new_main_name);
+      set_main_name (new_main_name, language_ada);
       return;
     }
 
   new_main_name = go_main_name ();
   if (new_main_name != NULL)
     {
-      set_main_name (new_main_name);
+      set_main_name (new_main_name, language_go);
       return;
     }
 
   new_main_name = pascal_main_name ();
   if (new_main_name != NULL)
     {
-      set_main_name (new_main_name);
+      set_main_name (new_main_name, language_pascal);
       return;
     }
 
   /* The languages above didn't identify the name of the main procedure.
      Fallback to "main".  */
-  set_main_name ("main");
+  set_main_name ("main", language_unknown);
 }
 
 char *
@@ -5034,13 +5076,22 @@ main_name (void)
   return name_of_main;
 }
 
+/* Return the language of the main function.  If it is not known,
+   return language_unknown.  */
+
+enum language
+main_language (void)
+{
+  return language_of_main;
+}
+
 /* Handle ``executable_changed'' events for the symtab module.  */
 
 static void
 symtab_observer_executable_changed (void)
 {
   /* NAME_OF_MAIN may no longer be the same, so reset it for now.  */
-  set_main_name (NULL);
+  set_main_name (NULL, language_unknown);
 }
 
 /* Return 1 if the supplied producer string matches the ARM RealView
@@ -5277,13 +5328,15 @@ one base name, and gdb will do file name comparisons more efficiently."),
                           NULL, NULL,
                           &setlist, &showlist);
 
-  add_setshow_boolean_cmd ("symtab-create", no_class, &symtab_create_debug,
-                          _("Set debugging of symbol table creation."),
-                          _("Show debugging of symbol table creation."), _("\
-When enabled, debugging messages are printed when building symbol tables."),
-                           NULL,
-                           NULL,
-                           &setdebuglist, &showdebuglist);
+  add_setshow_zuinteger_cmd ("symtab-create", no_class, &symtab_create_debug,
+                            _("Set debugging of symbol table creation."),
+                            _("Show debugging of symbol table creation."), _("\
+When enabled (non-zero), debugging messages are printed when building\n\
+symbol tables.  A value of 1 (one) normally provides enough information.\n\
+A value greater than 1 provides more verbose information."),
+                            NULL,
+                            NULL,
+                            &setdebuglist, &showdebuglist);
 
   observer_attach_executable_changed (symtab_observer_executable_changed);
 }
This page took 0.051198 seconds and 4 git commands to generate.