This is the mail archive of the
archer@sourceware.org
mailing list for the Archer project.
[python][rfc] Change gdb.Symbol to use attributes instead ofgetter methods.
- 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:43:50 -0200
- Subject: [python][rfc] Change gdb.Symbol to use attributes instead ofgetter methods.
- References: <cover.1228508475.git.bauerman@br.ibm.com>
Changed all gdb.Symbol methods to attributes, since they are trivial
enough.
2008-12-05 Thiago Jung Bauermann <bauerman@br.ibm.com>
* python/python-symbol.c (sympy_get_value, sympy_get_symtab,
sympy_get_linkage_name, sympy_get_print_name, sympy_is_argument,
sympy_is_constant, sympy_is_function, sympy_is_variable): Change
to conform to Python getter signature.
(sympy_get_natural_name): Rename to ...
(sympy_get_name): ... this. Change to conform to Python getter
signature.
(sympy_get_class): Rename to ...
(sympy_get_addr_class): ... this. Change to conform to Python
getter signature.
(symbol_object_methods): Remove in favor of ...
(symbol_object_getset): ... this.
(symbol_object_type): Set tp_getset field. Unset tp_methods field.
* python/lib/gdb/command/backtrace.py: Adjust to use gdb.Symbol
attributes rather than functions.
* python/lib/gdb/function/in_scope.py: Adjust to use gdb.Symbol
attributes rather than functions.
diff --git a/gdb/python/lib/gdb/command/backtrace.py b/gdb/python/lib/gdb/command/backtrace.py
index 916a039..fd99ae1 100644
--- a/gdb/python/lib/gdb/command/backtrace.py
+++ b/gdb/python/lib/gdb/command/backtrace.py
@@ -26,12 +26,12 @@ class FrameWrapper:
self.frame = frame;
def write_symbol (self, stream, sym, block):
- if len (sym.get_linkage_name ()):
- nsym, is_field_of_this = gdb.lookup_symbol (sym.get_linkage_name (), block, gdb.SYMBOL_VAR_DOMAIN)
- if nsym.get_class () != gdb.SYMBOL_LOC_REGISTER:
+ if len (sym.linkage_name):
+ nsym, is_field_of_this = gdb.lookup_symbol (sym.linkage_name, block, gdb.SYMBOL_VAR_DOMAIN)
+ if nsym.addr_class != gdb.SYMBOL_LOC_REGISTER:
sym = nsym
- stream.write (sym.get_print_name () + "=")
+ stream.write (sym.print_name + "=")
try:
val = self.frame.read_var_value (sym)
if val != None:
@@ -49,10 +49,10 @@ class FrameWrapper:
return
first = True
- block = func.get_value ()
+ block = func.value
for sym in block:
- if sym.is_argument ():
+ if sym.is_argument:
continue;
self.write_symbol (stream, sym, block)
@@ -63,10 +63,10 @@ class FrameWrapper:
return
first = True
- block = func.get_value ()
+ block = func.value
for sym in block:
- if not sym.is_argument ():
+ if not sym.is_argument:
continue;
if not first:
diff --git a/gdb/python/lib/gdb/function/in_scope.py b/gdb/python/lib/gdb/function/in_scope.py
index 3ad0d40..e9e589b 100644
--- a/gdb/python/lib/gdb/function/in_scope.py
+++ b/gdb/python/lib/gdb/function/in_scope.py
@@ -32,7 +32,7 @@ Receives as argument a list of names separated by whitespace."""
for sym in block:
if (sym.is_argument () or sym.is_constant ()
or sym.is_function () or sym.is_variable ()):
- sym_name = sym.get_print_name ()
+ sym_name = sym.name
if sym_name in vars:
found.add (sym_name)
diff --git a/gdb/python/python-symbol.c b/gdb/python/python-symbol.c
index d8237dc..a3fc09a 100644
--- a/gdb/python/python-symbol.c
+++ b/gdb/python/python-symbol.c
@@ -46,7 +46,7 @@ sympy_str (PyObject *self)
}
static PyObject *
-sympy_get_value (PyObject *self, PyObject *args)
+sympy_get_value (PyObject *self, void *closure)
{
symbol_object *self_sym = (symbol_object *) self;
@@ -62,7 +62,7 @@ sympy_get_value (PyObject *self, PyObject *args)
}
static PyObject *
-sympy_get_symtab (PyObject *self, PyObject *args)
+sympy_get_symtab (PyObject *self, void *closure)
{
symbol_object *self_sym = (symbol_object *) self;
@@ -70,7 +70,7 @@ sympy_get_symtab (PyObject *self, PyObject *args)
}
static PyObject *
-sympy_get_natural_name (PyObject *self, PyObject *args)
+sympy_get_name (PyObject *self, void *closure)
{
symbol_object *self_sym = (symbol_object *) self;
@@ -78,7 +78,7 @@ sympy_get_natural_name (PyObject *self, PyObject *args)
}
static PyObject *
-sympy_get_linkage_name (PyObject *self, PyObject *args)
+sympy_get_linkage_name (PyObject *self, void *closure)
{
symbol_object *self_sym = (symbol_object *) self;
@@ -86,7 +86,7 @@ sympy_get_linkage_name (PyObject *self, PyObject *args)
}
static PyObject *
-sympy_get_print_name (PyObject *self, PyObject *args)
+sympy_get_print_name (PyObject *self, void *closure)
{
symbol_object *self_sym = (symbol_object *) self;
@@ -94,7 +94,7 @@ sympy_get_print_name (PyObject *self, PyObject *args)
}
static PyObject *
-sympy_get_class (PyObject *self, PyObject *args)
+sympy_get_addr_class (PyObject *self, void *closure)
{
symbol_object *self_sym = (symbol_object *) self;
@@ -102,7 +102,7 @@ sympy_get_class (PyObject *self, PyObject *args)
}
static PyObject *
-sympy_is_argument (PyObject *self, PyObject *args)
+sympy_is_argument (PyObject *self, void *closure)
{
symbol_object *self_sym = (symbol_object *) self;
@@ -110,7 +110,7 @@ sympy_is_argument (PyObject *self, PyObject *args)
}
static PyObject *
-sympy_is_constant (PyObject *self, PyObject *args)
+sympy_is_constant (PyObject *self, void *closure)
{
symbol_object *self_sym = (symbol_object *) self;
enum address_class class = SYMBOL_CLASS (self_sym->symbol);
@@ -119,7 +119,7 @@ sympy_is_constant (PyObject *self, PyObject *args)
}
static PyObject *
-sympy_is_function (PyObject *self, PyObject *args)
+sympy_is_function (PyObject *self, void *closure)
{
symbol_object *self_sym = (symbol_object *) self;
enum address_class class = SYMBOL_CLASS (self_sym->symbol);
@@ -128,7 +128,7 @@ sympy_is_function (PyObject *self, PyObject *args)
}
static PyObject *
-sympy_is_variable (PyObject *self, PyObject *args)
+sympy_is_variable (PyObject *self, void *closure)
{
symbol_object *self_sym = (symbol_object *) self;
enum address_class class = SYMBOL_CLASS (self_sym->symbol);
@@ -265,28 +265,28 @@ gdbpy_initialize_symbols (void)
-static PyMethodDef symbol_object_methods[] = {
- { "get_value", sympy_get_value, METH_NOARGS,
- "Return the value of the symbol." },
- { "get_symtab", sympy_get_symtab, METH_NOARGS,
- "Return the value of the symbol." },
- { "get_natural_name", sympy_get_natural_name, METH_NOARGS,
- "Return the \"natural\" name of the symbol." },
- { "get_linkage_name", sympy_get_linkage_name, METH_NOARGS,
- "Return the name of the symbol as used by the linker." },
- { "get_print_name", sympy_get_print_name, METH_NOARGS,
- "Return the name of the symbol in a form suitable for output." },
- { "get_class", sympy_get_class, METH_NOARGS,
- "Return the class of the symbol." },
- { "is_argument", sympy_is_argument, METH_NOARGS,
- "Return True if symbol is the argument of a function." },
- { "is_constant", sympy_is_constant, METH_NOARGS,
- "Return True if symbol is a function or method." },
- { "is_function", sympy_is_function, METH_NOARGS,
- "Return True if symbol is a function or method." },
- { "is_variable", sympy_is_variable, METH_NOARGS,
- "Return True if symbol is a variable." },
- {NULL} /* Sentinel */
+static PyGetSetDef symbol_object_getset[] = {
+ { "value", sympy_get_value, NULL, "Value of the symbol.", NULL },
+ { "symtab", sympy_get_symtab, NULL, "Symbol table holding the symbol.",
+ NULL },
+ { "name", sympy_get_name, NULL,
+ "Name of the symbol, as it appears in the source code.", NULL },
+ { "linkage_name", sympy_get_linkage_name, NULL,
+ "Name of the symbol, as used by the linker (i.e., may be mangled).", NULL },
+ { "print_name", sympy_get_print_name, NULL,
+ "Name of the symbol in a form suitable for output.\n\
+This is either name or linkage_name, depending on whether the user asked GDB\n\
+to display demangled or mangled names.", NULL },
+ { "addr_class", sympy_get_addr_class, NULL, "Address class of the symbol." },
+ { "is_argument", sympy_is_argument, NULL,
+ "True if the symbol is an argument of a function." },
+ { "is_constant", sympy_is_constant, NULL,
+ "True if the symbol is a constant." },
+ { "is_function", sympy_is_function, NULL,
+ "True if the symbol is a function or method." },
+ { "is_variable", sympy_is_variable, NULL,
+ "True if the symbol is a variable." },
+ { NULL } /* Sentinel */
};
PyTypeObject symbol_object_type = {
@@ -318,5 +318,7 @@ PyTypeObject symbol_object_type = {
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
- symbol_object_methods /* tp_methods */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ symbol_object_getset /* tp_getset */
};
--
1.5.6.3