1 # Copyright (C) 2015 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.
20 from gdb
.unwinder
import Unwinder
, register_unwinder
22 class TestGlobalUnwinder(Unwinder
):
24 super(TestGlobalUnwinder
, self
).__init
__("global_unwinder")
26 def __call__(self
, unwinder_info
):
27 print("%s called" % self
.name
)
30 class TestProgspaceUnwinder(Unwinder
):
31 def __init__(self
, name
):
32 super(TestProgspaceUnwinder
, self
).__init
__("%s_ps_unwinder" % name
)
34 def __call__(self
, unwinder_info
):
35 print("%s called" % self
.name
)
38 class TestObjfileUnwinder(Unwinder
):
39 def __init__(self
, name
):
40 super(TestObjfileUnwinder
, self
).__init
__("%s_obj_unwinder" % name
)
42 def __call__(self
, unwinder_info
):
43 print("%s called" % self
.name
)
48 gdb
.unwinder
.register_unwinder(None, TestGlobalUnwinder())
49 saw_runtime_error
= False
51 gdb
.unwinder
.register_unwinder(None, TestGlobalUnwinder(), replace
=False)
53 saw_runtime_error
= True
54 if not saw_runtime_error
:
55 raise RuntimeError("Missing runtime error from register_unwinder.")
56 gdb
.unwinder
.register_unwinder(None, TestGlobalUnwinder(), replace
=True)
57 gdb
.unwinder
.register_unwinder(gdb
.current_progspace(),
58 TestProgspaceUnwinder("py_unwind_maint"))
59 print("Python script imported")