[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.
This commit is contained in:
Christian Biesinger
2019-07-30 11:04:37 -05:00
parent 5c4dde850c
commit 2906593ffe
10 changed files with 116 additions and 0 deletions

View File

@ -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

View File

@ -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);

View File

@ -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,