1 # Copyright (C) 2015-2018 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 """Unwinder class and register_unwinder function."""
21 class Unwinder(object):
22 """Base class (or a template) for frame unwinders written in Python.
24 An unwinder has a single method __call__ and the attributes
28 name: The name of the unwinder.
29 enabled: A boolean indicating whether the unwinder is enabled.
32 def __init__(self
, name
):
36 name: An identifying name for the unwinder.
41 def __call__(self
, pending_frame
):
42 """GDB calls this method to unwind a frame.
45 pending_frame: gdb.PendingFrame instance.
48 gdb.UnwindInfo instance.
50 raise NotImplementedError("Unwinder __call__.")
53 def register_unwinder(locus
, unwinder
, replace
=False):
54 """Register unwinder in given locus.
56 The unwinder is prepended to the locus's unwinders list. Unwinder
57 name should be unique.
60 locus: Either an objfile, progspace, or None (in which case
61 the unwinder is registered globally).
62 unwinder: An object of a gdb.Unwinder subclass
63 replace: If True, replaces existing unwinder with the same name.
64 Otherwise, raises exception if unwinder with the same
71 RuntimeError: Unwinder name is not unique
72 TypeError: Bad locus type
75 if gdb
.parameter("verbose"):
76 gdb
.write("Registering global %s unwinder ...\n" % unwinder
.name
)
78 elif isinstance(locus
, gdb
.Objfile
) or isinstance(locus
, gdb
.Progspace
):
79 if gdb
.parameter("verbose"):
80 gdb
.write("Registering %s unwinder for %s ...\n" %
81 (unwinder
.name
, locus
.filename
))
83 raise TypeError("locus should be gdb.Objfile or gdb.Progspace or None")
86 for needle
in locus
.frame_unwinders
:
87 if needle
.name
== unwinder
.name
:
89 del locus
.frame_unwinders
[i
]
91 raise RuntimeError("Unwinder %s already exists." %
94 locus
.frame_unwinders
.insert(0, unwinder
)
95 gdb
.invalidate_cached_frames()
This page took 0.067777 seconds and 4 git commands to generate.