2012-09-13 22:35:16 +08:00
|
|
|
/* Support functions for general registry objects.
|
|
|
|
|
2019-01-01 14:01:51 +08:00
|
|
|
Copyright (C) 2011-2019 Free Software Foundation, Inc.
|
2012-09-13 22:35:16 +08:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#include "defs.h"
|
|
|
|
#include "registry.h"
|
|
|
|
const struct registry_data *
|
|
|
|
register_data_with_cleanup (struct registry_data_registry *registry,
|
|
|
|
registry_data_callback save,
|
|
|
|
registry_data_callback free)
|
|
|
|
{
|
|
|
|
struct registry_data_registration **curr;
|
|
|
|
|
|
|
|
/* Append new registration. */
|
|
|
|
for (curr = ®istry->registrations;
|
|
|
|
*curr != NULL;
|
|
|
|
curr = &(*curr)->next)
|
|
|
|
;
|
|
|
|
|
2013-12-29 06:31:23 +08:00
|
|
|
*curr = XNEW (struct registry_data_registration);
|
2012-09-13 22:35:16 +08:00
|
|
|
(*curr)->next = NULL;
|
2013-12-29 06:31:23 +08:00
|
|
|
(*curr)->data = XNEW (struct registry_data);
|
2012-09-13 22:35:16 +08:00
|
|
|
(*curr)->data->index = registry->num_registrations++;
|
|
|
|
(*curr)->data->save = save;
|
|
|
|
(*curr)->data->free = free;
|
|
|
|
|
|
|
|
return (*curr)->data;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
registry_alloc_data (struct registry_data_registry *registry,
|
|
|
|
struct registry_fields *fields)
|
|
|
|
{
|
|
|
|
gdb_assert (fields->data == NULL);
|
|
|
|
fields->num_data = registry->num_registrations;
|
replace XCALLOC with XCNEWVEC or XCNEW
This removes XCALLOC and replaces it either with XCNEWVEC, or, if the
number of elements being requested was 1, with XCNEW.
2014-01-13 Tom Tromey <tromey@redhat.com>
* defs.h (XCALLOC): Remove.
* bcache.c (bcache_xmalloc): Use XCNEW, not XCALLOC.
(print_bcache_statistics): Use XCNEWVEC, not XCALLOC.
* dwarf2loc.c (allocate_piece_closure): Likewise.
* elfread.c (elf_symfile_segments): Likewise.
(elf_symfile_segments): Likewise.
* gdbtypes.c (copy_type_recursive): Likewise.
* i386-tdep.c (i386_gdbarch_init): Use XCNEW, not XCALLOC.
* jit.c (jit_frame_sniffer): Use XCNEWVEC, not XCALLOC.
* minsyms.c (prim_record_minimal_symbol_full): Use XCNEW, not
XCALLOC.
* mt-tdep.c (mt_gdbarch_init): Likewise.
* opencl-lang.c (allocate_lval_closure): Use XCNEWVEC, not
XCALLOC.
* psymtab.c (psymbol_compare): Use XCNEW, not XCALLOC.
* regcache.c (regcache_xmalloc_1): Use XCNEWVEC, not XCALLOC.
* registry.c (registry_alloc_data): Likewise.
* rs6000-tdep.c (rs6000_gdbarch_init): Use XCNEW, not XCALLOC.
* s390-linux-tdep.c (s390_gdbarch_init): Likewise.
* serial.c (serial_fdopen_ops): Likewise.
* solib-aix.c (solib_aix_get_section_offsets): Use XCNEWVEC, not
XCALLOC.
* spu-tdep.c (spu_gdbarch_init): Use XCNEW, not XCALLOC.
* symfile.c (default_symfile_segments): Use XCNEW and XCNEWVEC,
not XCALLOC.
2013-12-29 06:32:27 +08:00
|
|
|
fields->data = XCNEWVEC (void *, fields->num_data);
|
2012-09-13 22:35:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
registry_clear_data (struct registry_data_registry *data_registry,
|
|
|
|
registry_callback_adaptor adaptor,
|
|
|
|
struct registry_container *container,
|
|
|
|
struct registry_fields *fields)
|
|
|
|
{
|
|
|
|
struct registry_data_registration *registration;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
gdb_assert (fields->data != NULL);
|
|
|
|
|
|
|
|
/* Process all the save handlers. */
|
|
|
|
|
|
|
|
for (registration = data_registry->registrations, i = 0;
|
|
|
|
i < fields->num_data;
|
|
|
|
registration = registration->next, i++)
|
|
|
|
if (fields->data[i] != NULL && registration->data->save != NULL)
|
|
|
|
adaptor (registration->data->save, container, fields->data[i]);
|
|
|
|
|
|
|
|
/* Now process all the free handlers. */
|
|
|
|
|
|
|
|
for (registration = data_registry->registrations, i = 0;
|
|
|
|
i < fields->num_data;
|
|
|
|
registration = registration->next, i++)
|
|
|
|
if (fields->data[i] != NULL && registration->data->free != NULL)
|
|
|
|
adaptor (registration->data->free, container, fields->data[i]);
|
|
|
|
|
|
|
|
memset (fields->data, 0, fields->num_data * sizeof (void *));
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
registry_container_free_data (struct registry_data_registry *data_registry,
|
|
|
|
registry_callback_adaptor adaptor,
|
|
|
|
struct registry_container *container,
|
|
|
|
struct registry_fields *fields)
|
|
|
|
{
|
|
|
|
void ***rdata = &fields->data;
|
|
|
|
gdb_assert (*rdata != NULL);
|
|
|
|
registry_clear_data (data_registry, adaptor, container, fields);
|
|
|
|
xfree (*rdata);
|
|
|
|
*rdata = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
registry_set_data (struct registry_fields *fields,
|
|
|
|
const struct registry_data *data,
|
|
|
|
void *value)
|
|
|
|
{
|
|
|
|
gdb_assert (data->index < fields->num_data);
|
|
|
|
fields->data[data->index] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
registry_data (struct registry_fields *fields,
|
|
|
|
const struct registry_data *data)
|
|
|
|
{
|
|
|
|
gdb_assert (data->index < fields->num_data);
|
|
|
|
return fields->data[data->index];
|
|
|
|
}
|