1"""
2Test that LLDB doesn't crash if the std module we load is empty.
3"""
4
5from lldbsuite.test.decorators import *
6from lldbsuite.test.lldbtest import *
7from lldbsuite.test import lldbutil
8import os
9
10
11class ImportStdModule(TestBase):
12
13    mydir = TestBase.compute_mydir(__file__)
14
15    # We only emulate a fake libc++ in this test and don't use the real libc++,
16    # but we still add the libc++ category so that this test is only run in
17    # test configurations where libc++ is actually supposed to be tested.
18    @add_test_categories(["libc++"])
19    @skipIfRemote
20    @skipIf(compiler=no_match("clang"))
21    def test(self):
22        self.build()
23
24        sysroot = os.path.join(os.getcwd(), "root")
25
26        # Set the sysroot.
27        self.runCmd("platform select --sysroot '" + sysroot + "' host",
28                    CURRENT_EXECUTABLE_SET)
29
30        lldbutil.run_to_source_breakpoint(self,
31                                          "// Set break point at this line.",
32                                          lldb.SBFileSpec("main.cpp"))
33
34        self.runCmd("settings set target.import-std-module true")
35
36        # Use the typedef that is only defined in our 'empty' module. If this fails, then LLDB
37        # somehow figured out the correct define for the header and compiled the right
38        # standard module that actually contains the std::vector template.
39        self.expect("expr MissingContent var = 3; var", substrs=['$0 = 3'])
40        # Try to access our mock std::vector. This should fail but not crash LLDB as the
41        # std::vector template should be missing from the std module.
42        self.expect("expr (size_t)v.size()",
43                    substrs=["Couldn't lookup symbols"],
44                    error=True)
45