1 # Copyright (C) 2015-2024 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 # This file is part of the GDB testsuite. It tests python unwinders.
21 from gdb
.unwinder
import Unwinder
, register_unwinder
24 class TestGlobalUnwinder(Unwinder
):
26 super(TestGlobalUnwinder
, self
).__init
__("global_unwinder")
28 def __call__(self
, unwinder_info
):
29 print("%s called" % self
.name
)
33 class TestProgspaceUnwinder(Unwinder
):
34 def __init__(self
, name
):
35 super(TestProgspaceUnwinder
, self
).__init
__("%s_ps_unwinder" % name
)
37 def __call__(self
, unwinder_info
):
38 print("%s called" % self
.name
)
42 class TestObjfileUnwinder(Unwinder
):
43 def __init__(self
, name
):
44 super(TestObjfileUnwinder
, self
).__init
__("%s_obj_unwinder" % name
)
46 def __call__(self
, unwinder_info
):
47 print("%s called" % self
.name
)
51 gdb
.unwinder
.register_unwinder(None, TestGlobalUnwinder())
52 saw_runtime_error
= False
54 gdb
.unwinder
.register_unwinder(None, TestGlobalUnwinder(), replace
=False)
56 saw_runtime_error
= True
57 if not saw_runtime_error
:
58 raise RuntimeError("Missing runtime error from register_unwinder.")
59 gdb
.unwinder
.register_unwinder(None, TestGlobalUnwinder(), replace
=True)
60 gdb
.unwinder
.register_unwinder(
61 gdb
.current_progspace(), TestProgspaceUnwinder("py_unwind_maint")
63 print("Python script imported")