#include "reggroups.h"
#include "osabi.h"
#include "symfile.h" /* For entry_point_address. */
+#include "gdb_obstack.h"
/* Static function declarations */
static void verify_gdbarch (struct gdbarch *gdbarch);
static void alloc_gdbarch_data (struct gdbarch *);
-static void free_gdbarch_data (struct gdbarch *);
static void init_gdbarch_swap (struct gdbarch *);
static void clear_gdbarch_swap (struct gdbarch *);
static void swapout_gdbarch_swap (struct gdbarch *);
{
/* Has this architecture been fully initialized? */
int initialized_p;
+
+ /* An obstack bound to the lifetime of the architecture. */
+ struct obstack *obstack;
+
/* basic architectural information */
const struct bfd_arch_info * bfd_arch_info;
int byte_order;
gdbarch_sigtramp_end_ftype *sigtramp_end;
gdbarch_in_function_epilogue_p_ftype *in_function_epilogue_p;
gdbarch_construct_inferior_arguments_ftype *construct_inferior_arguments;
- gdbarch_dwarf2_build_frame_info_ftype *dwarf2_build_frame_info;
gdbarch_elf_make_msymbol_special_ftype *elf_make_msymbol_special;
gdbarch_coff_make_msymbol_special_ftype *coff_make_msymbol_special;
const char * name_of_malloc;
struct gdbarch startup_gdbarch =
{
1, /* Always initialized. */
+ NULL, /* The obstack. */
/* basic architecture information */
&bfd_default_arch_struct, /* bfd_arch_info */
BFD_ENDIAN_BIG, /* byte_order */
0, /* sigtramp_end */
generic_in_function_epilogue_p, /* in_function_epilogue_p */
construct_inferior_arguments, /* construct_inferior_arguments */
- 0, /* dwarf2_build_frame_info */
0, /* elf_make_msymbol_special */
0, /* coff_make_msymbol_special */
"malloc", /* name_of_malloc */
architecture. This ensures that the new architectures initial
values are not influenced by the previous architecture. Once
everything is parameterised with gdbarch, this will go away. */
- struct gdbarch *current_gdbarch = XMALLOC (struct gdbarch);
+ struct gdbarch *current_gdbarch;
+
+ /* Create an obstack for allocating all the per-architecture memory,
+ then use that to allocate the architecture vector. */
+ struct obstack *obstack = XMALLOC (struct obstack);
+ obstack_init (obstack);
+ current_gdbarch = obstack_alloc (obstack, sizeof (*current_gdbarch));
memset (current_gdbarch, 0, sizeof (*current_gdbarch));
+ current_gdbarch->obstack = obstack;
alloc_gdbarch_data (current_gdbarch);
}
+/* Allocate extra space using the per-architecture obstack. */
+
+void *
+gdbarch_obstack_zalloc (struct gdbarch *arch, long size)
+{
+ void *data = obstack_alloc (arch->obstack, size);
+ memset (data, 0, size);
+ return data;
+}
+
+
/* Free a gdbarch struct. This should never happen in normal
operation --- once you've created a gdbarch, you keep it around.
However, if an architecture's init function encounters an error
void
gdbarch_free (struct gdbarch *arch)
{
+ struct obstack *obstack;
gdb_assert (arch != NULL);
- free_gdbarch_data (arch);
- xfree (arch);
+ gdb_assert (!arch->initialized_p);
+ obstack = arch->obstack;
+ obstack_free (obstack, 0); /* Includes the ARCH. */
+ xfree (obstack);
}
/* Skip verify of sigtramp_end, has predicate */
/* Skip verify of in_function_epilogue_p, invalid_p == 0 */
/* Skip verify of construct_inferior_arguments, invalid_p == 0 */
- /* Skip verify of dwarf2_build_frame_info, has predicate */
/* Skip verify of elf_make_msymbol_special, invalid_p == 0 */
/* Skip verify of coff_make_msymbol_special, invalid_p == 0 */
/* Skip verify of name_of_malloc, invalid_p == 0 */
"gdbarch_dump: DEPRECATED_USE_GENERIC_DUMMY_FRAMES = %d\n",
DEPRECATED_USE_GENERIC_DUMMY_FRAMES);
#endif
-#ifdef DWARF2_BUILD_FRAME_INFO_P
- fprintf_unfiltered (file,
- "gdbarch_dump: %s # %s\n",
- "DWARF2_BUILD_FRAME_INFO_P()",
- XSTRING (DWARF2_BUILD_FRAME_INFO_P ()));
- fprintf_unfiltered (file,
- "gdbarch_dump: DWARF2_BUILD_FRAME_INFO_P() = %d\n",
- DWARF2_BUILD_FRAME_INFO_P ());
-#endif
-#ifdef DWARF2_BUILD_FRAME_INFO
-#if GDB_MULTI_ARCH
- /* Macro might contain `[{}]' when not multi-arch */
- fprintf_unfiltered (file,
- "gdbarch_dump: %s # %s\n",
- "DWARF2_BUILD_FRAME_INFO(objfile)",
- XSTRING (DWARF2_BUILD_FRAME_INFO (objfile)));
-#endif
- if (GDB_MULTI_ARCH)
- fprintf_unfiltered (file,
- "gdbarch_dump: DWARF2_BUILD_FRAME_INFO = <0x%08lx>\n",
- (long) current_gdbarch->dwarf2_build_frame_info
- /*DWARF2_BUILD_FRAME_INFO ()*/);
-#endif
#ifdef DWARF2_REG_TO_REGNUM
fprintf_unfiltered (file,
"gdbarch_dump: %s # %s\n",
gdbarch->construct_inferior_arguments = construct_inferior_arguments;
}
-int
-gdbarch_dwarf2_build_frame_info_p (struct gdbarch *gdbarch)
-{
- gdb_assert (gdbarch != NULL);
- return gdbarch->dwarf2_build_frame_info != NULL;
-}
-
-void
-gdbarch_dwarf2_build_frame_info (struct gdbarch *gdbarch, struct objfile *objfile)
-{
- gdb_assert (gdbarch != NULL);
- gdb_assert (gdbarch->dwarf2_build_frame_info != NULL);
- if (gdbarch_debug >= 2)
- fprintf_unfiltered (gdb_stdlog, "gdbarch_dwarf2_build_frame_info called\n");
- gdbarch->dwarf2_build_frame_info (objfile);
-}
-
-void
-set_gdbarch_dwarf2_build_frame_info (struct gdbarch *gdbarch,
- gdbarch_dwarf2_build_frame_info_ftype dwarf2_build_frame_info)
-{
- gdbarch->dwarf2_build_frame_info = dwarf2_build_frame_info;
-}
-
void
gdbarch_elf_make_msymbol_special (struct gdbarch *gdbarch, asymbol *sym, struct minimal_symbol *msym)
{
unsigned index;
int init_p;
gdbarch_data_init_ftype *init;
- gdbarch_data_free_ftype *free;
};
struct gdbarch_data_registration
(*curr)->data->index = gdbarch_data_registry.nr++;
(*curr)->data->init = init;
(*curr)->data->init_p = 1;
- (*curr)->data->free = free;
return (*curr)->data;
}
{
gdb_assert (gdbarch->data == NULL);
gdbarch->nr_data = gdbarch_data_registry.nr;
- gdbarch->data = xcalloc (gdbarch->nr_data, sizeof (void*));
+ gdbarch->data = GDBARCH_OBSTACK_CALLOC (gdbarch, gdbarch->nr_data, void *);
}
-static void
-free_gdbarch_data (struct gdbarch *gdbarch)
-{
- struct gdbarch_data_registration *rego;
- gdb_assert (gdbarch->data != NULL);
- for (rego = gdbarch_data_registry.registrations;
- rego != NULL;
- rego = rego->next)
- {
- struct gdbarch_data *data = rego->data;
- gdb_assert (data->index < gdbarch->nr_data);
- if (data->free != NULL && gdbarch->data[data->index] != NULL)
- {
- data->free (gdbarch, gdbarch->data[data->index]);
- gdbarch->data[data->index] = NULL;
- }
- }
- xfree (gdbarch->data);
- gdbarch->data = NULL;
-}
-
-
/* Initialize the current value of the specified per-architecture
data-pointer. */
void *pointer)
{
gdb_assert (data->index < gdbarch->nr_data);
- if (gdbarch->data[data->index] != NULL)
- {
- gdb_assert (data->free != NULL);
- data->free (gdbarch, gdbarch->data[data->index]);
- }
+ gdb_assert (gdbarch->data[data->index] == NULL);
gdbarch->data[data->index] = pointer;
}
{
if (rego->data != NULL)
{
- (*curr) = XMALLOC (struct gdbarch_swap);
+ (*curr) = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct gdbarch_swap);
(*curr)->source = rego;
- (*curr)->swap = xmalloc (rego->sizeof_data);
+ (*curr)->swap = gdbarch_obstack_zalloc (gdbarch, rego->sizeof_data);
(*curr)->next = NULL;
curr = &(*curr)->next;
}