]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-pp-registration.py
1 # Copyright (C) 2010-2018 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 python pretty
17 # printer registration.
24 def lookup_function_lookup_test(val
):
25 class PrintFunctionLookup(object):
26 def __init__(self
, val
):
30 return ("x=<" + str(self
.val
["x"]) +
31 "> y=<" + str(self
.val
["y"]) + ">")
33 typename
= gdb
.types
.get_basic_type(val
.type).tag
34 # Note: typename could be None.
35 if typename
== "function_lookup_test":
36 return PrintFunctionLookup(val
)
41 def __init__(self
, val
):
47 return "s1 a=<" + str(self
.val
["a"]) + "> b=<" + str(self
.val
["b"]) + ">"
51 def __init__(self
, val
):
57 return "s2 a=<" + str(self
.val
["a"]) + "> b=<" + str(self
.val
["b"]) + ">"
60 def build_pretty_printer1():
61 pp
= gdb
.printing
.RegexpCollectionPrettyPrinter("pp-test")
63 pp
.add_printer('struct s', '^struct s$', pp_s1
)
64 pp
.add_printer('s', '^s$', pp_s1
)
69 def build_pretty_printer2():
70 # This intentionally has the same name as build_pretty_printer1.
71 # It is used to test the "replace" functionality of
72 # register_pretty_printer.
73 pp
= gdb
.printing
.RegexpCollectionPrettyPrinter("pp-test")
75 pp
.add_printer('struct s', '^struct s$', pp_s2
)
76 pp
.add_printer('s', '^s$', pp_s2
)
80 # Note: Registering the printers is done in the .exp file.