1 # Copyright (C) 2020-2021 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 # 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..
22 from gdb.unwinder import Unwinder
27 class dummy_unwinder(Unwinder):
28 """A dummy unwinder that looks at a bunch of registers as part of
29 the unwinding process."""
31 class frame_id(object):
34 def __init__(self, sp, pc):
35 """Create the frame id."""
40 """Create the unwinder."""
41 Unwinder.__init__(self, "dummy stack unwinder")
42 self.void_ptr_t = gdb.lookup_type("void").pointer()
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:
51 # Collect the names of all registers to read.
52 self.regs = list(pending_frame.architecture().register_names())
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."""
60 for r in self.get_regs(pending_frame):
61 v = pending_frame.read_register(r).cast(self.void_ptr_t)
63 print("Dummy unwinder, exception")
69 # Register the ComRV stack unwinder.
70 gdb.unwinder.register_unwinder(None, dummy_unwinder(), True)
72 print("Python script imported")