This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[python][rfc] Change gdb.Block to use attributes instead of gettermethods.
- From: Thiago Jung Bauermann <bauerman at br dot ibm dot com>
- To: archer ml <archer at sourceware dot org>
- Date: Fri, 05 Dec 2008 19:42:15 -0200
- Subject: [python][rfc] Change gdb.Block to use attributes instead of gettermethods.
- References: <cover.1228508475.git.bauerman@br.ibm.com>
This patch changes all methods of gdb.Block to attributes, since they
are very simple.
2008-12-03 Thiago Jung Bauermann <bauerman@br.ibm.com>
* python/lib/gdb/function/in_scope.py: Adjust to use gdb.Block
attributes rather than functions.
* python/python-block.c (blpy_get_start, blpy_get_end,
blpy_get_function, blpy_get_superblock): Change to conform to
Python getter signature.
(block_object_methods): Remove in favor of ...
(block_object_getset): ... this.
(gdbpy_get_block_for_pc): Rename to ...
(gdbpy_block_for_pc): ... this.
* python/python-internal.h (gdbpy_get_block_for_pc): Rename
prototype to ...
(gdbpy_block_for_pc): ... this.
* python/python.c (GdbMethods): Rename function from
`get_block_for_pc' to `block_for_pc'.
diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
index f110b6a..56b1562 100644
--- a/gdb/python/lib/gdb/function/in_scope.py
+++ b/gdb/python/lib/gdb/function/in_scope.py
@@ -27,7 +27,7 @@ Receives as argument a list of names separated by whitespace."""
def invoke (self, var):
vars = set (var.string().split())
found = set ()
- block = gdb.get_block_for_pc (gdb.get_selected_frame ().get_pc ())
+ block = gdb.block_for_pc (gdb.get_selected_frame ().get_pc ())
while block:
for sym in block:
if (sym.is_argument () or sym.is_constant ()
@@ -36,7 +36,7 @@ Receives as argument a list of names separated by whitespace."""
if sym_name in vars:
found.add (sym_name)
- block = block.get_superblock ()
+ block = block.superblock
return vars == found
diff --git a/gdb/python/python-block.c b/gdb/python/python-block.c
index e41ad9b..e4d2eb7 100644
--- a/gdb/python/python-block.c
+++ b/gdb/python/python-block.c
@@ -64,7 +64,7 @@ blpy_itersymbols (PyObject *self, PyObject *args)
}
static PyObject *
-blpy_get_start (PyObject *self, PyObject *args)
+blpy_get_start (PyObject *self, void *closure)
{
block_object *self_block = (block_object *) self;
@@ -72,7 +72,7 @@ blpy_get_start (PyObject *self, PyObject *args)
}
static PyObject *
-blpy_get_end (PyObject *self, PyObject *args)
+blpy_get_end (PyObject *self, void *closure)
{
block_object *self_block = (block_object *) self;
@@ -80,7 +80,7 @@ blpy_get_end (PyObject *self, PyObject *args)
}
static PyObject *
-blpy_get_function (PyObject *self, PyObject *args)
+blpy_get_function (PyObject *self, void *closure)
{
block_object *self_block = (block_object *) self;
struct symbol *sym;
@@ -93,7 +93,7 @@ blpy_get_function (PyObject *self, PyObject *args)
}
static PyObject *
-blpy_get_superblock (PyObject *self, PyObject *args)
+blpy_get_superblock (PyObject *self, void *closure)
{
block_object *self_block = (block_object *) self;
struct block *block;
@@ -157,7 +157,7 @@ blpy_block_syms_iternext (PyObject *self)
or 0 if there is none. */
PyObject *
-gdbpy_get_block_for_pc (PyObject *self, PyObject *args)
+gdbpy_block_for_pc (PyObject *self, PyObject *args)
{
unsigned PY_LONG_LONG pc;
struct block *block;
@@ -194,18 +194,14 @@ gdbpy_initialize_blocks (void)
-static PyMethodDef block_object_methods[] = {
- { "itersymbols", blpy_itersymbols, METH_NOARGS,
- "Return an iterator to walk through the symbols in the block." },
- { "get_start", blpy_get_start, METH_NOARGS,
- "Return the start address of this block." },
- { "get_end", blpy_get_end, METH_NOARGS,
- "Return the end address of this block." },
- { "get_function", blpy_get_function, METH_NOARGS,
- "Return the symbol that names this block, or None." },
- { "get_superblock", blpy_get_superblock, METH_NOARGS,
- "Return the block containing this block, or None." },
- {NULL} /* Sentinel */
+static PyGetSetDef block_object_getset[] = {
+ { "start", blpy_get_start, NULL, "Start address of the block.", NULL },
+ { "end", blpy_get_end, NULL, "End address of the block.", NULL },
+ { "function", blpy_get_function, NULL,
+ "Symbol that names the block, or None.", NULL },
+ { "superblock", blpy_get_superblock, NULL,
+ "Block containing the block, or None.", NULL },
+ { NULL } /* Sentinel */
};
PyTypeObject block_object_type = {
@@ -237,7 +233,9 @@ PyTypeObject block_object_type = {
0, /* tp_weaklistoffset */
blpy_iter, /* tp_iter */
0, /* tp_iternext */
- block_object_methods /* tp_methods */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ block_object_getset /* tp_getset */
};
static PyTypeObject block_syms_iterator_object_type = {
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index f66d674..ab73f71 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -76,7 +76,7 @@ PyObject *gdbpy_get_current_frame (PyObject *, PyObject *);
PyObject *gdbpy_frame_stop_reason_string (PyObject *, PyObject *);
PyObject *gdbpy_lookup_symbol (PyObject *self, PyObject *args);
PyObject *gdbpy_get_selected_frame (PyObject *self, PyObject *args);
-PyObject *gdbpy_get_block_for_pc (PyObject *self, PyObject *args);
+PyObject *gdbpy_block_for_pc (PyObject *self, PyObject *args);
PyObject *symtab_and_line_to_sal_object (struct symtab_and_line sal);
PyObject *symtab_to_symtab_object (struct symtab *symtab);
diff --git a/gdb/python/python.c b/gdb/python/python.c
index b6fbc73..ddcd378 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1379,7 +1379,7 @@ static PyMethodDef GdbMethods[] =
{ "find_pc_function", gdbpy_find_pc_function, METH_VARARGS,
"Return the function containing the given pc value, or None." },
- { "get_block_for_pc", gdbpy_get_block_for_pc, METH_VARARGS,
+ { "block_for_pc", gdbpy_block_for_pc, METH_VARARGS,
"Return the block containing the given pc value, or None." },
{ "decode_line", gdbpy_decode_line, METH_VARARGS,
--
1.5.6.3