/* GDB routines for manipulating objfiles.
- Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003, 2004, 2007, 2008, 2009, 2010, 2011
- Free Software Foundation, Inc.
+ Copyright (C) 1992-2004, 2007-2012 Free Software Foundation, Inc.
Contributed by Cygnus Support, using pieces from other GDB modules.
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* This file contains support routines for creating, manipulating, and
- destroying objfile structures. */
+ destroying objfile structures. */
#include "defs.h"
#include "bfd.h" /* Binary File Description */
static void objfile_free_data (struct objfile *objfile);
/* Externally visible variables that are owned by this module.
- See declarations in objfile.h for more info. */
+ See declarations in objfile.h for more info. */
-struct objfile *current_objfile; /* For symbol file being read in */
struct objfile *rt_common_objfile; /* For runtime common symbols */
struct objfile_pspace_info
return info;
}
-/* Records whether any objfiles appeared or disappeared since we last updated
- address to obj section map. */
-
-/* Locate all mappable sections of a BFD file.
- objfile_p_char is a char * to get it through
- bfd_map_over_sections; we cast it back to its proper type. */
-
/* Called via bfd_map_over_sections to build up the section table that
the objfile references. The objfile contains pointers to the start
of the table (objfile->sections) and to the first location after
- the end of the table (objfile->sections_end). */
+ the end of the table (objfile->sections_end). */
static void
add_to_objfile_sections (struct bfd *abfd, struct bfd_section *asect,
- void *objfile_p_char)
+ void *objfilep)
{
- struct objfile *objfile = (struct objfile *) objfile_p_char;
+ struct objfile *objfile = (struct objfile *) objfilep;
struct obj_section section;
flagword aflag;
aflag = bfd_get_section_flags (abfd, asect);
-
if (!(aflag & SEC_ALLOC))
return;
-
- if (0 == bfd_section_size (abfd, asect))
+ if (bfd_section_size (abfd, asect) == 0)
return;
+
section.objfile = objfile;
section.the_bfd_section = asect;
section.ovly_mapped = 0;
}
/* Builds a section table for OBJFILE.
- Returns 0 if OK, 1 on error (in which case bfd_error contains the
- error).
Note that while we are building the table, which goes into the
- psymbol obstack, we hijack the sections_end pointer to instead hold
+ objfile obstack, we hijack the sections_end pointer to instead hold
a count of the number of sections. When bfd_map_over_sections
returns, this count is used to compute the pointer to the end of
the sections table, which then overwrites the count.
Also note that the OFFSET and OVLY_MAPPED in each table entry
are initialized to zero.
- Also note that if anything else writes to the psymbol obstack while
- we are building the table, we're pretty much hosed. */
+ Also note that if anything else writes to the objfile obstack while
+ we are building the table, we're pretty much hosed. */
-int
+void
build_objfile_section_table (struct objfile *objfile)
{
- /* objfile->sections can be already set when reading a mapped symbol
- file. I believe that we do need to rebuild the section table in
- this case (we rebuild other things derived from the bfd), but we
- can't free the old one (it's in the objfile_obstack). So we just
- waste some memory. */
-
objfile->sections_end = 0;
bfd_map_over_sections (objfile->obfd,
add_to_objfile_sections, (void *) objfile);
objfile->sections = obstack_finish (&objfile->objfile_obstack);
objfile->sections_end = objfile->sections + (size_t) objfile->sections_end;
- return (0);
}
/* Given a pointer to an initialized bfd (ABFD) and some flag bits
The FLAGS word contains various bits (OBJF_*) that can be taken as
requests for specific operations. Other bits like OBJF_SHARED are
- simply copied through to the new objfile flags member. */
+ simply copied through to the new objfile flags member. */
/* NOTE: carlton/2003-02-04: This function is called with args NULL, 0
by jv-lang.c, to create an artificial objfile used to hold
/* Update the per-objfile information that comes from the bfd, ensuring
that any data that is reference is saved in the per-objfile data
- region. */
+ region. */
objfile->obfd = gdb_bfd_ref (abfd);
if (abfd != NULL)
objfile->mtime = bfd_get_mtime (abfd);
/* Build section table. */
-
- if (build_objfile_section_table (objfile))
- {
- error (_("Can't find the file sections in `%s': %s"),
- objfile->name, bfd_errmsg (bfd_get_error ()));
- }
+ build_objfile_section_table (objfile);
}
else
{
objfile->pspace = current_program_space;
/* Initialize the section indexes for this objfile, so that we can
- later detect if they are used w/o being properly assigned to. */
+ later detect if they are used w/o being properly assigned to. */
objfile->sect_index_text = -1;
objfile->sect_index_data = -1;
objfile->sect_index_bss = -1;
objfile->sect_index_rodata = -1;
- /* We don't yet have a C++-specific namespace symtab. */
-
- objfile->cp_namespace_symtab = NULL;
-
- /* Add this file onto the tail of the linked list of other such files. */
+ /* Add this file onto the tail of the linked list of other such files. */
objfile->next = NULL;
if (object_files == NULL)
last_one->next = objfile;
}
- /* Save passed in flag bits. */
+ /* Save passed in flag bits. */
objfile->flags |= flags;
/* Rebuild section map next time we need it. */
return objfile->gdbarch;
}
-/* Initialize entry point information for this objfile. */
+/* Initialize entry point information for this objfile. */
void
init_entry_point_info (struct objfile *objfile)
return retval;
}
-/* Create the terminating entry of OBJFILE's minimal symbol table.
- If OBJFILE->msymbols is zero, allocate a single entry from
- OBJFILE->objfile_obstack; otherwise, just initialize
- OBJFILE->msymbols[OBJFILE->minimal_symbol_count]. */
-void
-terminate_minimal_symbol_table (struct objfile *objfile)
-{
- if (! objfile->msymbols)
- objfile->msymbols = ((struct minimal_symbol *)
- obstack_alloc (&objfile->objfile_obstack,
- sizeof (objfile->msymbols[0])));
-
- {
- struct minimal_symbol *m
- = &objfile->msymbols[objfile->minimal_symbol_count];
-
- memset (m, 0, sizeof (*m));
- /* Don't rely on these enumeration values being 0's. */
- MSYMBOL_TYPE (m) = mst_unknown;
- SYMBOL_SET_LANGUAGE (m, language_unknown);
- }
-}
-
/* Iterator on PARENT and every separate debug objfile of PARENT.
The usage pattern is:
for (objfile = parent;
/* Put one object file before a specified on in the global list.
This can be used to make sure an object file is destroyed before
- another when using ALL_OBJFILES_SAFE to free all objfiles. */
+ another when using ALL_OBJFILES_SAFE to free all objfiles. */
void
put_objfile_before (struct objfile *objfile, struct objfile *before_this)
{
If OBJFILE turns out to be in the list, we zap it's NEXT pointer after
unlinking it, just to ensure that we have completely severed any linkages
- between the OBJFILE and the list. */
+ between the OBJFILE and the list. */
void
unlink_objfile (struct objfile *objfile)
parent->separate_debug_objfile = objfile;
/* Put the separate debug object before the normal one, this is so that
- usage of the ALL_OBJFILES_SAFE macro will stay safe. */
+ usage of the ALL_OBJFILES_SAFE macro will stay safe. */
put_objfile_before (objfile, parent);
}
may be using the symbol information at the same time (when mmalloc is
extended to support cooperative locking). When more than one process
is using the mapped symbol info, we need to be more careful about when
- we free objects in the reusable area. */
+ we free objects in the reusable area. */
void
free_objfile (struct objfile *objfile)
lists. */
preserve_values (objfile);
+ /* It still may reference data modules have associated with the objfile and
+ the symbol file data. */
+ forget_cached_source_info_for_objfile (objfile);
+
/* First do any symbol file specific actions required when we are
finished with a particular symbol file. Note that if the objfile
is using reusable symbol information (via mmalloc) then each of
these routines is responsible for doing the correct thing, either
freeing things which are valid only during this particular gdb
- execution, or leaving them to be reused during the next one. */
+ execution, or leaving them to be reused during the next one. */
if (objfile->sf != NULL)
{
(*objfile->sf->sym_finish) (objfile);
}
- /* Discard any data modules have associated with the objfile. */
+ /* Discard any data modules have associated with the objfile. The function
+ still may reference objfile->obfd. */
objfile_free_data (objfile);
gdb_bfd_unref (objfile->obfd);
- /* Remove it from the chain of all objfiles. */
+ /* Remove it from the chain of all objfiles. */
unlink_objfile (objfile);
linkage unit, gdb used to do these things whenever the monolithic
symbol table was blown away. How much still needs to be done
is unknown, but we play it safe for now and keep each action until
- it is shown to be no longer needed. */
+ it is shown to be no longer needed. */
/* Not all our callers call clear_symtab_users (objfile_purge_solibs,
for example), so we need to call this here. */
innermost_block = NULL;
/* Check to see if the current_source_symtab belongs to this objfile,
- and if so, call clear_current_source_symtab_and_line. */
+ and if so, call clear_current_source_symtab_and_line. */
{
struct symtab_and_line cursal = get_current_source_symtab_and_line ();
- struct symtab *s;
- ALL_OBJFILE_SYMTABS (objfile, s)
- {
- if (s == cursal.symtab)
- clear_current_source_symtab_and_line ();
- }
+ if (cursal.symtab && cursal.symtab->objfile == objfile)
+ clear_current_source_symtab_and_line ();
}
- /* The last thing we do is free the objfile struct itself. */
+ /* The last thing we do is free the objfile struct itself. */
xfree (objfile->name);
if (objfile->global_psymbols.list)
xfree (objfile->global_psymbols.list);
if (objfile->static_psymbols.list)
xfree (objfile->static_psymbols.list);
- /* Free the obstacks for non-reusable objfiles */
+ /* Free the obstacks for non-reusable objfiles. */
psymbol_bcache_free (objfile->psymbol_cache);
bcache_xfree (objfile->macro_cache);
bcache_xfree (objfile->filename_cache);
obj_section_addr (s));
}
+ /* Relocating probes. */
+ if (objfile->sf && objfile->sf->sym_probe_fns)
+ objfile->sf->sym_probe_fns->sym_relocate_probe (objfile,
+ new_offsets, delta);
+
/* Data changed. */
return 1;
}
do_cleanups (my_cleanups);
}
- /* Relocate breakpoints as necessary, after things are relocated. */
+ /* Relocate breakpoints as necessary, after things are relocated. */
if (changed)
breakpoint_re_set ();
}
int
objfile_has_partial_symbols (struct objfile *objfile)
{
- return objfile->sf ? objfile->sf->qf->has_symbols (objfile) : 0;
+ if (!objfile->sf)
+ return 0;
+
+ /* If we have not read psymbols, but we have a function capable of reading
+ them, then that is an indication that they are in fact available. Without
+ this function the symbols may have been already read in but they also may
+ not be present in this objfile. */
+ if ((objfile->flags & OBJF_PSYMTABS_READ) == 0
+ && objfile->sf->sym_read_psymbols != NULL)
+ return 1;
+
+ return objfile->sf->qf->has_symbols (objfile);
}
/* Return non-zero if OBJFILE has full symbols. */
/* Many places in gdb want to test just to see if we have any partial
symbols available. This function returns zero if none are currently
- available, nonzero otherwise. */
+ available, nonzero otherwise. */
int
have_partial_symbols (void)
/* Many places in gdb want to test just to see if we have any full
symbols available. This function returns zero if none are currently
- available, nonzero otherwise. */
+ available, nonzero otherwise. */
int
have_full_symbols (void)
/* This operations deletes all objfile entries that represent solibs that
weren't explicitly loaded by the user, via e.g., the add-symbol-file
- command.
- */
+ command. */
+
void
objfile_purge_solibs (void)
{
ALL_OBJFILES_SAFE (objf, temp)
{
/* We assume that the solib package has been purged already, or will
- be soon.
- */
+ be soon. */
+
if (!(objf->flags & OBJF_USERLOADED) && (objf->flags & OBJF_SHARED))
free_objfile (objf);
}
/* Many places in gdb want to test just to see if we have any minimal
symbols available. This function returns zero if none are currently
- available, nonzero otherwise. */
+ available, nonzero otherwise. */
int
have_minimal_symbols (void)
/* Sections are at the same address. This could happen if
A) we have an objfile and a separate debuginfo.
B) we are confused, and have added sections without proper relocation,
- or something like that. */
+ or something like that. */
const struct objfile *const objfile1 = sect1->objfile;
const struct objfile *const objfile2 = sect2->objfile;
{
const bfd_vma lma = bfd_section_lma (abfd, section);
- if (lma != 0 && lma != bfd_section_vma (abfd, section)
+ if (overlay_debugging && lma != 0 && lma != bfd_section_vma (abfd, section)
&& (bfd_get_file_flags (abfd) & BFD_IN_MEMORY) == 0)
/* This is an overlay section. IN_MEMORY check is needed to avoid
discarding sections from the "system supplied DSO" (aka vdso)
*pmap_size = map_size;
}
-/* Bsearch comparison function. */
+/* Bsearch comparison function. */
static int
bsearch_cmp (const void *key, const void *elt)