/* GDB routines for manipulating objfiles.
Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003, 2004, 2007 Free Software Foundation, Inc.
+ 2002, 2003, 2004, 2007, 2008 Free Software Foundation, Inc.
Contributed by Cygnus Support, using pieces from other GDB modules.
#include "block.h"
#include "dictionary.h"
#include "source.h"
+#include "addrmap.h"
+#include "arch-utils.h"
+#include "exec.h"
/* Prototypes for local functions */
}
if (abfd != NULL)
{
+ /* Look up the gdbarch associated with the BFD. */
+ objfile->gdbarch = gdbarch_from_bfd (abfd);
+
objfile->name = xstrdup (bfd_get_filename (abfd));
objfile->mtime = bfd_get_mtime (abfd);
return (objfile);
}
+/* Retrieve the gdbarch associated with OBJFILE. */
+struct gdbarch *
+get_objfile_arch (struct objfile *objfile)
+{
+ return objfile->gdbarch;
+}
+
/* Initialize entry point information for this objfile. */
void
the startup file because it contains the entry point. */
objfile->ei.entry_point = bfd_get_start_address (objfile->obfd);
}
+ else if (bfd_get_file_flags (objfile->obfd) & DYNAMIC
+ && bfd_get_start_address (objfile->obfd) != 0)
+ /* Some shared libraries may have entry points set and be
+ runnable. There's no clear way to indicate this, so just check
+ for values other than zero. */
+ objfile->ei.entry_point = bfd_get_start_address (objfile->obfd);
else
{
/* Examination of non-executable.o files. Short-circuit this stuff. */
void
objfile_relocate (struct objfile *objfile, struct section_offsets *new_offsets)
{
+ struct obj_section *s;
struct section_offsets *delta =
((struct section_offsets *)
alloca (SIZEOF_N_SECTION_OFFSETS (objfile->num_sections)));
b = BLOCKVECTOR_BLOCK (bv, i);
BLOCK_START (b) += ANOFFSET (delta, s->block_line_section);
BLOCK_END (b) += ANOFFSET (delta, s->block_line_section);
+ if (BLOCKVECTOR_MAP (bv))
+ addrmap_relocate (BLOCKVECTOR_MAP (bv),
+ ANOFFSET (delta, s->block_line_section));
ALL_BLOCK_SYMBOLS (b, iter, sym)
{
But I'm leaving out that test, on the theory that
they can't possibly pass the tests below. */
if ((SYMBOL_CLASS (sym) == LOC_LABEL
- || SYMBOL_CLASS (sym) == LOC_STATIC
- || SYMBOL_CLASS (sym) == LOC_INDIRECT)
+ || SYMBOL_CLASS (sym) == LOC_STATIC)
&& SYMBOL_SECTION (sym) >= 0)
{
SYMBOL_VALUE_ADDRESS (sym) +=
}
}
+ /* Update the table in exec_ops, used to read memory. */
+ ALL_OBJFILE_OSECTIONS (objfile, s)
+ {
+ int idx = s->the_bfd_section->index;
+
+ exec_set_section_address (bfd_get_filename (objfile->obfd), idx,
+ s->addr);
+ }
+
/* Relocate breakpoints as necessary, after things are relocated. */
breakpoint_re_set ();
}
struct objfile_data
{
unsigned index;
+ void (*cleanup) (struct objfile *, void *);
};
struct objfile_data_registration
static struct objfile_data_registry objfile_data_registry = { NULL, 0 };
const struct objfile_data *
-register_objfile_data (void)
+register_objfile_data_with_cleanup (void (*cleanup) (struct objfile *, void *))
{
struct objfile_data_registration **curr;
(*curr)->next = NULL;
(*curr)->data = XMALLOC (struct objfile_data);
(*curr)->data->index = objfile_data_registry.num_registrations++;
+ (*curr)->data->cleanup = cleanup;
return (*curr)->data;
}
+const struct objfile_data *
+register_objfile_data (void)
+{
+ return register_objfile_data_with_cleanup (NULL);
+}
+
static void
objfile_alloc_data (struct objfile *objfile)
{
objfile_free_data (struct objfile *objfile)
{
gdb_assert (objfile->data != NULL);
+ clear_objfile_data (objfile);
xfree (objfile->data);
objfile->data = NULL;
}
void
clear_objfile_data (struct objfile *objfile)
{
+ struct objfile_data_registration *registration;
+ int i;
+
gdb_assert (objfile->data != NULL);
+
+ for (registration = objfile_data_registry.registrations, i = 0;
+ i < objfile->num_data;
+ registration = registration->next, i++)
+ if (objfile->data[i] != NULL && registration->data->cleanup)
+ registration->data->cleanup (objfile, objfile->data[i]);
+
memset (objfile->data, 0, objfile->num_data * sizeof (void *));
}