This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[python] Make gdb.lookup_symbol accept keyword arguments.
- From: Thiago Jung Bauermann <bauerman at br dot ibm dot com>
- To: archer ml <archer at sourceware dot org>
- Date: Fri, 27 Feb 2009 16:53:10 -0300
- Subject: [python] Make gdb.lookup_symbol accept keyword arguments.
Hi,
Just committed this which adds keyword arguments to gdb.lookup_symbol.
* python/python-symbol.c (gdbpy_lookup_symbol): Accept keyword
arguments as well.
* python/python-internal.h (gdbpy_lookup_symbol): Update
prototype.
* python/python.c (GdbMethods): Change `lookup_symbol' entry to
also accept keyword arguments.
---
gdb/python/python-internal.h | 2 +-
gdb/python/python-symbol.c | 18 ++++++++++--------
gdb/python/python.c | 8 ++++++--
3 files changed, 17 insertions(+), 11 deletions(-)
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 12422af..4aae0aa 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -78,7 +78,7 @@ PyObject *gdbpy_breakpoints (PyObject *, PyObject *);
PyObject *gdbpy_frames (PyObject *, PyObject *);
PyObject *gdbpy_newest_frame (PyObject *, PyObject *);
PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *);
-PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args);
+PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args, PyObject *kw);
PyObject *gdbpy_selected_frame (PyObject *self, PyObject *args);
PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args);
PyObject *gdbpy_read_memory (PyObject *self, PyObject *args);
diff --git a/gdb/python/python-symbol.c b/gdb/python/python-symbol.c
index 223e6d3..c7fda5c 100644
--- a/gdb/python/python-symbol.c
+++ b/gdb/python/python-symbol.c
@@ -166,21 +166,23 @@ symbol_object_to_symbol (PyObject *obj)
return ((symbol_object *) obj)->symbol;
}
-/* This function has less arguments than its C counterpart, to simplify the
- Python interface: name, block and domain. The other two arguments are always
- assumed to be set, and 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. */
-PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args)
+/* Implementation of
+ gdb.lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this)
+ 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)
{
int domain = VAR_DOMAIN, is_a_field_of_this = 0;
const char *name;
+ static char *keywords[] = { "name", "block", "domain", NULL };
struct symbol *symbol;
PyObject *block_obj = NULL, *ret_tuple, *sym_obj, *bool_obj;
struct block *block = NULL;
- if (! PyArg_ParseTuple (args, "s|O!i", &name, &block_object_type, &block_obj,
- &domain))
+ if (! PyArg_ParseTupleAndKeywords (args, kw, "s|O!i", keywords, &name,
+ &block_object_type, &block_obj, &domain))
return NULL;
if (block_obj)
diff --git a/gdb/python/python.c b/gdb/python/python.c
index d32a9e5..c9f2231 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1859,8 +1859,12 @@ static PyMethodDef GdbMethods[] =
{ "frame_stop_reason_string", gdbpy_frame_stop_reason_string,
METH_VARARGS, "Return a string explaining unwind stop reason" },
- { "lookup_symbol", gdbpy_lookup_symbol, METH_VARARGS,
- "Return the symbol corresponding to the given name, or None." },
+ { "lookup_symbol", (PyCFunction) gdbpy_lookup_symbol,
+ METH_VARARGS | METH_KEYWORDS,
+ "lookup_symbol (name [, block] [, domain]) -> (symbol, is_field_of_this)\n\
+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)." },
{ "solib_address", gdbpy_solib_address, METH_VARARGS,
"Return shared library holding a given address, or None." },
--
1.5.6.5