This page was produced by an automated import process, and may have formatting errors; feel free to fix.

Per-architecture module data

The multi-arch framework includes a mechanism for adding module specific per-architecture data-pointers to the struct gdbarch architecture object.

A module registers one or more per-architecture data-pointers using:

Architecture Function: ''struct gdbarch_data *'' gdbarch_data_register_pre_init ''(gdbarch_data_pre_init_ftype *''pre_init'')''

pre_init is used to, on-demand, allocate an initial value for a per-architecture data-pointer using the architecture’s obstack (passed in as a parameter). Since pre_init can be called during architecture creation, it is not parameterized with the architecture. and must not call modules that use per-architecture data.

Architecture Function: ''struct gdbarch_data *'' gdbarch_data_register_post_init ''(gdbarch_data_post_init_ftype *''post_init'')''

post_init is used to obtain an initial value for a per-architecture data-pointer after. Since post_init is always called after architecture creation, it both receives the fully initialized architecture and is free to call modules that use per-architecture data (care needs to be taken to ensure that those other modules do not try to call back to this module as that will create in cycles in the initialization call graph).

These functions return a struct gdbarch_data that is used to identify the per-architecture data-pointer added for that module.

The per-architecture data-pointer is accessed using the function:

Architecture Function: ''void *'' gdbarch_data ''(struct gdbarch *''gdbarch'', struct gdbarch_data *''data_handle'')''

Given the architecture arch and module data handle data_handle (returned by gdbarch_data_register_pre_init or gdbarch_data_register_post_init), this function returns the current value of the per-architecture data-pointer. If the data pointer is NULL, it is first initialized by calling the corresponding pre_init or post_init method.

The examples below assume the following definitions:

struct nozel { int total; };
static struct gdbarch_data *nozel_handle;

A module can extend the architecture vector, adding additional per-architecture data, using the pre_init method. The module’s per-architecture data is then initialized during architecture creation.

In the below, the module’s per-architecture nozel is added. An architecture can specify its nozel by calling set_gdbarch_nozel from gdbarch_init.

static void *
nozel_pre_init (struct obstack *obstack)
{
  struct nozel *data = OBSTACK_ZALLOC (obstack, struct nozel);
  return data;
}

extern void
set_gdbarch_nozel (struct gdbarch *gdbarch, int total)
{
  struct nozel *data = gdbarch_data (gdbarch, nozel_handle);
  data->total = nozel;
}

A module can on-demand create architecture dependent data structures using post_init.

In the below, the nozel’s total is computed on-demand by nozel_post_init using information obtained from the architecture.

static void *
nozel_post_init (struct gdbarch *gdbarch)
{
  struct nozel *data = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct nozel);
  nozel->total = gdbarch… (gdbarch);
  return data;
}

extern int
nozel_total (struct gdbarch *gdbarch)
{
  struct nozel *data = gdbarch_data (gdbarch, nozel_handle);
  return data->total;
}

None: Internals Per_002darchitecture-module-data (last edited 2013-08-20 23:41:09 by StanShebs)

All content (C) 2008 Free Software Foundation. For terms of use, redistribution, and modification, please see the WikiLicense page.