Hi everyone, the Python pretty printer for a 'std::vector<bool>' currently returns integers as values for the elements, which e.g. leads to the situation that a 'gdb.Value' constructed from that doesn't have 'bool' type, but an integer type ('long long' for my test with gdb 8.2.1 on Debian testing, amd64). Returning bool values ('True'/'False') would make sure that the type is clear and can thus help improve the displayed type. More details in [1].
The attached patch changes the behaviour of the pretty printer accordingly. I'd be glad to receive feedback on this and also notes in case anything else is needed. (This is my first contribution.) So far, I've tested this with GDB 8.2.1 on Debian testing. ChangeLog: * PR libstdc++/90945: Have pretty printer return bool instead of int for value of std::vector<bool> elements Regards, Michael [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90945
>From c62cbd47ea8602e2351ff3b0c4c80fa8cb71e313 Mon Sep 17 00:00:00 2001 From: Michael Weghorn <m.wegh...@posteo.de> Date: Wed, 19 Jun 2019 17:22:16 +0200 Subject: [PATCH] Have std::vector printer's iterator return bool Have the pretty-printer for 'std::vector<bool>' return a value of type 'bool' rather than an 'int'. This way, the type is clear and that can be used for better display and a 'gdb.Value' constructed from the returned value will have type 'bool' again, not e.g. 'long long' as happened previously (at least with GDB 8.2.1 on amd64). diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 05143153bee..177db3c0fdb 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -363,15 +363,12 @@ class StdVectorPrinter: if self.item == self.finish and self.so >= self.fo: raise StopIteration elt = self.item.dereference() - if elt & (1 << self.so): - obit = 1 - else: - obit = 0 + val = elt & (1 << self.so) != 0 self.so = self.so + 1 if self.so >= self.isize: self.item = self.item + 1 self.so = 0 - return ('[%d]' % count, obit) + return ('[%d]' % count, val) else: if self.item == self.finish: raise StopIteration -- 2.20.1