]>
Commit | Line | Data |
---|---|---|
4a94e368 | 1 | # Copyright (C) 2020-2022 Free Software Foundation, Inc. |
9fc501fd AB |
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 | ||
13123da8 SM |
26 | |
27 | class dummy_unwinder(Unwinder): | |
28 | """A dummy unwinder that looks at a bunch of registers as part of | |
9fc501fd AB |
29 | the unwinding process.""" |
30 | ||
13123da8 SM |
31 | class frame_id(object): |
32 | """Basic frame id.""" | |
9fc501fd | 33 | |
13123da8 SM |
34 | def __init__(self, sp, pc): |
35 | """Create the frame id.""" | |
9fc501fd AB |
36 | self.sp = sp |
37 | self.pc = pc | |
38 | ||
13123da8 | 39 | def __init__(self): |
9fc501fd | 40 | """Create the unwinder.""" |
13123da8 | 41 | Unwinder.__init__(self, "dummy stack unwinder") |
9fc501fd AB |
42 | self.void_ptr_t = gdb.lookup_type("void").pointer() |
43 | self.regs = None | |
44 | ||
13123da8 | 45 | def get_regs(self, pending_frame): |
9fc501fd AB |
46 | """Return a list of register names that should be read. Only |
47 | gathers the list once, then caches the result.""" | |
f9e59d06 | 48 | if self.regs is not None: |
9fc501fd AB |
49 | return self.regs |
50 | ||
51 | # Collect the names of all registers to read. | |
13123da8 | 52 | self.regs = list(pending_frame.architecture().register_names()) |
9fc501fd AB |
53 | |
54 | return self.regs | |
55 | ||
13123da8 | 56 | def __call__(self, pending_frame): |
9fc501fd AB |
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: | |
13123da8 SM |
60 | for r in self.get_regs(pending_frame): |
61 | v = pending_frame.read_register(r).cast(self.void_ptr_t) | |
9fc501fd | 62 | except: |
13123da8 | 63 | print("Dummy unwinder, exception") |
9fc501fd AB |
64 | raise |
65 | ||
66 | return None | |
67 | ||
13123da8 | 68 | |
9fc501fd | 69 | # Register the ComRV stack unwinder. |
13123da8 | 70 | gdb.unwinder.register_unwinder(None, dummy_unwinder(), True) |
9fc501fd | 71 | |
13123da8 | 72 | print("Python script imported") |