]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-framefilter.py
1 # Copyright (C) 2013-2021 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-based
20 from gdb
.FrameDecorator
import FrameDecorator
24 class Reverse_Function(FrameDecorator
):
25 def __init__(self
, fobj
):
26 super(Reverse_Function
, self
).__init
__(fobj
)
30 fname
= str(self
.fobj
.function())
33 if fname
== "end_func":
34 extra
= self
.fobj
.inferior_frame().read_var("str").string()
37 fname
= fname
[::-1] + extra
41 class Dummy(FrameDecorator
):
42 def __init__(self
, fobj
):
43 super(Dummy
, self
).__init
__(fobj
)
47 return "Dummy function"
53 return "Dummy filename"
56 return [("Foo", gdb
.Value(12)), ("Bar", "Stuff"), ("FooBar", 42)]
58 def frame_locals(self
):
73 gdb
.frame_filters
[self
.name
] = self
75 def filter(self
, frame_iter
):
76 # Python 3.x moved the itertools.imap functionality to map(),
77 # so check if it is available.
78 if hasattr(itertools
, "imap"):
79 frame_iter
= itertools
.imap(Reverse_Function
, frame_iter
)
81 frame_iter
= map(Reverse_Function
, frame_iter
)
86 class ElidingFrameDecorator(FrameDecorator
):
87 def __init__(self
, frame
, elided_frames
):
88 super(ElidingFrameDecorator
, self
).__init
__(frame
)
89 self
.elided_frames
= elided_frames
92 return iter(self
.elided_frames
)
95 # Regression test for an overflow in the python layer.
96 bitsize
= 8 * gdb
.lookup_type("void").pointer().sizeof
97 mask
= (1 << bitsize
) - 1
98 return 0xFFFFFFFFFFFFFFFF & mask
101 class ElidingIterator
:
102 def __init__(self
, ii
):
103 self
.input_iterator
= ii
109 frame
= next(self
.input_iterator
)
110 if str(frame
.function()) != "func1":
113 # Suppose we want to return the 'func1' frame but elide the
114 # next frame. E.g., if call in our interpreter language takes
115 # two C frames to implement, and the first one we see is the
117 elided
= next(self
.input_iterator
)
118 return ElidingFrameDecorator(frame
, [elided
])
120 # Python 3.x requires __next__(self) while Python 2.x requires
121 # next(self). Define next(self), and for Python 3.x create this
132 gdb
.frame_filters
[self
.name
] = self
134 def filter(self
, frame_iter
):
135 return ElidingIterator(frame_iter
)
138 # This is here so the test can change the kind of error that is
140 name_error
= RuntimeError
142 # A simple decorator that gives an error when computing the function.
143 class ErrorInName(FrameDecorator
):
144 def __init__(self
, frame
):
145 FrameDecorator
.__init
__(self
, frame
)
148 raise name_error("whoops")
151 # A filter that supplies buggy frames. Disabled by default.
157 gdb
.frame_filters
[self
.name
] = self
159 def filter(self
, frame_iter
):
160 # Python 3.x moved the itertools.imap functionality to map(),
161 # so check if it is available.
162 if hasattr(itertools
, "imap"):
163 return itertools
.imap(ErrorInName
, frame_iter
)
165 return map(ErrorInName
, frame_iter
)