From: Paul Koning Date: Tue, 11 Dec 2012 20:54:52 +0000 (+0000) Subject: * gdb.python/py-prettyprint.py (_iterator): Remove exception_flag X-Git-Tag: cgen-snapshot-20130101~147 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2960a434c3403a088a3491b12cd3e79cbd641966;p=external%2Fbinutils.git * 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. --- diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 7bdf963..0673bab 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 227046e..bd0671f 100644 --- a/gdb/testsuite/gdb.python/py-prettyprint.py +++ b/gdb/testsuite/gdb.python/py-prettyprint.py @@ -23,6 +23,14 @@ 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: if exception_flag: raise gdb.MemoryError ('hi bob') yield ('[%d]' % int (pointer - start), pointer.dereference()) @@ -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 ef07055..eca8ec9 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 bf0bf14..8cf93c1 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" } }