ignore invalid DOF provider sections
[binutils-gdb.git] / gdb / testsuite / gdb.python / py-bad-printers.py
blob37c818b81fabfbea3c9a61acee347487c21126f7
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.
21 import re
22 import gdb.printing
25 class BadChildrenContainerPrinter1(object):
26 """Children iterator doesn't return a tuple of two elements."""
28 def __init__(self, val):
29 self.val = val
31 def to_string(self):
32 return 'container %s with %d elements' % (self.val['name'], self.val['len'])
34 @staticmethod
35 def _bad_iterator(pointer, len):
36 start = pointer
37 end = pointer + len
38 while pointer != end:
39 yield 'intentional violation of children iterator protocol'
40 pointer += 1
42 def children(self):
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):
50 self.val = val
52 def to_string(self):
53 return 'container %s with %d elements' % (self.val['name'], self.val['len'])
55 @staticmethod
56 def _bad_iterator(pointer, len):
57 start = pointer
58 end = pointer + len
59 while pointer != end:
60 # The first argument is supposed to be a string.
61 yield (42, 'intentional violation of children iterator protocol')
62 pointer += 1
64 def children(self):
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)
76 return pp
79 my_pretty_printer = build_pretty_printer()
80 gdb.printing.register_pretty_printer(gdb, my_pretty_printer)