blob: 0784dcb7d8ac2fd2994b2fb9077c0c94569146b8 [file] [log] [blame]
Ewan Crawford90ff7912015-07-14 10:56:58 +00001"""
2Test calling user defined functions using expression evaluation.
3
4Note:
5 LLDBs current first choice of evaluating functions is using the IR interpreter,
6 which is only supported on Hexagon. Otherwise JIT is used for the evaluation.
7
8"""
9
10import unittest2
11import lldb
12import lldbutil
13from lldbtest import *
14
15class ExprCommandCallUserDefinedFunction(TestBase):
16
17 mydir = TestBase.compute_mydir(__file__)
18
19 def setUp(self):
20 # Call super's setUp().
21 TestBase.setUp(self)
22 # Find the line number to break for main.c.
23 self.line = line_number('main.cpp',
24 '// Please test these expressions while stopped at this line:')
Todd Fiala0f247a42015-10-06 15:23:52 +000025 @expectedFlakeyDarwin("llvm.org/pr20274") # intermittent failure on MacOSX, dsym only
Zachary Turner2878bf42015-08-18 20:01:28 +000026 @expectedFailureWindows("llvm.org/pr24489: Name lookup not working correctly on Windows")
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000027 def test(self):
Ewan Crawford90ff7912015-07-14 10:56:58 +000028 """Test return values of user defined function calls."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000029 self.build()
Ewan Crawford90ff7912015-07-14 10:56:58 +000030
31 # Set breakpoint in main and run exe
32 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
33 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)
34
35 self.runCmd("run", RUN_SUCCEEDED)
36
37 # Test recursive function call.
38 self.expect("expr fib(5)", substrs = ['$0 = 5'])
39
40 # Test function with more than one paramter
41 self.expect("expr add(4,8)", substrs = ['$1 = 12'])
42
43 # Test nesting function calls in function paramters
44 self.expect("expr add(add(5,2),add(3,4))", substrs = ['$2 = 14'])
45 self.expect("expr add(add(5,2),fib(5))", substrs = ['$3 = 12'])
46
47 # Test function with pointer paramter
48 self.expect("exp stringCompare((const char*) \"Hello world\")", substrs = ['$4 = true'])
49 self.expect("exp stringCompare((const char*) \"Hellworld\")", substrs = ['$5 = false'])
50
51
52if __name__ == '__main__':
53 import atexit
54 lldb.SBDebugger.Initialize()
55 atexit.register(lambda: lldb.SBDebugger.Terminate())
56 unittest2.main()