diff options
author | Tom Tromey <tom@tromey.com> | 2022-06-01 15:31:15 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2022-08-04 13:28:04 -0600 |
commit | cb275538dbddfbb3c2c372a665ac48e6f617ea33 (patch) | |
tree | 7bc54ff4fc92c9b1cee74c2d7b9ae452b5ffec8b /gdb/python/py-registers.c | |
parent | 8b1540430107b0752485ab9e6a841dbbacd45681 (diff) | |
download | binutils-cb275538dbddfbb3c2c372a665ac48e6f617ea33.zip binutils-cb275538dbddfbb3c2c372a665ac48e6f617ea33.tar.gz binutils-cb275538dbddfbb3c2c372a665ac48e6f617ea33.tar.bz2 |
Use registry in gdbarch
gdbarch implements its own registry-like approach. This patch changes
it to instead use registry.h. It's a rather large patch but largely
uninteresting -- it's mostly a straightforward conversion from the old
approach to the new one.
The main benefit of this change is that it introduces type safety to
the gdbarch registry. It also removes a bunch of code.
One possible drawback is that, previously, the gdbarch registry
differentiated between pre- and post-initialization setup. This
doesn't seem very important to me, though.
Diffstat (limited to 'gdb/python/py-registers.c')
-rw-r--r-- | gdb/python/py-registers.c | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/gdb/python/py-registers.c b/gdb/python/py-registers.c index bbb322f..f22575a 100644 --- a/gdb/python/py-registers.c +++ b/gdb/python/py-registers.c @@ -25,8 +25,12 @@ #include "user-regs.h" #include <unordered_map> +/* Per-gdbarch data type. */ +typedef std::vector<gdbpy_ref<>> gdbpy_register_type; + /* Token to access per-gdbarch data related to register descriptors. */ -static struct gdbarch_data *gdbpy_register_object_data = NULL; +static const registry<gdbarch>::key<gdbpy_register_type> + gdbpy_register_object_data; /* Structure for iterator over register descriptors. */ struct register_descriptor_iterator_object { @@ -85,16 +89,6 @@ struct reggroup_object { extern PyTypeObject reggroup_object_type CPYCHECKER_TYPE_OBJECT_FOR_TYPEDEF ("reggroup_object"); -/* Associates a vector of gdb.RegisterDescriptor objects with GDBARCH as - gdbarch_data via the gdbarch post init registration mechanism - (gdbarch_data_register_post_init). */ - -static void * -gdbpy_register_object_data_init (struct gdbarch *gdbarch) -{ - return new std::vector<gdbpy_ref<>>; -} - /* Return a gdb.RegisterGroup object wrapping REGGROUP. The register group objects are cached, and the same Python object will always be returned for the same REGGROUP pointer. */ @@ -156,9 +150,10 @@ static gdbpy_ref<> gdbpy_get_register_descriptor (struct gdbarch *gdbarch, int regnum) { - auto &vec - = *(std::vector<gdbpy_ref<>> *) gdbarch_data (gdbarch, - gdbpy_register_object_data); + gdbpy_register_type *vecp = gdbpy_register_object_data.get (gdbarch); + if (vecp == nullptr) + vecp = gdbpy_register_object_data.emplace (gdbarch); + gdbpy_register_type &vec = *vecp; /* Ensure that we have enough entries in the vector. */ if (vec.size () <= regnum) @@ -422,14 +417,6 @@ gdbpy_parse_register_id (struct gdbarch *gdbarch, PyObject *pyo_reg_id, return false; } -void _initialize_py_registers (); -void -_initialize_py_registers () -{ - gdbpy_register_object_data - = gdbarch_data_register_post_init (gdbpy_register_object_data_init); -} - /* Initializes the new Python classes from this file in the gdb module. */ int |