1 # Copyright (C) 2010-2022 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
24 def lookup_function_lookup_test(val):
25 class PrintFunctionLookup(object):
26 def __init__(self, val):
30 return "x=<" + str(self.val["x"]) + "> y=<" + str(self.val["y"]) + ">"
32 typename = gdb.types.get_basic_type(val.type).tag
33 # Note: typename could be None.
34 if typename == "function_lookup_test":
35 return PrintFunctionLookup(val)
40 def __init__(self, val):
47 raise Exception("&a(%s) != b(%s)" % (str(a.address), str(b)))
48 return "a=<" + str(self.val["a"]) + "> b=<" + str(self.val["b"]) + ">"
52 def __init__(self, val):
56 return "a=<" + str(self.val["a"]) + "> b=<" + str(self.val["b"]) + ">"
59 def build_pretty_printer():
60 pp = gdb.printing.RegexpCollectionPrettyPrinter("pp-test")
62 pp.add_printer("struct s", "^struct s$", pp_s)
63 pp.add_printer("s", "^s$", pp_s)
65 # Use a lambda this time to exercise doing things this way.
66 pp.add_printer("struct ss", "^struct ss$", lambda val: pp_ss(val))
67 pp.add_printer("ss", "^ss$", lambda val: pp_ss(val))
72 gdb.printing.FlagEnumerationPrinter("enum flag_enum"),
78 gdb.printing.register_pretty_printer(gdb, lookup_function_lookup_test)
79 my_pretty_printer = build_pretty_printer()
80 gdb.printing.register_pretty_printer(gdb, my_pretty_printer)