public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-tromey-python:  * python/python-value.c (valpy_getitem): Convert field name to
@ 2008-11-03 20:33 tromey
  0 siblings, 0 replies; only message in thread
From: tromey @ 2008-11-03 20:33 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  216d6dbe872c72303a3d24b1538e44560b003df3 (commit)
       via  b59ad346cfa6c3f89be348ef4f4029a2f421220e (commit)
       via  344a0cdf12f3c60ad027f536f209dea7be51e1f0 (commit)
      from  ef2a3a61d8b15e44a5e4a69109026b9f892250a7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 216d6dbe872c72303a3d24b1538e44560b003df3
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Nov 3 13:33:51 2008 -0700

    	* python/python-value.c (valpy_getitem): Convert field name to
    	host string.  Handle array accesses.
    	(valpy_invert): New function.
    	(valpy_lsh): Likewise.
    	(valpy_rsh): Likewise.
    	(valpy_and): Likewise.
    	(valpy_or): Likewise.
    	(valpy_xor): Likewise.
    	(value_object_as_number): Update for new methods.
    	(enum valpy_opcode) <VALPY_LSH, VALPY_RSH, VALPY_BITAND,
    	VALPY_BITXOR, VALPY_BITOR>: New constants.
    	(valpy_binop): Update.

commit b59ad346cfa6c3f89be348ef4f4029a2f421220e
Merge: 344a0cdf12f3c60ad027f536f209dea7be51e1f0 ef2a3a61d8b15e44a5e4a69109026b9f892250a7
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Nov 3 11:45:24 2008 -0700

    Merge branch 'archer-tromey-python' of ssh://sourceware.org/git/archer into archer-tromey-python

commit 344a0cdf12f3c60ad027f536f209dea7be51e1f0
Author: Tom Tromey <tromey@redhat.com>
Date:   Fri Oct 31 11:24:11 2008 -0600

    	* python/python.c (_initialize_python): Call
    	gdbpy_initialize_objfile.
    	(gdbpy_current_objfile): New global.
    	(gdbpy_get_current_objfile): New function.
    	(gdbpy_new_objfile): Set gdbpy_current_objfile.  Use real path to
    	objfile.  Change filename computation.
    	(GdbMethods): Add get_current_objfile, get_objfiles.
    	(gdbpy_get_objfiles): New function.
    	(find_pretty_printer): Remove dict_name argument, add is_mi.
    	Search objfile printers first.
    	(search_pp_dictionary): New function.
    	(apply_pretty_printer): Update.
    	(apply_val_pretty_printer): Likewise.
    	(gdbpy_get_varobj_pretty_printer): Likewise.
    	(GDBPY_AUTO_FILENAME): Change value.
    	* python/python-objfile.c: New file.
    	* python/python-internal.h (objfile_to_objfile_object): Declare.
    	(gdbpy_initialize_objfile): Declare.
    	(objfpy_get_mi_printers, objfpy_get_cli_printers): Declare.
    	* Makefile.in (SUBDIR_PYTHON_OBS): Add python-objfile.o.
    	(SUBDIR_PYTHON_SRCS): Add python-objfile.c.
    	(python-objfile.o): New target.

-----------------------------------------------------------------------

Summary of changes:
 gdb/ChangeLog                |   40 ++++++
 gdb/Makefile.in              |    6 +
 gdb/python/python-internal.h |    5 +
 gdb/python/python-objfile.c  |  281 ++++++++++++++++++++++++++++++++++++++++++
 gdb/python/python-value.c    |  116 +++++++++++++++---
 gdb/python/python.c          |  157 ++++++++++++++++++-----
 6 files changed, 553 insertions(+), 52 deletions(-)
 create mode 100644 gdb/python/python-objfile.c

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 8def8d3..51e62a8 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,43 @@
+2008-11-03  Tom Tromey  <tromey@redhat.com>
+
+	* python/python-value.c (valpy_getitem): Convert field name to
+	host string.  Handle array accesses.
+	(valpy_invert): New function.
+	(valpy_lsh): Likewise.
+	(valpy_rsh): Likewise.
+	(valpy_and): Likewise.
+	(valpy_or): Likewise.
+	(valpy_xor): Likewise.
+	(value_object_as_number): Update for new methods.
+	(enum valpy_opcode) <VALPY_LSH, VALPY_RSH, VALPY_BITAND,
+	VALPY_BITXOR, VALPY_BITOR>: New constants.
+	(valpy_binop): Update.
+
+2008-10-31  Tom Tromey  <tromey@redhat.com>
+
+	* python/python.c (_initialize_python): Call
+	gdbpy_initialize_objfile.
+	(gdbpy_current_objfile): New global.
+	(gdbpy_get_current_objfile): New function.
+	(gdbpy_new_objfile): Set gdbpy_current_objfile.  Use real path to
+	objfile.  Change filename computation.
+	(GdbMethods): Add get_current_objfile, get_objfiles.
+	(gdbpy_get_objfiles): New function.
+	(find_pretty_printer): Remove dict_name argument, add is_mi.
+	Search objfile printers first.
+	(search_pp_dictionary): New function.
+	(apply_pretty_printer): Update.
+	(apply_val_pretty_printer): Likewise.
+	(gdbpy_get_varobj_pretty_printer): Likewise.
+	(GDBPY_AUTO_FILENAME): Change value.
+	* python/python-objfile.c: New file.
+	* python/python-internal.h (objfile_to_objfile_object): Declare.
+	(gdbpy_initialize_objfile): Declare.
+	(objfpy_get_mi_printers, objfpy_get_cli_printers): Declare.
+	* Makefile.in (SUBDIR_PYTHON_OBS): Add python-objfile.o.
+	(SUBDIR_PYTHON_SRCS): Add python-objfile.c.
+	(python-objfile.o): New target.
+
 2008-10-27  Tom Tromey  <tromey@redhat.com>
 
 	* python/python.c (_initialize_python) <_format_children>: Handle
diff --git a/gdb/Makefile.in b/gdb/Makefile.in
index 1706b6b..a0716af 100644
--- a/gdb/Makefile.in
+++ b/gdb/Makefile.in
@@ -277,6 +277,7 @@ SUBDIR_PYTHON_OBS = \
 	python-frame.o \
 	python-function.o \
 	python-hooks.o \
+	python-objfile.o \
 	python-param.o \
 	python-symbol.o \
 	python-symtab.o \
@@ -291,6 +292,7 @@ SUBDIR_PYTHON_SRCS = \
 	python/python-frame.c \
 	python/python-function.c \
 	python/python-hooks.c \
+	python/python-objfile.c \
 	python/python-param.c \
 	python/python-symbol.c \
 	python/python-symtab.c \
@@ -1891,6 +1893,10 @@ python-hooks.o: $(srcdir)/python/python-hooks.c
 	$(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/python-hooks.c
 	$(POSTCOMPILE)
 
+python-objfile.o: $(srcdir)/python/python-objfile.c
+	$(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/python-objfile.c
+	$(POSTCOMPILE)
+
 python-param.o: $(srcdir)/python/python-param.c
 	$(COMPILE) $(PYTHON_CFLAGS) $(srcdir)/python/python-param.c
 	$(POSTCOMPILE)
diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h
index 12b9917..6dff805 100644
--- a/gdb/python/python-internal.h
+++ b/gdb/python/python-internal.h
@@ -73,6 +73,10 @@ PyObject *block_to_block_object (struct block *block);
 PyObject *value_to_value_object (struct value *v);
 PyObject *gdb_owned_value_to_value_object (struct value *v);
 PyObject *type_to_type_object (struct type *);
+PyObject *objfile_to_objfile_object (struct objfile *);
+
+PyObject *objfpy_get_mi_printers (PyObject *, void *);
+PyObject *objfpy_get_cli_printers (PyObject *, void *);
 
 struct block *block_object_to_block (PyObject *obj);
 struct symbol *symbol_object_to_symbol (PyObject *obj);
@@ -91,6 +95,7 @@ void gdbpy_initialize_symbols (void);
 void gdbpy_initialize_types (void);
 void gdbpy_initialize_blocks (void);
 void gdbpy_initialize_functions (void);
+void gdbpy_initialize_objfile (void);
 void gdbpy_initialize_parameters (void);
 
 struct cleanup *make_cleanup_py_decref (PyObject *py);
diff --git a/gdb/python/python-objfile.c b/gdb/python/python-objfile.c
new file mode 100644
index 0000000..6b5a7c3
--- /dev/null
+++ b/gdb/python/python-objfile.c
@@ -0,0 +1,281 @@
+/* Python interface to objfiles.
+
+   Copyright (C) 2008 Free Software Foundation, Inc.
+
+   This file is part of GDB.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#include "defs.h"
+#include "python-internal.h"
+#include "charset.h"
+#include "objfiles.h"
+
+typedef struct
+{
+  PyObject_HEAD
+
+  /* The corresponding objfile.  */
+  struct objfile *objfile;
+
+  /* The pretty-printer dictionaries.  */
+  PyObject *mi_printers;
+  PyObject *cli_printers;
+} objfile_object;
+
+static PyTypeObject objfile_object_type;
+
+static const struct objfile_data *objfpy_objfile_data_key;
+
+\f
+
+/* An Objfile method which returns the objfile's file name, or None.  */
+static PyObject *
+objfpy_filename (PyObject *self, PyObject *args)
+{
+  objfile_object *obj = (objfile_object *) self;
+  if (obj->objfile && obj->objfile->name)
+    return PyString_Decode (obj->objfile->name, strlen (obj->objfile->name),
+			    host_charset (), NULL);
+  Py_RETURN_NONE;
+}
+
+static void
+objfpy_dealloc (PyObject *o)
+{
+  objfile_object *self = (objfile_object *) o;
+  Py_XDECREF (self->mi_printers);
+  Py_XDECREF (self->cli_printers);
+  self->ob_type->tp_free ((PyObject *) self);
+}
+
+static PyObject *
+objfpy_new (PyTypeObject *type, PyObject *args, PyObject *keywords)
+{
+  objfile_object *self = (objfile_object *) type->tp_alloc (type, 0);
+  if (self)
+    {
+      self->objfile = NULL;
+      /* Initialize in case of early return.  */
+      self->cli_printers = NULL;
+
+      self->mi_printers = PyDict_New ();
+      if (!self->mi_printers)
+	{
+	  Py_DECREF (self);
+	  return NULL;
+	}
+      self->cli_printers = PyDict_New ();
+      if (!self->cli_printers)
+	{
+	  Py_DECREF (self);
+	  return NULL;
+	}
+    }
+  return (PyObject *) self;
+}
+
+PyObject *
+objfpy_get_mi_printers (PyObject *o, void *ignore)
+{
+  objfile_object *self = (objfile_object *) o;
+  Py_INCREF (self->mi_printers);
+  return self->mi_printers;
+}
+
+static int
+objfpy_set_mi_printers (PyObject *o, PyObject *value, void *ignore)
+{
+  objfile_object *self = (objfile_object *) o;
+  if (! value)
+    {
+      PyErr_SetString (PyExc_TypeError,
+		       "cannot delete the mi_pretty_printers attribute");
+      return -1;
+    }
+
+  if (! PyDict_Check (value))
+    {
+      PyErr_SetString (PyExc_TypeError,
+		       "the mi_pretty_printers attribute must be a dictionary");
+      return -1;
+    }
+
+  Py_XDECREF (self->mi_printers);
+  Py_INCREF (value);
+  self->mi_printers = value;
+
+  return 0;
+}
+
+PyObject *
+objfpy_get_cli_printers (PyObject *o, void *ignore)
+{
+  objfile_object *self = (objfile_object *) o;
+  Py_INCREF (self->cli_printers);
+  return self->cli_printers;
+}
+
+static int
+objfpy_set_cli_printers (PyObject *o, PyObject *value, void *ignore)
+{
+  objfile_object *self = (objfile_object *) o;
+  if (! value)
+    {
+      PyErr_SetString (PyExc_TypeError,
+		       "cannot delete the cli_pretty_printers attribute");
+      return -1;
+    }
+
+  if (! PyDict_Check (value))
+    {
+      PyErr_SetString (PyExc_TypeError,
+		       "the cli_pretty_printers attribute must be a dictionary");
+      return -1;
+    }
+
+  Py_XDECREF (self->cli_printers);
+  Py_INCREF (value);
+  self->cli_printers = value;
+
+  return 0;
+}
+
+\f
+
+/* Clear the OBJFILE pointer in an Objfile object and remove the
+   reference.  */
+static void
+clean_up_objfile (struct objfile *objfile, void *datum)
+{
+  objfile_object *object = datum;
+  object->objfile = NULL;
+  Py_DECREF ((PyObject *) object);
+}
+
+/* Return the Python object of type Objfile representing OBJFILE.  If
+   the object has already been created, return it.  Otherwise, create
+   it.  Return NULL and set the Python error on failure.  */
+PyObject *
+objfile_to_objfile_object (struct objfile *objfile)
+{
+  objfile_object *object;
+
+  object = objfile_data (objfile, objfpy_objfile_data_key);
+  if (!object)
+    {
+      object = PyObject_New (objfile_object, &objfile_object_type);
+      if (object)
+	{
+	  PyObject *dict;
+
+	  object->objfile = objfile;
+	  /* Initialize in case of early return.  */
+	  object->cli_printers = NULL;
+
+	  object->mi_printers = PyDict_New ();
+	  if (!object->mi_printers)
+	    {
+	      Py_DECREF (object);
+	      return NULL;
+	    }
+
+	  object->cli_printers = PyDict_New ();
+	  if (!object->cli_printers)
+	    {
+	      Py_DECREF (object);
+	      return NULL;
+	    }
+
+	  set_objfile_data (objfile, objfpy_objfile_data_key, object);
+	}
+    }
+
+  return (PyObject *) object;
+}
+
+void
+gdbpy_initialize_objfile (void)
+{
+  objfpy_objfile_data_key
+    = register_objfile_data_with_cleanup (clean_up_objfile);
+
+  objfile_object_type.tp_new = PyType_GenericNew;
+  if (PyType_Ready (&objfile_object_type) < 0)
+    return;
+
+  Py_INCREF (&objfile_object_type);
+  PyModule_AddObject (gdb_module, "Objfile", (PyObject *) &objfile_object_type);
+}
+
+\f
+
+static PyGetSetDef objfile_getset[] =
+{
+  { "mi_pretty_printers", objfpy_get_mi_printers, objfpy_set_mi_printers,
+    "MI pretty printers", NULL },
+  { "cli_pretty_printers", objfpy_get_cli_printers, objfpy_set_cli_printers,
+    "CLI pretty printers", NULL },
+  { NULL }
+};
+
+static PyMethodDef objfile_object_methods[] =
+{
+  { "get_filename", objfpy_filename, METH_NOARGS,
+    "Return the objfile's filename, or None." },
+  {NULL}  /* Sentinel */
+};
+
+static PyTypeObject objfile_object_type =
+{
+  PyObject_HEAD_INIT (NULL)
+  0,				  /*ob_size*/
+  "gdb.Objfile",		  /*tp_name*/
+  sizeof (objfile_object),	  /*tp_basicsize*/
+  0,				  /*tp_itemsize*/
+  objfpy_dealloc,		  /*tp_dealloc*/
+  0,				  /*tp_print*/
+  0,				  /*tp_getattr*/
+  0,				  /*tp_setattr*/
+  0,				  /*tp_compare*/
+  0,				  /*tp_repr*/
+  0,				  /*tp_as_number*/
+  0,				  /*tp_as_sequence*/
+  0,				  /*tp_as_mapping*/
+  0,				  /*tp_hash */
+  0,				  /*tp_call*/
+  0,				  /*tp_str*/
+  0,				  /*tp_getattro*/
+  0,				  /*tp_setattro*/
+  0,				  /*tp_as_buffer*/
+  Py_TPFLAGS_DEFAULT,		  /*tp_flags*/
+  "GDB objfile object",		  /* tp_doc */
+  0,				  /* tp_traverse */
+  0,				  /* tp_clear */
+  0,				  /* tp_richcompare */
+  0,				  /* tp_weaklistoffset */
+  0,				  /* tp_iter */
+  0,				  /* tp_iternext */
+  objfile_object_methods,	  /* tp_methods */
+  0,				  /* tp_members */
+  objfile_getset,		  /* tp_getset */
+  0,				  /* tp_base */
+  0,				  /* tp_dict */
+  0,				  /* tp_descr_get */
+  0,				  /* tp_descr_set */
+  0,				  /* tp_dictoffset */
+  0,				  /* tp_init */
+  0,				  /* tp_alloc */
+  objfpy_new,			  /* tp_new */
+};
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 5064ccf..04039ce 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -196,26 +196,37 @@ static PyObject *
 valpy_getitem (PyObject *self, PyObject *key)
 {
   value_object *self_value = (value_object *) self;
-  char *field;
+  char *field = NULL;
+  struct value *idx = NULL;
   struct value *res_val = NULL;	  /* Initialize to appease gcc warning.  */
-  struct cleanup *old;
   volatile struct gdb_exception except;
 
-  field = python_string_to_target_string (key);
-  if (field == NULL)
-    return NULL;
-
-  old = make_cleanup (xfree, field);
+  if (PyUnicode_Check (key) || PyString_Check (key))
+    {  
+      field = python_string_to_host_string (key);
+      if (field == NULL)
+	return NULL;
+    }
 
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
       struct value *tmp = self_value->value;
-      res_val = value_struct_elt (&tmp, NULL, field, 0, NULL);
+
+      if (field)
+	res_val = value_struct_elt (&tmp, NULL, field, 0, NULL);
+      else
+	{
+	  /* Assume we are attempting an array access, and let the
+	     value code throw an exception if the index has an invalid
+	     type.  */
+	  struct value *idx = convert_value_from_python (key);
+	  res_val = value_subscript (tmp, idx);
+	}
     }
+  if (field)
+    xfree (field);
   GDB_PY_HANDLE_EXCEPTION (except);
 
-  do_cleanups (old);
-
   return value_to_value_object (res_val);
 }
 
@@ -265,7 +276,12 @@ enum valpy_opcode
   VALPY_MUL,
   VALPY_DIV,
   VALPY_REM,
-  VALPY_POW
+  VALPY_POW,
+  VALPY_LSH,
+  VALPY_RSH,
+  VALPY_BITAND,
+  VALPY_BITOR,
+  VALPY_BITXOR
 };
 
 /* If TYPE is a reference, return the target; otherwise return TYPE.  */
@@ -347,6 +363,21 @@ valpy_binop (enum valpy_opcode opcode, PyObject *self, PyObject *other)
 	case VALPY_POW:
 	  res_val = value_binop (arg1, arg2, BINOP_EXP);
 	  break;
+	case VALPY_LSH:
+	  res_val = value_binop (arg1, arg2, BINOP_LSH);
+	  break;
+	case VALPY_RSH:
+	  res_val = value_binop (arg1, arg2, BINOP_RSH);
+	  break;
+	case VALPY_BITAND:
+	  res_val = value_binop (arg1, arg2, BINOP_BITWISE_AND);
+	  break;
+	case VALPY_BITOR:
+	  res_val = value_binop (arg1, arg2, BINOP_BITWISE_IOR);
+	  break;
+	case VALPY_BITXOR:
+	  res_val = value_binop (arg1, arg2, BINOP_BITWISE_XOR);
+	  break;
 	}
     }
   GDB_PY_HANDLE_EXCEPTION (except);
@@ -457,6 +488,57 @@ valpy_nonzero (PyObject *self)
     }
 }
 
+/* Implements ~ for value objects.  */
+static PyObject *
+valpy_invert (PyObject *self)
+{
+  struct value *val = NULL;
+  volatile struct gdb_exception except;
+
+  TRY_CATCH (except, RETURN_MASK_ALL)
+    {
+      val = value_complement (((value_object *) self)->value);
+    }
+  GDB_PY_HANDLE_EXCEPTION (except);
+
+  return value_to_value_object (val);
+}
+
+/* Implements left shift for value objects.  */
+static PyObject *
+valpy_lsh (PyObject *self, PyObject *other)


hooks/post-receive
--
Repository for Project Archer.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-11-03 20:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-11-03 20:33 [SCM] archer-tromey-python: * python/python-value.c (valpy_getitem): Convert field name to tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).