1 # Copyright (C) 2023-2024 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 17 import itertools 18 19 import gdb 20 from gdb.FrameDecorator import DAPFrameDecorator 21 22 23 class ElidingFrameDecorator(DAPFrameDecorator): 24 def __init__(self, frame, elided_frames): 25 super(ElidingFrameDecorator, self).__init__(frame) 26 self.elided_frames = elided_frames 27 28 def elided(self): 29 return iter(self.elided_frames) 30 31 32 class ElidingIterator: 33 def __init__(self, ii): 34 self.input_iterator = ii 35 36 def __iter__(self): 37 return self 38 39 def __next__(self): 40 frame = next(self.input_iterator) 41 if str(frame.function()) != "function": 42 return frame 43 44 # Elide the next three frames. 45 elided = [] 46 elided.append(next(self.input_iterator)) 47 elided.append(next(self.input_iterator)) 48 elided.append(next(self.input_iterator)) 49 50 return ElidingFrameDecorator(frame, elided) 51 52 53 class FrameElider: 54 def __init__(self): 55 self.name = "Elider" 56 self.priority = 900 57 self.enabled = True 58 gdb.frame_filters[self.name] = self 59 60 def filter(self, frame_iter): 61 return ElidingIterator(frame_iter) 62 63 64 FrameElider() 65