1# Copyright (C) 2015-2023 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 19import gdb.types 20from gdb.unwinder import Unwinder, register_unwinder 21 22 23class TestGlobalUnwinder(Unwinder): 24 def __init__(self): 25 super(TestGlobalUnwinder, self).__init__("global_unwinder") 26 27 def __call__(self, unwinder_info): 28 print("%s called" % self.name) 29 return None 30 31 32class TestProgspaceUnwinder(Unwinder): 33 def __init__(self, name): 34 super(TestProgspaceUnwinder, self).__init__("%s_ps_unwinder" % name) 35 36 def __call__(self, unwinder_info): 37 print("%s called" % self.name) 38 return None 39 40 41class TestObjfileUnwinder(Unwinder): 42 def __init__(self, name): 43 super(TestObjfileUnwinder, self).__init__("%s_obj_unwinder" % name) 44 45 def __call__(self, unwinder_info): 46 print("%s called" % self.name) 47 return None 48 49 50gdb.unwinder.register_unwinder(None, TestGlobalUnwinder()) 51saw_runtime_error = False 52try: 53 gdb.unwinder.register_unwinder(None, TestGlobalUnwinder(), replace=False) 54except RuntimeError: 55 saw_runtime_error = True 56if not saw_runtime_error: 57 raise RuntimeError("Missing runtime error from register_unwinder.") 58gdb.unwinder.register_unwinder(None, TestGlobalUnwinder(), replace=True) 59gdb.unwinder.register_unwinder( 60 gdb.current_progspace(), TestProgspaceUnwinder("py_unwind_maint") 61) 62print("Python script imported") 63