gdb: Add a find method for RegisterDescriptorIterator
Adds a new method 'find' to the gdb.RegisterDescriptorIterator class, this allows gdb.RegisterDescriptor objects to be looked up directly by register name rather than having to iterate over all registers. This will be of use for a later commit. I've documented the new function in the manual, but I don't think a NEWS entry is required here, as, since the last release, the whole register descriptor mechanism is new, and is already mentioned in the NEWS file. gdb/ChangeLog: * python/py-registers.c: Add 'user-regs.h' include. (register_descriptor_iter_find): New function. (register_descriptor_iterator_object_methods): New static global methods array. (register_descriptor_iterator_object_type): Add pointer to methods array. gdb/testsuite/ChangeLog: * gdb.python/py-arch-reg-names.exp: Add additional tests. gdb/doc/ChangeLog: * python.texi (Registers In Python): Document new find function.
This commit is contained in:
parent
67411cbf63
commit
14fa8fb307
6 changed files with 84 additions and 1 deletions
|
@ -23,6 +23,7 @@
|
|||
#include "disasm.h"
|
||||
#include "reggroups.h"
|
||||
#include "python-internal.h"
|
||||
#include "user-regs.h"
|
||||
#include <unordered_map>
|
||||
|
||||
/* Token to access per-gdbarch data related to register descriptors. */
|
||||
|
@ -337,6 +338,38 @@ gdbpy_register_descriptor_iter_next (PyObject *self)
|
|||
while (true);
|
||||
}
|
||||
|
||||
/* Implement:
|
||||
|
||||
gdb.RegisterDescriptorIterator.find (self, name) -> gdb.RegisterDescriptor
|
||||
|
||||
Look up a descriptor for register with NAME. If no matching register is
|
||||
found then return None. */
|
||||
|
||||
static PyObject *
|
||||
register_descriptor_iter_find (PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
static const char *keywords[] = { "name", NULL };
|
||||
const char *register_name = NULL;
|
||||
|
||||
register_descriptor_iterator_object *iter_obj
|
||||
= (register_descriptor_iterator_object *) self;
|
||||
struct gdbarch *gdbarch = iter_obj->gdbarch;
|
||||
|
||||
if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s", keywords,
|
||||
®ister_name))
|
||||
return NULL;
|
||||
|
||||
if (register_name != NULL && *register_name != '\0')
|
||||
{
|
||||
int regnum = user_reg_map_name_to_regnum (gdbarch, register_name,
|
||||
strlen (register_name));
|
||||
if (regnum >= 0)
|
||||
return gdbpy_get_register_descriptor (gdbarch, regnum).release ();
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
/* Initializes the new Python classes from this file in the gdb module. */
|
||||
|
||||
int
|
||||
|
@ -377,6 +410,15 @@ gdbpy_initialize_registers ()
|
|||
(PyObject *) ®ister_descriptor_iterator_object_type));
|
||||
}
|
||||
|
||||
static PyMethodDef register_descriptor_iterator_object_methods [] = {
|
||||
{ "find", (PyCFunction) register_descriptor_iter_find,
|
||||
METH_VARARGS | METH_KEYWORDS,
|
||||
"registers (name) -> gdb.RegisterDescriptor.\n\
|
||||
Return a register descriptor for the register NAME, or None if no register\n\
|
||||
with that name exists in this iterator." },
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject register_descriptor_iterator_object_type = {
|
||||
PyVarObject_HEAD_INIT (NULL, 0)
|
||||
"gdb.RegisterDescriptorIterator", /*tp_name*/
|
||||
|
@ -405,7 +447,7 @@ PyTypeObject register_descriptor_iterator_object_type = {
|
|||
0, /*tp_weaklistoffset */
|
||||
gdbpy_register_descriptor_iter, /*tp_iter */
|
||||
gdbpy_register_descriptor_iter_next, /*tp_iternext */
|
||||
0 /*tp_methods */
|
||||
register_descriptor_iterator_object_methods /*tp_methods */
|
||||
};
|
||||
|
||||
static gdb_PyGetSetDef gdbpy_register_descriptor_getset[] = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue