This is the mail archive of the 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]

[python][rfc] Attempt to print the base class if a there is no Pythonpretty-printer for a derived class.

The bug is detailed here:

In summary, given this class:

class Y : public std::tr1::unordered_map<int, char *>

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.


2009-03-27 Phil Muldoon <>

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

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

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