From 2960a434c3403a088a3491b12cd3e79cbd641966 Mon Sep 17 00:00:00 2001 From: Paul Koning Date: Tue, 11 Dec 2012 20:54:52 +0000 Subject: [PATCH] * gdb.python/py-prettyprint.py (_iterator): Remove exception_flag exception. (_iterator_except): New function. (ArrayPrinter): Use _iterator function instead of local _iterator class for Python 3 compatibility. (NoStringContainerPrinter): Use _iterator_except instead of _iterator. * gdb.python/py-typeprint.exp: Use exec(open(...).read()) instead of execfile for Python 3 compatibility. * gdb.python/python.exp: Handle Python 2.4 exception traceback format in error_prompt test. --- gdb/testsuite/ChangeLog | 14 ++++++++++ gdb/testsuite/gdb.python/py-prettyprint.py | 30 ++++++++-------------- gdb/testsuite/gdb.python/py-typeprint.exp | 2 +- gdb/testsuite/gdb.python/python.exp | 2 +- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 7bdf9634167..0673bab3040 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,17 @@ +2012-12-11 Paul Koning + + * gdb.python/py-prettyprint.py (_iterator): Remove exception_flag + exception. + (_iterator_except): New function. + (ArrayPrinter): Use _iterator function instead of local _iterator + class for Python 3 compatibility. + (NoStringContainerPrinter): Use _iterator_except instead of + _iterator. + * gdb.python/py-typeprint.exp: Use exec(open(...).read()) instead of + execfile for Python 3 compatibility. + * gdb.python/python.exp: Handle Python 2.4 exception traceback + format in error_prompt test. + 2012-12-10 Paul Koning * gdb.base/charset.exp: Change print syntax for Python 3 diff --git a/gdb/testsuite/gdb.python/py-prettyprint.py b/gdb/testsuite/gdb.python/py-prettyprint.py index 227046e10ef..bd0671f9cc5 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.py +++ b/gdb/testsuite/gdb.python/py-prettyprint.py @@ -20,6 +20,14 @@ import re import gdb def _iterator (pointer, len): + start = pointer + end = pointer + len + while pointer != end: + yield ('[%d]' % int (pointer - start), pointer.dereference()) + pointer += 1 + +# Same as _iterator but can be told to raise an exception. +def _iterator_except (pointer, len): start = pointer end = pointer + len while pointer != end: @@ -49,23 +57,7 @@ class ContainerPrinter (object): return _iterator(self.val['elements'], self.val['len']) # Treats a container as array. -class ArrayPrinter: - class _iterator: - def __init__ (self, pointer, len): - self.start = pointer - self.pointer = pointer - self.end = pointer + len - - def __iter__(self): - return self - - def next(self): - if self.pointer == self.end: - raise StopIteration - result = self.pointer - self.pointer = self.pointer + 1 - return ('[%d]' % int (result - self.start), result.dereference()) - +class ArrayPrinter (object): def __init__(self, val): self.val = val @@ -73,7 +65,7 @@ class ArrayPrinter: return 'array %s with %d elements' % (self.val['name'], self.val['len']) def children(self): - return self._iterator(self.val['elements'], self.val['len']) + return _iterator(self.val['elements'], self.val['len']) def display_hint (self): return 'array' @@ -90,7 +82,7 @@ class NoStringContainerPrinter (object): return None def children(self): - return _iterator(self.val['elements'], self.val['len']) + return _iterator_except (self.val['elements'], self.val['len']) class pp_s (object): def __init__(self, val): diff --git a/gdb/testsuite/gdb.python/py-typeprint.exp b/gdb/testsuite/gdb.python/py-typeprint.exp index ef0705519cc..eca8ec9e7e2 100644 --- a/gdb/testsuite/gdb.python/py-typeprint.exp +++ b/gdb/testsuite/gdb.python/py-typeprint.exp @@ -28,7 +28,7 @@ if { [skip_python_tests] } { continue } set remote_python_file [remote_download host ${srcdir}/${subdir}/${testfile}.py] -gdb_test_no_output "python execfile ('${remote_python_file}')" +gdb_test_no_output "python exec (open ('${remote_python_file}').read ())" cp_test_ptype_class s "basic test" "class" "templ" { { field public "T x;" } diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp index bf0bf144e67..8cf93c1f7e4 100644 --- a/gdb/testsuite/gdb.python/python.exp +++ b/gdb/testsuite/gdb.python/python.exp @@ -362,7 +362,7 @@ gdb_py_test_multiple "prompt substitution readline" \ "end" "" gdb_test_multiple "python gdb.prompt_hook = error_prompt" "set the hook" { - -re "Python Exception <(type 'exceptions.|class ')RuntimeError'> Python exception called.*" { + -re "Python Exception (exceptions.RuntimeError|<(type 'exceptions.|class ')RuntimeError'>) Python exception called.*" { pass "set hook" } } -- 2.30.2