public inbox for archer-commits@sourceware.org
help / color / mirror / Atom feed
* [SCM]  archer-tromey-python:  * gdb.python/python-prettyprint.exp (run_lang_tests): Add tests.
@ 2008-10-20 17:57 tromey
  0 siblings, 0 replies; only message in thread
From: tromey @ 2008-10-20 17:57 UTC (permalink / raw)
  To: archer-commits

The branch, archer-tromey-python has been updated
       via  24c99704a1274c445251bd3216b99cc0461fe5ec (commit)
       via  b1db3ee8f7cf7a0f2edc2911cf3d9c060f7e95de (commit)
       via  f1b043e93320576a2e882a7745f581223accc8af (commit)
       via  9da260e74de39996ed579fb7886de66e59473e60 (commit)
      from  2bc3ef69f6e3b09c8b81a1373913b761209a2f76 (commit)

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

- Log -----------------------------------------------------------------
commit 24c99704a1274c445251bd3216b99cc0461fe5ec
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Oct 20 11:56:58 2008 -0600

    	* gdb.python/python-prettyprint.exp (run_lang_tests): Add tests.
    	* gdb.python/python-prettyprint.c (string_repr, container): New
    	types.
    	(array): New global.
    	(zzz_type): New typedef.
    	(make_string, make_container, add_item): New functions.
    	(main): Add variables.
    	* gdb.python/python-prettyprint.py (string_print): New function.
    	(ContainerPrinter): New class.

commit b1db3ee8f7cf7a0f2edc2911cf3d9c060f7e95de
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Oct 20 11:10:00 2008 -0600

    	* python/python.c (pretty_print_one_value): Copy value if needed.

commit f1b043e93320576a2e882a7745f581223accc8af
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Oct 20 10:59:23 2008 -0600

    	* python/python-value.c (value_to_value_object): Initialize
    	owned_by_gdb field.
    	(valpy_new): Likewise.

commit 9da260e74de39996ed579fb7886de66e59473e60
Author: Tom Tromey <tromey@redhat.com>
Date:   Mon Oct 20 09:59:03 2008 -0600

    	* gdb.python/python-prettyprint.exp (run_lang_tests): Use python's
    	execfile to read .py file.
    	* gdb.python/python-prettyprint.py: Remove 'python' command.

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

Summary of changes:
 gdb/ChangeLog                                   |   10 ++++
 gdb/python/python-value.c                       |    2 +
 gdb/python/python.c                             |    8 +++
 gdb/testsuite/ChangeLog                         |   18 ++++++++
 gdb/testsuite/gdb.python/python-prettyprint.c   |   54 +++++++++++++++++++++++
 gdb/testsuite/gdb.python/python-prettyprint.exp |    5 ++-
 gdb/testsuite/gdb.python/python-prettyprint.py  |   37 +++++++++++++++-
 7 files changed, 132 insertions(+), 2 deletions(-)

First 500 lines of diff:
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 5417a52..991d3cf 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,13 @@
+2008-10-20  Tom Tromey  <tromey@redhat.com>
+
+	* python/python.c (pretty_print_one_value): Copy value if needed.
+
+2008-10-20  Tom Tromey  <tromey@redhat.com>
+
+	* python/python-value.c (value_to_value_object): Initialize
+	owned_by_gdb field.
+	(valpy_new): Likewise.
+
 2008-10-19  Tom Tromey  <tromey@redhat.com>
 
 	* python/python.c: Remove forward declarations.
diff --git a/gdb/python/python-value.c b/gdb/python/python-value.c
index 8b47994..7d677dd 100644
--- a/gdb/python/python-value.c
+++ b/gdb/python/python-value.c
@@ -106,6 +106,7 @@ valpy_new (PyTypeObject *subtype, PyObject *args, PyObject *keywords)
     }
 
   value_obj->value = value;
+  value_obj->owned_by_gdb = 0;
   release_value (value);
   value_prepend_to_list (&values_in_python, value);
 
@@ -671,6 +672,7 @@ value_to_value_object (struct value *val)
   if (val_obj != NULL)
     {
       val_obj->value = val;
+      val_obj->owned_by_gdb = 0;
       release_value (val);
       value_prepend_to_list (&values_in_python, val);
     }
diff --git a/gdb/python/python.c b/gdb/python/python.c
index ad5864f..c4e0fbd 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -708,6 +708,14 @@ pretty_print_one_value (PyObject *func, struct value *value,
 	{
 	  if (PyString_Check (result))
 	    output = xstrdup (PyString_AsString (result));
+	  else if (PyObject_TypeCheck (result, &value_object_type))
+	    {
+	      /* If we just call convert_value_from_python for this
+		 type, we won't know who owns the result.  For this
+		 one case we need to copy the resulting value.  */
+	      struct value *v = value_object_to_value (result);
+	      *out_value = value_copy (v);
+	    }
 	  else
 	    *out_value = convert_value_from_python (result);
 	  Py_DECREF (result);
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 1079648..9e7e4a7 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,21 @@
+2008-10-20  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.python/python-prettyprint.exp (run_lang_tests): Add tests.
+	* gdb.python/python-prettyprint.c (string_repr, container): New
+	types.
+	(array): New global.
+	(zzz_type): New typedef.
+	(make_string, make_container, add_item): New functions.
+	(main): Add variables.
+	* gdb.python/python-prettyprint.py (string_print): New function.
+	(ContainerPrinter): New class.
+
+2008-10-20  Tom Tromey  <tromey@redhat.com>
+
+	* gdb.python/python-prettyprint.exp (run_lang_tests): Use python's
+	execfile to read .py file.
+	* gdb.python/python-prettyprint.py: Remove 'python' command.
+
 2008-10-17  Paul Pluzhnikov  <ppluzhnikov@google.com>
 	
 	* gdb.python/python-prettyprint.exp,
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.c b/gdb/testsuite/gdb.python/python-prettyprint.c
index 152b786..3c449bd 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.c
+++ b/gdb/testsuite/gdb.python/python-prettyprint.c
@@ -38,6 +38,55 @@ struct SS {
 };
 #endif
 
+typedef struct string_repr
+{
+  struct whybother
+  {
+    const char *contents;
+  } whybother;
+} string;
+
+/* This lets us avoid malloc.  */
+int array[100];
+
+struct container
+{
+  string name;
+  int len;
+  int *elements;
+};
+
+typedef struct container zzz_type;
+
+string
+make_string (const char *s)
+{
+  string result;
+  result.whybother.contents = s;
+  return result;
+}
+
+zzz_type
+make_container (const char *s)
+{
+  zzz_type result;
+
+  result.name = make_string (s);
+  result.len = 0;
+  result.elements = 0;
+
+  return result;
+}
+
+void
+add_item (zzz_type *c, int val)
+{
+  if (c->len == 0)
+    c->elements = array;
+  c->elements[c->len] = val;
+  ++c->len;
+}
+
 void init_s(struct s *s, int a)
 {
   s->a = a;
@@ -55,6 +104,8 @@ main ()
 {
   struct ss  ss;
   struct ss  ssa[2];
+  string x = make_string ("this is x");
+  zzz_type c = make_container ("container");
 
   init_ss(&ss, 1, 2);
   init_ss(ssa+0, 3, 4);
@@ -77,5 +128,8 @@ main ()
   init_s(&cpssa[1].s, 14);
 #endif
 
+  add_item (&c, 23);
+  add_item (&c, 72);
+
   return 0;      /* break to inspect struct and union */
 }
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.exp b/gdb/testsuite/gdb.python/python-prettyprint.exp
index f494c0e..0c9a08b 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.exp
+++ b/gdb/testsuite/gdb.python/python-prettyprint.exp
@@ -58,7 +58,7 @@ proc run_lang_tests {lang} {
 	".*Breakpoint.*"
     gdb_test "continue" ".*Breakpoint.*"
     
-    gdb_test "source ${srcdir}/${subdir}/${testfile}.py" ""
+    gdb_test "python execfile ('${srcdir}/${subdir}/${testfile}.py')" ""
     
     gdb_test "print ss" " = a=< a=<1> b=<$hex>> b=< a=<2> b=<$hex>>"
     gdb_test "print ssa\[1\]" " = a=< a=<5> b=<$hex>> b=< a=<6> b=<$hex>>"
@@ -71,6 +71,9 @@ proc run_lang_tests {lang} {
 	gdb_test "print cpssa\[1\]" " = {zss = 13, s =  a=<14> b=<$hex>}"
 	gdb_test "print cpssa" " = {{zss = 11, s =  a=<12> b=<$hex>}, {zss = 13, s =  a=<14> b=<$hex>}}"
     }
+
+  gdb_test "print x" " = $hex \"this is x\""
+  gdb_test "print c" " = \"container $hex .\"container.\" with 2 elements..?.0. = 23..?.1. = 72\""
 }
 
 run_lang_tests "c"
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.py b/gdb/testsuite/gdb.python/python-prettyprint.py
index c5b7201..78a91b4 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.py
+++ b/gdb/testsuite/gdb.python/python-prettyprint.py
@@ -16,7 +16,33 @@
 # This file is part of the GDB testsuite.  It tests python pretty
 # printers.
 
-python
+# Test returning a Value from a printer.
+def string_print (val):
+    return val['whybother']['contents']
+
+# Test a class-based printer.
+class ContainerPrinter:
+    class _iterator:
+        def __init__ (self, pointer, len):
+            self.start = pointer
+            self.pointer = pointer
+            self.end = pointer + len
+
+        def __iter__(self):
+            return self
+
+        def next(self):
+            if self.pointer == self.end:
+                raise StopIteration
+            result = self.pointer
+            self.pointer = self.pointer + 1
+            return ('[%d]' % int (result - self.start), result.dereference())
+
+    def header(self, val):
+        return 'container %s with %d elements' % (val['name'], val['len'])
+
+    def children(self, val):
+        return self._iterator(val['elements'], val['len'])
 
 def pp_s(val):
   a = val["a"]
@@ -34,3 +60,12 @@ gdb.cli_pretty_printers['^S$']   = pp_s
 
 gdb.cli_pretty_printers['^struct ss$']  = pp_ss
 gdb.cli_pretty_printers['^ss$']  = pp_ss
+
+# Note that we purposely omit the typedef names here.
+# Printer lookup is based on canonical name.
+# However, we do need both tagged and untagged variants, to handle
+# both the C and C++ cases.
+gdb.cli_pretty_printers['^struct string_repr$'] = string_print
+gdb.cli_pretty_printers['^struct container$'] = ContainerPrinter()
+gdb.cli_pretty_printers['^string_repr$'] = string_print
+gdb.cli_pretty_printers['^container$'] = ContainerPrinter()


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


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

only message in thread, other threads:[~2008-10-20 17:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-10-20 17:57 [SCM] archer-tromey-python: * gdb.python/python-prettyprint.exp (run_lang_tests): Add tests 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).