]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR59161 make pretty printers always return strings
authorJonathan Wakely <jwakely@redhat.com>
Thu, 18 May 2017 09:23:38 +0000 (10:23 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Thu, 18 May 2017 09:23:38 +0000 (10:23 +0100)
Backport from mainline
2016-12-15  Jonathan Wakely  <jwakely@redhat.com>

PR libstdc++/59161
* python/libstdcxx/v6/printers.py (StdListIteratorPrinter.to_string)
(StdSlistIteratorPrinter.to_string, StdVectorIteratorPrinter.to_string)
(StdRbtreeIteratorPrinter.to_string, StdDequeIteratorPrinter.to_string)
(StdDebugIteratorPrinter.to_string): Return string instead of
gdb.Value.
* testsuite/libstdc++-prettyprinters/59161.cc: New test.

From-SVN: r248182

libstdc++-v3/ChangeLog
libstdc++-v3/python/libstdcxx/v6/printers.py
libstdc++-v3/testsuite/libstdc++-prettyprinters/59161.cc [new file with mode: 0644]

index 21a2b09a3f40a0dc1a0aca83b7d007c0906b3504..2938b3e967605252287bd4d935f65ff32994b243 100644 (file)
@@ -1,5 +1,16 @@
 2017-05-18  Jonathan Wakely  <jwakely@redhat.com>
 
+       Backport from mainline
+       2016-12-15  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/59161
+       * python/libstdcxx/v6/printers.py (StdListIteratorPrinter.to_string)
+       (StdSlistIteratorPrinter.to_string, StdVectorIteratorPrinter.to_string)
+       (StdRbtreeIteratorPrinter.to_string, StdDequeIteratorPrinter.to_string)
+       (StdDebugIteratorPrinter.to_string): Return string instead of
+       gdb.Value.
+       * testsuite/libstdc++-prettyprinters/59161.cc: New test.
+
        Backport from mainline
        2016-10-11  Jonathan Wakely  <jwakely@redhat.com>
 
index 3b4badfe9bdc81088b1d942df9ccb126d81121d2..9adc642182ca8bc557e7de0cd43e49644893d17e 100644 (file)
@@ -176,7 +176,7 @@ class StdListIteratorPrinter:
     def to_string(self):
         nodetype = find_type(self.val.type, '_Node')
         nodetype = nodetype.strip_typedefs().pointer()
-        return self.val['_M_node'].cast(nodetype).dereference()['_M_data']
+        return str(self.val['_M_node'].cast(nodetype).dereference()['_M_data'])
 
 class StdSlistPrinter:
     "Print a __gnu_cxx::slist"
@@ -221,7 +221,7 @@ class StdSlistIteratorPrinter:
     def to_string(self):
         nodetype = find_type(self.val.type, '_Node')
         nodetype = nodetype.strip_typedefs().pointer()
-        return self.val['_M_node'].cast(nodetype).dereference()['_M_data']
+        return str(self.val['_M_node'].cast(nodetype).dereference()['_M_data'])
 
 class StdVectorPrinter:
     "Print a std::vector"
@@ -306,7 +306,7 @@ class StdVectorIteratorPrinter:
         self.val = val
 
     def to_string(self):
-        return self.val['_M_current'].dereference()
+        return str(self.val['_M_current'].dereference())
 
 class StdTuplePrinter:
     "Print a std::tuple"
@@ -464,7 +464,7 @@ class StdRbtreeIteratorPrinter:
 
     def to_string (self):
         node = self.val['_M_node'].cast(self.link_type).dereference()
-        return get_value_from_Rb_tree_node(node)
+        return str(get_value_from_Rb_tree_node(node))
 
 class StdDebugIteratorPrinter:
     "Print a debug enabled version of an iterator"
@@ -476,7 +476,7 @@ class StdDebugIteratorPrinter:
     # and return the wrapped iterator value.
     def to_string (self):
         itype = self.val.type.template_argument(0)
-        return self.val.cast(itype)
+        return str(self.val.cast(itype))
 
 class StdMapPrinter:
     "Print a std::map or std::multimap"
@@ -669,7 +669,7 @@ class StdDequeIteratorPrinter:
         self.val = val
 
     def to_string(self):
-        return self.val['_M_cur'].dereference()
+        return str(self.val['_M_cur'].dereference())
 
 class StdStringPrinter:
     "Print a std::basic_string of some kind"
diff --git a/libstdc++-v3/testsuite/libstdc++-prettyprinters/59161.cc b/libstdc++-v3/testsuite/libstdc++-prettyprinters/59161.cc
new file mode 100644 (file)
index 0000000..a2d7f96
--- /dev/null
@@ -0,0 +1,69 @@
+// { dg-do run }
+// { dg-options "-g -O0" }
+
+// Copyright (C) 2011-2016 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
+// <http://www.gnu.org/licenses/>.
+
+#include <deque>
+#include <list>
+#include <ext/slist>
+#include <set>
+#include <vector>
+#include <debug/vector>
+#include <iostream>
+
+struct C {
+  C(int& i) : ref(i) { }
+  int& ref;
+  bool operator<(const C& c) const { return ref < c.ref; }
+};
+
+int main()
+{
+  int i = 1;
+  C c(i);
+
+  std::deque<C> d;
+  d.push_back(c);
+  std::deque<C>::iterator diter = d.begin();
+// { dg-final { regexp-test diter {ref = @0x.*} } }
+
+  std::list<C> l;
+  l.push_back(c);
+  std::list<C>::iterator liter = l.begin();
+  // Need to ensure the list<C>::iterator::_Node typedef is in the debuginfo:
+  int tmp __attribute__((unused)) = (*liter).ref;
+// { dg-final { regexp-test liter {ref = @0x.*} } }
+
+  __gnu_cxx::slist<C> sl;
+  sl.push_front(c);
+  __gnu_cxx::slist<C>::iterator sliter = sl.begin();
+// { dg-final { regexp-test sliter {ref = @0x.*} } }
+
+  std::set<C> s;
+  s.insert(c);
+  std::set<C>::iterator siter = s.begin();
+// { dg-final { regexp-test siter {ref = @0x.*} } }
+
+  std::vector<C> v(1, c);
+  std::vector<C>::iterator viter = v.begin();
+// { dg-final { regexp-test viter {ref = @0x.*} } }
+
+  std::cout << "\n";
+  return 0;                    // Mark SPOT
+}
+// { dg-final { gdb-test SPOT } }