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