diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py index 33f22e85796..554ab66bc56 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -10,8 +10,15 @@ import gdb import re +import sys import debugger_pretty_printers_common as rustpp +# We want a version of `range` which doesn't allocate an intermediate list, +# specifically it should use a lazy iterator. In Python 2 this was `xrange`, but +# if we're running with Python 3 then we need to use `range` instead. +if sys.version_info.major >= 3: + xrange = range + #=============================================================================== # GDB Pretty Printing Module for Rust #=============================================================================== @@ -215,7 +222,7 @@ class RustSlicePrinter: assert data_ptr.type.get_dwarf_type_kind() == rustpp.DWARF_TYPE_CODE_PTR raw_ptr = data_ptr.get_wrapped_value() - for index in range(0, length): + for index in xrange(0, length): yield (str(index), (raw_ptr + index).dereference()) @@ -244,7 +251,7 @@ class RustStdVecPrinter: def children(self): (length, data_ptr, cap) = rustpp.extract_length_ptr_and_cap_from_std_vec(self.__val) gdb_ptr = data_ptr.get_wrapped_value() - for index in range(0, length): + for index in xrange(0, length): yield (str(index), (gdb_ptr + index).dereference())