1 # Copyright (C) 2008-2015 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # This file is part of the GDB testsuite. It tests GDB's handling of
17 # bad python pretty printers.
19 # Test a printer with a bad children iterator.
25 class BadChildrenContainerPrinter1(object):
26 """Children iterator doesn't return a tuple of two elements."""
28 def __init__(self
, val
):
32 return 'container %s with %d elements' % (self
.val
['name'], self
.val
['len'])
35 def _bad_iterator(pointer
, len):
39 yield 'intentional violation of children iterator protocol'
43 return self
._bad
_iterator
(self
.val
['elements'], self
.val
['len'])
46 class BadChildrenContainerPrinter2(object):
47 """Children iterator returns a tuple of two elements with bad values."""
49 def __init__(self
, val
):
53 return 'container %s with %d elements' % (self
.val
['name'], self
.val
['len'])
56 def _bad_iterator(pointer
, len):
60 # The first argument is supposed to be a string.
61 yield (42, 'intentional violation of children iterator protocol')
65 return self
._bad
_iterator
(self
.val
['elements'], self
.val
['len'])
68 def build_pretty_printer():
69 pp
= gdb
.printing
.RegexpCollectionPrettyPrinter("bad-printers")
71 pp
.add_printer('container1', '^container$',
72 BadChildrenContainerPrinter1
)
73 pp
.add_printer('container2', '^container$',
74 BadChildrenContainerPrinter2
)
79 my_pretty_printer
= build_pretty_printer()
80 gdb
.printing
.register_pretty_printer(gdb
, my_pretty_printer
)