printers.py (NodeIteratorPrinter): New.

2018-03-08  François Dumont  <fdumont@gcc.gnu.org>

	* python/libstdcxx/v6/printers.py (NodeIteratorPrinter): New.
	(StdListIteratorPrinter): Inherit from latter.
	(StdFwdListIteratorPrinter): New, inherit from latter.
	(StdDebugIteratorPrinter.to_string): Use non-debug iterator printer
	when iterator has no associated container.
	(build_libstdcxx_dictionary): Add __gnu_cxx::_Fwd_list_iterator and
	__gnu_cxx::_Fwd_list_const_iterator printers. Remove __norm namespace
	registrations.
	* testsuite/libstdc++-prettyprinters/debug.cc: Adapt.
	* testsuite/libstdc++-prettyprinters/debug_cxx11.cc: Adapt.

From-SVN: r258350
This commit is contained in:
François Dumont 2018-03-08 06:26:15 +00:00
parent 1b1a188198
commit fe6bd21a0b
4 changed files with 47 additions and 24 deletions

View File

@ -1,3 +1,16 @@
2018-03-08 François Dumont <fdumont@gcc.gnu.org>
* python/libstdcxx/v6/printers.py (NodeIteratorPrinter): New.
(StdListIteratorPrinter): Inherit from latter.
(StdFwdListIteratorPrinter): New, inherit from latter.
(StdDebugIteratorPrinter.to_string): Use non-debug iterator printer
when iterator has no associated container.
(build_libstdcxx_dictionary): Add __gnu_cxx::_Fwd_list_iterator and
__gnu_cxx::_Fwd_list_const_iterator printers. Remove __norm namespace
registrations.
* testsuite/libstdc++-prettyprinters/debug.cc: Adapt.
* testsuite/libstdc++-prettyprinters/debug_cxx11.cc: Adapt.
2018-03-06 Ville Voutilainen <ville.voutilainen@gmail.com> 2018-03-06 Ville Voutilainen <ville.voutilainen@gmail.com>
PR libstdc++/84601 PR libstdc++/84601

View File

@ -249,21 +249,32 @@ class StdListPrinter:
return 'empty %s' % (self.typename) return 'empty %s' % (self.typename)
return '%s' % (self.typename) return '%s' % (self.typename)
class StdListIteratorPrinter: class NodeIteratorPrinter:
"Print std::list::iterator" def __init__(self, typename, val, contname):
def __init__(self, typename, val):
self.val = val self.val = val
self.typename = typename self.typename = typename
self.contname = contname
def to_string(self): def to_string(self):
if not self.val['_M_node']: if not self.val['_M_node']:
return 'non-dereferenceable iterator for std::list' return 'non-dereferenceable iterator for std::%s' % (self.contname)
nodetype = find_type(self.val.type, '_Node') nodetype = find_type(self.val.type, '_Node')
nodetype = nodetype.strip_typedefs().pointer() nodetype = nodetype.strip_typedefs().pointer()
node = self.val['_M_node'].cast(nodetype).dereference() node = self.val['_M_node'].cast(nodetype).dereference()
return str(get_value_from_list_node(node)) return str(get_value_from_list_node(node))
class StdListIteratorPrinter(NodeIteratorPrinter):
"Print std::list::iterator"
def __init__(self, typename, val):
NodeIteratorPrinter.__init__(self, typename, val, 'list')
class StdFwdListIteratorPrinter(NodeIteratorPrinter):
"Print std::forward_list::iterator"
def __init__(self, typename, val):
NodeIteratorPrinter.__init__(self, typename, val, 'forward_list')
class StdSlistPrinter: class StdSlistPrinter:
"Print a __gnu_cxx::slist" "Print a __gnu_cxx::slist"
@ -575,10 +586,12 @@ class StdDebugIteratorPrinter:
# and return the wrapped iterator value. # and return the wrapped iterator value.
def to_string (self): def to_string (self):
base_type = gdb.lookup_type('__gnu_debug::_Safe_iterator_base') base_type = gdb.lookup_type('__gnu_debug::_Safe_iterator_base')
safe_seq = self.val.cast(base_type)['_M_sequence']
if not safe_seq or self.val['_M_version'] != safe_seq['_M_version']:
return "invalid iterator"
itype = self.val.type.template_argument(0) itype = self.val.type.template_argument(0)
safe_seq = self.val.cast(base_type)['_M_sequence']
if not safe_seq:
return str(self.val.cast(itype))
if self.val['_M_version'] != safe_seq['_M_version']:
return "invalid iterator"
return str(self.val.cast(itype)) return str(self.val.cast(itype))
def num_elements(num): def num_elements(num):
@ -1731,21 +1744,14 @@ def build_libstdcxx_dictionary ():
StdVectorIteratorPrinter) StdVectorIteratorPrinter)
libstdcxx_printer.add_version('__gnu_cxx::', '_Slist_iterator', libstdcxx_printer.add_version('__gnu_cxx::', '_Slist_iterator',
StdSlistIteratorPrinter) StdSlistIteratorPrinter)
libstdcxx_printer.add_version('__gnu_cxx::', '_Fwd_list_iterator',
StdFwdListIteratorPrinter)
libstdcxx_printer.add_version('__gnu_cxx::', '_Fwd_list_const_iterator',
StdFwdListIteratorPrinter)
# Debug (compiled with -D_GLIBCXX_DEBUG) printer # Debug (compiled with -D_GLIBCXX_DEBUG) printer
# registrations. The Rb_tree debug iterator when unwrapped # registrations.
# from the encapsulating __gnu_debug::_Safe_iterator does not
# have the __norm namespace. Just use the existing printer
# registration for that.
libstdcxx_printer.add('__gnu_debug::_Safe_iterator', libstdcxx_printer.add('__gnu_debug::_Safe_iterator',
StdDebugIteratorPrinter) StdDebugIteratorPrinter)
libstdcxx_printer.add('std::__norm::_List_iterator',
StdListIteratorPrinter)
libstdcxx_printer.add('std::__norm::_List_const_iterator',
StdListIteratorPrinter)
libstdcxx_printer.add('std::__norm::_Deque_const_iterator',
StdDequeIteratorPrinter)
libstdcxx_printer.add('std::__norm::_Deque_iterator',
StdDequeIteratorPrinter)
build_libstdcxx_dictionary () build_libstdcxx_dictionary ()

View File

@ -19,7 +19,9 @@
// with this library; see the file COPYING3. If not see // with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
#define _GLIBCXX_DEBUG #ifndef _GLIBCXX_DEBUG
# define _GLIBCXX_DEBUG
#endif
#include <string> #include <string>
#include <deque> #include <deque>
@ -96,7 +98,7 @@ main()
v.push_back(1); v.push_back(1);
v.push_back(2); v.push_back(2);
std::vector<int>::iterator viter0; std::vector<int>::iterator viter0;
// { dg-final { note-test viter0 {invalid iterator} } } // { dg-final { note-test viter0 {non-dereferenceable iterator for std::vector} } }
std::vector<int>::iterator viter1 = v.begin(); std::vector<int>::iterator viter1 = v.begin();
std::vector<int>::iterator viter2 = viter1 + 1; std::vector<int>::iterator viter2 = viter1 + 1;
v.erase(viter1); v.erase(viter1);

View File

@ -19,7 +19,9 @@
// with this library; see the file COPYING3. If not see // with this library; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>. // <http://www.gnu.org/licenses/>.
#define _GLIBCXX_DEBUG #ifndef _GLIBCXX_DEBUG
# define _GLIBCXX_DEBUG
#endif
#include <forward_list> #include <forward_list>
#include <unordered_map> #include <unordered_map>
@ -31,7 +33,7 @@ main()
{ {
std::forward_list<std::string> flst; std::forward_list<std::string> flst;
std::forward_list<std::string>::iterator flstiter0; std::forward_list<std::string>::iterator flstiter0;
// { dg-final { note-test flstiter0 {invalid iterator}} } // { dg-final { note-test flstiter0 {non-dereferenceable iterator for std::forward_list}} }
flst.push_front("dum"); flst.push_front("dum");
std::forward_list<std::string>::iterator flstiter1 = flst.begin(); std::forward_list<std::string>::iterator flstiter1 = flst.begin();
// { dg-final { note-test *flstiter1 {"dum"}} } // { dg-final { note-test *flstiter1 {"dum"}} }