1""" 2Check that missing module source files are correctly handled by LLDB. 3""" 4 5from lldbsuite.test.decorators import * 6from lldbsuite.test.lldbtest import * 7from lldbsuite.test import lldbutil 8import os 9import shutil 10 11 12class TestCase(TestBase): 13 14 mydir = TestBase.compute_mydir(__file__) 15 16 # We only emulate a fake libc++ in this test and don't use the real libc++, 17 # but we still add the libc++ category so that this test is only run in 18 # test configurations where libc++ is actually supposed to be tested. 19 @add_test_categories(["libc++"]) 20 @skipIf(compiler=no_match("clang")) 21 def test(self): 22 # The path to our temporary target root that contains the temporary 23 # module sources. 24 target_sysroot = self.getBuildArtifact("root") 25 26 # Copy the sources to the root. 27 shutil.copytree(self.getSourcePath("root"), target_sysroot) 28 # Build the binary with the copied sources. 29 self.build() 30 # Delete the copied sources so that they are now unavailable. 31 shutil.rmtree(target_sysroot) 32 33 # Set the sysroot where our dummy libc++ used to exist. Just to make 34 # sure we don't find some existing headers on the system that could 35 # XPASS this test. 36 self.runCmd("platform select --sysroot '" + target_sysroot + "' host") 37 38 lldbutil.run_to_source_breakpoint(self, 39 "// Set break point at this line.", 40 lldb.SBFileSpec("main.cpp")) 41 42 # Import the std C++ module and run an expression. 43 # As we deleted the sources, LLDB should refuse the load the module 44 # and just print the normal error we get from the expression. 45 self.runCmd("settings set target.import-std-module true") 46 self.expect("expr v.unknown_identifier", error=True, 47 substrs=["no member named 'unknown_identifier'"]) 48 # Check that there is no confusing error about failing to build the 49 # module. 50 self.expect("expr v.unknown_identifier", error=True, matching=False, 51 substrs=["could not build module 'std'"]) 52 53 # Test the fallback mode. It should also just print the normal 54 # error but not mention a failed module build. 55 self.runCmd("settings set target.import-std-module fallback") 56 57 self.expect("expr v.unknown_identifier", error=True, 58 substrs=["no member named 'unknown_identifier'"]) 59 self.expect("expr v.unknown_identifier", error=True, matching=False, 60 substrs=["could not build module 'std'"]) 61