diff options
author | Christian Biesinger <cbiesinger@google.com> | 2019-07-30 11:04:37 -0500 |
---|---|---|
committer | Christian Biesinger <cbiesinger@google.com> | 2019-07-30 11:04:37 -0500 |
commit | 2906593ffecef89f8d64e0f1ca21494be71d0ebd (patch) | |
tree | 8749c60aa8e9da72303e4be797345492dc3018a7 /gdb/python | |
parent | 5c4dde850c0d4874d3bbe6dd1989bf0f7a5ed1c3 (diff) | |
download | fsf-binutils-gdb-2906593ffecef89f8d64e0f1ca21494be71d0ebd.zip fsf-binutils-gdb-2906593ffecef89f8d64e0f1ca21494be71d0ebd.tar.gz fsf-binutils-gdb-2906593ffecef89f8d64e0f1ca21494be71d0ebd.tar.bz2 |
[PR/24474] Add gdb.lookup_static_symbol to the python API
Similar to lookup_global_symbol, except that it checks the
STATIC_SCOPE.
gdb/ChangeLog:
2019-07-30 Christian Biesinger <cbiesinger@google.com>
PR/24474: Add a function to lookup static variables.
* NEWS: Mention this new function.
* python/py-symbol.c (gdbpy_lookup_static_symbol): New function.
* python/python-internal.h (gdbpy_lookup_static_symbol): New function.
* python/python.c (python_GdbMethods): Add new function.
gdb/doc/ChangeLog:
2019-07-30 Christian Biesinger <cbiesinger@google.com>
* python.texi (Symbols In Python): Document new function
gdb.lookup_static_symbol.
gdb/testsuite/ChangeLog:
2019-07-30 Christian Biesinger <cbiesinger@google.com>
* gdb.python/py-symbol.c: Add a static variable and one in an anonymous
namespace.
* gdb.python/py-symbol.exp: Test gdb.lookup_static_symbol.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-symbol.c | 40 | ||||
-rw-r--r-- | gdb/python/python-internal.h | 2 | ||||
-rw-r--r-- | gdb/python/python.c | 4 |
3 files changed, 46 insertions, 0 deletions
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index 8605ae71..2b10e21 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -471,6 +471,46 @@ gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw) return sym_obj; } +/* Implementation of + gdb.lookup_static_symbol (name [, domain) -> symbol or None. */ + +PyObject * +gdbpy_lookup_static_symbol (PyObject *self, PyObject *args, PyObject *kw) +{ + const char *name; + int domain = VAR_DOMAIN; + static const char *keywords[] = { "name", "domain", NULL }; + struct symbol *symbol = NULL; + PyObject *sym_obj; + + if (!gdb_PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name, + &domain)) + return NULL; + + try + { + symbol = lookup_static_symbol (name, (domain_enum) domain).symbol; + } + catch (const gdb_exception &except) + { + GDB_PY_HANDLE_EXCEPTION (except); + } + + if (symbol) + { + sym_obj = symbol_to_symbol_object (symbol); + if (!sym_obj) + return NULL; + } + else + { + sym_obj = Py_None; + Py_INCREF (Py_None); + } + + return sym_obj; +} + /* 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 e6a3fe0..c557843 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -424,6 +424,8 @@ PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *); PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw); PyObject *gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw); +PyObject *gdbpy_lookup_static_symbol (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 96bee7c..162470d 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1978,6 +1978,10 @@ a boolean indicating if name is a field of the current implied argument\n\ METH_VARARGS | METH_KEYWORDS, "lookup_global_symbol (name [, domain]) -> symbol\n\ Return the symbol corresponding to the given name (or None)." }, + { "lookup_static_symbol", (PyCFunction) gdbpy_lookup_static_symbol, + METH_VARARGS | METH_KEYWORDS, + "lookup_static_symbol (name [, domain]) -> symbol\n\ +Return the static-linkage symbol corresponding to the given name (or None)." }, { "lookup_objfile", (PyCFunction) gdbpy_lookup_objfile, METH_VARARGS | METH_KEYWORDS, |