xref: /netbsd-src/external/gpl3/gdb/dist/gdb/testsuite/gdb.python/py-completion.py (revision 3a0e586386038907db1bf587e70954aa7539b5e8)
1# Copyright (C) 2014-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 testcase tests PR python/16699
17
18import gdb
19
20
21class CompleteFileInit(gdb.Command):
22    def __init__(self):
23        gdb.Command.__init__(
24            self, "completefileinit", gdb.COMMAND_USER, gdb.COMPLETE_FILENAME
25        )
26
27    def invoke(self, argument, from_tty):
28        raise gdb.GdbError("not implemented")
29
30
31class CompleteFileNone(gdb.Command):
32    def __init__(self):
33        gdb.Command.__init__(self, "completefilenone", gdb.COMMAND_USER)
34
35    def invoke(self, argument, from_tty):
36        raise gdb.GdbError("not implemented")
37
38    def complete(self, text, word):
39        return None
40
41
42class CompleteFileMethod(gdb.Command):
43    def __init__(self):
44        gdb.Command.__init__(self, "completefilemethod", gdb.COMMAND_USER)
45
46    def invoke(self, argument, from_tty):
47        raise gdb.GdbError("not implemented")
48
49    def complete(self, text, word):
50        return gdb.COMPLETE_FILENAME
51
52
53class CompleteFileCommandCond(gdb.Command):
54    def __init__(self):
55        gdb.Command.__init__(self, "completefilecommandcond", gdb.COMMAND_USER)
56
57    def invoke(self, argument, from_tty):
58        raise gdb.GdbError("not implemented")
59
60    def complete(self, text, word):
61        # This is a test made to know if the command
62        # completion still works fine.  When the user asks to
63        # complete something like "completefilecommandcond
64        # /path/to/py-completion-t", it should not complete to
65        # "/path/to/py-completion-test/", but instead just
66        # wait for input.
67        if "py-completion-t" in text:
68            return gdb.COMPLETE_COMMAND
69        else:
70            return gdb.COMPLETE_FILENAME
71
72
73class CompleteLimit1(gdb.Command):
74    def __init__(self):
75        gdb.Command.__init__(self, "completelimit1", gdb.COMMAND_USER)
76
77    def invoke(self, argument, from_tty):
78        raise gdb.GdbError("not implemented")
79
80    def complete(self, text, word):
81        return ["cl11", "cl12", "cl13"]
82
83
84class CompleteLimit2(gdb.Command):
85    def __init__(self):
86        gdb.Command.__init__(self, "completelimit2", gdb.COMMAND_USER)
87
88    def invoke(self, argument, from_tty):
89        raise gdb.GdbError("not implemented")
90
91    def complete(self, text, word):
92        return [
93            "cl21",
94            "cl23",
95            "cl25",
96            "cl27",
97            "cl29",
98            "cl22",
99            "cl24",
100            "cl26",
101            "cl28",
102            "cl210",
103        ]
104
105
106class CompleteLimit3(gdb.Command):
107    def __init__(self):
108        gdb.Command.__init__(self, "completelimit3", gdb.COMMAND_USER)
109
110    def invoke(self, argument, from_tty):
111        raise gdb.GdbError("not implemented")
112
113    def complete(self, text, word):
114        return [
115            "cl31",
116            "cl33",
117            "cl35",
118            "cl37",
119            "cl39",
120            "cl32",
121            "cl34",
122            "cl36",
123            "cl38",
124            "cl310",
125        ]
126
127
128class CompleteLimit4(gdb.Command):
129    def __init__(self):
130        gdb.Command.__init__(self, "completelimit4", gdb.COMMAND_USER)
131
132    def invoke(self, argument, from_tty):
133        raise gdb.GdbError("not implemented")
134
135    def complete(self, text, word):
136        return [
137            "cl41",
138            "cl43",
139            "cl45",
140            "cl47",
141            "cl49",
142            "cl42",
143            "cl44",
144            "cl46",
145            "cl48",
146            "cl410",
147        ]
148
149
150class CompleteLimit5(gdb.Command):
151    def __init__(self):
152        gdb.Command.__init__(self, "completelimit5", gdb.COMMAND_USER)
153
154    def invoke(self, argument, from_tty):
155        raise gdb.GdbError("not implemented")
156
157    def complete(self, text, word):
158        return [
159            "cl51",
160            "cl53",
161            "cl55",
162            "cl57",
163            "cl59",
164            "cl52",
165            "cl54",
166            "cl56",
167            "cl58",
168            "cl510",
169        ]
170
171
172class CompleteLimit6(gdb.Command):
173    def __init__(self):
174        gdb.Command.__init__(self, "completelimit6", gdb.COMMAND_USER)
175
176    def invoke(self, argument, from_tty):
177        raise gdb.GdbError("not implemented")
178
179    def complete(self, text, word):
180        return [
181            "cl61",
182            "cl63",
183            "cl65",
184            "cl67",
185            "cl69",
186            "cl62",
187            "cl64",
188            "cl66",
189            "cl68",
190            "cl610",
191        ]
192
193
194class CompleteLimit7(gdb.Command):
195    def __init__(self):
196        gdb.Command.__init__(self, "completelimit7", gdb.COMMAND_USER)
197
198    def invoke(self, argument, from_tty):
199        raise gdb.GdbError("not implemented")
200
201    def complete(self, text, word):
202        return [
203            "cl71",
204            "cl73",
205            "cl75",
206            "cl77",
207            "cl79",
208            "cl72",
209            "cl74",
210            "cl76",
211            "cl78",
212            "cl710",
213        ]
214
215
216class CompleteBrkCharException(gdb.Command):
217    def __init__(self):
218        gdb.Command.__init__(self, "complete_brkchar_exception", gdb.COMMAND_USER)
219
220    def invoke(self, argument, from_tty):
221        raise gdb.GdbError("not implemented")
222
223    def complete(self, text, word):
224        if word is None:
225            raise gdb.GdbError("brkchars exception")
226        else:
227            raise gdb.GdbError("completion exception")
228
229
230class CompleteRaiseException(gdb.Command):
231    def __init__(self):
232        gdb.Command.__init__(self, "complete_raise_exception", gdb.COMMAND_USER)
233
234    def invoke(self, argument, from_tty):
235        raise gdb.GdbError("not implemented")
236
237    def complete(self, text, word):
238        if word is None:
239            return []
240        else:
241            raise gdb.GdbError("completion exception")
242
243
244CompleteFileInit()
245CompleteFileNone()
246CompleteFileMethod()
247CompleteFileCommandCond()
248CompleteLimit1()
249CompleteLimit2()
250CompleteLimit3()
251CompleteLimit4()
252CompleteLimit5()
253CompleteLimit6()
254CompleteLimit7()
255CompleteBrkCharException()
256CompleteRaiseException()
257