static char *
build_id_to_debug_filename (struct build_id *build_id)
{
- char *link, *s, *retval = NULL;
- gdb_byte *data = build_id->data;
- size_t size = build_id->size;
+ char *link, *debugdir, *retval = NULL;
/* DEBUG_FILE_DIRECTORY/.build-id/ab/cdef */
- link = xmalloc (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
- + 2 * size + (sizeof ".debug" - 1) + 1);
- s = link + sprintf (link, "%s/.build-id/", debug_file_directory);
- if (size > 0)
- {
- size--;
- s += sprintf (s, "%02x", (unsigned) *data++);
- }
- if (size > 0)
- *s++ = '/';
- while (size-- > 0)
- s += sprintf (s, "%02x", (unsigned) *data++);
- strcpy (s, ".debug");
-
- /* lrealpath() is expensive even for the usually non-existent files. */
- if (access (link, F_OK) == 0)
- retval = lrealpath (link);
- xfree (link);
-
- if (retval != NULL && !build_id_verify (retval, build_id))
+ link = alloca (strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
+ + 2 * build_id->size + (sizeof ".debug" - 1) + 1);
+
+ /* Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
+ cause "/.build-id/..." lookups. */
+
+ debugdir = debug_file_directory;
+ do
{
- xfree (retval);
- retval = NULL;
+ char *s, *debugdir_end;
+ gdb_byte *data = build_id->data;
+ size_t size = build_id->size;
+
+ while (*debugdir == DIRNAME_SEPARATOR)
+ debugdir++;
+
+ debugdir_end = strchr (debugdir, DIRNAME_SEPARATOR);
+ if (debugdir_end == NULL)
+ debugdir_end = &debugdir[strlen (debugdir)];
+
+ memcpy (link, debugdir, debugdir_end - debugdir);
+ s = &link[debugdir_end - debugdir];
+ s += sprintf (s, "/.build-id/");
+ if (size > 0)
+ {
+ size--;
+ s += sprintf (s, "%02x", (unsigned) *data++);
+ }
+ if (size > 0)
+ *s++ = '/';
+ while (size-- > 0)
+ s += sprintf (s, "%02x", (unsigned) *data++);
+ strcpy (s, ".debug");
+
+ /* lrealpath() is expensive even for the usually non-existent files. */
+ if (access (link, F_OK) == 0)
+ retval = lrealpath (link);
+
+ if (retval != NULL && !build_id_verify (retval, build_id))
+ {
+ xfree (retval);
+ retval = NULL;
+ }
+
+ if (retval != NULL)
+ break;
+
+ debugdir = debugdir_end;
}
+ while (*debugdir != 0);
return retval;
}
static int
separate_debug_file_exists (const char *name, unsigned long crc,
- const char *parent_name)
+ struct objfile *parent_objfile)
{
unsigned long file_crc = 0;
bfd *abfd;
gdb_byte buffer[8*1024];
int count;
+ struct stat parent_stat, abfd_stat;
+
+ /* Find a separate debug info file as if symbols would be present in
+ PARENT_OBJFILE itself this function would not be called. .gnu_debuglink
+ section can contain just the basename of PARENT_OBJFILE without any
+ ".debug" suffix as "/usr/lib/debug/path/to/file" is a separate tree where
+ the separate debug infos with the same basename can exist. */
+
+ if (strcmp (name, parent_objfile->name) == 0)
+ return 0;
if (remote_filename_p (name))
abfd = remote_bfd_open (name, gnutarget);
if (!abfd)
return 0;
+ /* Verify symlinks were not the cause of strcmp name difference above.
+
+ Some operating systems, e.g. Windows, do not provide a meaningful
+ st_ino; they always set it to zero. (Windows does provide a
+ meaningful st_dev.) Do not indicate a duplicate library in that
+ case. While there is no guarantee that a system that provides
+ meaningful inode numbers will never set st_ino to zero, this is
+ merely an optimization, so we do not need to worry about false
+ negatives. */
+
+ if (bfd_stat (abfd, &abfd_stat) == 0
+ && bfd_stat (parent_objfile->obfd, &parent_stat) == 0
+ && abfd_stat.st_dev == parent_stat.st_dev
+ && abfd_stat.st_ino == parent_stat.st_ino
+ && abfd_stat.st_ino != 0)
+ {
+ bfd_close (abfd);
+ return 0;
+ }
+
while ((count = bfd_bread (buffer, sizeof (buffer), abfd)) > 0)
file_crc = gnu_debuglink_crc32 (file_crc, buffer, count);
{
warning (_("the debug information found in \"%s\""
" does not match \"%s\" (CRC mismatch).\n"),
- name, parent_name);
+ name, parent_objfile->name);
return 0;
}
find_separate_debug_file (struct objfile *objfile)
{
asection *sect;
- char *basename, *name_copy;
+ char *basename, *name_copy, *debugdir;
char *dir = NULL;
char *debugfile = NULL;
char *canon_name = NULL;
strcpy (debugfile, dir);
strcat (debugfile, basename);
- if (separate_debug_file_exists (debugfile, crc32, objfile->name))
+ if (separate_debug_file_exists (debugfile, crc32, objfile))
goto cleanup_return_debugfile;
/* Then try in the subdirectory named DEBUG_SUBDIRECTORY. */
strcat (debugfile, "/");
strcat (debugfile, basename);
- if (separate_debug_file_exists (debugfile, crc32, objfile->name))
+ if (separate_debug_file_exists (debugfile, crc32, objfile))
goto cleanup_return_debugfile;
- /* Then try in the global debugfile directory. */
- strcpy (debugfile, debug_file_directory);
- strcat (debugfile, "/");
- strcat (debugfile, dir);
- strcat (debugfile, basename);
-
- if (separate_debug_file_exists (debugfile, crc32, objfile->name))
- goto cleanup_return_debugfile;
+ /* Then try in the global debugfile directories.
+
+ Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
+ cause "/..." lookups. */
- /* If the file is in the sysroot, try using its base path in the
- global debugfile directory. */
- if (canon_name
- && strncmp (canon_name, gdb_sysroot, strlen (gdb_sysroot)) == 0
- && IS_DIR_SEPARATOR (canon_name[strlen (gdb_sysroot)]))
+ debugdir = debug_file_directory;
+ do
{
- strcpy (debugfile, debug_file_directory);
- strcat (debugfile, canon_name + strlen (gdb_sysroot));
+ char *debugdir_end;
+
+ while (*debugdir == DIRNAME_SEPARATOR)
+ debugdir++;
+
+ debugdir_end = strchr (debugdir, DIRNAME_SEPARATOR);
+ if (debugdir_end == NULL)
+ debugdir_end = &debugdir[strlen (debugdir)];
+
+ memcpy (debugfile, debugdir, debugdir_end - debugdir);
+ debugfile[debugdir_end - debugdir] = 0;
strcat (debugfile, "/");
+ strcat (debugfile, dir);
strcat (debugfile, basename);
- if (separate_debug_file_exists (debugfile, crc32, objfile->name))
+ if (separate_debug_file_exists (debugfile, crc32, objfile))
goto cleanup_return_debugfile;
+
+ /* If the file is in the sysroot, try using its base path in the
+ global debugfile directory. */
+ if (canon_name
+ && strncmp (canon_name, gdb_sysroot, strlen (gdb_sysroot)) == 0
+ && IS_DIR_SEPARATOR (canon_name[strlen (gdb_sysroot)]))
+ {
+ memcpy (debugfile, debugdir, debugdir_end - debugdir);
+ debugfile[debugdir_end - debugdir] = 0;
+ strcat (debugfile, canon_name + strlen (gdb_sysroot));
+ strcat (debugfile, "/");
+ strcat (debugfile, basename);
+
+ if (separate_debug_file_exists (debugfile, crc32, objfile))
+ goto cleanup_return_debugfile;
+ }
+
+ debugdir = debugdir_end;
}
+ while (*debugdir != 0);
xfree (debugfile);
debugfile = NULL;
objfile->psymbol_cache = bcache_xmalloc ();
bcache_xfree (objfile->macro_cache);
objfile->macro_cache = bcache_xmalloc ();
+ bcache_xfree (objfile->filename_cache);
+ objfile->filename_cache = bcache_xmalloc ();
if (objfile->demangled_names_hash != NULL)
{
htab_delete (objfile->demangled_names_hash);
objfile->psymbol_cache = bcache_xmalloc ();
objfile->macro_cache = bcache_xmalloc ();
+ objfile->filename_cache = bcache_xmalloc ();
/* obstack_init also initializes the obstack so it is
empty. We could use obstack_specify_allocation but
gdb_obstack.h specifies the alloc/dealloc
symtab = (struct symtab *)
obstack_alloc (&objfile->objfile_obstack, sizeof (struct symtab));
memset (symtab, 0, sizeof (*symtab));
- symtab->filename = obsavestring (filename, strlen (filename),
- &objfile->objfile_obstack);
+ symtab->filename = (char *) bcache (filename, strlen (filename) + 1,
+ objfile->filename_cache);
symtab->fullname = NULL;
symtab->language = deduce_language_from_filename (filename);
- symtab->debugformat = obsavestring ("unknown", 7,
- &objfile->objfile_obstack);
+ symtab->debugformat = "unknown";
/* Hook it to the objfile it comes from */
}
struct partial_symtab *
-allocate_psymtab (char *filename, struct objfile *objfile)
+allocate_psymtab (const char *filename, struct objfile *objfile)
{
struct partial_symtab *psymtab;
sizeof (struct partial_symtab));
memset (psymtab, 0, sizeof (struct partial_symtab));
- psymtab->filename = obsavestring (filename, strlen (filename),
- &objfile->objfile_obstack);
+ psymtab->filename = (char *) bcache (filename, strlen (filename) + 1,
+ objfile->filename_cache);
psymtab->symtab = NULL;
/* Prepend it to the psymtab list for the objfile it belongs to.
struct partial_symtab *
start_psymtab_common (struct objfile *objfile,
- struct section_offsets *section_offsets, char *filename,
+ struct section_offsets *section_offsets,
+ const char *filename,
CORE_ADDR textlow, struct partial_symbol **global_syms,
struct partial_symbol **static_syms)
{
different domain (or address) is possible and correct. */
static const struct partial_symbol *
-add_psymbol_to_bcache (char *name, int namelength, domain_enum domain,
+add_psymbol_to_bcache (char *name, int namelength, int copy_name,
+ domain_enum domain,
enum address_class class,
long val, /* Value as a long */
CORE_ADDR coreaddr, /* Value as a CORE_ADDR */
enum language language, struct objfile *objfile,
int *added)
{
- char *buf = name;
/* psymbol is static so that there will be no uninitialized gaps in the
structure which might contain random data, causing cache misses in
bcache. */
static struct partial_symbol psymbol;
-
- if (name[namelength] != '\0')
- {
- buf = alloca (namelength + 1);
- /* Create local copy of the partial symbol */
- memcpy (buf, name, namelength);
- buf[namelength] = '\0';
- }
+
+ /* However, we must ensure that the entire 'value' field has been
+ zeroed before assigning to it, because an assignment may not
+ write the entire field. */
+ memset (&psymbol.ginfo.value, 0, sizeof (psymbol.ginfo.value));
/* val and coreaddr are mutually exclusive, one of them *will* be zero */
if (val != 0)
{
PSYMBOL_DOMAIN (&psymbol) = domain;
PSYMBOL_CLASS (&psymbol) = class;
- SYMBOL_SET_NAMES (&psymbol, buf, namelength, objfile);
+ SYMBOL_SET_NAMES (&psymbol, name, namelength, copy_name, objfile);
/* Stash the partial symbol away in the cache */
return bcache_full (&psymbol, sizeof (struct partial_symbol),
cache. */
const struct partial_symbol *
-add_psymbol_to_list (char *name, int namelength, domain_enum domain,
+add_psymbol_to_list (char *name, int namelength, int copy_name,
+ domain_enum domain,
enum address_class class,
struct psymbol_allocation_list *list,
long val, /* Value as a long */
int added;
/* Stash the partial symbol away in the cache */
- psym = add_psymbol_to_bcache (name, namelength, domain, class,
+ psym = add_psymbol_to_bcache (name, namelength, copy_name, domain, class,
val, coreaddr, language, objfile, &added);
/* Do not duplicate global partial symbols. */
add_setshow_optional_filename_cmd ("debug-file-directory", class_support,
&debug_file_directory, _("\
-Set the directory where separate debug symbols are searched for."), _("\
-Show the directory where separate debug symbols are searched for."), _("\
+Set the directories where separate debug symbols are searched for."), _("\
+Show the directories where separate debug symbols are searched for."), _("\
Separate debug symbols are first searched for in the same\n\
directory as the binary, then in the `" DEBUG_SUBDIRECTORY "' subdirectory,\n\
and lastly at the path of the directory of the binary with\n\
-the global debug-file directory prepended."),
+each global debug-file-directory component prepended."),
NULL,
show_debug_file_directory,
&setlist, &showlist);