+2021-03-26 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * gdb.python/py-prettyprint.c (struct container): Add 'is_array_p'
+ member.
+ (make_container): Initialise is_array_p.
+ * gdb.python/py-prettyprint.exp: Add new tests.
+ * gdb.python/py-prettyprint.py (ContainerPrinter.display_hint):
+ Check is_array_p and possibly return 'array'.
+
2021-03-26 Andrew Burgess <andrew.burgess@embecosm.com>
* gdb.cp/breakpoint.exp: Extend test names to make them unique.
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_array_p=1"
+ gdb_test "print c" " = container \"container\" with 2 elements = \\{23, 72\\}" \
+ "print c, pretty printing on, display hint is now array"
+
+ # Setting is_map_p while _is_array_p is also set will cause the
+ # display_hint method to raise an exception (see py-prettyprint.py).
gdb_test_no_output "set variable c.is_map_p=1"
+
+ # This test checks what happens when the display hint throws an
+ # error. GDB just treats this as though the display hint was
+ # None.
+ set py_exception \
+ [multi_line \
+ "Traceback\[^\r\n\]+" \
+ "\\s+File \"\[^\r\n\]+/py-prettyprint.py\", line \[0-9\]+, in display_hint" \
+ "\\s+raise Exception \[^\r\n\]+" \
+ "Exception: invalid object state found in display_hint"]
+ gdb_test "print c" \
+ [multi_line \
+ " = ${py_exception}" \
+ "container \"container\" with 2 elements = {" \
+ "\\s+\\\[0\\\] = 23," \
+ "\\s+\\\[1\\\] = 72" \
+ "}"] \
+ "print c, pretty printing on, exception raised from display_hint"
+
+ # Unset is_array_p so that display_hint no longer raises an
+ # exception.
+ gdb_test_no_output "set variable c.is_array_p=0"
+
gdb_test "print c" " = container \"container\" with 2 elements = \{$nl \\\[23\\\] = 72$nl\}" \
"print c, pretty printing on, display hint is now map"
return _iterator(self.val['elements'], self.val['len'])
def display_hint (self):
+ if (self.val['is_map_p'] and self.val['is_array_p']):
+ raise Exception ("invalid object state found in display_hint")
+
if (self.val['is_map_p']):
return 'map'
+ elif (self.val['is_array_p']):
+ return 'array'
else:
return None