From 51e89ab08b1a3e425d3c1bec8dea081b5e843831 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Damien?= Date: Tue, 5 Jul 2016 19:57:44 +0200 Subject: [PATCH 1/2] Use lazy range in gdb pretty printers --- src/etc/gdb_rust_pretty_printing.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py index 33f22e85796..ad0c9d085aa 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -10,8 +10,12 @@ import gdb import re +import sys import debugger_pretty_printers_common as rustpp +if sys.version_info.major >= 3: + xrange = range + #=============================================================================== # GDB Pretty Printing Module for Rust #=============================================================================== @@ -215,7 +219,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 +248,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()) From 01c4b64b1ce4560918e59faeb481b5de25898baf Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 6 Jul 2016 11:17:26 -0700 Subject: [PATCH 2/2] etc: Comment why we're binding xrange Just mention there are differences between python versions --- src/etc/gdb_rust_pretty_printing.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/etc/gdb_rust_pretty_printing.py b/src/etc/gdb_rust_pretty_printing.py index ad0c9d085aa..554ab66bc56 100755 --- a/src/etc/gdb_rust_pretty_printing.py +++ b/src/etc/gdb_rust_pretty_printing.py @@ -13,6 +13,9 @@ 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