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 @skipIfRemote 22 def test(self): 23 # The path to our temporary target root that contains the temporary 24 # module sources. 25 target_sysroot = self.getBuildArtifact("root") 26 27 # Copy the sources to the root. 28 shutil.copytree(self.getSourcePath("root"), target_sysroot) 29 # Build the binary with the copied sources. 30 self.build() 31 # Delete the copied sources so that they are now unavailable. 32 shutil.rmtree(target_sysroot) 33 34 # Set the sysroot where our dummy libc++ used to exist. Just to make 35 # sure we don't find some existing headers on the system that could 36 # XPASS this test. 37 self.runCmd("platform select --sysroot '" + target_sysroot + "' host") 38 39 lldbutil.run_to_source_breakpoint(self, 40 "// Set break point at this line.", 41 lldb.SBFileSpec("main.cpp")) 42 43 # Import the std C++ module and run an expression. 44 # As we deleted the sources, LLDB should refuse the load the module 45 # and just print the normal error we get from the expression. 46 self.runCmd("settings set target.import-std-module true") 47 self.expect("expr v.unknown_identifier", error=True, 48 substrs=["no member named 'unknown_identifier'"]) 49 # Check that there is no confusing error about failing to build the 50 # module. 51 self.expect("expr v.unknown_identifier", error=True, matching=False, 52 substrs=["could not build module 'std'"]) 53 54 # Test the fallback mode. It should also just print the normal 55 # error but not mention a failed module build. 56 self.runCmd("settings set target.import-std-module fallback") 57 58 self.expect("expr v.unknown_identifier", error=True, 59 substrs=["no member named 'unknown_identifier'"]) 60 self.expect("expr v.unknown_identifier", error=True, matching=False, 61 substrs=["could not build module 'std'"]) 62