1""" 2Test importing the 'std' C++ module and evaluate expressions with it. 3""" 4 5from lldbsuite.test.decorators import * 6from lldbsuite.test.lldbtest import * 7from lldbsuite.test import lldbutil 8 9 10class ImportStdModule(TestBase): 11 12 mydir = TestBase.compute_mydir(__file__) 13 14 @add_test_categories(["libc++"]) 15 @skipIf(compiler=no_match("clang")) 16 def test(self): 17 self.build() 18 19 lldbutil.run_to_source_breakpoint(self, 20 "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) 21 22 # Activate importing of std module. 23 self.runCmd("settings set target.import-std-module true") 24 # Calling some normal std functions that return non-template types. 25 self.expect_expr("std::abs(-42)", result_type="int", result_value="42") 26 self.expect_expr("std::div(2, 1).quot", result_type="int", result_value="2") 27 # Using types from std. 28 self.expect_expr("(std::size_t)33U", result_type="std::size_t", result_value="33") 29 # Calling templated functions that return non-template types. 30 self.expect_expr("char char_a = 'b'; char char_b = 'a'; std::swap(char_a, char_b); char_a", 31 result_type="char", result_value="'a'") 32 33 @add_test_categories(["libc++"]) 34 @skipIf(compiler=no_match("clang")) 35 def test_non_cpp_language(self): 36 self.build() 37 38 lldbutil.run_to_source_breakpoint(self, 39 "// Set break point at this line.", lldb.SBFileSpec("main.cpp")) 40 41 # Activate importing of std module. 42 self.runCmd("settings set target.import-std-module true") 43 # These languages don't support C++ modules, so they shouldn't 44 # be able to evaluate the expression. 45 self.expect("expr -l C -- std::abs(-42)", error=True) 46 self.expect("expr -l C99 -- std::abs(-42)", error=True) 47 self.expect("expr -l C11 -- std::abs(-42)", error=True) 48 self.expect("expr -l ObjC -- std::abs(-42)", error=True) 49