From b1f3973b9c55a1406c13ade5cb14239d5b17a465 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Tue, 2 Mar 2021 14:19:56 +0000 Subject: gdb/testsuite: more testing of pretty printer 'array' display_hint This commit adds a couple of tests to the python pretty printer testing. I've added a test for the 'array' display hint. This display hint is tested by gdb.python/py-mi.exp, however, the MI testing is done via the varobj interface, and this code makes its own direct calls to the Python pretty printers from gdb/varobj.c. What this means is that the interface to the pretty printers in gdb/python/py-prettyprint.c is not tested for the 'array' display hint path. I also added a test for what happens when the display_hint method raises an exception. There wasn't a bug that inspired this test, just while adding the previous test I thought, I wonder what happens if... The current behaviour of GDB seems reasonable, GDB displays the Python exception, and then continues printing the value as if display_hint had returned None. I added a test to lock in this behaviour. gdb/testsuite/ChangeLog: * 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'. --- gdb/testsuite/gdb.python/py-prettyprint.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gdb/testsuite/gdb.python/py-prettyprint.py') diff --git a/gdb/testsuite/gdb.python/py-prettyprint.py b/gdb/testsuite/gdb.python/py-prettyprint.py index 5f09ea8..fab03a6 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.py +++ b/gdb/testsuite/gdb.python/py-prettyprint.py @@ -57,8 +57,13 @@ class ContainerPrinter (object): 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 -- cgit v1.1