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