xref: /llvm-project/lldb/test/API/lang/mixed/TestMixedLanguages.py (revision d33fa70dddcb29d5fd85188e119f034e585ccccf)
199451b44SJordan Rupprecht"""Test that lldb works correctly on compile units form different languages."""
299451b44SJordan Rupprecht
399451b44SJordan Rupprecht
499451b44SJordan Rupprechtimport re
599451b44SJordan Rupprechtimport lldb
699451b44SJordan Rupprechtfrom lldbsuite.test.lldbtest import *
799451b44SJordan Rupprecht
899451b44SJordan Rupprecht
999451b44SJordan Rupprechtclass MixedLanguagesTestCase(TestBase):
1099451b44SJordan Rupprecht    def test_language_of_frame(self):
1199451b44SJordan Rupprecht        """Test that the language defaults to the language of the current frame."""
1299451b44SJordan Rupprecht        self.build()
1399451b44SJordan Rupprecht        exe = self.getBuildArtifact("a.out")
1499451b44SJordan Rupprecht        self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
1599451b44SJordan Rupprecht
1699451b44SJordan Rupprecht        # Execute the cleanup function during test case tear down
1799451b44SJordan Rupprecht        # to restore the frame format.
1899451b44SJordan Rupprecht        def cleanup():
1999451b44SJordan Rupprecht            self.runCmd(
202238dcc3SJonas Devlieghere                "settings set frame-format %s" % self.format_string, check=False
212238dcc3SJonas Devlieghere            )
222238dcc3SJonas Devlieghere
2399451b44SJordan Rupprecht        self.addTearDownHook(cleanup)
2499451b44SJordan Rupprecht        self.runCmd("settings show frame-format")
252238dcc3SJonas Devlieghere        m = re.match('^frame-format \(format-string\) = "(.*)"$', self.res.GetOutput())
2699451b44SJordan Rupprecht        self.assertTrue(m, "Bad settings string")
2799451b44SJordan Rupprecht        self.format_string = m.group(1)
2899451b44SJordan Rupprecht
2999451b44SJordan Rupprecht        # Change the default format to print the language.
3099451b44SJordan Rupprecht        format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}\`${function.name}{${function.pc-offset}}}{, lang=${language}}\n"
3199451b44SJordan Rupprecht        self.runCmd("settings set frame-format %s" % format_string)
322238dcc3SJonas Devlieghere        self.expect(
332238dcc3SJonas Devlieghere            "settings show frame-format",
342238dcc3SJonas Devlieghere            SETTING_MSG("frame-format"),
352238dcc3SJonas Devlieghere            substrs=[format_string],
362238dcc3SJonas Devlieghere        )
3799451b44SJordan Rupprecht
3899451b44SJordan Rupprecht        # Run to BP at main (in main.c) and test that the language is C.
3999451b44SJordan Rupprecht        self.runCmd("breakpoint set -n main")
4099451b44SJordan Rupprecht        self.runCmd("run")
412238dcc3SJonas Devlieghere        self.expect("thread backtrace", substrs=["`main", "lang=c"])
4299451b44SJordan Rupprecht        # Make sure evaluation of C++11 fails.
43*d33fa70dSAdrian Prantl        self.expect("expr foo != nullptr", error=True, substrs=["error"])
4499451b44SJordan Rupprecht
4599451b44SJordan Rupprecht        # Run to BP at foo (in foo.cpp) and test that the language is C++.
4699451b44SJordan Rupprecht        self.runCmd("breakpoint set -n foo")
4799451b44SJordan Rupprecht        self.runCmd("continue")
482238dcc3SJonas Devlieghere        self.expect("thread backtrace", substrs=["`::foo()", "lang=c++"])
4999451b44SJordan Rupprecht        # Make sure we can evaluate an expression requiring C++11
5099451b44SJordan Rupprecht        # (note: C++11 is enabled by default for C++).
512238dcc3SJonas Devlieghere        self.expect("expr foo != nullptr", patterns=["true"])
52