diff options
author | Doug Evans <dje@google.com> | 2011-02-22 22:48:12 +0000 |
---|---|---|
committer | Doug Evans <dje@google.com> | 2011-02-22 22:48:12 +0000 |
commit | 6e6fbe60bc0412fec955d539b445b66b14a04e69 (patch) | |
tree | 369fa1e0716583cb0acf3890749ec42a6d0fae4b /gdb/python | |
parent | 1d41d745ca37dc95f93c8e1a148b3c46c85d7273 (diff) | |
download | gdb-6e6fbe60bc0412fec955d539b445b66b14a04e69.zip gdb-6e6fbe60bc0412fec955d539b445b66b14a04e69.tar.gz gdb-6e6fbe60bc0412fec955d539b445b66b14a04e69.tar.bz2 |
Add gdb.lookup_global_symbol python function.
* NEWS: Add entry.
* python/py-symbol.c (gdbpy_lookup_global_symbol): New function.
* python/python-internal.h (gdbpy_lookup_global_symbol): Declare it.
* python/python.c (GdbMethods): Add entry for lookup_global_symbol.
doc/
* gdb.texinfo (Symbols In Python): Document lookup_global_symbol.
Clarify behaviour of lookup_symbol when `block' argument is omitted,
add description of result, fix @defun formatting.
testsuite/
* gdb.python/py-symbol.exp: Test lookup_global_symbol.
Diffstat (limited to 'gdb/python')
-rw-r--r-- | gdb/python/py-symbol.c | 34 | ||||
-rw-r--r-- | gdb/python/python-internal.h | 2 | ||||
-rw-r--r-- | gdb/python/python.c | 4 |
3 files changed, 40 insertions, 0 deletions
diff --git a/gdb/python/py-symbol.c b/gdb/python/py-symbol.c index e072dc8..390d612 100644 --- a/gdb/python/py-symbol.c +++ b/gdb/python/py-symbol.c @@ -236,6 +236,7 @@ sympy_dealloc (PyObject *obj) A tuple with 2 elements is always returned. The first is the symbol object or None, the second is a boolean with the value of is_a_field_of_this (see comment in lookup_symbol_in_language). */ + PyObject * gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw) { @@ -294,6 +295,39 @@ gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw) return ret_tuple; } +/* Implementation of + gdb.lookup_global_symbol (name [, domain]) -> symbol or None. */ + +PyObject * +gdbpy_lookup_global_symbol (PyObject *self, PyObject *args, PyObject *kw) +{ + int domain = VAR_DOMAIN; + const char *name; + static char *keywords[] = { "name", "domain", NULL }; + struct symbol *symbol; + PyObject *sym_obj; + + if (! PyArg_ParseTupleAndKeywords (args, kw, "s|i", keywords, &name, + &domain)) + return NULL; + + symbol = lookup_symbol_global (name, NULL, domain); + + 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 134268b..49b6acf 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -136,6 +136,8 @@ PyObject *gdbpy_history (PyObject *self, PyObject *args); PyObject *gdbpy_breakpoints (PyObject *, PyObject *); 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_newest_frame (PyObject *self, PyObject *args); PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args); PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args); diff --git a/gdb/python/python.c b/gdb/python/python.c index b79504a..2977a56 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -1145,6 +1145,10 @@ Return a Type corresponding to the given name." }, Return a tuple with the symbol corresponding to the given name (or None) and\n\ a boolean indicating if name is a field of the current implied argument\n\ `this' (when the current language is object-oriented)." }, + { "lookup_global_symbol", (PyCFunction) gdbpy_lookup_global_symbol, + METH_VARARGS | METH_KEYWORDS, + "lookup_global_symbol (name [, domain]) -> symbol\n\ +Return the symbol corresponding to the given name (or None)." }, { "block_for_pc", gdbpy_block_for_pc, METH_VARARGS, "Return the block containing the given pc value, or None." }, { "solib_name", gdbpy_solib_name, METH_VARARGS, |