Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test calling user defined functions using expression evaluation. |
| 3 | |
| 4 | Note: |
| 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 | |
| 10 | import unittest2 |
| 11 | import lldb |
| 12 | import lldbutil |
| 13 | from lldbtest import * |
| 14 | |
| 15 | class 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 Fiala | 0f247a4 | 2015-10-06 15:23:52 +0000 | [diff] [blame] | 25 | @expectedFlakeyDarwin("llvm.org/pr20274") # intermittent failure on MacOSX, dsym only |
Zachary Turner | 2878bf4 | 2015-08-18 20:01:28 +0000 | [diff] [blame] | 26 | @expectedFailureWindows("llvm.org/pr24489: Name lookup not working correctly on Windows") |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 27 | def test(self): |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 28 | """Test return values of user defined function calls.""" |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 29 | self.build() |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 30 | |
| 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 | |
| 52 | if __name__ == '__main__': |
| 53 | import atexit |
| 54 | lldb.SBDebugger.Initialize() |
| 55 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 56 | unittest2.main() |