blob: 0c9f6f647b8e2fa61f3f6d58ea7068d8c4817e10 [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:')
25 @skipUnlessDarwin
26 @dsym_test
27 @expectedFailureDarwin("llvm.org/pr20274") # intermittent failure on MacOSX
28 def test_with_dsym(self):
29 """Test return values of user defined function calls."""
30 self.buildDsym()
31 self.call_function()
32
33 @dwarf_test
Zachary Turner2878bf42015-08-18 20:01:28 +000034 @expectedFailureWindows("llvm.org/pr24489: Name lookup not working correctly on Windows")
Ewan Crawford90ff7912015-07-14 10:56:58 +000035 @expectedFailureFreeBSD("llvm.org/pr20274") # intermittent failure
36 def test_with_dwarf(self):
37 """Test return values of user defined function calls."""
38 self.buildDwarf()
39 self.call_functions()
40
41 def call_functions(self):
42 """Test return values of user defined function calls."""
43
44 # Set breakpoint in main and run exe
45 self.runCmd("file a.out", CURRENT_EXECUTABLE_SET)
46 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True)
47
48 self.runCmd("run", RUN_SUCCEEDED)
49
50 # Test recursive function call.
51 self.expect("expr fib(5)", substrs = ['$0 = 5'])
52
53 # Test function with more than one paramter
54 self.expect("expr add(4,8)", substrs = ['$1 = 12'])
55
56 # Test nesting function calls in function paramters
57 self.expect("expr add(add(5,2),add(3,4))", substrs = ['$2 = 14'])
58 self.expect("expr add(add(5,2),fib(5))", substrs = ['$3 = 12'])
59
60 # Test function with pointer paramter
61 self.expect("exp stringCompare((const char*) \"Hello world\")", substrs = ['$4 = true'])
62 self.expect("exp stringCompare((const char*) \"Hellworld\")", substrs = ['$5 = false'])
63
64
65if __name__ == '__main__':
66 import atexit
67 lldb.SBDebugger.Initialize()
68 atexit.register(lambda: lldb.SBDebugger.Terminate())
69 unittest2.main()