149948906SRaphael Isemannimport lldb
249948906SRaphael Isemannfrom lldbsuite.test.decorators import *
349948906SRaphael Isemannfrom lldbsuite.test.lldbtest import *
449948906SRaphael Isemannfrom lldbsuite.test import lldbutil
549948906SRaphael Isemann
649948906SRaphael Isemann
7*2238dcc3SJonas Devlieghereclass TestCase(TestBase):
849948906SRaphael Isemann    def test(self):
949948906SRaphael Isemann        """
1049948906SRaphael Isemann        Tests that running the utility expression that retrieves the Objective-C
1149948906SRaphael Isemann        class list works even when user-code contains functions with apparently
1249948906SRaphael Isemann        conflicting identifiers (e.g. 'free') but that are not in the global
1349948906SRaphael Isemann        scope.
1449948906SRaphael Isemann
1549948906SRaphael Isemann        This is *not* supposed to test what happens when there are actual
1649948906SRaphael Isemann        conflicts such as when a user somehow defined their own '::free'
1749948906SRaphael Isemann        function.
1849948906SRaphael Isemann        """
1949948906SRaphael Isemann
2049948906SRaphael Isemann        self.build()
21*2238dcc3SJonas Devlieghere        lldbutil.run_to_source_breakpoint(
22*2238dcc3SJonas Devlieghere            self, "// break here", lldb.SBFileSpec("main.mm")
23*2238dcc3SJonas Devlieghere        )
2449948906SRaphael Isemann
2549948906SRaphael Isemann        # First check our side effect variable is in its initial state.
2649948906SRaphael Isemann        self.expect_expr("called_function", result_summary='"none"')
2749948906SRaphael Isemann
2849948906SRaphael Isemann        # Get the (dynamic) type of our 'id' variable so that our Objective-C
2949948906SRaphael Isemann        # runtime information is updated.
3049948906SRaphael Isemann        str_val = self.expect_expr("str")
3149948906SRaphael Isemann        dyn_val = str_val.GetDynamicValue(lldb.eDynamicCanRunTarget)
3249948906SRaphael Isemann        dyn_type = dyn_val.GetTypeName()
3349948906SRaphael Isemann
3449948906SRaphael Isemann        # Check our side effect variable which should still be in its initial
3549948906SRaphael Isemann        # state if none of our trap functions were called.
3649948906SRaphael Isemann        # If this is failing, then LLDB called one of the trap functions.
3749948906SRaphael Isemann        self.expect_expr("called_function", result_summary='"none"')
3849948906SRaphael Isemann
3949948906SRaphael Isemann        # Double check that our dynamic type is correct. This is done last
4049948906SRaphael Isemann        # as the assert message from above is the more descriptive one (it
4149948906SRaphael Isemann        # contains the unintentionally called function).
4249948906SRaphael Isemann        self.assertEqual(dyn_type, "__NSCFConstantString *")
43