/* 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.
#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"
#include "solist.h"
#include "macrotab.h"
#include "macroscope.h"
+#include "ada-lang.h"
#include "psymtab.h"
#include "parser-defs.h"
/* */
/* 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.
}
}
+/* 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
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);
}
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;
}
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
/* 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)
{
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
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. */
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);
/* 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);
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
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;
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);
}