diff options
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-symbol.c | 61 | ||||
-rw-r--r-- | gdb/python/python-internal.h | 2 | ||||
-rw-r--r-- | gdb/python/python.c | 4 |
3 files changed, 67 insertions, 0 deletions
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index 4c88877bcbe..647c54b0a5b 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -23,6 +23,7 @@ #include "symtab.h" #include "python-internal.h" #include "objfiles.h" +#include "symfile.h" typedef struct sympy_symbol_object { PyObject_HEAD @@ -534,6 +535,66 @@ gdbpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw) return sym_obj; } +/* Implementation of + gdb.lookup_static_symbols (name [, domain]) -> symbol list. + + Returns a list of all static symbols matching NAME in DOMAIN. */ + +PyObject * +gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, PyObject *kw) +{ + const char *name; + int domain = VAR_DOMAIN; + static const char *keywords[] = { "name", "domain", NULL }; + + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name, + &domain)) + return NULL; + + gdbpy_ref<> return_list (PyList_New (0)); + if (return_list == NULL) + return NULL; + + try + { + /* Expand any symtabs that contain potentially matching symbols. */ + lookup_name_info lookup_name (name, symbol_name_match_type::FULL); + expand_symtabs_matching (NULL, lookup_name, NULL, NULL, ALL_DOMAIN); + + for (objfile *objfile : current_program_space->objfiles ()) + { + for (compunit_symtab *cust : objfile->compunits ()) + { + const struct blockvector *bv; + const struct block *block; + + bv = COMPUNIT_BLOCKVECTOR (cust); + block = BLOCKVECTOR_BLOCK (bv, STATIC_BLOCK); + + if (block != nullptr) + { + symbol *symbol = lookup_symbol_in_static_block + (name, block, (domain_enum) domain).symbol; + + if (symbol != nullptr) + { + PyObject *sym_obj + = symbol_to_symbol_object (symbol); + if (PyList_Append (return_list.get (), sym_obj) == -1) + return NULL; + } + } + } + } + } + catch (const gdb_exception &except) + { + GDB_PY_HANDLE_EXCEPTION (except); + } + + return return_list.release (); +} + /* This function is called when an objfile is about to be freed. Invalidate the symbol as further actions on the symbol would result in bad data. All access to obj->symbol should be gated by diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index c5578430cff..703c60032c0 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -426,6 +426,8 @@ PyObject *gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw); PyObject *gdbpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw); +PyObject *gdbpy_lookup_static_symbols (PyObject *self, PyObject *args, + PyObject *kw); PyObject *gdbpy_start_recording (PyObject *self, PyObject *args); PyObject *gdbpy_current_recording (PyObject *self, PyObject *args); PyObject *gdbpy_stop_recording (PyObject *self, PyObject *args); diff --git a/gdb/python/python.c b/gdb/python/python.c index ddf0e72d26f..f94214e1b24 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1994,6 +1994,10 @@ Return the symbol corresponding to the given name (or None)." }, METH_VARARGS | METH_KEYWORDS, "lookup_static_symbol (name [, domain]) -> symbol\n\ Return the static-linkage symbol corresponding to the given name (or None)." }, + { "lookup_static_symbols", (PyCFunction) gdbpy_lookup_static_symbols, + METH_VARARGS | METH_KEYWORDS, + "lookup_static_symbols (name [, domain]) -> symbol\n\ +Return a list of all static-linkage symbols corresponding to the given name." }, { "lookup_objfile", (PyCFunction) gdbpy_lookup_objfile, METH_VARARGS | METH_KEYWORDS, |