+2018-02-01  Leszek Swirski  <leszeks@google.com>
+
+       * varobj.c (varobj_formatted_print_options): Allow recursive
+       pretty printing if pretty printing is enabled.
+
 2018-02-01  Leszek Swirski  <leszeks@google.com>
 
        * c-exp.y (lex_one_token, classify_name, yylex): Don't classify
 
+2018-02-01  Simon Marchi  <simon.marchi@polymtl.ca>
+           Leszek Swirski  <leszeks@google.com>
+
+       * gdb.python/py-prettyprint.c
+       (struct to_string_returns_value_inner,
+       struct to_string_returns_value_wrapper): New.
+       (main): Add tsrvw variable.
+       * gdb.python/py-prettyprint.py (ToStringReturnsValueInner,
+       ToStringReturnsValueWrapper): New classes.
+       (register_pretty_printers): Register new pretty-printers.
+       * gdb.python/py-prettyprint.exp (run_lang_tests): Test printing
+       recursive pretty printer.
+       * gdb.python/py-mi.exp: Likewise.
+
 2018-02-01  Leszek Swirski  <leszeks@google.com>
 
        * gdb.cp/filename.cc, gdb.cp/filename.exp: Test that member
 
 mi_create_dynamic_varobj children_as_list children_as_list 1 \
     "printer whose children are returned as a list"
 
+# Test that when a pretty-printer returns a gdb.Value in its to_string, we call
+# the pretty-printer of that value too.
+mi_create_varobj_checked tsrvw tsrvw  \
+    "struct to_string_returns_value_wrapper" \
+    "create tsrvw varobj"
+mi_check_varobj_value tsrvw "Inner to_string 1989" "check tsrvw varobj value"
+mi_gdb_test "-data-evaluate-expression tsrvw" \
+    "\\^done,value=\"Inner to_string 1989\"" \
+    "check tsrvw expression value"
+
 # Regression test for bug 14741.
 mi_continue_to_line \
     [gdb_get_line_number {breakpoint bug 14741} ${srcfile}] \
 
 };
 #endif
 
+struct to_string_returns_value_inner
+{
+  int val;
+};
+
+struct to_string_returns_value_wrapper
+{
+  struct to_string_returns_value_inner inner;
+};
+
 struct substruct {
   int a;
   int b;
   struct lazystring estring, estring2, estring3;
   struct hint_error hint_error;
   struct children_as_list children_as_list;
+  struct to_string_returns_value_wrapper tsrvw = { { 1989 } };
 
   nstype.elements = narray;
   nstype.len = 0;
 
     
     gdb_test "print arraystruct" " = {$nl *y = 7, *$nl *x = { a=<23> b=<$hex>,  a=<24> b=<$hex>} *$nl *}"
 
+    # Test that when a pretty-printer returns a gdb.Value in its to_string, we
+    # call the pretty-printer of that value too.
+    gdb_test "print tsrvw" " = Inner to_string 1989"
+
     if {$lang == "c++"} {
        gdb_test "print cps" "=  a=<8> b=<$hex>"
        gdb_test "print cpss" " = {$nl *zss = 9, *$nl *s =  a=<10> b=<$hex>$nl}"
 
     def children(self):
         return _iterator_except (self.val['elements'], self.val['len'])
 
+# See ToStringReturnsValueWrapper.
+class ToStringReturnsValueInner:
+
+    def __init__(self, val):
+        self.val = val
+
+    def to_string(self):
+        return 'Inner to_string {}'.format(int(self.val['val']))
+
+# Test a printer that returns a gdb.Value in its to_string.  That gdb.Value
+# also has its own pretty-printer.
+class ToStringReturnsValueWrapper:
+
+    def __init__(self, val):
+        self.val = val
+
+    def to_string(self):
+        return self.val['inner']
+
 class pp_s (object):
     def __init__(self, val):
         self.val = val
     pretty_printers_dict[re.compile ('^string_repr$')] = string_print
     pretty_printers_dict[re.compile ('^container$')] = ContainerPrinter
     pretty_printers_dict[re.compile ('^justchildren$')] = NoStringContainerPrinter
-    
+
+    pretty_printers_dict[re.compile ('^struct to_string_returns_value_inner$')] = ToStringReturnsValueInner
+    pretty_printers_dict[re.compile ('^to_string_returns_value_inner$')] = ToStringReturnsValueInner
+    pretty_printers_dict[re.compile ('^struct to_string_returns_value_wrapper$')] = ToStringReturnsValueWrapper
+    pretty_printers_dict[re.compile ('^to_string_returns_value_wrapper$')] = ToStringReturnsValueWrapper
+
     pretty_printers_dict[re.compile ('^struct ns$')]  = pp_ns
     pretty_printers_dict[re.compile ('^ns$')]  = pp_ns
 
 
 {
   get_formatted_print_options (opts, format_code[(int) format]);
   opts->deref_ref = 0;
-  opts->raw = 1;
+  opts->raw = !pretty_printing;
 }
 
 std::string