This is the mail archive of the archer@sourceware.org mailing list for the Archer project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[python][rfc] Use attributes in gdb.Symtab and gdb.Symtab_and_line.


For gdb.Symtab, changed get_filename method to filename attribute, but
kept to_fullname as a method.

For gdb.Symtab_and_line, changed all methods to attributes. 


2008-12-05  Thiago Jung Bauermann  <bauerman@br.ibm.com>

	* python/python-symtab.c (stpy_filename): Rename to ...
	(stpy_get_filename): ... this. Change to conform to Python getter
	signature.
	(salpy_pc): Rename to ...
	(salpy_get_pc): ... this. Change to conform to Python
	getter signature.
	(salpy_line): Rename to ...
	(salpy_get_line): ... this. Change to conform to Python
	getter signature.
	(salpy_getsymtab): Rename to ...
	(salpy_get_symtab): ... this.
	(salpy_setsymtab): Remove.
	(symtab_object_getset): New.
	(symtab_object_methods): Remove `get_filename' entry.
	(symtab_object_type): Set tp_getset field.
	(sal_object_methods): Remove in favor of ...
	(sal_object_getset): ... this.
	(sal_object_type): Set tp_getset field. Unset tp_methods field.
	* python/lib/gdb/command/backtrace.py: Adjust to use gdb.Symtab and
	gdb.Symtab_and_line attributes rather than functions.

diff --git a/gdb/python/lib/gdb/command/backtrace.py b/gdb/python/lib/gdb/command/backtrace.py
index fd99ae1..1de9725 100644
--- a/gdb/python/lib/gdb/command/backtrace.py
+++ b/gdb/python/lib/gdb/command/backtrace.py
@@ -88,7 +88,7 @@ class FrameWrapper:
             name = self.frame.name ()
             if not name:
                 name = "??"
-            if pc != sal.get_pc () or not sal.symtab:
+            if pc != sal.pc or not sal.symtab:
                 stream.write (" 0x%08x in" % pc)
             stream.write (" " + name + " (")
 
@@ -97,11 +97,11 @@ class FrameWrapper:
 
             stream.write (")")
 
-            if sal.symtab and sal.symtab.get_filename ():
-                stream.write (" at " + sal.symtab.get_filename ())
-                stream.write (":" + str (sal.get_line ()))
+            if sal.symtab and sal.symtab.filename:
+                stream.write (" at " + sal.symtab.filename)
+                stream.write (":" + str (sal.line))
 
-            if not self.frame.name () or (not sal.symtab or not sal.symtab.get_filename ()):
+            if not self.frame.name () or (not sal.symtab or not sal.symtab.filename):
                 lib = gdb.solib_address (pc)
                 if lib:
                     stream.write (" from " + lib)
diff --git a/gdb/python/python-symtab.c b/gdb/python/python-symtab.c
index fab4161..55352bc 100644
--- a/gdb/python/python-symtab.c
+++ b/gdb/python/python-symtab.c
@@ -57,9 +57,8 @@ stpy_str (PyObject *self)
   return result;
 }
 
-/* FIXME: maybe this should be an attribute instead of a method?  */
 static PyObject *
-stpy_filename (PyObject *self, PyObject *args)
+stpy_get_filename (PyObject *self, void *closure)
 {
   symtab_object *self_symtab = (symtab_object *) self;
   PyObject *str_obj;
@@ -113,19 +112,19 @@ salpy_str (PyObject *self)
 }
 
 static PyObject *
-salpy_pc (PyObject *self, PyObject *args)
+salpy_get_pc (PyObject *self, void *closure)
 {
   return PyLong_FromUnsignedLongLong (((sal_object *) self)->sal->pc);
 }
 
 static PyObject *
-salpy_line (PyObject *self, PyObject *args)
+salpy_get_line (PyObject *self, void *closure)
 {
   return PyLong_FromUnsignedLongLong (((sal_object *) self)->sal->line);
 }
 
 static PyObject *
-salpy_getsymtab (PyObject *self, void *closure)
+salpy_get_symtab (PyObject *self, void *closure)
 {
   sal_object *self_sal = (sal_object *) self;
 
@@ -134,14 +133,6 @@ salpy_getsymtab (PyObject *self, void *closure)
   return (PyObject *) self_sal->symtab;
 }
 
-static int
-salpy_setsymtab (PyObject *self, PyObject *value, void *closure)
-{
-  PyErr_SetString (PyExc_TypeError, "The symtab attribute can't be modified.");
-
-  return -1;
-}
-
 static void 
 salpy_dealloc (PyObject *self)
 {
@@ -231,9 +222,13 @@ gdbpy_initialize_symtabs (void)
 
 
 
+static PyGetSetDef symtab_object_getset[] = {
+  { "filename", stpy_get_filename, NULL,
+    "The symbol table's source filename.", NULL },
+  {NULL}  /* Sentinel */
+};
+
 static PyMethodDef symtab_object_methods[] = {
-  { "get_filename", stpy_filename, METH_NOARGS,
-    "Return the symtab's source filename." },
   { "to_fullname", stpy_to_fullname, METH_NOARGS,
     "Return the symtab's full source filename." },
   {NULL}  /* Sentinel */
@@ -268,19 +263,16 @@ static PyTypeObject symtab_object_type = {
   0,				  /* tp_weaklistoffset */
   0,				  /* tp_iter */
   0,				  /* tp_iternext */
-  symtab_object_methods		  /* tp_methods */
-};
-
-static PyGetSetDef sal_object_getseters[] = {
-  { "symtab", salpy_getsymtab, salpy_setsymtab, "Symtab object.", NULL },
-  {NULL}  /* Sentinel */
+  symtab_object_methods,	  /* tp_methods */
+  0,				  /* tp_members */
+  symtab_object_getset		  /* tp_getset */
 };
 
-static PyMethodDef sal_object_methods[] = {
-  { "get_pc", salpy_pc, METH_NOARGS,
-    "Return the symtab_and_line's pc." },
-  { "get_line", salpy_line, METH_NOARGS,
-    "Return the symtab_and_line's line." },
+static PyGetSetDef sal_object_getset[] = {
+  { "symtab", salpy_get_symtab, NULL, "Symtab object.", NULL },
+  { "pc", salpy_get_pc, NULL, "Return the symtab_and_line's pc.", NULL },
+  { "line", salpy_get_line, NULL,
+    "Return the symtab_and_line's line.", NULL },
   {NULL}  /* Sentinel */
 };
 
@@ -313,7 +305,7 @@ static PyTypeObject sal_object_type = {
   0,				  /* tp_weaklistoffset */
   0,				  /* tp_iter */
   0,				  /* tp_iternext */
-  sal_object_methods,		  /* tp_methods */
+  0,				  /* tp_methods */
   0,				  /* tp_members */
-  sal_object_getseters		  /* tp_getset */
+  sal_object_getset		  /* tp_getset */
 };
-- 
1.5.6.3



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]