1 # Copyright (C) 2008, 2009 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
21 # Test returning a Value from a printer.
23 def __init__(self
, val
):
27 return self
.val
['whybother']['contents']
29 # Test a class-based printer.
30 class ContainerPrinter
:
32 def __init__ (self
, pointer
, len):
34 self
.pointer
= pointer
35 self
.end
= pointer
+ len
41 if self
.pointer
== self
.end
:
44 self
.pointer
= self
.pointer
+ 1
45 return ('[%d]' % int (result
- self
.start
), result
.dereference())
47 def __init__(self
, val
):
51 return 'container %s with %d elements' % (self
.val
['name'], self
.val
['len'])
54 return self
._iterator
(self
.val
['elements'], self
.val
['len'])
57 def __init__(self
, val
):
64 raise Exception("&a(%s) != b(%s)" % (str(a
.address
), str(b
)))
65 return " a=<" + str(self
.val
["a"]) + "> b=<" + str(self
.val
["b"]) + ">"
68 def __init__(self
, val
):
72 return "a=<" + str(self
.val
["a"]) + "> b=<" + str(self
.val
["b"]) + ">"
75 def __init__(self
, val
):
79 return "a=<" + str(self
.val
['a']) + "> b=<" + str(self
.val
["b"]) + ">"
81 class pp_multiple_virtual
:
82 def __init__ (self
, val
):
86 return "pp value variable is: " + str (self
.val
['value'])
89 def __init__ (self
, val
):
93 return "pp class name: " + self
.val
.type.tag
96 def __init__(self
, val
):
100 return self
.val
['s'].string(gdb
.parameter('target-charset'))
103 "Print a std::basic_string of some kind"
105 def __init__(self
, val
):
109 len = self
.val
['length']
110 return self
.val
['null_str'].string (gdb
.parameter ('target-charset'), length
= len)
112 def display_hint (self
):
118 def __init__ (self
, val
):
121 def to_string (self
):
122 return "x = %s" % self
.val
['x']
125 yield 's', self
.val
['s']
126 yield 'x', self
.val
['x']
128 def lookup_function (val
):
129 "Look-up and return a pretty-printer that can print val."
134 # If it points to a reference, get the reference.
135 if type.code
== gdb
.TYPE_CODE_REF
:
136 type = type.target ()
138 # Get the unqualified type, stripped of typedefs.
139 type = type.unqualified ().strip_typedefs ()
147 # Iterate over local dictionary of types to determine
148 # if a printer is registered for that type. Return an
149 # instantiation of the printer if found.
150 for function
in pretty_printers_dict
:
151 if function
.match (typename
):
152 return pretty_printers_dict
[function
] (val
)
154 # Cannot find a pretty printer. Return None.
159 def register_pretty_printers ():
160 pretty_printers_dict
[re
.compile ('^struct s$')] = pp_s
161 pretty_printers_dict
[re
.compile ('^s$')] = pp_s
162 pretty_printers_dict
[re
.compile ('^S$')] = pp_s
164 pretty_printers_dict
[re
.compile ('^struct ss$')] = pp_ss
165 pretty_printers_dict
[re
.compile ('^ss$')] = pp_ss
166 pretty_printers_dict
[re
.compile ('^const S &$')] = pp_s
167 pretty_printers_dict
[re
.compile ('^SSS$')] = pp_sss
169 pretty_printers_dict
[re
.compile ('^VirtualTest$')] = pp_multiple_virtual
170 pretty_printers_dict
[re
.compile ('^Vbase1$')] = pp_vbase1
172 pretty_printers_dict
[re
.compile ('^struct nullstr$')] = pp_nullstr
173 pretty_printers_dict
[re
.compile ('^nullstr$')] = pp_nullstr
175 # Note that we purposely omit the typedef names here.
176 # Printer lookup is based on canonical name.
177 # However, we do need both tagged and untagged variants, to handle
178 # both the C and C++ cases.
179 pretty_printers_dict
[re
.compile ('^struct string_repr$')] = string_print
180 pretty_printers_dict
[re
.compile ('^struct container$')] = ContainerPrinter
181 pretty_printers_dict
[re
.compile ('^string_repr$')] = string_print
182 pretty_printers_dict
[re
.compile ('^container$')] = ContainerPrinter
184 pretty_printers_dict
[re
.compile ('^struct ns$')] = pp_ns
185 pretty_printers_dict
[re
.compile ('^ns$')] = pp_ns
187 pretty_printers_dict
[re
.compile ('^struct outerstruct$')] = pp_outer
188 pretty_printers_dict
[re
.compile ('^outerstruct$')] = pp_outer
190 pretty_printers_dict
= {}
192 register_pretty_printers ()
193 gdb
.pretty_printers
.append (lookup_function
)
This page took 0.03652 seconds and 5 git commands to generate.