aboutsummaryrefslogtreecommitdiff
path: root/packages/Python/lldbsuite/test/lang/mixed
diff options
context:
space:
mode:
Diffstat (limited to 'packages/Python/lldbsuite/test/lang/mixed')
-rw-r--r--packages/Python/lldbsuite/test/lang/mixed/Makefile6
-rw-r--r--packages/Python/lldbsuite/test/lang/mixed/TestMixedLanguages.py56
-rw-r--r--packages/Python/lldbsuite/test/lang/mixed/foo.cpp11
-rw-r--r--packages/Python/lldbsuite/test/lang/mixed/main.c15
4 files changed, 88 insertions, 0 deletions
diff --git a/packages/Python/lldbsuite/test/lang/mixed/Makefile b/packages/Python/lldbsuite/test/lang/mixed/Makefile
new file mode 100644
index 000000000000..860343ee907c
--- /dev/null
+++ b/packages/Python/lldbsuite/test/lang/mixed/Makefile
@@ -0,0 +1,6 @@
+LEVEL = ../../make
+
+CXX_SOURCES := foo.cpp
+C_SOURCES := main.c
+
+include $(LEVEL)/Makefile.rules
diff --git a/packages/Python/lldbsuite/test/lang/mixed/TestMixedLanguages.py b/packages/Python/lldbsuite/test/lang/mixed/TestMixedLanguages.py
new file mode 100644
index 000000000000..d11f03b878ae
--- /dev/null
+++ b/packages/Python/lldbsuite/test/lang/mixed/TestMixedLanguages.py
@@ -0,0 +1,56 @@
+"""Test that lldb works correctly on compile units form different languages."""
+
+from __future__ import print_function
+
+
+
+import os, time, re
+import lldb
+from lldbsuite.test.lldbtest import *
+
+class MixedLanguagesTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ def test_language_of_frame(self):
+ """Test that the language defaults to the language of the current frame."""
+ self.build()
+ exe = os.path.join(os.getcwd(), "a.out")
+ self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
+
+ # Execute the cleanup function during test case tear down
+ # to restore the frame format.
+ def cleanup():
+ self.runCmd("settings set frame-format %s" % self.format_string, check=False)
+ self.addTearDownHook(cleanup)
+ self.runCmd("settings show frame-format")
+ m = re.match(
+ '^frame-format \(format-string\) = "(.*)\"$',
+ self.res.GetOutput())
+ self.assertTrue(m, "Bad settings string")
+ self.format_string = m.group(1)
+
+ # Change the default format to print the language.
+ format_string = "frame #${frame.index}: ${frame.pc}{ ${module.file.basename}`${function.name}{${function.pc-offset}}}{, lang=${language}}\n"
+ self.runCmd("settings set frame-format %s" % format_string)
+ self.expect("settings show frame-format", SETTING_MSG("frame-format"),
+ substrs = [format_string])
+
+ # Run to BP at main (in main.c) and test that the language is C.
+ self.runCmd("breakpoint set -n main")
+ self.runCmd("run")
+ self.expect("thread backtrace",
+ substrs = ["`main", "lang=c"])
+ # Make sure evaluation of C++11 fails.
+ self.expect("expr foo != nullptr", error=True,
+ startstr = "error")
+
+ # Run to BP at foo (in foo.cpp) and test that the language is C++.
+ self.runCmd("breakpoint set -n foo")
+ self.runCmd("continue")
+ self.expect("thread backtrace",
+ substrs = ["`::foo()", "lang=c++"])
+ # Make sure we can evaluate an expression requiring C++11
+ # (note: C++11 is enabled by default for C++).
+ self.expect("expr foo != nullptr",
+ patterns = ["true"])
diff --git a/packages/Python/lldbsuite/test/lang/mixed/foo.cpp b/packages/Python/lldbsuite/test/lang/mixed/foo.cpp
new file mode 100644
index 000000000000..8a5a6a2b5416
--- /dev/null
+++ b/packages/Python/lldbsuite/test/lang/mixed/foo.cpp
@@ -0,0 +1,11 @@
+namespace ns {
+ int func(void)
+ {
+ return 0;
+ }
+}
+
+extern "C" int foo(void)
+{
+ return ns::func();
+}
diff --git a/packages/Python/lldbsuite/test/lang/mixed/main.c b/packages/Python/lldbsuite/test/lang/mixed/main.c
new file mode 100644
index 000000000000..f5c5d19f2c89
--- /dev/null
+++ b/packages/Python/lldbsuite/test/lang/mixed/main.c
@@ -0,0 +1,15 @@
+int foo(void);
+static int static_value = 0;
+
+int
+bar()
+{
+ static_value++;
+ return static_value;
+}
+
+int main (int argc, char const *argv[])
+{
+ bar(); // breakpoint_in_main
+ return foo();
+}