Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test lldb Python commands. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
| 8 | from lldbtest import * |
| 9 | |
| 10 | class CmdPythonTestCase(TestBase): |
| 11 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 12 | mydir = TestBase.compute_mydir(__file__) |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 13 | |
| 14 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
Johnny Chen | f1548d4 | 2012-04-06 00:56:05 +0000 | [diff] [blame] | 15 | @dsym_test |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 16 | def test_with_dsym (self): |
| 17 | self.buildDsym () |
| 18 | self.pycmd_tests () |
| 19 | |
Johnny Chen | f1548d4 | 2012-04-06 00:56:05 +0000 | [diff] [blame] | 20 | @dwarf_test |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 21 | def test_with_dwarf (self): |
| 22 | self.buildDwarf () |
| 23 | self.pycmd_tests () |
| 24 | |
| 25 | def pycmd_tests (self): |
| 26 | exe = os.path.join (os.getcwd(), "a.out") |
| 27 | self.expect("file " + exe, |
| 28 | patterns = [ "Current executable set to .*a.out" ]) |
| 29 | |
| 30 | self.runCmd("command source py_import") |
| 31 | |
Johnny Chen | 04a101d | 2011-10-12 17:50:41 +0000 | [diff] [blame] | 32 | # This is the function to remove the custom commands in order to have a |
| 33 | # clean slate for the next test case. |
| 34 | def cleanup(): |
| 35 | self.runCmd('command script delete welcome', check=False) |
| 36 | self.runCmd('command script delete targetname', check=False) |
| 37 | self.runCmd('command script delete longwait', check=False) |
Enrico Granata | 0a305db | 2011-11-07 22:57:04 +0000 | [diff] [blame] | 38 | self.runCmd('command script delete mysto', check=False) |
| 39 | self.runCmd('command script delete tell_sync', check=False) |
| 40 | self.runCmd('command script delete tell_async', check=False) |
| 41 | self.runCmd('command script delete tell_curr', check=False) |
Johnny Chen | 1d9cb8a | 2011-12-14 20:40:27 +0000 | [diff] [blame] | 42 | self.runCmd('command script delete bug11569', check=False) |
Johnny Chen | 04a101d | 2011-10-12 17:50:41 +0000 | [diff] [blame] | 43 | |
| 44 | # Execute the cleanup function during test case tear down. |
| 45 | self.addTearDownHook(cleanup) |
| 46 | |
Daniel Malea | 249287a | 2013-02-19 16:08:57 +0000 | [diff] [blame] | 47 | # Interact with debugger in synchronous mode |
| 48 | self.setAsync(False) |
| 49 | |
Johnny Chen | 3e15c4d | 2011-08-24 18:19:50 +0000 | [diff] [blame] | 50 | # We don't want to display the stdout if not in TraceOn() mode. |
| 51 | if not self.TraceOn(): |
| 52 | self.HideStdout() |
| 53 | |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 54 | self.expect('welcome Enrico', |
| 55 | substrs = ['Hello Enrico, welcome to LLDB']); |
| 56 | |
| 57 | self.expect("help welcome", |
| 58 | substrs = ['Just a docstring for welcome_impl', |
| 59 | 'A command that says hello to LLDB users']) |
| 60 | |
Enrico Granata | 08633ee | 2011-09-09 17:49:36 +0000 | [diff] [blame] | 61 | self.expect("help", |
Enrico Granata | 735152e | 2014-09-15 17:52:44 +0000 | [diff] [blame^] | 62 | substrs = ['For more information run', |
Enrico Granata | 08633ee | 2011-09-09 17:49:36 +0000 | [diff] [blame] | 63 | 'welcome']) |
| 64 | |
| 65 | self.expect("help -a", |
Enrico Granata | 735152e | 2014-09-15 17:52:44 +0000 | [diff] [blame^] | 66 | substrs = ['For more information run', |
Enrico Granata | 08633ee | 2011-09-09 17:49:36 +0000 | [diff] [blame] | 67 | 'welcome']) |
| 68 | |
| 69 | self.expect("help -u", matching=False, |
Enrico Granata | 735152e | 2014-09-15 17:52:44 +0000 | [diff] [blame^] | 70 | substrs = ['For more information run']) |
Enrico Granata | 08633ee | 2011-09-09 17:49:36 +0000 | [diff] [blame] | 71 | |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 72 | self.runCmd("command script delete welcome"); |
| 73 | |
| 74 | self.expect('welcome Enrico', matching=False, error=True, |
| 75 | substrs = ['Hello Enrico, welcome to LLDB']); |
| 76 | |
| 77 | self.expect('targetname', |
| 78 | substrs = ['a.out']) |
| 79 | |
| 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", |
Enrico Granata | 735152e | 2014-09-15 17:52:44 +0000 | [diff] [blame^] | 88 | substrs = ['This command takes','\'raw\' input', |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 89 | 'quote stuff']) |
| 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 | 0a305db | 2011-11-07 22:57:04 +0000 | [diff] [blame] | 111 | |
Daniel Malea | d82ac9e | 2013-02-21 21:18:07 +0000 | [diff] [blame] | 112 | # Test that a python command can redefine itself |
Enrico Granata | 735152e | 2014-09-15 17:52:44 +0000 | [diff] [blame^] | 113 | self.expect('command script add -f foobar welcome -h "just some help"') |
| 114 | |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 115 | self.runCmd("command script clear") |
| 116 | |
Daniel Malea | d82ac9e | 2013-02-21 21:18:07 +0000 | [diff] [blame] | 117 | # Test that re-defining an existing command works |
| 118 | self.runCmd('command script add my_command --function welcome.welcome_impl') |
| 119 | self.expect('my_command Blah', substrs = ['Hello Blah, welcome to LLDB']) |
| 120 | |
| 121 | self.runCmd('command script add my_command --function welcome.target_name_impl') |
| 122 | self.expect('my_command', substrs = ['a.out']) |
| 123 | |
| 124 | self.runCmd("command script clear") |
| 125 | |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 126 | self.expect('command script list', matching=False, |
| 127 | substrs = ['targetname', |
| 128 | 'longwait']) |
| 129 | |
Enrico Granata | 0a305db | 2011-11-07 22:57:04 +0000 | [diff] [blame] | 130 | self.expect('command script add -f foobar frame', error=True, |
| 131 | substrs = ['cannot add command']) |
| 132 | |
Johnny Chen | 1d9cb8a | 2011-12-14 20:40:27 +0000 | [diff] [blame] | 133 | # http://llvm.org/bugs/show_bug.cgi?id=11569 |
| 134 | # LLDBSwigPythonCallCommand crashes when a command script returns an object |
| 135 | self.runCmd('command script add -f bug11569 bug11569') |
| 136 | # This should not crash. |
| 137 | self.runCmd('bug11569', check=False) |
| 138 | |
Enrico Granata | cb2921d | 2011-08-24 17:45:40 +0000 | [diff] [blame] | 139 | if __name__ == '__main__': |
| 140 | import atexit |
| 141 | lldb.SBDebugger.Initialize() |
| 142 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 143 | unittest2.main() |
| 144 | |