blob: b8a891630c3d60076d4de6d2aea373c3afb49637 [file] [log] [blame]
Enrico Granatacb2921d2011-08-24 17:45:40 +00001"""
2Test lldb Python commands.
3"""
4
Zachary Turner77db4a82015-10-22 20:06:20 +00005import lldb_shared
6
Enrico Granatacb2921d2011-08-24 17:45:40 +00007import os, time
Enrico Granatacb2921d2011-08-24 17:45:40 +00008import lldb
9from lldbtest import *
10
11class CmdPythonTestCase(TestBase):
12
Greg Clayton4570d3e2013-12-10 23:19:29 +000013 mydir = TestBase.compute_mydir(__file__)
Enrico Granatacb2921d2011-08-24 17:45:40 +000014
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000015 def test (self):
16 self.build ()
Enrico Granatacb2921d2011-08-24 17:45:40 +000017 self.pycmd_tests ()
18
19 def pycmd_tests (self):
Enrico Granatae87764f2015-05-27 05:04:35 +000020 self.runCmd("command source py_import")
21
Ed Maste39db0f62015-05-28 16:06:48 +000022 # Verify command that specifies eCommandRequiresTarget returns failure
23 # without a target.
Enrico Granatae87764f2015-05-27 05:04:35 +000024 self.expect('targetname',
25 substrs = ['a.out'], matching=False, error=True)
26
Enrico Granatacb2921d2011-08-24 17:45:40 +000027 exe = os.path.join (os.getcwd(), "a.out")
28 self.expect("file " + exe,
29 patterns = [ "Current executable set to .*a.out" ])
30
Enrico Granatae87764f2015-05-27 05:04:35 +000031 self.expect('targetname',
32 substrs = ['a.out'], matching=True, error=False)
Enrico Granatacb2921d2011-08-24 17:45:40 +000033
Johnny Chen04a101d2011-10-12 17:50:41 +000034 # This is the function to remove the custom commands in order to have a
35 # clean slate for the next test case.
36 def cleanup():
37 self.runCmd('command script delete welcome', check=False)
38 self.runCmd('command script delete targetname', check=False)
39 self.runCmd('command script delete longwait', check=False)
Enrico Granata0a305db2011-11-07 22:57:04 +000040 self.runCmd('command script delete mysto', check=False)
41 self.runCmd('command script delete tell_sync', check=False)
42 self.runCmd('command script delete tell_async', check=False)
43 self.runCmd('command script delete tell_curr', check=False)
Johnny Chen1d9cb8a2011-12-14 20:40:27 +000044 self.runCmd('command script delete bug11569', check=False)
Enrico Granata06be0592014-10-01 21:47:29 +000045 self.runCmd('command script delete takes_exe_ctx', check=False)
Johnny Chen04a101d2011-10-12 17:50:41 +000046
47 # Execute the cleanup function during test case tear down.
48 self.addTearDownHook(cleanup)
49
Daniel Malea249287a2013-02-19 16:08:57 +000050 # Interact with debugger in synchronous mode
51 self.setAsync(False)
52
Johnny Chen3e15c4d2011-08-24 18:19:50 +000053 # We don't want to display the stdout if not in TraceOn() mode.
54 if not self.TraceOn():
55 self.HideStdout()
56
Enrico Granatacb2921d2011-08-24 17:45:40 +000057 self.expect('welcome Enrico',
58 substrs = ['Hello Enrico, welcome to LLDB']);
59
60 self.expect("help welcome",
61 substrs = ['Just a docstring for welcome_impl',
62 'A command that says hello to LLDB users'])
63
Enrico Granata08633ee2011-09-09 17:49:36 +000064 self.expect("help",
Enrico Granata735152e2014-09-15 17:52:44 +000065 substrs = ['For more information run',
Enrico Granata08633ee2011-09-09 17:49:36 +000066 'welcome'])
67
68 self.expect("help -a",
Enrico Granata735152e2014-09-15 17:52:44 +000069 substrs = ['For more information run',
Enrico Granata08633ee2011-09-09 17:49:36 +000070 'welcome'])
71
72 self.expect("help -u", matching=False,
Enrico Granata735152e2014-09-15 17:52:44 +000073 substrs = ['For more information run'])
Enrico Granata08633ee2011-09-09 17:49:36 +000074
Enrico Granatacb2921d2011-08-24 17:45:40 +000075 self.runCmd("command script delete welcome");
76
77 self.expect('welcome Enrico', matching=False, error=True,
78 substrs = ['Hello Enrico, welcome to LLDB']);
79
Enrico Granatacb2921d2011-08-24 17:45:40 +000080 self.expect('targetname fail', error=True,
81 substrs = ['a test for error in command'])
82
83 self.expect('command script list',
84 substrs = ['targetname',
Enrico Granata735152e2014-09-15 17:52:44 +000085 'For more information run'])
Enrico Granatacb2921d2011-08-24 17:45:40 +000086
87 self.expect("help targetname",
Sean Callanane6553d82014-10-06 17:58:15 +000088 substrs = ['This', 'command', 'takes', '\'raw\'', 'input',
89 'quote', 'stuff'])
Enrico Granatacb2921d2011-08-24 17:45:40 +000090
91 self.expect("longwait",
92 substrs = ['Done; if you saw the delays I am doing OK'])
93
Enrico Granata0a305db2011-11-07 22:57:04 +000094 self.runCmd("b main")
95 self.runCmd("run")
96 self.runCmd("mysto 3")
97 self.expect("frame variable array",
98 substrs = ['[0] = 79630','[1] = 388785018','[2] = 0'])
99 self.runCmd("mysto 3")
100 self.expect("frame variable array",
101 substrs = ['[0] = 79630','[4] = 388785018','[5] = 0'])
102
103# we cannot use the stepover command to check for async execution mode since LLDB
104# seems to get confused when events start to queue up
105 self.expect("tell_sync",
106 substrs = ['running sync'])
107 self.expect("tell_async",
108 substrs = ['running async'])
109 self.expect("tell_curr",
Daniel Malea249287a2013-02-19 16:08:57 +0000110 substrs = ['I am running sync'])
Enrico Granata06be0592014-10-01 21:47:29 +0000111
112# check that the execution context is passed in to commands that ask for it
113 self.expect("takes_exe_ctx", substrs = ["a.out"])
Enrico Granata0a305db2011-11-07 22:57:04 +0000114
Daniel Malead82ac9e2013-02-21 21:18:07 +0000115 # Test that a python command can redefine itself
Enrico Granata735152e2014-09-15 17:52:44 +0000116 self.expect('command script add -f foobar welcome -h "just some help"')
117
Enrico Granatacb2921d2011-08-24 17:45:40 +0000118 self.runCmd("command script clear")
119
Daniel Malead82ac9e2013-02-21 21:18:07 +0000120 # Test that re-defining an existing command works
Enrico Granata6f79bb22015-03-13 22:22:28 +0000121 self.runCmd('command script add my_command --class welcome.WelcomeCommand')
Daniel Malead82ac9e2013-02-21 21:18:07 +0000122 self.expect('my_command Blah', substrs = ['Hello Blah, welcome to LLDB'])
123
Enrico Granatae87764f2015-05-27 05:04:35 +0000124 self.runCmd('command script add my_command --class welcome.TargetnameCommand')
Daniel Malead82ac9e2013-02-21 21:18:07 +0000125 self.expect('my_command', substrs = ['a.out'])
126
127 self.runCmd("command script clear")
128
Enrico Granatacb2921d2011-08-24 17:45:40 +0000129 self.expect('command script list', matching=False,
130 substrs = ['targetname',
131 'longwait'])
132
Enrico Granata0a305db2011-11-07 22:57:04 +0000133 self.expect('command script add -f foobar frame', error=True,
134 substrs = ['cannot add command'])
135
Johnny Chen1d9cb8a2011-12-14 20:40:27 +0000136 # http://llvm.org/bugs/show_bug.cgi?id=11569
137 # LLDBSwigPythonCallCommand crashes when a command script returns an object
138 self.runCmd('command script add -f bug11569 bug11569')
139 # This should not crash.
140 self.runCmd('bug11569', check=False)