xref: /netbsd-src/external/gpl3/gdb/dist/gdb/testsuite/gdb.python/py-unwind-maint.py (revision 3117ece4fc4a4ca4489ba793710b60b0d26bab6c)
1# Copyright (C) 2015-2024 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# This file is part of the GDB testsuite.  It tests python unwinders.
17
18import re
19
20import gdb.types
21from gdb.unwinder import Unwinder, register_unwinder
22
23
24class TestGlobalUnwinder(Unwinder):
25    def __init__(self):
26        super(TestGlobalUnwinder, self).__init__("global_unwinder")
27
28    def __call__(self, unwinder_info):
29        print("%s called" % self.name)
30        return None
31
32
33class TestProgspaceUnwinder(Unwinder):
34    def __init__(self, name):
35        super(TestProgspaceUnwinder, self).__init__("%s_ps_unwinder" % name)
36
37    def __call__(self, unwinder_info):
38        print("%s called" % self.name)
39        return None
40
41
42class TestObjfileUnwinder(Unwinder):
43    def __init__(self, name):
44        super(TestObjfileUnwinder, self).__init__("%s_obj_unwinder" % name)
45
46    def __call__(self, unwinder_info):
47        print("%s called" % self.name)
48        return None
49
50
51gdb.unwinder.register_unwinder(None, TestGlobalUnwinder())
52saw_runtime_error = False
53try:
54    gdb.unwinder.register_unwinder(None, TestGlobalUnwinder(), replace=False)
55except RuntimeError:
56    saw_runtime_error = True
57if not saw_runtime_error:
58    raise RuntimeError("Missing runtime error from register_unwinder.")
59gdb.unwinder.register_unwinder(None, TestGlobalUnwinder(), replace=True)
60gdb.unwinder.register_unwinder(
61    gdb.current_progspace(), TestProgspaceUnwinder("py_unwind_maint")
62)
63print("Python script imported")
64