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:') |
| 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 |
| 34 | @expectedFailureFreeBSD("llvm.org/pr20274") # intermittent failure |
| 35 | def test_with_dwarf(self): |
| 36 | """Test return values of user defined function calls.""" |
| 37 | self.buildDwarf() |
| 38 | self.call_functions() |
| 39 | |
| 40 | def call_functions(self): |
| 41 | """Test return values of user defined function calls.""" |
| 42 | |
| 43 | # Set breakpoint in main and run exe |
| 44 | self.runCmd("file a.out", CURRENT_EXECUTABLE_SET) |
| 45 | lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.line, num_expected_locations=-1, loc_exact=True) |
| 46 | |
| 47 | self.runCmd("run", RUN_SUCCEEDED) |
| 48 | |
| 49 | # Test recursive function call. |
| 50 | self.expect("expr fib(5)", substrs = ['$0 = 5']) |
| 51 | |
| 52 | # Test function with more than one paramter |
| 53 | self.expect("expr add(4,8)", substrs = ['$1 = 12']) |
| 54 | |
| 55 | # Test nesting function calls in function paramters |
| 56 | self.expect("expr add(add(5,2),add(3,4))", substrs = ['$2 = 14']) |
| 57 | self.expect("expr add(add(5,2),fib(5))", substrs = ['$3 = 12']) |
| 58 | |
| 59 | # Test function with pointer paramter |
| 60 | self.expect("exp stringCompare((const char*) \"Hello world\")", substrs = ['$4 = true']) |
| 61 | self.expect("exp stringCompare((const char*) \"Hellworld\")", substrs = ['$5 = false']) |
| 62 | |
| 63 | |
| 64 | if __name__ == '__main__': |
| 65 | import atexit |
| 66 | lldb.SBDebugger.Initialize() |
| 67 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 68 | unittest2.main() |