From: Michael Weghorn Date: Wed, 19 Jun 2019 22:57:06 +0000 (+0000) Subject: Have std::vector printer's iterator return bool for vector X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=36d0dada6773d7fd7c5ace64c90e723930a3b81e;p=gcc.git Have std::vector printer's iterator return bool for vector Have the pretty-printer for 'std::vector' 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). 2019-06-19 Michael Weghorn Jonathan Wakely PR libstdc++/90945 * python/libstdcxx/v6/printers.py (StdVectorPrinter._iterator): Use values of type bool for vector elements. * testsuite/libstdc++-prettyprinters/simple.cc: Test vector. * testsuite/libstdc++-prettyprinters/simple11.cc: Likewise. Co-Authored-By: Jonathan Wakely From-SVN: r272490 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index cff842cfc9e..a481420781d 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,12 @@ +2019-06-19 Michael Weghorn + Jonathan Wakely + + PR libstdc++/90945 + * python/libstdcxx/v6/printers.py (StdVectorPrinter._iterator): Use + values of type bool for vector elements. + * testsuite/libstdc++-prettyprinters/simple.cc: Test vector. + * testsuite/libstdc++-prettyprinters/simple11.cc: Likewise. + 2019-06-19 Jonathan Wakely PR libstdc++/90920 partially revert r263433 diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 05143153bee..cd79a1fa6e6 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -362,16 +362,12 @@ class StdVectorPrinter: if self.bitvec: 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 + elt = bool(self.item.dereference() & (1 << self.so)) 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, elt) else: if self.item == self.finish: raise StopIteration @@ -382,7 +378,7 @@ class StdVectorPrinter: def __init__(self, typename, val): self.typename = strip_versioned_namespace(typename) self.val = val - self.is_bool = val.type.template_argument(0).code == gdb.TYPE_CODE_BOOL + self.is_bool = val.type.template_argument(0).code == gdb.TYPE_CODE_BOOL def children(self): return self._iterator(self.val['_M_impl']['_M_start'], @@ -422,6 +418,8 @@ class StdVectorIteratorPrinter: return 'non-dereferenceable iterator for std::vector' return str(self.val['_M_current'].dereference()) +# TODO add printer for vector's _Bit_iterator and _Bit_const_iterator + class StdTuplePrinter: "Print a std::tuple" diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc index 60dfdc597f3..04c1ef683a6 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc @@ -116,6 +116,16 @@ main() std::vector::iterator viter0; // { dg-final { note-test viter0 {non-dereferenceable iterator for std::vector} } } + std::vector vb; + vb.reserve(100); + vb.push_back(true); + vb.push_back(true); + vb.push_back(false); + vb.push_back(false); + vb.push_back(true); + vb.erase(vb.begin()); +// { dg-final { regexp-test vb {std::(__debug::)?vector of length 4, capacity 128 = \\{true, false, false, true\\}} } } + __gnu_cxx::slist sll; sll.push_front(23); sll.push_front(47); diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc index b18f5cc22a9..ace217cc9e8 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc @@ -109,6 +109,16 @@ main() std::vector::iterator viter0; // { dg-final { note-test viter0 {non-dereferenceable iterator for std::vector} } } + std::vector vb; + vb.reserve(100); + vb.push_back(true); + vb.push_back(true); + vb.push_back(false); + vb.push_back(false); + vb.push_back(true); + vb.erase(vb.begin()); +// { dg-final { regexp-test vb {std::(__debug::)?vector of length 4, capacity 128 = \\{true, false, false, true\\}} } } + __gnu_cxx::slist sll; sll.push_front(23); sll.push_front(47);