blob: c9a1db2b427e25f7d2a7efc802ee1c469ef3a4cd [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
Zachary Turner77db4a82015-10-22 20:06:20 +000010import lldb_shared
11
Ewan Crawford90ff7912015-07-14 10:56:58 +000012import lldb
13import lldbutil
14from lldbtest import *
15
16class ExprCommandCallUserDefinedFunction(TestBase):
17
18 mydir = TestBase.compute_mydir(__file__)
19
20 def setUp(self):
21 # Call super's setUp().
22 TestBase.setUp(self)
23 # Find the line number to break for main.c.
24 self.line = line_number('main.cpp',
25 '// Please test these expressions while stopped at this line:')
Todd Fiala873111e2015-10-06 15:57:55 +000026 @expectedFlakeyDsym("llvm.org/pr20274")
Zachary Turner2878bf42015-08-18 20:01:28 +000027 @expectedFailureWindows("llvm.org/pr24489: Name lookup not working correctly on Windows")
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000028 def test(self):
Ewan Crawford90ff7912015-07-14 10:56:58 +000029 """Test return values of user defined function calls."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000030 self.build()
Ewan Crawford90ff7912015-07-14 10:56:58 +000031
32 # Set breakpoint in main and run exe
33 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
34 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)
35
36 self.runCmd("run", RUN_SUCCEEDED)
37
38 # Test recursive function call.
39 self.expect("expr fib(5)", substrs = ['$0 = 5'])
40
41 # Test function with more than one paramter
42 self.expect("expr add(4,8)", substrs = ['$1 = 12'])
43
44 # Test nesting function calls in function paramters
45 self.expect("expr add(add(5,2),add(3,4))", substrs = ['$2 = 14'])
46 self.expect("expr add(add(5,2),fib(5))", substrs = ['$3 = 12'])
47
48 # Test function with pointer paramter
49 self.expect("exp stringCompare((const char*) \"Hello world\")", substrs = ['$4 = true'])
50 self.expect("exp stringCompare((const char*) \"Hellworld\")", substrs = ['$5 = false'])