gdb: Python unwinders, inline frames, and tail-call frames
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-unwind-inline.py
1 # Copyright (C) 2020 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 class dummy_unwinder (Unwinder):
27 """ A dummy unwinder that looks at a bunch of registers as part of
28 the unwinding process."""
29
30 class frame_id (object):
31 """ Basic frame id."""
32
33 def __init__ (self, sp, pc):
34 """ Create the frame id."""
35 self.sp = sp
36 self.pc = pc
37
38 def __init__ (self):
39 """Create the unwinder."""
40 Unwinder.__init__ (self, "dummy stack unwinder")
41 self.void_ptr_t = gdb.lookup_type("void").pointer()
42 self.regs = None
43
44 def get_regs (self, pending_frame):
45 """Return a list of register names that should be read. Only
46 gathers the list once, then caches the result."""
47 if (self.regs != None):
48 return self.regs
49
50 # Collect the names of all registers to read.
51 self.regs = list (pending_frame.architecture ()
52 .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 # Register the ComRV stack unwinder.
69 gdb.unwinder.register_unwinder (None, dummy_unwinder (), True)
70
71 print ("Python script imported")
This page took 0.031597 seconds and 4 git commands to generate.