diff options
| author | Tom Tromey <tromey@redhat.com> | 2012-11-12 17:41:59 +0000 | 
|---|---|---|
| committer | Tom Tromey <tromey@redhat.com> | 2012-11-12 17:41:59 +0000 | 
| commit | 18a9fc1261b8a654fe6db7eea7e60b0c59296d96 (patch) | |
| tree | 50b1290ab9827f259ea103cf50367d7ac6c0e878 /gdb/python/py-progspace.c | |
| parent | bd69fc683f383772bb8fab43c5d4af8d0cd4a8b4 (diff) | |
| download | binutils-18a9fc1261b8a654fe6db7eea7e60b0c59296d96.zip binutils-18a9fc1261b8a654fe6db7eea7e60b0c59296d96.tar.gz binutils-18a9fc1261b8a654fe6db7eea7e60b0c59296d96.tar.bz2  | |
	* NEWS: Update.
	* data-directory/Makefile.in (PYTHON_FILES): Add
	type_printers.py.
	* python/lib/gdb/command/type_printers.py: New file.
	* python/lib/gdb/command/types.py (TypePrinter): New class.
	(_get_some_type_recognizers, get_type_recognizers,
	apply_type_recognizers, register_type_printer): New
	functions.
	* python/py-objfile.c (objfile_object) <type_printers>: New
	field.
	(objfpy_dealloc): Decref new field.
	(objfpy_new): Set new field.
	(objfpy_get_type_printers, objfpy_set_type_printers): New
	functions.
	(objfile_to_objfile_object): Set new field.
	(objfile_getset): Add "type_printers".
	* python/py-progspace.c (pspace_object) <type_printers>: New
	field.
	(pspy_dealloc): Decref new field.
	(pspy_new): Set new field.
	(pspy_get_type_printers, pspy_set_type_printers): New functions.
	(pspace_to_pspace_object): Set new field.
	(pspace_getset): Add "type_printers".
	* python/python.c (start_type_printers, apply_type_printers,
	free_type_printers): New functions.
	(_initialize_python): Set gdb.type_printers.
	* python/python.h (start_type_printers, apply_type_printers,
	free_type_printers): Declare.
	* typeprint.c (type_print_raw_options, default_ptype_flags):
	Update for new fields.
	(do_free_global_table, create_global_typedef_table,
	find_global_typedef): New functions.
	(find_typedef_in_hash): Use find_global_typedef.
	(whatis_exp): Use create_global_typedef_table.  Change cleanup
	handling.
	* typeprint.h (struct type_print_options) <global_typedefs,
	global_printers>: New fields.
doc
	* gdb.texinfo (Symbols): Document "info type-printers",
	"enable type-printer" and "disable type-printer".
	(Python API): Add new node to menu.
	(Type Printing API): New node.
	(Progspaces In Python): Document type_printers field.
	(Objfiles In Python): Likewise.
	(gdb.types) <get_type_recognizers, apply_type_recognizers,
	register_type_printer, TypePrinter>: Document.
testsuite
	* gdb.base/completion.exp: Update for "info type-printers".
	* gdb.python/py-typeprint.cc: New file.
	* gdb.python/py-typeprint.exp: New file.
	* gdb.python/py-typeprint.py: New file.
Diffstat (limited to 'gdb/python/py-progspace.c')
| -rw-r--r-- | gdb/python/py-progspace.c | 62 | 
1 files changed, 62 insertions, 0 deletions
diff --git a/gdb/python/py-progspace.c b/gdb/python/py-progspace.c index e4b029b..c1b1cac 100644 --- a/gdb/python/py-progspace.c +++ b/gdb/python/py-progspace.c @@ -34,6 +34,9 @@ typedef struct    /* The pretty-printer list of functions.  */    PyObject *printers; + +  /* The type-printer list.  */ +  PyObject *type_printers;  } pspace_object;  static PyTypeObject pspace_object_type; @@ -66,6 +69,7 @@ pspy_dealloc (PyObject *self)    pspace_object *ps_self = (pspace_object *) self;    Py_XDECREF (ps_self->printers); +  Py_XDECREF (ps_self->type_printers);    self->ob_type->tp_free (self);  } @@ -84,6 +88,13 @@ pspy_new (PyTypeObject *type, PyObject *args, PyObject *keywords)  	  Py_DECREF (self);  	  return NULL;  	} + +      self->type_printers = PyList_New (0); +      if (!self->type_printers) +	{ +	  Py_DECREF (self); +	  return NULL; +	}      }    return (PyObject *) self;  } @@ -126,6 +137,48 @@ pspy_set_printers (PyObject *o, PyObject *value, void *ignore)    return 0;  } +/* Get the 'type_printers' attribute.  */ + +static PyObject * +pspy_get_type_printers (PyObject *o, void *ignore) +{ +  pspace_object *self = (pspace_object *) o; + +  Py_INCREF (self->type_printers); +  return self->type_printers; +} + +/* Set the 'type_printers' attribute.  */ + +static int +pspy_set_type_printers (PyObject *o, PyObject *value, void *ignore) +{ +  PyObject *tmp; +  pspace_object *self = (pspace_object *) o; + +  if (! value) +    { +      PyErr_SetString (PyExc_TypeError, +		       "cannot delete the type_printers attribute"); +      return -1; +    } + +  if (! PyList_Check (value)) +    { +      PyErr_SetString (PyExc_TypeError, +		       "the type_printers attribute must be a list"); +      return -1; +    } + +  /* Take care in case the LHS and RHS are related somehow.  */ +  tmp = self->type_printers; +  Py_INCREF (value); +  self->type_printers = value; +  Py_XDECREF (tmp); + +  return 0; +} +  /* Clear the PSPACE pointer in a Pspace object and remove the reference.  */ @@ -168,6 +221,13 @@ pspace_to_pspace_object (struct program_space *pspace)  	      return NULL;  	    } +	  object->type_printers = PyList_New (0); +	  if (!object->type_printers) +	    { +	      Py_DECREF (object); +	      return NULL; +	    } +  	  set_program_space_data (pspace, pspy_pspace_data_key, object);  	}      } @@ -197,6 +257,8 @@ static PyGetSetDef pspace_getset[] =      "The progspace's main filename, or None.", NULL },    { "pretty_printers", pspy_get_printers, pspy_set_printers,      "Pretty printers.", NULL }, +  { "type_printers", pspy_get_type_printers, pspy_set_type_printers, +    "Type printers.", NULL },    { NULL }  };  | 
