diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-09-15 13:34:14 +0100 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2021-10-22 13:42:49 +0100 |
commit | 8b87fbe6bb5f682fef889630664884ea8e7d6444 (patch) | |
tree | c6e54c9f2311f10a9195ffb80f059eb26899ddfd /gdb/python | |
parent | 431be556b0bdd0733dedec2368d8d6a72cacea72 (diff) | |
download | gdb-8b87fbe6bb5f682fef889630664884ea8e7d6444.zip gdb-8b87fbe6bb5f682fef889630664884ea8e7d6444.tar.gz gdb-8b87fbe6bb5f682fef889630664884ea8e7d6444.tar.bz2 |
gdb/python: new gdb.architecture_names function
Add a new function to the Python API, gdb.architecture_names(). This
function returns a list containing all of the supported architecture
names within the current build of GDB.
The values returned in this list are all of the possible values that
can be returned from gdb.Architecture.name().
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-arch.c | 23 | ||||
-rw-r--r-- | gdb/python/python-internal.h | 1 | ||||
-rw-r--r-- | gdb/python/python.c | 4 |
3 files changed, 28 insertions, 0 deletions
diff --git a/gdb/python/py-arch.c b/gdb/python/py-arch.c index 66f2d28..3e7970a 100644 --- a/gdb/python/py-arch.c +++ b/gdb/python/py-arch.c @@ -271,6 +271,29 @@ archpy_register_groups (PyObject *self, PyObject *args) return gdbpy_new_reggroup_iterator (gdbarch); } +/* Implementation of gdb.architecture_names(). Return a list of all the + BFD architecture names that GDB understands. */ + +PyObject * +gdbpy_all_architecture_names (PyObject *self, PyObject *args) +{ + gdbpy_ref<> list (PyList_New (0)); + if (list == nullptr) + return nullptr; + + std::vector<const char *> name_list = gdbarch_printable_names (); + for (const char *name : name_list) + { + gdbpy_ref <> py_name (PyString_FromString (name)); + if (py_name == nullptr) + return nullptr; + if (PyList_Append (list.get (), py_name.get ()) < 0) + return nullptr; + } + + return list.release (); +} + void _initialize_py_arch (); void _initialize_py_arch () diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 022d4a6..2ad3bc9 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -469,6 +469,7 @@ PyObject *objfpy_get_xmethods (PyObject *, void *); PyObject *gdbpy_lookup_objfile (PyObject *self, PyObject *args, PyObject *kw); PyObject *gdbarch_to_arch_object (struct gdbarch *gdbarch); +PyObject *gdbpy_all_architecture_names (PyObject *self, PyObject *args); PyObject *gdbpy_new_register_descriptor_iterator (struct gdbarch *gdbarch, const char *group_name); diff --git a/gdb/python/python.c b/gdb/python/python.c index 44ec4b7..5b1c295 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -2324,6 +2324,10 @@ Set the value of the convenience variable $NAME." }, Register a TUI window constructor." }, #endif /* TUI */ + { "architecture_names", gdbpy_all_architecture_names, METH_NOARGS, + "architecture_names () -> List.\n\ +Return a list of all the architecture names GDB understands." }, + {NULL, NULL, 0, NULL} }; |