printed.
This method is optional. If it does exist, this method must return a
-string.
+string or the special value @code{None}.
Some display hints are predefined by @value{GDBN}:
adding quotation marks, possibly escaping some characters, respecting
@code{set print elements}, and the like.
@end table
+
+The special value @code{None} causes @value{GDBN} to apply the default
+display rules.
@end defun
@defun pretty_printer.to_string (self)
+2019-03-26 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * gdb.python/py-prettyprint.c (struct container) <is_map_p>: New
+ field.
+ (make_container): Initialise new field.
+ * gdb.python/py-prettyprint.exp: Add new tests.
+ * gdb.python/py-prettyprint.py (class ContainerPrinter)
+ <display_hint>: New method.
+
2019-03-26 Andrew Burgess <andrew.burgess@embecosm.com>
* gdb.python/py-prettyprint.exp: Use gdb_breakpoint and
gdb_test_no_output "set python print-stack full"
gdb_test "print hint_error" "Exception: hint failed\r\nhint_error_val"
- gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}"
+ gdb_test "print c" " = container \"container\" with 2 elements = {$nl *.0. = 23,$nl *.1. = 72$nl}" \
+ "print c, pretty printing on, default display hint"
+
+ gdb_test_no_output "set variable c.is_map_p=1"
+ gdb_test "print c" " = container \"container\" with 2 elements = \{$nl \\\[23\\\] = 72$nl\}" \
+ "print c, pretty printing on, display hint is now map"
gdb_test "print nstype" " = {$nl *.0. = 7,$nl *.1. = 42$nl}"
gdb_test "print nstype" " = {.0. = 7, .1. = 42}" \
"print nstype on one line"
+ # Now we have pretty printing turned off, try printing 'c' again.
+ gdb_test "print c" " = container \"container\" with 2 elements = \{\\\[23\\\] = 72\}" \
+ "print c, pretty printing off, display hint is now map"
+
+ gdb_test_no_output "set variable c.is_map_p=0"
+ gdb_test "print c" " = container \"container\" with 2 elements = \{\\\[0\\\] = 23, \\\[1\\\] = 72\}" \
+ "print c, pretty printing off, default display hint"
+
# Check that GDB doesn't lose typedefs when looking for a printer.
gdb_test "print an_int" " = -1"
gdb_test "print (int) an_int" " = -1"
def children(self):
return _iterator(self.val['elements'], self.val['len'])
+ def display_hint (self):
+ if (self.val['is_map_p']):
+ return 'map'
+ else:
+ return None
+
# Treats a container as array.
class ArrayPrinter (object):
def __init__(self, val):