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]

Re: [python] more tests and documentation


Paul> Notice that (from the end user perspective) 'print vs' and 'print
Paul> vs[0]' are semantically very close, so it's surprizing that one
Paul> prints more "junk" than the other.

Good point.

I was worried that there would be some confusion in a pretty-printer
between reference types and ordinary types -- but if Value ever
exposes this difference, pretty-printers can cope.

I'm checking in the appended, which fixes this.

Tom

2008-10-23  Tom Tromey  <tromey@redhat.com>

	* python/python.c (find_pretty_printer): Strip reference types.

2008-10-23  Tom Tromey  <tromey@redhat.com>

	* gdb.texinfo (Pretty Printing): Update.

2008-10-23  Tom Tromey  <tromey@redhat.com>

	* gdb.python/python-prettyprint.exp (run_lang_tests): Test
	printing a reference.
	* gdb.python/python-prettyprint.c (main): Add reference.


diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index b41175f..ea1020e 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -17994,8 +17994,10 @@ The Python dictionary @code{gdb.cli_pretty_printers} maps regular
 expressions (strings) onto pretty-printers.  A pretty-printer is
 either a function or an object.
 
-When printing a value, @value{GDBN} first compares the name of the
-value's canonical type (the type after following all typedefs) to each
+When printing a value, @value{GDBN} first computes the values'
+canonical type by following typedefs, following a reference type to
+its referenced type, and removing qualifiers, such as @code{const} or
+@code{volatile}.  The name of this type is then compared to each
 regular expression.  If a regular expression matches, then the
 corresponding pretty-printer is invoked with a @code{gdb.Value}
 representing the value to be printed.
diff --git a/gdb/python/python.c b/gdb/python/python.c
index c6395fb..6d280d9 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -632,6 +632,9 @@ find_pretty_printer (struct type *type, PyObject **dictp, char *dict_name)
   /* Get the name of the type.  */
   TRY_CATCH (except, RETURN_MASK_ALL)
     {
+      /* If we have a reference, use the referenced type.  */
+      if (TYPE_CODE (type) == TYPE_CODE_REF)
+	type = TYPE_TARGET_TYPE (type);
       /* Strip off any qualifiers from the type.  */
       type = make_cv_type (0, 0, type, NULL);
       type_name = get_type (type);
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.c b/gdb/testsuite/gdb.python/python-prettyprint.c
index 1336d91..f99e6f9 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.c
+++ b/gdb/testsuite/gdb.python/python-prettyprint.c
@@ -137,6 +137,8 @@ main ()
   init_s(&cpssa[1].s, 14);
 
   SSS sss(15, cps);
+
+  SSS& ref (sss);
 #endif
 
   add_item (&c, 23);		/* MI breakpoint here */
diff --git a/gdb/testsuite/gdb.python/python-prettyprint.exp b/gdb/testsuite/gdb.python/python-prettyprint.exp
index 7c654a4..d07d195 100644
--- a/gdb/testsuite/gdb.python/python-prettyprint.exp
+++ b/gdb/testsuite/gdb.python/python-prettyprint.exp
@@ -71,6 +71,7 @@ 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 sss" "= a=<15> b=< a=<8> b=<$hex>>"
+	gdb_test "print ref" "= a=<15> b=< a=<8> b=<$hex>>"
     }
 
     gdb_test "print x" " = $hex \"this is x\""


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