libstdc++/77645 Fix xmethods for std::list
authorJonathan Wakely <jwakely@redhat.com>
Mon, 19 Sep 2016 15:49:19 +0000 (16:49 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 19 Sep 2016 15:49:19 +0000 (16:49 +0100)
PR libstdc++/77645
* python/libstdcxx/v6/xmethods.py (DequeWorkerBase.index): Rename
argument.
(ListWorkerBase.get_value_from_node): Define new method.
(ListFrontWorker.__call__, ListBackWorker.__call__): Use it.

From-SVN: r240233

libstdc++-v3/ChangeLog
libstdc++-v3/python/libstdcxx/v6/xmethods.py

index 70ff276beb47fa64a59058e7316cb852c1124fb8..8bbd29c720c3a96870828aba5d696d0dd49d796e 100644 (file)
@@ -1,3 +1,11 @@
+2016-09-19  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR libstdc++/77645
+       * python/libstdcxx/v6/xmethods.py (DequeWorkerBase.index): Rename
+       argument.
+       (ListWorkerBase.get_value_from_node): Define new method.
+       (ListFrontWorker.__call__, ListBackWorker.__call__): Use it.
+
 2016-09-17  Jonathan Wakely  <jwakely@redhat.com>
 
        * python/libstdcxx/v6/printers.py (StdVariantPrinter): Define.
index eccd57400f9a5e3baa9d3d714dd9b6455fbd95b0..95f9af9db25d6df113f80b7e6861d82a25b34dfc 100644 (file)
@@ -174,10 +174,10 @@ class DequeWorkerBase(gdb.xmethod.XMethodWorker):
         first = obj['_M_impl']['_M_finish']['_M_first']
         return (last_node - first_node) * self._bufsize + (cur - first)
 
-    def index(self, obj, index):
+    def index(self, obj, idx):
         first_node = obj['_M_impl']['_M_start']['_M_node']
-        index_node = first_node + index / self._bufsize
-        return index_node[0][index % self._bufsize]
+        index_node = first_node + idx / self._bufsize
+        return index_node[0][idx % self._bufsize]
 
 class DequeEmptyWorker(DequeWorkerBase):
     def get_arg_types(self):
@@ -328,6 +328,15 @@ class ListWorkerBase(gdb.xmethod.XMethodWorker):
     def get_arg_types(self):
         return None
 
+    def get_value_from_node(self, node):
+        node = node.dereference()
+        if node.type.fields()[1].name == '_M_data':
+            # C++03 implementation, node contains the value as a member
+            return node['_M_data']
+        # C++11 implementation, node stores value in __aligned_membuf
+        addr = node['_M_storage'].address
+        return addr.cast(self._val_type.pointer()).dereference()
+
 class ListEmptyWorker(ListWorkerBase):
     def get_result_type(self, obj):
         return get_bool_type()
@@ -358,7 +367,7 @@ class ListFrontWorker(ListWorkerBase):
 
     def __call__(self, obj):
         node = obj['_M_impl']['_M_node']['_M_next'].cast(self._node_type)
-        return node['_M_data']
+        return self.get_value_from_node(node)
 
 class ListBackWorker(ListWorkerBase):
     def get_result_type(self, obj):
@@ -366,7 +375,7 @@ class ListBackWorker(ListWorkerBase):
 
     def __call__(self, obj):
         prev_node = obj['_M_impl']['_M_node']['_M_prev'].cast(self._node_type)
-        return prev_node['_M_data']
+        return self.get_value_from_node(prev_node)
 
 class ListMethodsMatcher(gdb.xmethod.XMethodMatcher):
     def __init__(self):