RFA: relax restrictions on per-architecture data registration
Jim Blandy
jimb@zwingli.cygnus.com
Fri Jun 1 16:31:00 GMT 2001
This is supposed to fix G++ V3 on non-multiarch targets. Not sure
this is right yet, just posting for the curious.
2001-06-01 Jim Blandy <jimb@redhat.com>
Expand the gdbarch per-architecture data vector as needed, rather
than requiring that all per-architecture data be registered before
the first gdbarch object is allocated.
* gdbarch.sh: Changes to effect the following:
* gdbarch.c (alloc_gdbarch_data, init_gdbarch_data): Delete
declarations and definitions.
(check_gdbarch_data): New function, and declaration.
(gdbarch_alloc): Don't call alloc_gdbarch_data; leaving the fields
zero is good enough.
(free_gdbarch_data): Tolerate a null data pointer. Free only
those data items gdbarch->data actually has allocated.
(set_gdbarch_data, gdbarch_data): Call check_gdbarch_data.
(gdbarch_update_p): No need to call init_gdbarch_data.
Index: gdb/gdbarch.sh
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.sh,v
retrieving revision 1.62
diff -c -r1.62 gdbarch.sh
*** gdb/gdbarch.sh 2001/05/14 16:43:35 1.62
--- gdb/gdbarch.sh 2001/06/01 23:29:14
***************
*** 1118,1125 ****
/* Static function declarations */
static void verify_gdbarch (struct gdbarch *gdbarch);
! static void alloc_gdbarch_data (struct gdbarch *);
! static void init_gdbarch_data (struct gdbarch *);
static void free_gdbarch_data (struct gdbarch *);
static void init_gdbarch_swap (struct gdbarch *);
static void swapout_gdbarch_swap (struct gdbarch *);
--- 1118,1124 ----
/* Static function declarations */
static void verify_gdbarch (struct gdbarch *gdbarch);
! static void check_gdbarch_data (struct gdbarch *);
static void free_gdbarch_data (struct gdbarch *);
static void init_gdbarch_swap (struct gdbarch *);
static void swapout_gdbarch_swap (struct gdbarch *);
***************
*** 1264,1271 ****
struct gdbarch *gdbarch = XMALLOC (struct gdbarch);
memset (gdbarch, 0, sizeof (*gdbarch));
- alloc_gdbarch_data (gdbarch);
-
gdbarch->tdep = tdep;
EOF
printf "\n"
--- 1263,1268 ----
***************
*** 1631,1696 ****
}
! /* Walk through all the registered users initializing each in turn. */
static void
! init_gdbarch_data (struct gdbarch *gdbarch)
{
! struct gdbarch_data_registration *rego;
! 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->init != NULL)
{
! void *pointer = data->init (gdbarch);
! set_gdbarch_data (gdbarch, data, pointer);
}
}
}
- /* Create/delete the gdbarch data vector. */
static void
! alloc_gdbarch_data (struct gdbarch *gdbarch)
{
! gdb_assert (gdbarch->data == NULL);
! gdbarch->nr_data = gdbarch_data_registry.nr;
! gdbarch->data = xcalloc (gdbarch->nr_data, sizeof (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 thee specified per-architecture
- data-pointer. */
-
void
set_gdbarch_data (struct gdbarch *gdbarch,
struct gdbarch_data *data,
void *pointer)
{
gdb_assert (data->index < gdbarch->nr_data);
if (data->free != NULL && gdbarch->data[data->index] != NULL)
data->free (gdbarch, gdbarch->data[data->index]);
--- 1628,1708 ----
}
! /* Delete GDBARCH's data vector. */
static void
! free_gdbarch_data (struct gdbarch *gdbarch)
{
! if (gdbarch->data != NULL)
{
! struct gdbarch_data_registration *rego;
!
! for (rego = gdbarch_data_registry.registrations;
! rego != NULL;
! rego = rego->next)
{
! struct gdbarch_data *data = rego->data;
!
! if (data->index < gdbarch->nr_data
! && 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;
}
}
+ /* Make sure that GDBARCH has space for all registered per-
+ architecture data. If not, expand the table and initialize the
+ data values. */
static void
! check_gdbarch_data (struct gdbarch *gdbarch)
{
! int nr_allocated = gdbarch->nr_data;
! /* How many per-architecture data items are registered so far? */
! int nr_registered = gdbarch_data_registry.nr;
!
! if (nr_allocated < nr_registered)
{
! /* Get enough room for all registered items, not just DATA. */
! int new_size = sizeof (gdbarch->data[0]) * nr_registered;
! struct gdbarch_data_registration *rego;
!
! /* Expand the array, or perhaps allocate it for the first time. */
! gdbarch->data = (void **) (gdbarch->data
! ? xrealloc (gdbarch->data, new_size)
! : xmalloc (new_size));
!
! /* Record the size now allocated. */
! gdbarch->nr_data = nr_registered;
!
! /* Initialize the elements we just added. */
! for (rego = gdbarch_data_registry.registrations;
! rego != NULL;
! rego = rego->next)
{
! struct gdbarch_data *data = rego->data;
!
! if (data->index >= nr_allocated)
! gdbarch->data[data->index]
! = (data->init != NULL ? data->init (gdbarch) : NULL);
}
}
}
void
set_gdbarch_data (struct gdbarch *gdbarch,
struct gdbarch_data *data,
void *pointer)
{
+ check_gdbarch_data (gdbarch);
gdb_assert (data->index < gdbarch->nr_data);
if (data->free != NULL && gdbarch->data[data->index] != NULL)
data->free (gdbarch, gdbarch->data[data->index]);
***************
*** 1703,1708 ****
--- 1715,1721 ----
void *
gdbarch_data (struct gdbarch_data *data)
{
+ check_gdbarch_data (current_gdbarch);
gdb_assert (data->index < current_gdbarch->nr_data);
return current_gdbarch->data[data->index];
}
***************
*** 2070,2080 ****
CURRENT_GDBARCH must be update before these modules are
called. */
init_gdbarch_swap (new_gdbarch);
-
- /* Initialize the per-architecture data-pointer of all parties that
- registered an interest in this architecture. CURRENT_GDBARCH
- must be updated before these modules are called. */
- init_gdbarch_data (new_gdbarch);
if (gdbarch_debug)
gdbarch_dump (current_gdbarch, gdb_stdlog);
--- 2083,2088 ----
Index: gdb/gdbarch.c
===================================================================
RCS file: /cvs/src/src/gdb/gdbarch.c,v
retrieving revision 1.59
diff -c -r1.59 gdbarch.c
*** gdb/gdbarch.c 2001/05/14 16:43:35 1.59
--- gdb/gdbarch.c 2001/06/01 23:29:16
***************
*** 65,72 ****
/* Static function declarations */
static void verify_gdbarch (struct gdbarch *gdbarch);
! static void alloc_gdbarch_data (struct gdbarch *);
! static void init_gdbarch_data (struct gdbarch *);
static void free_gdbarch_data (struct gdbarch *);
static void init_gdbarch_swap (struct gdbarch *);
static void swapout_gdbarch_swap (struct gdbarch *);
--- 65,71 ----
/* Static function declarations */
static void verify_gdbarch (struct gdbarch *gdbarch);
! static void check_gdbarch_data (struct gdbarch *);
static void free_gdbarch_data (struct gdbarch *);
static void init_gdbarch_swap (struct gdbarch *);
static void swapout_gdbarch_swap (struct gdbarch *);
***************
*** 398,405 ****
struct gdbarch *gdbarch = XMALLOC (struct gdbarch);
memset (gdbarch, 0, sizeof (*gdbarch));
- alloc_gdbarch_data (gdbarch);
-
gdbarch->tdep = tdep;
gdbarch->bfd_arch_info = info->bfd_arch_info;
--- 397,402 ----
***************
*** 4337,4402 ****
}
! /* Walk through all the registered users initializing each in turn. */
static void
! init_gdbarch_data (struct gdbarch *gdbarch)
{
! struct gdbarch_data_registration *rego;
! 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->init != NULL)
{
! void *pointer = data->init (gdbarch);
! set_gdbarch_data (gdbarch, data, pointer);
}
}
}
- /* Create/delete the gdbarch data vector. */
static void
! alloc_gdbarch_data (struct gdbarch *gdbarch)
{
! gdb_assert (gdbarch->data == NULL);
! gdbarch->nr_data = gdbarch_data_registry.nr;
! gdbarch->data = xcalloc (gdbarch->nr_data, sizeof (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 thee specified per-architecture
- data-pointer. */
-
void
set_gdbarch_data (struct gdbarch *gdbarch,
struct gdbarch_data *data,
void *pointer)
{
gdb_assert (data->index < gdbarch->nr_data);
if (data->free != NULL && gdbarch->data[data->index] != NULL)
data->free (gdbarch, gdbarch->data[data->index]);
--- 4334,4414 ----
}
! /* Delete GDBARCH's data vector. */
static void
! free_gdbarch_data (struct gdbarch *gdbarch)
{
! if (gdbarch->data != NULL)
{
! struct gdbarch_data_registration *rego;
!
! for (rego = gdbarch_data_registry.registrations;
! rego != NULL;
! rego = rego->next)
{
! struct gdbarch_data *data = rego->data;
!
! if (data->index < gdbarch->nr_data
! && 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;
}
}
+ /* Make sure that GDBARCH has space for all registered per-
+ architecture data. If not, expand the table and initialize the
+ data values. */
static void
! check_gdbarch_data (struct gdbarch *gdbarch)
{
! int nr_allocated = gdbarch->nr_data;
! /* How many per-architecture data items are registered so far? */
! int nr_registered = gdbarch_data_registry.nr;
!
! if (nr_allocated < nr_registered)
{
! /* Get enough room for all registered items, not just DATA. */
! int new_size = sizeof (gdbarch->data[0]) * nr_registered;
! struct gdbarch_data_registration *rego;
!
! /* Expand the array, or perhaps allocate it for the first time. */
! gdbarch->data = (void **) (gdbarch->data
! ? xrealloc (gdbarch->data, new_size)
! : xmalloc (new_size));
!
! /* Record the size now allocated. */
! gdbarch->nr_data = nr_registered;
!
! /* Initialize the elements we just added. */
! for (rego = gdbarch_data_registry.registrations;
! rego != NULL;
! rego = rego->next)
{
! struct gdbarch_data *data = rego->data;
!
! if (data->index >= nr_allocated)
! gdbarch->data[data->index]
! = (data->init != NULL ? data->init (gdbarch) : NULL);
}
}
}
void
set_gdbarch_data (struct gdbarch *gdbarch,
struct gdbarch_data *data,
void *pointer)
{
+ check_gdbarch_data (gdbarch);
gdb_assert (data->index < gdbarch->nr_data);
if (data->free != NULL && gdbarch->data[data->index] != NULL)
data->free (gdbarch, gdbarch->data[data->index]);
***************
*** 4409,4414 ****
--- 4421,4427 ----
void *
gdbarch_data (struct gdbarch_data *data)
{
+ check_gdbarch_data (current_gdbarch);
gdb_assert (data->index < current_gdbarch->nr_data);
return current_gdbarch->data[data->index];
}
***************
*** 4776,4786 ****
CURRENT_GDBARCH must be update before these modules are
called. */
init_gdbarch_swap (new_gdbarch);
-
- /* Initialize the per-architecture data-pointer of all parties that
- registered an interest in this architecture. CURRENT_GDBARCH
- must be updated before these modules are called. */
- init_gdbarch_data (new_gdbarch);
if (gdbarch_debug)
gdbarch_dump (current_gdbarch, gdb_stdlog);
--- 4789,4794 ----
More information about the Gdb-patches
mailing list