xref: /llvm-project/lldb/test/API/commands/expression/import-std-module/empty-module/TestEmptyStdModule.py (revision 4cc8f2a017c76af25234afc7c380550e9c93135c)
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    # We only emulate a fake libc++ in this test and don't use the real libc++,
14    # but we still add the libc++ category so that this test is only run in
15    # test configurations where libc++ is actually supposed to be tested.
16    @add_test_categories(["libc++"])
17    @skipIfRemote
18    @skipIf(compiler=no_match("clang"))
19    def test(self):
20        self.build()
21
22        sysroot = os.path.join(os.getcwd(), "root")
23
24        # Set the sysroot.
25        self.runCmd("platform select --sysroot '" + sysroot + "' host",
26                    CURRENT_EXECUTABLE_SET)
27
28        lldbutil.run_to_source_breakpoint(self,
29                                          "// Set break point at this line.",
30                                          lldb.SBFileSpec("main.cpp"))
31
32        self.runCmd("settings set target.import-std-module true")
33
34        # Use the typedef that is only defined in our 'empty' module. If this fails, then LLDB
35        # somehow figured out the correct define for the header and compiled the right
36        # standard module that actually contains the std::vector template.
37        self.expect("expr MissingContent var = 3; var", substrs=['$0 = 3'])
38        # Try to access our mock std::vector. This should fail but not crash LLDB as the
39        # std::vector template should be missing from the std module.
40        self.expect("expr (size_t)v.size()",
41                    substrs=["Couldn't lookup symbols"],
42                    error=True)
43