public inbox for archer@sourceware.org
 help / color / mirror / Atom feed
* [python][rfc] Attempt to print the base class if a there is no Python pretty-printer for a derived class.
@ 2009-03-27 17:05 Phil Muldoon
  2009-03-27 17:34 ` Tom Tromey
  2009-03-27 17:43 ` Pedro Alves
  0 siblings, 2 replies; 14+ messages in thread
From: Phil Muldoon @ 2009-03-27 17:05 UTC (permalink / raw)
  To: Project Archer

[-- Attachment #1: Type: text/plain, Size: 832 bytes --]

The bug is detailed here: 
http://sourceware.org/bugzilla/show_bug.cgi?id=10008

In summary, given this class:

class Y : public std::tr1::unordered_map<int, char *>
{
public:
  Y()
  {
  }
};

Any Python pretty-printers that have been written and registered to 
print std::tr1::unordered_map will not work on Y. But there is no 
reason, given the lack of a more specialized printer for Y, why the 
printer for unordered_map should not print the parts of Y it can 
accurately print. This patch attempts to find a base class printer if a 
specialized printer does not exist for the class in question.

Built and tested on x8664, with no regressions.

Phil

2009-03-27  Phil Muldoon  <pmuldoon@redhat.com>

       * cp-valprint.c (cp_print_value_fields): Attempt to run
       apply_val_pretty_print on the baseclass of a class.






[-- Attachment #2: derived_class.patch --]
[-- Type: text/x-patch, Size: 1376 bytes --]

diff --git a/gdb/cp-valprint.c b/gdb/cp-valprint.c
index a96a81a..efc13e5 100644
--- a/gdb/cp-valprint.c
+++ b/gdb/cp-valprint.c
@@ -36,6 +36,7 @@
 #include "valprint.h"
 #include "cp-support.h"
 #include "language.h"
+#include "python/python.h"
 
 /* Controls printing of vtbl's */
 static void
@@ -155,16 +156,33 @@ cp_print_value_fields (struct type *type, struct type *real_type,
   int i, len, n_baseclasses;
   char *last_dont_print = obstack_next_free (&dont_print_statmem_obstack);
   int fields_seen = 0;
+  int result = 0;
+  struct type *baseclass;
 
   CHECK_TYPEDEF (type);
 
-  fprintf_filtered (stream, "{");
   len = TYPE_NFIELDS (type);
   n_baseclasses = TYPE_N_BASECLASSES (type);
 
+  /* Attempt to run the Python pretty-printers on the base class of
+  the derived class. */
+  if (!options->raw)
+    if (n_baseclasses > 0)
+      {  
+	
+	baseclass = check_typedef (TYPE_BASECLASS (type,0));
+	result = apply_val_pretty_printer (baseclass, valaddr, offset,
+					   address, stream, recurse, options,
+					   current_language);
+
+	if (result)
+	  return;
+      }
+
   /* First, print out baseclasses such that we don't print
      duplicates of virtual baseclasses.  */
 
+  fprintf_filtered (stream, "{");
   if (n_baseclasses > 0)
     cp_print_value (type, real_type, valaddr, offset, address, stream,
 		    recurse + 1, options, dont_print_vb);

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2009-03-27 19:25 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-27 17:05 [python][rfc] Attempt to print the base class if a there is no Python pretty-printer for a derived class Phil Muldoon
2009-03-27 17:34 ` Tom Tromey
2009-03-27 17:43   ` Phil Muldoon
2009-03-27 17:47     ` Tom Tromey
2009-03-27 17:46   ` Paul Pluzhnikov
2009-03-27 18:00     ` Tom Tromey
2009-03-27 18:28     ` Phil Muldoon
2009-03-27 17:43 ` Pedro Alves
2009-03-27 17:50   ` Tom Tromey
2009-03-27 18:05     ` Pedro Alves
2009-03-27 18:36       ` Tom Tromey
2009-03-27 19:08       ` Phil Muldoon
2009-03-27 19:25         ` Pedro Alves
2009-03-27 18:05     ` Phil Muldoon

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).