199451b44SJordan Rupprecht"""Test that importing modules in Objective-C works as expected.""" 299451b44SJordan Rupprecht 399451b44SJordan Rupprecht 499451b44SJordan Rupprechtimport lldb 599451b44SJordan Rupprechtfrom lldbsuite.test.decorators import * 699451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import * 799451b44SJordan Rupprechtfrom lldbsuite.test import lldbutil 899451b44SJordan Rupprecht 999451b44SJordan Rupprecht 1099451b44SJordan Rupprechtclass ObjCModulesTestCase(TestBase): 1199451b44SJordan Rupprecht def setUp(self): 1299451b44SJordan Rupprecht # Call super's setUp(). 1399451b44SJordan Rupprecht TestBase.setUp(self) 1499451b44SJordan Rupprecht # Find the line number to break inside main(). 15*2238dcc3SJonas Devlieghere self.line = line_number("main.m", "// Set breakpoint 0 here.") 1699451b44SJordan Rupprecht 1799451b44SJordan Rupprecht @skipIf(macos_version=["<", "10.12"]) 1899451b44SJordan Rupprecht def test_expr(self): 1999451b44SJordan Rupprecht self.build() 2099451b44SJordan Rupprecht exe = self.getBuildArtifact("a.out") 2199451b44SJordan Rupprecht self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 2299451b44SJordan Rupprecht 2399451b44SJordan Rupprecht # Break inside the foo function which takes a bar_ptr argument. 2499451b44SJordan Rupprecht lldbutil.run_break_set_by_file_and_line( 25*2238dcc3SJonas Devlieghere self, "main.m", self.line, num_expected_locations=1, loc_exact=True 26*2238dcc3SJonas Devlieghere ) 2799451b44SJordan Rupprecht 2899451b44SJordan Rupprecht self.runCmd("run", RUN_SUCCEEDED) 2999451b44SJordan Rupprecht 3099451b44SJordan Rupprecht # The stop reason of the thread should be breakpoint. 31*2238dcc3SJonas Devlieghere self.expect( 32*2238dcc3SJonas Devlieghere "thread list", 33*2238dcc3SJonas Devlieghere STOPPED_DUE_TO_BREAKPOINT, 34*2238dcc3SJonas Devlieghere substrs=["stopped", "stop reason = breakpoint"], 35*2238dcc3SJonas Devlieghere ) 3699451b44SJordan Rupprecht 3799451b44SJordan Rupprecht # The breakpoint should have a hit count of 1. 389f0b5f9aSSYNOPSYS\georgiev lldbutil.check_breakpoint(self, bpno=1, expected_hit_count=1) 3999451b44SJordan Rupprecht 40*2238dcc3SJonas Devlieghere self.expect( 41*2238dcc3SJonas Devlieghere "expr @import Darwin; 3", 42*2238dcc3SJonas Devlieghere VARIABLES_DISPLAYED_CORRECTLY, 43*2238dcc3SJonas Devlieghere substrs=["int", "3"], 44*2238dcc3SJonas Devlieghere ) 4599451b44SJordan Rupprecht 46*2238dcc3SJonas Devlieghere self.expect("expr getpid()", VARIABLES_DISPLAYED_CORRECTLY, substrs=["pid_t"]) 4799451b44SJordan Rupprecht 4899451b44SJordan Rupprecht self.expect( 4999451b44SJordan Rupprecht "expr @import Foundation; 4", 5099451b44SJordan Rupprecht VARIABLES_DISPLAYED_CORRECTLY, 51*2238dcc3SJonas Devlieghere substrs=["int", "4"], 52*2238dcc3SJonas Devlieghere ) 5399451b44SJordan Rupprecht 5499451b44SJordan Rupprecht # Type lookup should still work and print something reasonable 5599451b44SJordan Rupprecht # for types from the module. 5699451b44SJordan Rupprecht self.expect("type lookup NSObject", substrs=["instanceMethod"]) 5799451b44SJordan Rupprecht 58*2238dcc3SJonas Devlieghere self.expect( 59*2238dcc3SJonas Devlieghere "expr string.length", 60*2238dcc3SJonas Devlieghere VARIABLES_DISPLAYED_CORRECTLY, 61*2238dcc3SJonas Devlieghere substrs=["NSUInteger", "5"], 62*2238dcc3SJonas Devlieghere ) 6399451b44SJordan Rupprecht 6499451b44SJordan Rupprecht self.expect( 65*2238dcc3SJonas Devlieghere "expr array.count", 6699451b44SJordan Rupprecht VARIABLES_DISPLAYED_CORRECTLY, 67*2238dcc3SJonas Devlieghere substrs=["NSUInteger", "3"], 68*2238dcc3SJonas Devlieghere ) 6999451b44SJordan Rupprecht 7099451b44SJordan Rupprecht self.expect( 71*2238dcc3SJonas Devlieghere 'expression *[NSURL URLWithString:@"http://lldb.llvm.org"]', 7299451b44SJordan Rupprecht VARIABLES_DISPLAYED_CORRECTLY, 73*2238dcc3SJonas Devlieghere substrs=["NSURL", "isa", "_urlString"], 74*2238dcc3SJonas Devlieghere ) 75*2238dcc3SJonas Devlieghere 76*2238dcc3SJonas Devlieghere self.expect( 77*2238dcc3SJonas Devlieghere 'expression [NSURL URLWithString:@"http://lldb.llvm.org"].scheme', 78*2238dcc3SJonas Devlieghere VARIABLES_DISPLAYED_CORRECTLY, 79*2238dcc3SJonas Devlieghere substrs=["http"], 80*2238dcc3SJonas Devlieghere ) 81a8350ce7SRaphael Isemann # Test that the NULL macro still works with a loaded module. 82a8350ce7SRaphael Isemann self.expect_expr("int *i = NULL; i == NULL", result_value="true") 83