File: py-unwind-inline.py

package info (click to toggle)
gdb-doc 10.1-1
  • links: PTS, VCS
  • area: non-free
  • in suites: bullseye
  • size: 237,684 kB
  • sloc: ansic: 1,939,544; asm: 342,614; exp: 164,373; cpp: 69,350; makefile: 58,777; sh: 25,051; yacc: 13,167; ada: 5,758; xml: 5,461; perl: 5,334; python: 4,759; pascal: 3,220; lisp: 1,575; tcl: 1,541; f90: 1,395; cs: 879; lex: 620; sed: 234; awk: 141; objc: 137; fortran: 62
file content (71 lines) | stat: -rw-r--r-- 2,514 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright (C) 2020 Free Software Foundation, Inc.

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

# A dummy stack unwinder used for testing the Python unwinders when we
# have inline frames.  This unwinder will never claim any frames,
# instead, all it does it try to read all registers possible target
# registers as part of the frame sniffing process..

import gdb
from gdb.unwinder import Unwinder

apb_global = None

class dummy_unwinder (Unwinder):
    """ A dummy unwinder that looks at a bunch of registers as part of
    the unwinding process."""

    class frame_id (object):
        """ Basic frame id."""

        def __init__ (self, sp, pc):
            """ Create the frame id."""
            self.sp = sp
            self.pc = pc

    def __init__ (self):
        """Create the unwinder."""
        Unwinder.__init__ (self, "dummy stack unwinder")
        self.void_ptr_t = gdb.lookup_type("void").pointer()
        self.regs = None

    def get_regs (self, pending_frame):
        """Return a list of register names that should be read.  Only
        gathers the list once, then caches the result."""
        if (self.regs != None):
            return self.regs

        # Collect the names of all registers to read.
        self.regs = list (pending_frame.architecture ()
                          .register_names ())

        return self.regs

    def __call__ (self, pending_frame):
        """Actually performs the unwind, or at least sniffs this frame
        to see if the unwinder should claim it, which is never does."""
        try:
            for r in (self.get_regs (pending_frame)):
                v = pending_frame.read_register (r).cast (self.void_ptr_t)
        except:
            print ("Dummy unwinder, exception")
            raise

        return None

# Register the ComRV stack unwinder.
gdb.unwinder.register_unwinder (None, dummy_unwinder (), True)

print ("Python script imported")