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 | |
Zachary Turner | 35d017f | 2015-10-23 17:04:29 +0000 | [diff] [blame^] | 10 | from __future__ import print_function |
| 11 | |
Zachary Turner | 77db4a8 | 2015-10-22 20:06:20 +0000 | [diff] [blame] | 12 | import lldb_shared |
| 13 | |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 14 | import lldb |
| 15 | import lldbutil |
| 16 | from lldbtest import * |
| 17 | |
| 18 | class 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 Fiala | 873111e | 2015-10-06 15:57:55 +0000 | [diff] [blame] | 28 | @expectedFlakeyDsym("llvm.org/pr20274") |
Zachary Turner | 2878bf4 | 2015-08-18 20:01:28 +0000 | [diff] [blame] | 29 | @expectedFailureWindows("llvm.org/pr24489: Name lookup not working correctly on Windows") |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 30 | def test(self): |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 31 | """Test return values of user defined function calls.""" |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 32 | self.build() |
Ewan Crawford | 90ff791 | 2015-07-14 10:56:58 +0000 | [diff] [blame] | 33 | |
| 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']) |