Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test lldb Python commands. |
| 3 | """ |
| 4 | |
Zachary Turner | 77db4a8 | 2015-10-22 20:06:20 +0000 | [diff] [blame] | 5 | import lldb_shared |
| 6 | |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 7 | import os, time |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 8 | import lldb |
| 9 | from lldbtest import * |
| 10 | |
| 11 | class CmdPythonTestCase(TestBase): |
| 12 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 13 | mydir = TestBase.compute_mydir(__file__) |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 14 | |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 15 | def test (self): |
| 16 | self.build () |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 17 | self.pycmd_tests () |
| 18 | |
| 19 | def pycmd_tests (self): |
Enrico Granata | e87764f | 2015-05-27 05:04:35 +0000 | [diff] [blame] | 20 | self.runCmd("command source py_import") |
| 21 | |
Ed Maste | 39db0f6 | 2015-05-28 16:06:48 +0000 | [diff] [blame] | 22 | # Verify command that specifies eCommandRequiresTarget returns failure |
| 23 | # without a target. |
Enrico Granata | e87764f | 2015-05-27 05:04:35 +0000 | [diff] [blame] | 24 | self.expect('targetname', |
| 25 | substrs = ['a.out'], matching=False, error=True) |
| 26 | |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 27 | exe = os.path.join (os.getcwd(), "a.out") |
| 28 | self.expect("file " + exe, |
| 29 | patterns = [ "Current executable set to .*a.out" ]) |
| 30 | |
Enrico Granata | e87764f | 2015-05-27 05:04:35 +0000 | [diff] [blame] | 31 | self.expect('targetname', |
| 32 | substrs = ['a.out'], matching=True, error=False) |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 33 | |
Johnny Chen | 04a101d | 2011-10-12 17:50:41 +0000 | [diff] [blame] | 34 | # 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 Granata | 0a305db | 2011-11-07 22:57:04 +0000 | [diff] [blame] | 40 | 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 Chen | 1d9cb8a | 2011-12-14 20:40:27 +0000 | [diff] [blame] | 44 | self.runCmd('command script delete bug11569', check=False) |
Enrico Granata | 06be059 | 2014-10-01 21:47:29 +0000 | [diff] [blame] | 45 | self.runCmd('command script delete takes_exe_ctx', check=False) |
Johnny Chen | 04a101d | 2011-10-12 17:50:41 +0000 | [diff] [blame] | 46 | |
| 47 | # Execute the cleanup function during test case tear down. |
| 48 | self.addTearDownHook(cleanup) |
| 49 | |
Daniel Malea | 249287a | 2013-02-19 16:08:57 +0000 | [diff] [blame] | 50 | # Interact with debugger in synchronous mode |
| 51 | self.setAsync(False) |
| 52 | |
Johnny Chen | 3e15c4d | 2011-08-24 18:19:50 +0000 | [diff] [blame] | 53 | # We don't want to display the stdout if not in TraceOn() mode. |
| 54 | if not self.TraceOn(): |
| 55 | self.HideStdout() |
| 56 | |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 57 | 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 Granata | 08633ee | 2011-09-09 17:49:36 +0000 | [diff] [blame] | 64 | self.expect("help", |
Enrico Granata | 735152e | 2014-09-15 17:52:44 +0000 | [diff] [blame] | 65 | substrs = ['For more information run', |
Enrico Granata | 08633ee | 2011-09-09 17:49:36 +0000 | [diff] [blame] | 66 | 'welcome']) |
| 67 | |
| 68 | self.expect("help -a", |
Enrico Granata | 735152e | 2014-09-15 17:52:44 +0000 | [diff] [blame] | 69 | substrs = ['For more information run', |
Enrico Granata | 08633ee | 2011-09-09 17:49:36 +0000 | [diff] [blame] | 70 | 'welcome']) |
| 71 | |
| 72 | self.expect("help -u", matching=False, |
Enrico Granata | 735152e | 2014-09-15 17:52:44 +0000 | [diff] [blame] | 73 | substrs = ['For more information run']) |
Enrico Granata | 08633ee | 2011-09-09 17:49:36 +0000 | [diff] [blame] | 74 | |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 75 | 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 Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 80 | 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 Granata | 735152e | 2014-09-15 17:52:44 +0000 | [diff] [blame] | 85 | 'For more information run']) |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 86 | |
| 87 | self.expect("help targetname", |
Sean Callanan | e6553d8 | 2014-10-06 17:58:15 +0000 | [diff] [blame] | 88 | substrs = ['This', 'command', 'takes', '\'raw\'', 'input', |
| 89 | 'quote', 'stuff']) |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 90 | |
| 91 | self.expect("longwait", |
| 92 | substrs = ['Done; if you saw the delays I am doing OK']) |
| 93 | |
Enrico Granata | 0a305db | 2011-11-07 22:57:04 +0000 | [diff] [blame] | 94 | 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 Malea | 249287a | 2013-02-19 16:08:57 +0000 | [diff] [blame] | 110 | substrs = ['I am running sync']) |
Enrico Granata | 06be059 | 2014-10-01 21:47:29 +0000 | [diff] [blame] | 111 | |
| 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 Granata | 0a305db | 2011-11-07 22:57:04 +0000 | [diff] [blame] | 114 | |
Daniel Malea | d82ac9e | 2013-02-21 21:18:07 +0000 | [diff] [blame] | 115 | # Test that a python command can redefine itself |
Enrico Granata | 735152e | 2014-09-15 17:52:44 +0000 | [diff] [blame] | 116 | self.expect('command script add -f foobar welcome -h "just some help"') |
| 117 | |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 118 | self.runCmd("command script clear") |
| 119 | |
Daniel Malea | d82ac9e | 2013-02-21 21:18:07 +0000 | [diff] [blame] | 120 | # Test that re-defining an existing command works |
Enrico Granata | 6f79bb2 | 2015-03-13 22:22:28 +0000 | [diff] [blame] | 121 | self.runCmd('command script add my_command --class welcome.WelcomeCommand') |
Daniel Malea | d82ac9e | 2013-02-21 21:18:07 +0000 | [diff] [blame] | 122 | self.expect('my_command Blah', substrs = ['Hello Blah, welcome to LLDB']) |
| 123 | |
Enrico Granata | e87764f | 2015-05-27 05:04:35 +0000 | [diff] [blame] | 124 | self.runCmd('command script add my_command --class welcome.TargetnameCommand') |
Daniel Malea | d82ac9e | 2013-02-21 21:18:07 +0000 | [diff] [blame] | 125 | self.expect('my_command', substrs = ['a.out']) |
| 126 | |
| 127 | self.runCmd("command script clear") |
| 128 | |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 129 | self.expect('command script list', matching=False, |
| 130 | substrs = ['targetname', |
| 131 | 'longwait']) |
| 132 | |
Enrico Granata | 0a305db | 2011-11-07 22:57:04 +0000 | [diff] [blame] | 133 | self.expect('command script add -f foobar frame', error=True, |
| 134 | substrs = ['cannot add command']) |
| 135 | |
Johnny Chen | 1d9cb8a | 2011-12-14 20:40:27 +0000 | [diff] [blame] | 136 | # 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) |