1 # Copyright (C) 2013-2014 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 # Python 3.x moved the itertools.imap functionality to map(),
74 # so check if it is available.
75 if hasattr(itertools
, "imap"):
76 frame_iter
= itertools
.imap (Reverse_Function
,
79 frame_iter
= map(Reverse_Function
, frame_iter
)
83 class ElidingFrameDecorator(FrameDecorator
):
85 def __init__(self
, frame
, elided_frames
):
86 super(ElidingFrameDecorator
, self
).__init
__(frame
)
87 self
.elided_frames
= elided_frames
90 return iter(self
.elided_frames
)
92 class ElidingIterator
:
93 def __init__(self
, ii
):
94 self
.input_iterator
= ii
100 frame
= next(self
.input_iterator
)
101 if str(frame
.function()) != 'func1':
104 # Suppose we want to return the 'func1' frame but elide the
105 # next frame. E.g., if call in our interpreter language takes
106 # two C frames to implement, and the first one we see is the
108 elided
= next(self
.input_iterator
)
109 return ElidingFrameDecorator(frame
, [elided
])
111 # Python 3.x requires __next__(self) while Python 2.x requires
112 # next(self). Define next(self), and for Python 3.x create this
117 class FrameElider ():
123 gdb
.frame_filters
[self
.name
] = self
125 def filter (self
, frame_iter
):
126 return ElidingIterator (frame_iter
)
This page took 0.031811 seconds and 4 git commands to generate.