fccb5886d1aa9c3fa37010f197e96e3d0c54e70e
[deliverable/binutils-gdb.git] / gdb / python / lib / gdb / FrameIterator.py
1 # Copyright (C) 2013-2021 Free Software Foundation, Inc.
2
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.
7 #
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.
12 #
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/>.
15
16 import gdb
17 import itertools
18
19
20 class FrameIterator(object):
21 """A gdb.Frame iterator. Iterates over gdb.Frames or objects that
22 conform to that interface."""
23
24 def __init__(self, frame_obj):
25 """Initialize a FrameIterator.
26
27 Arguments:
28 frame_obj the starting frame."""
29
30 super(FrameIterator, self).__init__()
31 self.frame = frame_obj
32
33 def __iter__(self):
34 return self
35
36 def next(self):
37 """next implementation.
38
39 Returns:
40 The next oldest frame."""
41
42 result = self.frame
43 if result is None:
44 raise StopIteration
45 self.frame = result.older()
46 return result
47
48 # Python 3.x requires __next__(self) while Python 2.x requires
49 # next(self). Define next(self), and for Python 3.x create this
50 # wrapper.
51 def __next__(self):
52 return self.next()
This page took 0.039951 seconds and 3 git commands to generate.