Fix "maint print" error messages
[binutils-gdb.git] / gdb / testsuite / gdb.python / py-unwind-maint.py
blob1d049a999f486369870aa167fd3a7cf4db71fa47
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.
18 import re
20 import gdb.types
21 from gdb.unwinder import Unwinder, register_unwinder
24 class TestGlobalUnwinder(Unwinder):
25 def __init__(self):
26 super(TestGlobalUnwinder, self).__init__("global_unwinder")
28 def __call__(self, unwinder_info):
29 print("%s called" % self.name)
30 return None
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)
39 return None
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)
48 return None
51 gdb.unwinder.register_unwinder(None, TestGlobalUnwinder())
52 saw_runtime_error = False
53 try:
54 gdb.unwinder.register_unwinder(None, TestGlobalUnwinder(), replace=False)
55 except RuntimeError:
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")