[AMDGPU] Add True16 register classes.
[llvm-project.git] / lldb / test / API / commands / command / script / TestCommandScript.py
blobcac11834fa7364594eb4da737318394475d10657
1 """
2 Test lldb Python commands.
3 """
6 import sys
7 import lldb
8 from lldbsuite.test.decorators import *
9 from lldbsuite.test.lldbtest import *
12 class CmdPythonTestCase(TestBase):
13 NO_DEBUG_INFO_TESTCASE = True
15 def test(self):
16 self.build()
17 self.pycmd_tests()
19 def pycmd_tests(self):
20 self.runCmd("command source py_import")
22 # Test that we did indeed add these commands as user commands:
23 interp = self.dbg.GetCommandInterpreter()
24 self.assertTrue(interp.UserCommandExists("foobar"), "foobar exists")
25 self.assertFalse(interp.CommandExists("foobar"), "It is not a builtin.")
27 # Test a bunch of different kinds of python callables with
28 # both 4 and 5 positional arguments.
29 self.expect("foobar", substrs=["All good"])
30 self.expect("foobar4", substrs=["All good"])
31 self.expect("vfoobar", substrs=["All good"])
32 self.expect("v5foobar", substrs=["All good"])
33 self.expect("sfoobar", substrs=["All good"])
34 self.expect("cfoobar", substrs=["All good"])
35 self.expect("ifoobar", substrs=["All good"])
36 self.expect("sfoobar4", substrs=["All good"])
37 self.expect("cfoobar4", substrs=["All good"])
38 self.expect("ifoobar4", substrs=["All good"])
39 self.expect("ofoobar", substrs=["All good"])
40 self.expect("ofoobar4", substrs=["All good"])
42 # Verify command that specifies eCommandRequiresTarget returns failure
43 # without a target.
44 self.expect("targetname", substrs=["a.out"], matching=False, error=True)
46 exe = self.getBuildArtifact("a.out")
47 self.expect("file " + exe, patterns=["Current executable set to .*a.out"])
49 self.expect("targetname", substrs=["a.out"], matching=True, error=False)
51 # This is the function to remove the custom commands in order to have a
52 # clean slate for the next test case.
53 def cleanup():
54 self.runCmd("command script delete welcome", check=False)
55 self.runCmd("command script delete targetname", check=False)
56 self.runCmd("command script delete longwait", check=False)
57 self.runCmd("command script delete mysto", check=False)
58 self.runCmd("command script delete tell_sync", check=False)
59 self.runCmd("command script delete tell_async", check=False)
60 self.runCmd("command script delete tell_curr", check=False)
61 self.runCmd("command script delete bug11569", check=False)
62 self.runCmd("command script delete takes_exe_ctx", check=False)
63 self.runCmd("command script delete decorated", check=False)
65 # Execute the cleanup function during test case tear down.
66 self.addTearDownHook(cleanup)
68 # Interact with debugger in synchronous mode
69 self.setAsync(False)
71 # We don't want to display the stdout if not in TraceOn() mode.
72 if not self.TraceOn():
73 self.HideStdout()
75 self.expect("welcome Enrico", substrs=["Hello Enrico, welcome to LLDB"])
77 self.expect(
78 "help welcome",
79 substrs=[
80 "Just a docstring for welcome_impl",
81 "A command that says hello to LLDB users",
85 decorated_commands = ["decorated" + str(n) for n in range(1, 5)]
86 for name in decorated_commands:
87 self.expect(name, substrs=["hello from " + name])
88 self.expect(
89 "help " + name, substrs=["Python command defined by @lldb.command"]
92 self.expect(
93 "help",
94 substrs=["For more information run"] + decorated_commands + ["welcome"],
97 self.expect(
98 "help -a",
99 substrs=["For more information run"] + decorated_commands + ["welcome"],
102 self.expect("help -u", matching=False, substrs=["For more information run"])
104 self.runCmd("command script delete welcome")
106 self.expect(
107 "welcome Enrico",
108 matching=False,
109 error=True,
110 substrs=["Hello Enrico, welcome to LLDB"],
113 self.expect(
114 "targetname fail", error=True, substrs=["a test for error in command"]
117 self.expect(
118 "command script list", substrs=["targetname", "For more information run"]
121 self.expect(
122 "help targetname",
123 substrs=["Expects", "'raw'", "input", "help", "raw-input"],
126 self.expect("longwait", substrs=["Done; if you saw the delays I am doing OK"])
128 self.runCmd("break set -f main.cpp -l 48")
129 self.runCmd("run")
130 self.runCmd("mysto 3")
131 self.expect(
132 "frame variable array",
133 substrs=["[0] = 79630", "[1] = 388785018", "[2] = 0"],
135 self.runCmd("mysto 3")
136 self.expect(
137 "frame variable array",
138 substrs=["[0] = 79630", "[4] = 388785018", "[5] = 0"],
141 # we cannot use the stepover command to check for async execution mode since LLDB
142 # seems to get confused when events start to queue up
143 self.expect("tell_sync", substrs=["running sync"])
144 self.expect("tell_async", substrs=["running async"])
145 self.expect("tell_curr", substrs=["I am running sync"])
147 # check that the execution context is passed in to commands that ask for it
148 self.expect("takes_exe_ctx", substrs=["a.out"])
150 # Test that a python command can redefine itself
151 self.expect('command script add -f foobar welcome -h "just some help"')
153 self.runCmd("command script clear")
155 # Test that re-defining an existing command works
156 self.runCmd("command script add my_command --class welcome.WelcomeCommand")
157 self.expect("my_command Blah", substrs=["Hello Blah, welcome to LLDB"])
159 self.runCmd(
160 "command script add my_command -o --class welcome.TargetnameCommand"
162 self.expect("my_command", substrs=["a.out"])
164 self.runCmd("command script clear")
166 self.expect(
167 "command script list", matching=False, substrs=["targetname", "longwait"]
170 self.expect(
171 "command script add -f foobar frame",
172 error=True,
173 substrs=["cannot add command"],
176 # http://llvm.org/bugs/show_bug.cgi?id=11569
177 # LLDBSwigPythonCallCommand crashes when a command script returns an
178 # object
179 self.runCmd("command script add -f bug11569 bug11569")
180 # This should not crash.
181 self.runCmd("bug11569", check=False)
183 # Make sure that a reference to a non-existent class raises an error:
184 bad_class_name = "LLDBNoSuchModule.LLDBNoSuchClass"
185 self.expect(
186 "command script add wont-work --class {0}".format(bad_class_name),
187 error=True,
188 substrs=[bad_class_name],
191 def test_persistence(self):
193 Ensure that function arguments meaningfully persist (and do not crash!)
194 even after the function terminates.
196 self.runCmd("command script import persistence.py")
197 self.runCmd("command script add -f persistence.save_debugger save_debugger")
198 self.expect("save_debugger", substrs=[str(self.dbg)])
200 # After the command completes, the debugger object should still be
201 # valid.
202 self.expect("script str(persistence.debugger_copy)", substrs=[str(self.dbg)])
203 # The result object will be replaced by an empty result object (in the
204 # "Started" state).
205 self.expect("script str(persistence.result_copy)", substrs=["Started"])