]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/testsuite/gdb.python/py-missing-debug.py
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / testsuite / gdb.python / py-missing-debug.py
1 # Copyright (C) 2023-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 import gdb
17 from gdb.missing_debug import MissingDebugHandler
18 from enum import Enum
19 import os
20
21 # A global log that is filled in by instances of the LOG_HANDLER class
22 # when they are called.
23 handler_call_log = []
24
25
26 class Mode(Enum):
27 RETURN_NONE = 0
28 RETURN_TRUE = 1
29 RETURN_FALSE = 2
30 RETURN_STRING = 3
31
32
33 class handler(MissingDebugHandler):
34 def __init__(self):
35 super().__init__("handler")
36 self._call_count = 0
37 self._mode = Mode.RETURN_NONE
38
39 def __call__(self, objfile):
40 global handler_call_log
41 handler_call_log.append(self.name)
42 self._call_count += 1
43 if self._mode == Mode.RETURN_NONE:
44 return None
45
46 if self._mode == Mode.RETURN_TRUE:
47 os.rename(self._src, self._dest)
48 return True
49
50 if self._mode == Mode.RETURN_FALSE:
51 return False
52
53 if self._mode == Mode.RETURN_STRING:
54 return self._dest
55
56 assert False
57
58 @property
59 def call_count(self):
60 """Return a count, the number of calls to __call__ since the last
61 call to set_mode.
62 """
63 return self._call_count
64
65 def set_mode(self, mode, *args):
66 self._call_count = 0
67 self._mode = mode
68
69 if mode == Mode.RETURN_NONE:
70 assert len(args) == 0
71 return
72
73 if mode == Mode.RETURN_TRUE:
74 assert len(args) == 2
75 self._src = args[0]
76 self._dest = args[1]
77 return
78
79 if mode == Mode.RETURN_FALSE:
80 assert len(args) == 0
81 return
82
83 if mode == Mode.RETURN_STRING:
84 assert len(args) == 1
85 self._dest = args[0]
86 return
87
88 assert False
89
90
91 class exception_handler(MissingDebugHandler):
92 def __init__(self):
93 super().__init__("exception_handler")
94 self.exception_type = None
95
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")
101
102
103 class log_handler(MissingDebugHandler):
104 def __call__(self, objfile):
105 global handler_call_log
106 handler_call_log.append(self.name)
107 return None
108
109
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))
113
114
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()
119
120 print("Success")