TestExprs.py revision ecd834d482ef001989d4ce60042e4d018a5ac569
1""" 2Test many basic expression commands. 3""" 4 5import os, time 6import unittest2 7import lldb 8from lldbtest import * 9 10class BasicExprCommandsTestCase(TestBase): 11 12 mydir = os.path.join("expression_command", "test") 13 14 def setUp(self): 15 # Call super's setUp(). 16 TestBase.setUp(self) 17 # Find the line number to break for main.c. 18 self.line = line_number('main.cpp', 19 '// Please test many expressions while stopped at this line:') 20 21 def test_many_expr_commands(self): 22 """These basic expression commands should work as expected.""" 23 self.buildDefault() 24 25 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) 26 27 self.expect("breakpoint set -f main.cpp -l %d" % self.line, 28 BREAKPOINT_CREATED, 29 startstr = "Breakpoint created: 1: file ='main.cpp', line = %d" % 30 self.line) 31 32 self.runCmd("run", RUN_SUCCEEDED) 33 34 self.expect("expression 2", 35 patterns = ["\(int\) \$.* = 2"]) 36 # (int) $0 = 1 37 38 self.expect("expression 2ull", 39 patterns = ["\(unsigned long long\) \$.* = 2"]) 40 # (unsigned long long) $1 = 2 41 42 self.expect("expression 2.234f", 43 patterns = ["\(float\) \$.* = 2\.234"]) 44 # (float) $2 = 2.234 45 46 self.expect("expression 2.234", 47 patterns = ["\(double\) \$.* = 2\.234"]) 48 # (double) $3 = 2.234 49 50 self.expect("expression 2+3", 51 patterns = ["\(int\) \$.* = 5"]) 52 # (int) $4 = 5 53 54 self.expect("expression argc", 55 patterns = ["\(int\) \$.* = 1"]) 56 # (int) $5 = 1 57 58 self.expect("expression argc + 22", 59 patterns = ["\(int\) \$.* = 23"]) 60 # (int) $6 = 23 61 62 self.expect("expression argv", 63 patterns = ["\(const char \*\*\) \$.* = 0x"]) 64 # (const char *) $7 = ... 65 66 self.expect("expression argv[0]", 67 substrs = ["(const char *)", 68 os.path.join(self.mydir, "a.out")]) 69 # (const char *) $8 = 0x... "/Volumes/data/lldb/svn/trunk/test/expression_command/test/a.out" 70 71 72 @unittest2.expectedFailure 73 # rdar://problem/8686536 74 # CommandInterpreter::HandleCommand is stripping \'s from input for WantsRawCommand commands 75 def test_expr_commands_can_handle_quotes(self): 76 """Throw some expression commands with quotes at lldb.""" 77 self.buildDefault() 78 79 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) 80 81 self.expect("breakpoint set -f main.cpp -l %d" % self.line, 82 BREAKPOINT_CREATED, 83 startstr = "Breakpoint created: 1: file ='main.cpp', line = %d" % 84 self.line) 85 86 self.runCmd("run", RUN_SUCCEEDED) 87 88 self.runCmd("expression 'a'") 89 self.runCmd('expression printf("\t\x68\n")') 90 self.runCmd('expression printf("\"\n")') 91 self.runCmd('expression printf("\'\n")') 92 93 94if __name__ == '__main__': 95 import atexit 96 lldb.SBDebugger.Initialize() 97 atexit.register(lambda: lldb.SBDebugger.Terminate()) 98 unittest2.main() 99