public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
From: tromey@sourceware.org
To: archer-commits@sourceware.org
Subject: [SCM]  archer-tromey-python: gdb
Date: Sun, 16 Nov 2008 16:56:00 -0000	[thread overview]
Message-ID: <20081116165647.8599.qmail@sourceware.org> (raw)

The branch, archer-tromey-python has been updated
       via  e97eeebcadd8e1ced9e9e428c6809e01a94dbfac (commit)
      from  80512129f1fb5c58348113fcc93ff854b1f7d6f3 (commit)

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

- Log -----------------------------------------------------------------
commit e97eeebcadd8e1ced9e9e428c6809e01a94dbfac
Author: Tom Tromey <tromey@redhat.com>
Date:   Sun Nov 16 09:56:30 2008 -0700

    gdb
    	* python/python-type.c (typy_code): New function.
    	(struct pyty_code): New type.
    	(ENTRY): New define.
    	(pyty_codes): New array.
    	(clean_up_objfile_types): Acquire GIL.
    	(gdbpy_initialize_types): Register new constants.
    	(type_object_methods): Add "code", "fields", "tag" methods.
    	(convert_field): New functionn.
    	(typy_fields): Likewise.
    	(typy_tag): Likewise.
    	(typy_lookup_typename): Allow struct/union/enum.  Change error
    	handling.
    	(typy_lookup_type): Update.
    	(typy_new): Likewise.
    gdb/doc
    	* gdb.texinfo (Types From Inferior): Update.

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

Summary of changes:
 gdb/ChangeLog            |   17 ++++
 gdb/doc/ChangeLog        |    4 +
 gdb/doc/gdb.texinfo      |  207 +++++++++++++++++++++++++++++++++++++++++++++-
 gdb/python/python-type.c |  197 ++++++++++++++++++++++++++++++++++++++++---
 4 files changed, 410 insertions(+), 15 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 94b6427..9de4746 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,20 @@
+2008-11-16  Tom Tromey  <tromey@redhat.com>
+
+	* python/python-type.c (typy_code): New function.
+	(struct pyty_code): New type.
+	(ENTRY): New define.
+	(pyty_codes): New array.
+	(clean_up_objfile_types): Acquire GIL.
+	(gdbpy_initialize_types): Register new constants.
+	(type_object_methods): Add "code", "fields", "tag" methods.
+	(convert_field): New functionn.
+	(typy_fields): Likewise.
+	(typy_tag): Likewise.
+	(typy_lookup_typename): Allow struct/union/enum.  Change error
+	handling.
+	(typy_lookup_type): Update.
+	(typy_new): Likewise.
+
 2008-11-15  Tom Tromey  <tromey@redhat.com>
 
 	* varobj.c (varobj_get_display_hint): Acquire GIL.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index 6dad6d3..0b85f5c 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2008-11-16  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.texinfo (Types From Inferior): Update.
+
 2008-11-13  Tom Tromey  <tromey@redhat.com>
 
 	* gdb.texinfo (Basic Python): Document gdb.get_objfiles and
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 42ed962..6a38009 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17931,6 +17931,46 @@ If @var{block} is given, then @var{name} is looked up in that scope.
 Otherwise, it is searched for globally.
 @end defmethod
 
+@defmethod Type code
+Return the type code for this type.  The type code will be one of the
+@code{TYPE_CODE_} constants defined below.
+@end defmethod
+
+@defmethod Type fields
+Return a sequence of all fields of this type.  If this type has no
+fields, the sequence will be empty.
+
+For structure and union types, this method returns the fields.  Range
+types have two fields, the minimum and maximum values.  Enum types
+have one field per enum constant.  Function and method types have one
+field per parameter.  The base types of C++ classes are also
+represented as fields.
+
+Each field is a dictionary, with some pre-defined elements:
+@table @code
+@item bitpos
+This element is not available for @code{static} fields.  For
+non-@code{static} fields, the value is the bit position of the field.
+
+@item name
+The name of the field.  This element is not available for anonymous
+fields.
+
+@item artificial
+This is @code{True} if the field is artificial, usually meaning that
+it was provided by the compiler and not the user.  This value is
+always provided, and is @code{False} if the field is not artificial.
+
+@item bitsize
+If the field is packed, or is a bitfield, then this will have a
+nonzero value, which is the size of the field in bits.  Otherwise,
+this will be zero; in this case the field's size is given by its type.
+
+@item type
+The type of the field.
+@end table
+@end defmethod
+
 @defmethod Type pointer
 Return a new @code{gdb.Type} object which represents a pointer to this
 type.
@@ -17942,7 +17982,16 @@ type.
 @end defmethod
 
 @defmethod Type sizeof
-Return the size of this type, in bytes.
+Return the size of this type, in target @code{char} units.  Usually, a
+target's @code{char} type will be an 8-bit byte.  However, on some
+unusual platforms, this type may have a different size.
+@end defmethod
+
+@defmethod Type tag
+Return the tag name for this type.  The tag name is the name after
+@code{struct}, @code{union}, or @code{enum} in C; not all languages
+have this concept.  If this type has no tag name, then @code{None} is
+returned.
 @end defmethod
 
 @defmethod Type target
@@ -17953,7 +18002,8 @@ For a pointer type, the target type is the type of the pointed-to
 object.  For an array type, the target type is the type of the
 elements of the array.  For a function type, the target type is the
 type of the return value.  For a complex type, the target type is the
-type of the elements.
+type of the elements.  For a typedef, the target type is the aliased
+type.
 @end defmethod
 
 @defmethod Type template_argument n [block]
@@ -17969,6 +18019,159 @@ Otherwise, it is searched for globally.
 @end defmethod
 @end table
 
+
+Each type has a code, which indicates what category this type falls
+into.  The available type categories are represented by constants
+defined in the @code{gdb} module:
+
+@table @code
+@findex TYPE_CODE_PTR
+@findex gdb.TYPE_CODE_PTR
+@item TYPE_CODE_PTR
+The type is a pointer.
+
+@findex TYPE_CODE_ARRAY
+@findex gdb.TYPE_CODE_ARRAY
+@item TYPE_CODE_ARRAY
+The type is an array.
+
+@findex TYPE_CODE_STRUCT
+@findex gdb.TYPE_CODE_STRUCT
+@item TYPE_CODE_STRUCT
+The type is a structure.
+
+@findex TYPE_CODE_UNION
+@findex gdb.TYPE_CODE_UNION
+@item TYPE_CODE_UNION
+The type is a union.
+
+@findex TYPE_CODE_ENUM
+@findex gdb.TYPE_CODE_ENUM
+@item TYPE_CODE_ENUM
+The type is an enum.
+
+@findex TYPE_CODE_FLAGS
+@findex gdb.TYPE_CODE_FLAGS
+@item TYPE_CODE_FLAGS
+A bit flags type.
+@c FIXME: what is this?
+
+@findex TYPE_CODE_FUNC
+@findex gdb.TYPE_CODE_FUNC
+@item TYPE_CODE_FUNC
+The type is a function.
+
+@findex TYPE_CODE_INT
+@findex gdb.TYPE_CODE_INT
+@item TYPE_CODE_INT
+The type is an integer type.
+
+@findex TYPE_CODE_FLT
+@findex gdb.TYPE_CODE_FLT
+@item TYPE_CODE_FLT
+A floating point type.
+
+@findex TYPE_CODE_VOID
+@findex gdb.TYPE_CODE_VOID
+@item TYPE_CODE_VOID
+The special type @code{void}.
+
+@findex TYPE_CODE_SET
+@findex gdb.TYPE_CODE_SET
+@item TYPE_CODE_SET
+A Pascal set type.
+
+@findex TYPE_CODE_RANGE
+@findex gdb.TYPE_CODE_RANGE
+@item TYPE_CODE_RANGE
+A range type, that is, an integer type with bounds.
+
+@findex TYPE_CODE_STRING
+@findex gdb.TYPE_CODE_STRING
+@item TYPE_CODE_STRING
+A string type.  Note that this is only used for certain languages with
+language-defined string types; C strings are not represented this way.
+
+@findex TYPE_CODE_BITSTRING
+@findex gdb.TYPE_CODE_BITSTRING
+@item TYPE_CODE_BITSTRING
+A string of bits.
+
+@findex TYPE_CODE_ERROR
+@findex gdb.TYPE_CODE_ERROR
+@item TYPE_CODE_ERROR
+An unknown or erroneous type.
+
+@findex TYPE_CODE_METHOD
+@findex gdb.TYPE_CODE_METHOD
+@item TYPE_CODE_METHOD
+A C++ method type.
+
+@findex TYPE_CODE_METHODPTR
+@findex gdb.TYPE_CODE_METHODPTR
+@item TYPE_CODE_METHODPTR
+A pointer-to-member-function.
+
+@findex TYPE_CODE_MEMBERPTR
+@findex gdb.TYPE_CODE_MEMBERPTR
+@item TYPE_CODE_MEMBERPTR
+A pointer-to-member.
+
+@findex TYPE_CODE_REF
+@findex gdb.TYPE_CODE_REF
+@item TYPE_CODE_REF
+A reference type.
+
+@findex TYPE_CODE_CHAR
+@findex gdb.TYPE_CODE_CHAR
+@item TYPE_CODE_CHAR
+A character type.
+
+@findex TYPE_CODE_BOOL
+@findex gdb.TYPE_CODE_BOOL
+@item TYPE_CODE_BOOL
+A boolean type.
+
+@findex TYPE_CODE_COMPLEX
+@findex gdb.TYPE_CODE_COMPLEX
+@item TYPE_CODE_COMPLEX
+A complex float type.
+
+@findex TYPE_CODE_TYPEDEF
+@findex gdb.TYPE_CODE_TYPEDEF
+@item TYPE_CODE_TYPEDEF
+A typedef to some other type.
+
+@findex TYPE_CODE_TEMPLATE
+@findex gdb.TYPE_CODE_TEMPLATE
+@item TYPE_CODE_TEMPLATE
+A C++ template type.  Note that this is not used for a template
+instantiation; those appear as ordinary struct types.
+@c FIXME I hope that is true
+
+@findex TYPE_CODE_TEMPLATE_ARG
+@findex gdb.TYPE_CODE_TEMPLATE_ARG
+@item TYPE_CODE_TEMPLATE_ARG
+A C++ template argument.
+@c FIXME: is this ever used?
+
+@findex TYPE_CODE_NAMESPACE
+@findex gdb.TYPE_CODE_NAMESPACE
+@item TYPE_CODE_NAMESPACE
+A C++ namespace.
+
+@findex TYPE_CODE_DECFLOAT
+@findex gdb.TYPE_CODE_DECFLOAT
+@item TYPE_CODE_DECFLOAT
+A decimal floating point type.
+
+@findex TYPE_CODE_INTERNAL_FUNCTION
+@findex gdb.TYPE_CODE_INTERNAL_FUNCTION
+@item TYPE_CODE_INTERNAL_FUNCTION
+A function internal to @var{GDBN}.  This is the type used to represent
+convenience functions.
+@end table
+
 @node Pretty Printing
 @subsubsection Pretty Printing
 
diff --git a/gdb/python/python-type.c b/gdb/python/python-type.c
index e0821d7..f24a023 100644
--- a/gdb/python/python-type.c
+++ b/gdb/python/python-type.c
@@ -50,6 +50,156 @@ typedef struct pyty_type_object
 
 static PyTypeObject type_object_type;
 
+/* This is used to initialize various gdb.TYPE_ constants.  */
+struct pyty_code
+{
+  /* The code.  */
+  enum type_code code;
+  /* The name.  */
+  const char *name;
+};
+
+#define ENTRY(X) { X, #X }
+
+static struct pyty_code pyty_codes[] =
+{
+  ENTRY (TYPE_CODE_PTR),
+  ENTRY (TYPE_CODE_ARRAY),
+  ENTRY (TYPE_CODE_STRUCT),
+  ENTRY (TYPE_CODE_UNION),
+  ENTRY (TYPE_CODE_ENUM),
+  ENTRY (TYPE_CODE_FLAGS),
+  ENTRY (TYPE_CODE_FUNC),
+  ENTRY (TYPE_CODE_INT),
+  ENTRY (TYPE_CODE_FLT),
+  ENTRY (TYPE_CODE_VOID),
+  ENTRY (TYPE_CODE_SET),
+  ENTRY (TYPE_CODE_RANGE),
+  ENTRY (TYPE_CODE_STRING),
+  ENTRY (TYPE_CODE_BITSTRING),
+  ENTRY (TYPE_CODE_ERROR),
+  ENTRY (TYPE_CODE_METHOD),
+  ENTRY (TYPE_CODE_METHODPTR),
+  ENTRY (TYPE_CODE_MEMBERPTR),
+  ENTRY (TYPE_CODE_REF),
+  ENTRY (TYPE_CODE_CHAR),
+  ENTRY (TYPE_CODE_BOOL),
+  ENTRY (TYPE_CODE_COMPLEX),
+  ENTRY (TYPE_CODE_TYPEDEF),
+  ENTRY (TYPE_CODE_TEMPLATE),
+  ENTRY (TYPE_CODE_TEMPLATE_ARG),
+  ENTRY (TYPE_CODE_NAMESPACE),
+  ENTRY (TYPE_CODE_DECFLOAT),
+  ENTRY (TYPE_CODE_INTERNAL_FUNCTION),
+  { TYPE_CODE_UNDEF, NULL }
+};
+
+\f
+
+/* Return the code for this type.  */
+static PyObject *
+typy_code (PyObject *self, PyObject *args)
+{
+  struct type *type = ((type_object *) self)->type;
+  return PyInt_FromLong (TYPE_CODE (type));
+}
+
+/* Helper function for typy_fields which converts a single field to a
+   dictionary.  Returns NULL on error.  */
+static PyObject *
+convert_field (PyObject *self, struct type *type, int field)
+{
+  PyObject *dict = PyDict_New ();
+  PyObject *arg;
+
+  if (!dict)
+    return NULL;
+
+  if (!TYPE_FIELD_STATIC (type, field))
+    {
+      arg = PyLong_FromLong (TYPE_FIELD_BITPOS (type, field));
+      if (!arg)
+	goto fail;
+
+      if (PyDict_SetItemString (dict, "bitpos", arg) < 0)
+	goto failarg;
+    }
+
+  if (TYPE_FIELD_NAME (type, field))
+    {
+      arg = PyString_FromString (TYPE_FIELD_NAME (type, field));
+      if (!arg)
+	goto fail;
+      if (PyDict_SetItemString (dict, "name", arg) < 0)
+	goto failarg;
+    }
+
+  arg = TYPE_FIELD_ARTIFICIAL (type, field) ? Py_True : Py_False;
+  Py_INCREF (arg);
+  if (PyDict_SetItemString (dict, "artificial", arg) < 0)
+    goto failarg;
+
+  arg = PyLong_FromLong (TYPE_FIELD_BITSIZE (type, field));
+  if (!arg)
+    goto fail;
+  if (PyDict_SetItemString (dict, "bitsize", arg) < 0)
+    goto failarg;
+
+  arg = type_to_type_object (self, TYPE_FIELD_TYPE (type, field));
+  if (!arg)
+    goto fail;
+  if (PyDict_SetItemString (dict, "type", arg) < 0)
+    goto failarg;
+
+  return dict;
+
+ failarg:
+  Py_DECREF (arg);
+ fail:
+  Py_DECREF (dict);
+  return NULL;
+}
+
+/* Return a sequence of all fields.  Each field is a dictionary with
+   some pre-defined keys.  */
+static PyObject *
+typy_fields (PyObject *self, PyObject *args)
+{
+  PyObject *result;
+  int i;
+  struct type *type = ((type_object *) self)->type;
+
+  result = PyList_New (0);
+
+  for (i = 0; i < TYPE_NFIELDS (type); ++i)
+    {
+      PyObject *dict = convert_field (self, type, i);
+      if (!dict)
+	{
+	  Py_DECREF (result);
+	  return NULL;
+	}
+      if (PyList_Append (result, dict))
+	{
+	  Py_DECREF (dict);
+	  Py_DECREF (result);
+	  return NULL;
+	}
+    }
+
+  return result;
+}
+
+/* Return the type's tag, or None.  */
+static PyObject *
+typy_tag (PyObject *self, PyObject *args)
+{
+  struct type *type = ((type_object *) self)->type;
+  if (!TYPE_TAG_NAME (type))
+    Py_RETURN_NONE;
+  return PyString_FromString (TYPE_TAG_NAME (type));
+}
+
 /* Return a Type object which represents a pointer to SELF.  */
 static PyObject *
 typy_pointer (PyObject *self, PyObject *args)
@@ -120,7 +270,14 @@ typy_lookup_typename (char *type_name, struct block *block)
   volatile struct gdb_exception except;
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
-      type = lookup_typename (type_name, block, 1);
+      if (!strncmp (type_name, "struct ", 7))
+	type = lookup_struct (type_name + 7, block);
+      else if (!strncmp (type_name, "union ", 6))
+	type = lookup_union (type_name + 6, block);
+      else if (!strncmp (type_name, "enum ", 5))
+	type = lookup_enum (type_name + 5, block);
+      else
+	type = lookup_typename (type_name, block, 0);
     }
   if (except.reason < 0)
     {
@@ -169,13 +326,6 @@ typy_lookup_type (struct demangle_component *demangled,
 
   type_name = cp_comp_to_string (demangled, 10);
   type = typy_lookup_typename (type_name, block);
-  if (! type)
-    {
-      PyErr_Format (PyExc_RuntimeError, "no such type named %s",
-		    type_name);
-      xfree (type_name);
-      return NULL;
-    }
   xfree (type_name);
 
   return type;
@@ -297,6 +447,13 @@ clean_up_objfile_types (struct objfile *objfile, void *datum)
 {
   type_object *obj = datum;
   htab_t copied_types;
+  struct cleanup *cleanup;
+  PyGILState_STATE state;
+
+  /* This prevents another thread from freeing the objects we're
+     operating on.  */
+  state = PyGILState_Ensure ();
+  cleanup = make_cleanup_py_restore_gil (&state);
 
   copied_types = create_copied_types_hash (objfile);
 
@@ -315,6 +472,8 @@ clean_up_objfile_types (struct objfile *objfile, void *datum)
     }
 
   htab_delete (copied_types);
+
+  do_cleanups (cleanup);
 }
 
 static void
@@ -380,11 +539,7 @@ typy_new (PyTypeObject *subtype, PyObject *args, PyObject *kwargs)
     {
       type = typy_lookup_typename (type_name, block);
       if (! type)
-	{
-	  PyErr_Format (PyExc_RuntimeError, "no such type named %s",
-			type_name);
-	  return NULL;
-	}
+	return NULL;


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


             reply	other threads:[~2008-11-16 16:56 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-16 16:56 tromey [this message]
  -- strict thread matches above, loose matches on Subject: below --
2009-04-07 20:28 tromey
2009-03-24 17:27 tromey
2009-02-05 19:56 tromey
2008-12-17 23:10 tromey
2008-12-15 22:38 tromey
2008-12-13  0:37 tromey
2008-12-12 23:54 tromey
2008-12-10 15:28 tromey
2008-12-09  0:33 tromey
2008-12-02 21:29 tromey
2008-12-01 19:10 tromey
2008-11-25 21:17 tromey
2008-11-21 18:25 tromey
2008-11-18 18:52 tromey
2008-11-18 15:54 tromey
2008-11-17 15:45 tromey
2008-11-16 22:18 tromey
2008-11-12  1:54 tromey
2008-11-10 14:15 tromey
2008-11-06 21:11 tromey
2008-11-06 19:58 tromey
2008-10-23 22:27 tromey
2008-10-23 21:28 tromey
2008-10-22 18:18 tromey
2008-10-21 18:32 tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20081116165647.8599.qmail@sourceware.org \
    --to=tromey@sourceware.org \
    --cc=archer-commits@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).