xref: /llvm-project/lldb/test/API/lang/objc/modules/TestObjCModules.py (revision a8350ce79d167643b53d06e2167535d24fe68dc3)
1"""Test that importing modules in Objective-C works as expected."""
2
3
4
5import unittest2
6
7import lldb
8from lldbsuite.test.decorators import *
9from lldbsuite.test.lldbtest import *
10from lldbsuite.test import lldbutil
11
12
13class ObjCModulesTestCase(TestBase):
14
15    mydir = TestBase.compute_mydir(__file__)
16
17    def setUp(self):
18        # Call super's setUp().
19        TestBase.setUp(self)
20        # Find the line number to break inside main().
21        self.line = line_number('main.m', '// Set breakpoint 0 here.')
22
23    @skipIf(macos_version=["<", "10.12"])
24    @skipIfReproducer # FIXME: Unexpected packet during (active) replay
25    def test_expr(self):
26        self.build()
27        exe = self.getBuildArtifact("a.out")
28        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
29
30        # Break inside the foo function which takes a bar_ptr argument.
31        lldbutil.run_break_set_by_file_and_line(
32            self, "main.m", self.line, num_expected_locations=1, loc_exact=True)
33
34        self.runCmd("run", RUN_SUCCEEDED)
35
36        # The stop reason of the thread should be breakpoint.
37        self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT,
38                    substrs=['stopped',
39                             'stop reason = breakpoint'])
40
41        # The breakpoint should have a hit count of 1.
42        self.expect("breakpoint list -f", BREAKPOINT_HIT_ONCE,
43                    substrs=[' resolved, hit count = 1'])
44
45        self.expect("expr @import Darwin; 3", VARIABLES_DISPLAYED_CORRECTLY,
46                    substrs=["int", "3"])
47
48        self.expect("expr getpid()", VARIABLES_DISPLAYED_CORRECTLY,
49                    substrs=["pid_t"])
50
51        self.expect(
52            "expr @import Foundation; 4",
53            VARIABLES_DISPLAYED_CORRECTLY,
54            substrs=[
55                "int",
56                "4"])
57
58        # Type lookup should still work and print something reasonable
59        # for types from the module.
60        self.expect("type lookup NSObject", substrs=["instanceMethod"])
61
62        self.expect("expr string.length", VARIABLES_DISPLAYED_CORRECTLY,
63                    substrs=["NSUInteger", "5"])
64
65        self.expect("expr array.count", VARIABLES_DISPLAYED_CORRECTLY,
66                    substrs=["NSUInteger", "3"])
67
68        self.expect(
69            "p *[NSURL URLWithString:@\"http://lldb.llvm.org\"]",
70            VARIABLES_DISPLAYED_CORRECTLY,
71            substrs=[
72                "NSURL",
73                "isa",
74                "_urlString"])
75
76        self.expect(
77            "p [NSURL URLWithString:@\"http://lldb.llvm.org\"].scheme",
78            VARIABLES_DISPLAYED_CORRECTLY,
79            substrs=["http"])
80        # Test that the NULL macro still works with a loaded module.
81        self.expect_expr("int *i = NULL; i == NULL", result_value="true")
82