From a448c922b542547f5972080afbf26c163e2a5c55 Mon Sep 17 00:00:00 2001 From: redi Date: Fri, 2 May 2014 16:00:57 +0000 Subject: PR libstdc++/59476 * python/libstdcxx/v6/printers.py (get_value_from_Rb_tree_node): New function to handle both C++03 and C++11 _Rb_tree_node implementations. (StdRbtreeIteratorPrinter, StdMapPrinter, StdSetPrinter): Use it. * testsuite/libstdc++-prettyprinters/simple.cc: Update comment to refer to... * testsuite/libstdc++-prettyprinters/simple11.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_9-branch@210007 138bc75d-0d04-0410-961f-82ee72b054a4 --- libstdc++-v3/ChangeLog | 10 +++ libstdc++-v3/python/libstdcxx/v6/printers.py | 25 +++++- .../testsuite/libstdc++-prettyprinters/simple.cc | 2 +- .../testsuite/libstdc++-prettyprinters/simple11.cc | 92 ++++++++++++++++++++++ 4 files changed, 125 insertions(+), 4 deletions(-) create mode 100644 libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc (limited to 'libstdc++-v3') diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 2a3a1c30377..71cc93f2362 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,13 @@ +2014-05-02 Jonathan Wakely + + PR libstdc++/59476 + * python/libstdcxx/v6/printers.py (get_value_from_Rb_tree_node): New + function to handle both C++03 and C++11 _Rb_tree_node implementations. + (StdRbtreeIteratorPrinter, StdMapPrinter, StdSetPrinter): Use it. + * testsuite/libstdc++-prettyprinters/simple.cc: Update comment to + refer to... + * testsuite/libstdc++-prettyprinters/simple11.cc: New. + 2014-04-27 Lars Gullik Bjønnes PR libstdc++/60710 diff --git a/libstdc++-v3/python/libstdcxx/v6/printers.py b/libstdc++-v3/python/libstdcxx/v6/printers.py index 05da17b61ea..1f1f860a5b0 100644 --- a/libstdc++-v3/python/libstdcxx/v6/printers.py +++ b/libstdc++-v3/python/libstdcxx/v6/printers.py @@ -375,6 +375,22 @@ class RbtreeIterator: self.node = node return result +def get_value_from_Rb_tree_node(node): + """Returns the value held in an _Rb_tree_node<_Val>""" + try: + member = node.type.fields()[1].name + if member == '_M_value_field': + # C++03 implementation, node contains the value as a member + return node['_M_value_field'] + elif member == '_M_storage': + # C++11 implementation, node stores value in __aligned_buffer + p = node['_M_storage']['_M_storage'].address + p = p.cast(node.type.template_argument(0).pointer()) + return p.dereference() + except: + pass + raise ValueError, "Unsupported implementation for %s" % str(node.type) + # This is a pretty printer for std::_Rb_tree_iterator (which is # std::map::iterator), and has nothing to do with the RbtreeIterator # class above. @@ -387,7 +403,8 @@ class StdRbtreeIteratorPrinter: def to_string (self): typename = str(self.val.type.strip_typedefs()) + '::_Link_type' nodetype = gdb.lookup_type(typename).strip_typedefs() - return self.val.cast(nodetype).dereference()['_M_value_field'] + node = self.val.cast(nodetype).dereference() + return get_value_from_Rb_tree_node(node) class StdDebugIteratorPrinter: "Print a debug enabled version of an iterator" @@ -417,7 +434,8 @@ class StdMapPrinter: def next(self): if self.count % 2 == 0: n = self.rbiter.next() - n = n.cast(self.type).dereference()['_M_value_field'] + n = n.cast(self.type).dereference() + n = get_value_from_Rb_tree_node(n) self.pair = n item = n['first'] else: @@ -458,7 +476,8 @@ class StdSetPrinter: def next(self): item = self.rbiter.next() - item = item.cast(self.type).dereference()['_M_value_field'] + item = item.cast(self.type).dereference() + item = get_value_from_Rb_tree_node(item) # FIXME: this is weird ... what to do? # Maybe a 'set' display hint? result = ('[%d]' % self.count, item) diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc index 66ae8f70e56..030207aa67c 100644 --- a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple.cc @@ -1,4 +1,4 @@ -// If you modify this, please update debug.cc as well. +// If you modify this, please update simple11.cc and debug.cc as well. // { dg-do run } // { dg-options "-g -O0" } diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc new file mode 100644 index 00000000000..e94bea6ec84 --- /dev/null +++ b/libstdc++-v3/testsuite/libstdc++-prettyprinters/simple11.cc @@ -0,0 +1,92 @@ +// If you modify this, please update simple.cc and debug.cc as well. + +// { dg-do run } +// { dg-options "-g -O0 -std=gnu++11" } + +// Copyright (C) 2011-2014 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +#include +#include +#include +#include +#include +#include +#include +#include + +int +main() +{ + std::string tem; + std::string str = "zardoz"; +// { dg-final { note-test str "\"zardoz\"" } } + + std::bitset<10> bs; + bs[0] = 1; + bs[5] = 1; + bs[7] = 1; +// { dg-final { note-test bs {std::bitset = {[0] = 1, [5] = 1, [7] = 1}} } } + + std::deque deq; + deq.push_back("one"); + deq.push_back("two"); +// { dg-final { note-test deq {std::deque with 2 elements = {"one", "two"}} } } + + std::deque::iterator deqiter = deq.begin(); +// { dg-final { note-test deqiter {"one"} } } + + std::list lst; + lst.push_back("one"); + lst.push_back("two"); +// { dg-final { note-test lst {std::list = {[0] = "one", [1] = "two"}} } } + + std::list::iterator lstiter = lst.begin(); + tem = *lstiter; +// { dg-final { note-test lstiter {"one"}} } + + std::list::const_iterator lstciter = lst.begin(); + tem = *lstciter; +// { dg-final { note-test lstciter {"one"}} } + + std::map mp; + mp["zardoz"] = 23; +// { dg-final { note-test mp {std::map with 1 elements = {["zardoz"] = 23}} } } + + std::map::iterator mpiter = mp.begin(); +// { dg-final { note-test mpiter {{first = "zardoz", second = 23}} } } + + std::set sp; + sp.insert("clownfish"); + sp.insert("barrel"); +// { dg-final { note-test sp {std::set with 2 elements = {[0] = "barrel", [1] = "clownfish"}} } } + + std::set::const_iterator spciter = sp.begin(); +// { dg-final { note-test spciter {"barrel"} } } + + __gnu_cxx::slist sll; + sll.push_front(23); + sll.push_front(47); +// { dg-final { note-test sll {__gnu_cxx::slist = {[0] = 47, [1] = 23}} } } + + __gnu_cxx::slist::iterator slliter = sll.begin(); +// { dg-final { note-test slliter {47} } } + + return 0; // Mark SPOT +} + +// { dg-final { gdb-test SPOT } } -- cgit v1.2.1