]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-missing-debug.py
1 # Copyright (C) 2023-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/>.
17 from gdb
.missing_debug
import MissingDebugHandler
21 # A global log that is filled in by instances of the LOG_HANDLER class
22 # when they are called.
33 class handler(MissingDebugHandler
):
35 super().__init
__("handler")
37 self
._mode
= Mode
.RETURN_NONE
39 def __call__(self
, objfile
):
40 global handler_call_log
41 handler_call_log
.append(self
.name
)
43 if self
._mode
== Mode
.RETURN_NONE
:
46 if self
._mode
== Mode
.RETURN_TRUE
:
47 os
.rename(self
._src
, self
._dest
)
50 if self
._mode
== Mode
.RETURN_FALSE
:
53 if self
._mode
== Mode
.RETURN_STRING
:
60 """Return a count, the number of calls to __call__ since the last
63 return self
._call
_count
65 def set_mode(self
, mode
, *args
):
69 if mode
== Mode
.RETURN_NONE
:
73 if mode
== Mode
.RETURN_TRUE
:
79 if mode
== Mode
.RETURN_FALSE
:
83 if mode
== Mode
.RETURN_STRING
:
91 class exception_handler(MissingDebugHandler
):
93 super().__init
__("exception_handler")
94 self
.exception_type
= None
96 def __call__(self
, objfile
):
97 global handler_call_log
98 handler_call_log
.append(self
.name
)
99 assert self
.exception_type
is not None
100 raise self
.exception_type("message")
103 class log_handler(MissingDebugHandler
):
104 def __call__(self
, objfile
):
105 global handler_call_log
106 handler_call_log
.append(self
.name
)
110 # A basic helper function, this keeps lines shorter in the TCL script.
111 def register(name
, locus
=None):
112 gdb
.missing_debug
.register_handler(locus
, log_handler(name
))
115 # Create instances of the handlers, but don't install any. We install
116 # these as needed from the TCL script.
117 rhandler
= exception_handler()
118 handler_obj
= handler()