1 """Test that lldb works correctly on compile units form different languages."""
6 from lldbsuite
.test
.lldbtest
import *
9 class MixedLanguagesTestCase(TestBase
):
10 def test_language_of_frame(self
):
11 """Test that the language defaults to the language of the current frame."""
13 exe
= self
.getBuildArtifact("a.out")
14 self
.runCmd("file " + exe
, CURRENT_EXECUTABLE_SET
)
16 # Execute the cleanup function during test case tear down
17 # to restore the frame format.
20 "settings set frame-format %s" % self
.format_string
, check
=False
23 self
.addTearDownHook(cleanup
)
24 self
.runCmd("settings show frame-format")
25 m
= re
.match('^frame-format \(format-string\) = "(.*)"$', self
.res
.GetOutput())
26 self
.assertTrue(m
, "Bad settings string")
27 self
.format_string
= m
.group(1)
29 # Change the default format to print the language.
30 format_string
= "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}\`${function.name}{${function.pc-offset}}}{, lang=${language}}\n"
31 self
.runCmd("settings set frame-format %s" % format_string
)
33 "settings show frame-format",
34 SETTING_MSG("frame-format"),
35 substrs
=[format_string
],
38 # Run to BP at main (in main.c) and test that the language is C.
39 self
.runCmd("breakpoint set -n main")
41 self
.expect("thread backtrace", substrs
=["`main", "lang=c"])
42 # Make sure evaluation of C++11 fails.
43 self
.expect("expr foo != nullptr", error
=True, startstr
="error")
45 # Run to BP at foo (in foo.cpp) and test that the language is C++.
46 self
.runCmd("breakpoint set -n foo")
47 self
.runCmd("continue")
48 self
.expect("thread backtrace", substrs
=["`::foo()", "lang=c++"])
49 # Make sure we can evaluate an expression requiring C++11
50 # (note: C++11 is enabled by default for C++).
51 self
.expect("expr foo != nullptr", patterns
=["true"])