1 # Copyright (C) 2020-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 # A dummy stack unwinder used for testing the Python unwinders when we 17 # have inline frames. This unwinder will never claim any frames, 18 # instead, all it does it try to read all registers possible target 19 # registers as part of the frame sniffing process.. 20 21 import gdb 22 from gdb.unwinder import Unwinder 23 24 apb_global = None 25 26 27 class dummy_unwinder(Unwinder): 28 """A dummy unwinder that looks at a bunch of registers as part of 29 the unwinding process.""" 30 31 class frame_id(object): 32 """Basic frame id.""" 33 34 def __init__(self, sp, pc): 35 """Create the frame id.""" 36 self.sp = sp 37 self.pc = pc 38 39 def __init__(self): 40 """Create the unwinder.""" 41 Unwinder.__init__(self, "dummy stack unwinder") 42 self.void_ptr_t = gdb.lookup_type("void").pointer() 43 self.regs = None 44 45 def get_regs(self, pending_frame): 46 """Return a list of register names that should be read. Only 47 gathers the list once, then caches the result.""" 48 if self.regs is not None: 49 return self.regs 50 51 # Collect the names of all registers to read. 52 self.regs = list(pending_frame.architecture().register_names()) 53 54 return self.regs 55 56 def __call__(self, pending_frame): 57 """Actually performs the unwind, or at least sniffs this frame 58 to see if the unwinder should claim it, which is never does.""" 59 try: 60 for r in self.get_regs(pending_frame): 61 v = pending_frame.read_register(r).cast(self.void_ptr_t) 62 except: 63 print("Dummy unwinder, exception") 64 raise 65 66 return None 67 68 69 # Register the ComRV stack unwinder. 70 gdb.unwinder.register_unwinder(None, dummy_unwinder(), True) 71 72 print("Python script imported") 73