/* Generic symbol file reading for the GNU debugger, GDB.
- Copyright (C) 1990-2018 Free Software Foundation, Inc.
+ Copyright (C) 1990-2019 Free Software Foundation, Inc.
Contributed by Cygnus Support, using pieces from other GDB modules.
#include "cli/cli-utils.h"
#include "common/byte-vector.h"
#include "selftest.h"
+#include "cli/cli-style.h"
#include <sys/types.h>
#include <fcntl.h>
initial symbol reading for this file. */
(*objfile->sf->sym_init) (objfile);
- clear_complaints (1);
+ clear_complaints ();
(*objfile->sf->sym_offsets) (objfile, *addrs);
}
/* We're done reading the symbol file; finish off complaints. */
- clear_complaints (0);
+ clear_complaints ();
}
/* Process a symbol file, as either the main file or as a dynamically
if (deprecated_pre_add_symbol_hook)
deprecated_pre_add_symbol_hook (name);
else
- printf_filtered (_("Reading symbols from %s...\n"), name);
+ {
+ puts_filtered (_("Reading symbols from "));
+ fputs_styled (name, file_name_style.style (), gdb_stdout);
+ puts_filtered ("...\n");
+ }
}
syms_from_objfile (objfile, addrs, add_flags);
objfile->sf->qf->expand_all_symtabs (objfile);
}
- if (should_print && !objfile_has_symbols (objfile))
+ /* Note that we only print a message if we have no symbols and have
+ no separate debug file. If there is a separate debug file which
+ does not have symbols, we'll have emitted this message for that
+ file, and so printing it twice is just redundant. */
+ if (should_print && !objfile_has_symbols (objfile)
+ && objfile->separate_debug_objfile == nullptr)
printf_filtered (_("(No debugging symbols found in %s)\n"), name);
if (should_print)
return 0;
if (separate_debug_file_debug)
- printf_filtered (_(" Trying %s\n"), name.c_str ());
+ {
+ printf_filtered (_(" Trying %s..."), name.c_str ());
+ gdb_flush (gdb_stdout);
+ }
gdb_bfd_ref_ptr abfd (gdb_bfd_open (name.c_str (), gnutarget, -1));
if (abfd == NULL)
- return 0;
+ {
+ if (separate_debug_file_debug)
+ printf_filtered (_(" no, unable to open.\n"));
+
+ return 0;
+ }
/* Verify symlinks were not the cause of filename_cmp name difference above.
{
if (abfd_stat.st_dev == parent_stat.st_dev
&& abfd_stat.st_ino == parent_stat.st_ino)
- return 0;
+ {
+ if (separate_debug_file_debug)
+ printf_filtered (_(" no, same file as the objfile.\n"));
+
+ return 0;
+ }
verified_as_different = 1;
}
else
file_crc_p = gdb_bfd_crc (abfd.get (), &file_crc);
if (!file_crc_p)
- return 0;
+ {
+ if (separate_debug_file_debug)
+ printf_filtered (_(" no, error computing CRC.\n"));
+
+ return 0;
+ }
if (crc != file_crc)
{
if (!verified_as_different)
{
if (!gdb_bfd_crc (parent_objfile->obfd, &parent_crc))
- return 0;
+ {
+ if (separate_debug_file_debug)
+ printf_filtered (_(" no, error computing CRC.\n"));
+
+ return 0;
+ }
}
if (verified_as_different || parent_crc != file_crc)
" does not match \"%s\" (CRC mismatch).\n"),
name.c_str (), objfile_name (parent_objfile));
+ if (separate_debug_file_debug)
+ printf_filtered (_(" no, CRC doesn't match.\n"));
+
return 0;
}
+ if (separate_debug_file_debug)
+ printf_filtered (_(" yes!\n"));
+
return 1;
}
Keep backward compatibility so that DEBUG_FILE_DIRECTORY being "" will
cause "/..." lookups. */
+ bool target_prefix = startswith (dir, "target:");
+ const char *dir_notarget = target_prefix ? dir + strlen ("target:") : dir;
std::vector<gdb::unique_xmalloc_ptr<char>> debugdir_vec
= dirnames_to_char_ptr_vec (debug_file_directory);
for (const gdb::unique_xmalloc_ptr<char> &debugdir : debugdir_vec)
{
- debugfile = debugdir.get ();
+ debugfile = target_prefix ? "target:" : "";
+ debugfile += debugdir.get ();
debugfile += "/";
- debugfile += dir;
+ debugfile += dir_notarget;
debugfile += debuglink;
if (separate_debug_file_exists (debugfile, crc32, objfile))
strlen (gdb_sysroot)) == 0
&& IS_DIR_SEPARATOR (canon_dir[strlen (gdb_sysroot)]))
{
- debugfile = debugdir.get ();
+ debugfile = target_prefix ? "target:" : "";
+ debugfile += debugdir.get ();
debugfile += (canon_dir + strlen (gdb_sysroot));
debugfile += "/";
debugfile += debuglink;
addr = parse_and_eval_address (argv[1]);
- ALL_OBJFILES (objf)
+ for (objfile *objfile : current_program_space->objfiles ())
{
- if ((objf->flags & OBJF_USERLOADED) != 0
- && (objf->flags & OBJF_SHARED) != 0
- && objf->pspace == pspace && is_addr_in_objfile (addr, objf))
- break;
+ if ((objfile->flags & OBJF_USERLOADED) != 0
+ && (objfile->flags & OBJF_SHARED) != 0
+ && objfile->pspace == pspace
+ && is_addr_in_objfile (addr, objfile))
+ {
+ objf = objfile;
+ break;
+ }
}
}
else if (argv[0] != NULL)
gdb::unique_xmalloc_ptr<char> filename (tilde_expand (argv[0]));
- ALL_OBJFILES (objf)
+ for (objfile *objfile : current_program_space->objfiles ())
{
- if ((objf->flags & OBJF_USERLOADED) != 0
- && (objf->flags & OBJF_SHARED) != 0
- && objf->pspace == pspace
- && filename_cmp (filename.get (), objfile_name (objf)) == 0)
- break;
+ if ((objfile->flags & OBJF_USERLOADED) != 0
+ && (objfile->flags & OBJF_SHARED) != 0
+ && objfile->pspace == pspace
+ && filename_cmp (filename.get (), objfile_name (objfile)) == 0)
+ {
+ objf = objfile;
+ break;
+ }
}
}
memcpy (offsets, objfile->section_offsets,
SIZEOF_N_SECTION_OFFSETS (num_offsets));
- /* FIXME: Do we have to free a whole linked list, or is this
- enough? */
- objfile->global_psymbols.clear ();
- objfile->static_psymbols.clear ();
-
- /* Free the obstacks for non-reusable objfiles. */
- psymbol_bcache_free (objfile->psymbol_cache);
- objfile->psymbol_cache = psymbol_bcache_init ();
+ objfile->reset_psymtabs ();
/* NB: after this call to obstack_free, objfiles_changed
will need to be called (see discussion below). */
obstack_free (&objfile->objfile_obstack, 0);
objfile->sections = NULL;
objfile->compunit_symtabs = NULL;
- objfile->psymtabs = NULL;
- objfile->psymtabs_addrmap = NULL;
- objfile->free_psymtabs = NULL;
objfile->template_symbols = NULL;
+ objfile->static_links = NULL;
/* obstack_init also initializes the obstack so it is
empty. We could use obstack_specify_allocation but
}
(*objfile->sf->sym_init) (objfile);
- clear_complaints (1);
+ clear_complaints ();
objfile->flags &= ~OBJF_PSYMTABS_READ;
}
/* We're done reading the symbol file; finish off complaints. */
- clear_complaints (0);
+ clear_complaints ();
/* Getting new symbols may change our opinion about what is
frameless. */
static void
overlay_invalidate_all (void)
{
- struct objfile *objfile;
struct obj_section *sect;
- ALL_OBJSECTIONS (objfile, sect)
- if (section_is_overlay (sect))
- sect->ovly_mapped = -1;
+ for (objfile *objfile : current_program_space->objfiles ())
+ ALL_OBJFILE_OSECTIONS (objfile, sect)
+ if (section_is_overlay (sect))
+ sect->ovly_mapped = -1;
}
/* Function: section_is_mapped (SECTION)
struct obj_section *
find_pc_overlay (CORE_ADDR pc)
{
- struct objfile *objfile;
struct obj_section *osect, *best_match = NULL;
if (overlay_debugging)
{
- ALL_OBJSECTIONS (objfile, osect)
- if (section_is_overlay (osect))
- {
- if (pc_in_mapped_range (pc, osect))
- {
- if (section_is_mapped (osect))
- return osect;
- else
- best_match = osect;
- }
- else if (pc_in_unmapped_range (pc, osect))
- best_match = osect;
- }
+ for (objfile *objfile : current_program_space->objfiles ())
+ ALL_OBJFILE_OSECTIONS (objfile, osect)
+ if (section_is_overlay (osect))
+ {
+ if (pc_in_mapped_range (pc, osect))
+ {
+ if (section_is_mapped (osect))
+ return osect;
+ else
+ best_match = osect;
+ }
+ else if (pc_in_unmapped_range (pc, osect))
+ best_match = osect;
+ }
}
return best_match;
}
struct obj_section *
find_pc_mapped_section (CORE_ADDR pc)
{
- struct objfile *objfile;
struct obj_section *osect;
if (overlay_debugging)
{
- ALL_OBJSECTIONS (objfile, osect)
- if (pc_in_mapped_range (pc, osect) && section_is_mapped (osect))
- return osect;
+ for (objfile *objfile : current_program_space->objfiles ())
+ ALL_OBJFILE_OSECTIONS (objfile, osect)
+ if (pc_in_mapped_range (pc, osect) && section_is_mapped (osect))
+ return osect;
}
return NULL;
list_overlays_command (const char *args, int from_tty)
{
int nmapped = 0;
- struct objfile *objfile;
struct obj_section *osect;
if (overlay_debugging)
{
- ALL_OBJSECTIONS (objfile, osect)
- if (section_is_mapped (osect))
- {
- struct gdbarch *gdbarch = get_objfile_arch (objfile);
- const char *name;
- bfd_vma lma, vma;
- int size;
-
- vma = bfd_section_vma (objfile->obfd, osect->the_bfd_section);
- lma = bfd_section_lma (objfile->obfd, osect->the_bfd_section);
- size = bfd_get_section_size (osect->the_bfd_section);
- name = bfd_section_name (objfile->obfd, osect->the_bfd_section);
-
- printf_filtered ("Section %s, loaded at ", name);
- fputs_filtered (paddress (gdbarch, lma), gdb_stdout);
- puts_filtered (" - ");
- fputs_filtered (paddress (gdbarch, lma + size), gdb_stdout);
- printf_filtered (", mapped at ");
- fputs_filtered (paddress (gdbarch, vma), gdb_stdout);
- puts_filtered (" - ");
- fputs_filtered (paddress (gdbarch, vma + size), gdb_stdout);
- puts_filtered ("\n");
-
- nmapped++;
- }
+ for (objfile *objfile : current_program_space->objfiles ())
+ ALL_OBJFILE_OSECTIONS (objfile, osect)
+ if (section_is_mapped (osect))
+ {
+ struct gdbarch *gdbarch = get_objfile_arch (objfile);
+ const char *name;
+ bfd_vma lma, vma;
+ int size;
+
+ vma = bfd_section_vma (objfile->obfd, osect->the_bfd_section);
+ lma = bfd_section_lma (objfile->obfd, osect->the_bfd_section);
+ size = bfd_get_section_size (osect->the_bfd_section);
+ name = bfd_section_name (objfile->obfd, osect->the_bfd_section);
+
+ printf_filtered ("Section %s, loaded at ", name);
+ fputs_filtered (paddress (gdbarch, lma), gdb_stdout);
+ puts_filtered (" - ");
+ fputs_filtered (paddress (gdbarch, lma + size), gdb_stdout);
+ printf_filtered (", mapped at ");
+ fputs_filtered (paddress (gdbarch, vma), gdb_stdout);
+ puts_filtered (" - ");
+ fputs_filtered (paddress (gdbarch, vma + size), gdb_stdout);
+ puts_filtered ("\n");
+
+ nmapped++;
+ }
}
if (nmapped == 0)
printf_filtered (_("No sections are mapped.\n"));
static void
map_overlay_command (const char *args, int from_tty)
{
- struct objfile *objfile, *objfile2;
struct obj_section *sec, *sec2;
if (!overlay_debugging)
error (_("Argument required: name of an overlay section"));
/* First, find a section matching the user supplied argument. */
- ALL_OBJSECTIONS (objfile, sec)
- if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args))
- {
- /* Now, check to see if the section is an overlay. */
- if (!section_is_overlay (sec))
- continue; /* not an overlay section */
-
- /* Mark the overlay as "mapped". */
- sec->ovly_mapped = 1;
-
- /* Next, make a pass and unmap any sections that are
- overlapped by this new section: */
- ALL_OBJSECTIONS (objfile2, sec2)
- if (sec2->ovly_mapped && sec != sec2 && sections_overlap (sec, sec2))
+ for (objfile *obj_file : current_program_space->objfiles ())
+ ALL_OBJFILE_OSECTIONS (obj_file, sec)
+ if (!strcmp (bfd_section_name (obj_file->obfd, sec->the_bfd_section),
+ args))
{
- if (info_verbose)
- printf_unfiltered (_("Note: section %s unmapped by overlap\n"),
- bfd_section_name (objfile->obfd,
- sec2->the_bfd_section));
- sec2->ovly_mapped = 0; /* sec2 overlaps sec: unmap sec2. */
+ /* Now, check to see if the section is an overlay. */
+ if (!section_is_overlay (sec))
+ continue; /* not an overlay section */
+
+ /* Mark the overlay as "mapped". */
+ sec->ovly_mapped = 1;
+
+ /* Next, make a pass and unmap any sections that are
+ overlapped by this new section: */
+ for (objfile *objfile2 : current_program_space->objfiles ())
+ ALL_OBJFILE_OSECTIONS (objfile2, sec2)
+ if (sec2->ovly_mapped && sec != sec2 && sections_overlap (sec,
+ sec2))
+ {
+ if (info_verbose)
+ printf_unfiltered (_("Note: section %s unmapped by overlap\n"),
+ bfd_section_name (obj_file->obfd,
+ sec2->the_bfd_section));
+ sec2->ovly_mapped = 0; /* sec2 overlaps sec: unmap sec2. */
+ }
+ return;
}
- return;
- }
error (_("No overlay section called %s"), args);
}
static void
unmap_overlay_command (const char *args, int from_tty)
{
- struct objfile *objfile;
struct obj_section *sec = NULL;
if (!overlay_debugging)
error (_("Argument required: name of an overlay section"));
/* First, find a section matching the user supplied argument. */
- ALL_OBJSECTIONS (objfile, sec)
- if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args))
- {
- if (!sec->ovly_mapped)
- error (_("Section %s is not mapped"), args);
- sec->ovly_mapped = 0;
- return;
- }
+ for (objfile *objfile : current_program_space->objfiles ())
+ ALL_OBJFILE_OSECTIONS (objfile, sec)
+ if (!strcmp (bfd_section_name (objfile->obfd, sec->the_bfd_section), args))
+ {
+ if (!sec->ovly_mapped)
+ error (_("Section %s is not mapped"), args);
+ sec->ovly_mapped = 0;
+ return;
+ }
error (_("No overlay section called %s"), args);
}
void
simple_overlay_update (struct obj_section *osect)
{
- struct objfile *objfile;
-
/* Were we given an osect to look up? NULL means do all of them. */
if (osect)
/* Have we got a cached copy of the target's overlay table? */
return;
/* Now may as well update all sections, even if only one was requested. */
- ALL_OBJSECTIONS (objfile, osect)
- if (section_is_overlay (osect))
- {
- int i;
- asection *bsect = osect->the_bfd_section;
-
- for (i = 0; i < cache_novlys; i++)
- if (cache_ovly_table[i][VMA] == bfd_section_vma (obfd, bsect)
- && cache_ovly_table[i][LMA] == bfd_section_lma (obfd, bsect))
- { /* obj_section matches i'th entry in ovly_table. */
- osect->ovly_mapped = cache_ovly_table[i][MAPPED];
- break; /* finished with inner for loop: break out. */
- }
- }
+ for (objfile *objfile : current_program_space->objfiles ())
+ ALL_OBJFILE_OSECTIONS (objfile, osect)
+ if (section_is_overlay (osect))
+ {
+ int i;
+ asection *bsect = osect->the_bfd_section;
+
+ for (i = 0; i < cache_novlys; i++)
+ if (cache_ovly_table[i][VMA] == bfd_section_vma (obfd, bsect)
+ && cache_ovly_table[i][LMA] == bfd_section_lma (obfd, bsect))
+ { /* obj_section matches i'th entry in ovly_table. */
+ osect->ovly_mapped = cache_ovly_table[i][MAPPED];
+ break; /* finished with inner for loop: break out. */
+ }
+ }
}
/* Set the output sections and output offsets for section SECTP in
gdb::function_view<expand_symtabs_exp_notify_ftype> expansion_notify,
enum search_domain kind)
{
- struct objfile *objfile;
-
- ALL_OBJFILES (objfile)
- {
- if (objfile->sf)
- objfile->sf->qf->expand_symtabs_matching (objfile, file_matcher,
- lookup_name,
- symbol_matcher,
- expansion_notify, kind);
- }
+ for (objfile *objfile : current_program_space->objfiles ())
+ {
+ if (objfile->sf)
+ objfile->sf->qf->expand_symtabs_matching (objfile, file_matcher,
+ lookup_name,
+ symbol_matcher,
+ expansion_notify, kind);
+ }
}
/* Wrapper around the quick_symbol_functions map_symbol_filenames "method".
map_symbol_filenames (symbol_filename_ftype *fun, void *data,
int need_fullname)
{
- struct objfile *objfile;
-
- ALL_OBJFILES (objfile)
- {
- if (objfile->sf)
- objfile->sf->qf->map_symbol_filenames (objfile, fun, data,
- need_fullname);
- }
+ for (objfile *objfile : current_program_space->objfiles ())
+ {
+ if (objfile->sf)
+ objfile->sf->qf->map_symbol_filenames (objfile, fun, data,
+ need_fullname);
+ }
}
#if GDB_SELF_TEST