]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-framefilter.py
1 # Copyright (C) 2013 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
23 class Reverse_Function (FrameDecorator
):
25 def __init__(self
, fobj
):
26 super(Reverse_Function
, self
).__init
__(fobj
)
30 fname
= str (self
.fobj
.function())
31 if (fname
== None or fname
== ""):
37 class Dummy (FrameDecorator
):
39 def __init__(self
, fobj
):
40 super(Dummy
, self
).__init
__(fobj
)
44 return "Dummy function"
50 return "Dummy filename"
52 def frame_args (self
):
53 return [("Foo",gdb
.Value(12)),("Bar","Stuff"), ("FooBar",42)]
55 def frame_locals (self
):
70 gdb
.frame_filters
[self
.name
] = self
72 def filter (self
, frame_iter
):
73 frame_iter
= itertools
.imap (Reverse_Function
,
77 class ElidingFrameDecorator(FrameDecorator
):
79 def __init__(self
, frame
, elided_frames
):
80 super(ElidingFrameDecorator
, self
).__init
__(frame
)
81 self
.elided_frames
= elided_frames
84 return iter(self
.elided_frames
)
86 class ElidingIterator
:
87 def __init__(self
, ii
):
88 self
.input_iterator
= ii
94 frame
= next(self
.input_iterator
)
95 if str(frame
.function()) != 'func1':
98 # Suppose we want to return the 'func1' frame but elide the
99 # next frame. E.g., if call in our interpreter language takes
100 # two C frames to implement, and the first one we see is the
102 elided
= next(self
.input_iterator
)
103 return ElidingFrameDecorator(frame
, [elided
])
105 class FrameElider ():
111 gdb
.frame_filters
[self
.name
] = self
113 def filter (self
, frame_iter
):
114 return ElidingIterator (frame_iter
)