Skip to content

Commit 273c9c7

Browse files
committed
Replace usage of StdVectorPrinter.Iterator's item and finish attributes.
The attributes were renamed as part of gcc-mirror/gcc@64f1210, which leaves VectorSizeWorker as the stable API definition in all libstdc++ pretty printer versions we support.
1 parent e0af82f commit 273c9c7

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

gdbmongo/decorable_printer.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import gdb
3636

3737
from gdbmongo import stdlib_printers, stdlib_xmethods
38+
from gdbmongo.libstdcxxutil import vector_size
3839
from gdbmongo.printer_protocol import PrettyPrinterProtocol
3940

4041

@@ -153,8 +154,7 @@ def __init__(self, val: gdb.Value, /) -> None:
153154
fr"^void {registry_type.name}::constructAt<\s*(.*)\s*>\(void\*\)$")
154155

155156
def __len__(self) -> int:
156-
iterator = stdlib_printers.StdVectorPrinter("std::vector", self.decorations_info).children()
157-
length = int(iterator.finish - iterator.item)
157+
length = int(vector_size(self.decorations_info))
158158
return length
159159

160160
def _iterate_raw_entries(self) -> typing.Iterator[typing.Tuple[gdb.Type, gdb.Value]]:
@@ -287,8 +287,7 @@ def __init__(self, val: gdb.Value, /) -> None:
287287
self._offset_field_name = "_offset"
288288

289289
def __len__(self) -> int:
290-
iterator = stdlib_printers.StdVectorPrinter("std::vector", self.registry_entries).children()
291-
length = int(iterator.finish - iterator.item)
290+
length = int(vector_size(self.registry_entries))
292291
return length
293292

294293
def _iterate_raw_entries(self) -> typing.Iterator[typing.Tuple[gdb.Type, gdb.Value]]:

gdbmongo/libstdcxxutil.py

+6
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,9 @@ def shared_ptr_get(obj: gdb.Value, /) -> gdb.Value:
2424
"""Return the stored T* pointer underlying a std::shared_ptr<T>."""
2525
xmethod_worker = stdlib_xmethods.SharedPtrMethodsMatcher().match(obj.type, "get")
2626
return xmethod_worker(obj)
27+
28+
29+
def vector_size(obj: gdb.Value, /) -> gdb.Value:
30+
"""Return the number of elements in a std::vector<T>."""
31+
xmethod_worker = stdlib_xmethods.VectorMethodsMatcher().match(obj.type, "size")
32+
return xmethod_worker(obj)

gdbmongo/stdlib_printers.pyi

+1-8
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,7 @@ class StdVectorPrinter(__PrettyPrinterProtocol):
8181
...
8282

8383
class Iterator(typing.Iterator[typing.Tuple[str, gdb.Value]], metaclass=abc.ABCMeta):
84-
85-
@property
86-
def item(self) -> gdb.Value:
87-
...
88-
89-
@property
90-
def finish(self) -> gdb.Value:
91-
...
84+
...
9285

9386
def children(self) -> Iterator:
9487
...

0 commit comments

Comments
 (0)