summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test
diff options
context:
space:
mode:
authorShafik Yaghmour <syaghmour@apple.com>2018-09-19 18:07:05 +0000
committerShafik Yaghmour <syaghmour@apple.com>2018-09-19 18:07:05 +0000
commit8306f76e56329f4efc02399cb11158ecabb54c17 (patch)
tree6ed632c142ca54fd3ad123aacba9d9a4cff9d892 /lldb/packages/Python/lldbsuite/test
parent86e5cb0e0bc938c9cf44d91eeffdce31ab5cb3ee (diff)
downloadbcm5719-llvm-8306f76e56329f4efc02399cb11158ecabb54c17.tar.gz
bcm5719-llvm-8306f76e56329f4efc02399cb11158ecabb54c17.zip
[DataFormatters] Add formatter for C++17 std::variant
rdar://problem/43691454 Patch by Shafik Yaghmour. Differential Revision: https://reviews.llvm.org/D51520 llvm-svn: 342563
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test')
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/Makefile7
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py81
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/main.cpp60
3 files changed, 148 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/Makefile
new file mode 100644
index 00000000000..a6ea665ef63
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/Makefile
@@ -0,0 +1,7 @@
+LEVEL = ../../../../../make
+
+CXX_SOURCES := main.cpp
+
+USE_LIBCPP := 1
+include $(LEVEL)/Makefile.rules
+CXXFLAGS += -std=c++17
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
new file mode 100644
index 00000000000..9ea7ac33166
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/TestDataFormatterLibcxxVariant.py
@@ -0,0 +1,81 @@
+"""
+Test lldb data formatter subsystem.
+"""
+
+from __future__ import print_function
+
+
+import os
+import time
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class LibcxxOptionalDataFormatterTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+
+ @add_test_categories(["libc++"])
+ ## We are skipping clang version less that 5.0 since this test requires -std=c++17
+ @skipIf(oslist=no_match(["macosx"]), compiler="clang", compiler_version=['<', '5.0'])
+ ## We are skipping gcc version less that 5.1 since this test requires -std=c++17
+ @skipIf(compiler="gcc", compiler_version=['<', '5.1'])
+
+ def test_with_run_command(self):
+ """Test that that file and class static variables display correctly."""
+ self.build()
+
+ (self.target, self.process, _, bkpt) = lldbutil.run_to_source_breakpoint(self, '// break here',
+ lldb.SBFileSpec("main.cpp", False))
+
+ self.runCmd( "frame variable has_variant" )
+
+ output = self.res.GetOutput()
+
+ ## The variable has_variant tells us if the test program
+ ## detected we have a sufficient libc++ version to support variant
+ ## false means we do not and therefore should skip the test
+ if output.find("(bool) has_variant = false") != -1 :
+ self.skipTest( "std::variant not supported" )
+
+ lldbutil.continue_to_breakpoint(self.process, bkpt)
+
+ self.expect("frame variable v1",
+ substrs=['v1 = Active Type = int {',
+ 'Value = 12',
+ '}'])
+
+ self.expect("frame variable v1_ref",
+ substrs=['v1_ref = Active Type = int : {',
+ 'Value = 12',
+ '}'])
+
+ self.expect("frame variable v_v1",
+ substrs=['v_v1 = Active Type = std::__1::variant<int, double, char> {',
+ 'Value = Active Type = int {',
+ 'Value = 12',
+ '}',
+ '}'])
+
+ lldbutil.continue_to_breakpoint(self.process, bkpt)
+
+ self.expect("frame variable v1",
+ substrs=['v1 = Active Type = double {',
+ 'Value = 2',
+ '}'])
+
+ lldbutil.continue_to_breakpoint(self.process, bkpt)
+
+ self.expect("frame variable v2",
+ substrs=['v2 = Active Type = double {',
+ 'Value = 2',
+ '}'])
+
+ self.expect("frame variable v3",
+ substrs=['v3 = Active Type = char {',
+ 'Value = \'A\'',
+ '}'])
+
+ self.expect("frame variable v_no_value",
+ substrs=['v_no_value = No Value'])
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/main.cpp
new file mode 100644
index 00000000000..c0bc4ae12c1
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/data-formatter/data-formatter-stl/libcxx/variant/main.cpp
@@ -0,0 +1,60 @@
+#include <cstdio>
+#include <string>
+#include <vector>
+
+// If we have libc++ 4.0 or greater we should have <variant>
+// According to libc++ C++1z status page https://libcxx.llvm.org/cxx1z_status.html
+#if _LIBCPP_VERSION >= 4000
+#include <variant>
+#define HAVE_VARIANT 1
+#else
+#define HAVE_VARIANT 0
+#endif
+
+struct S {
+ operator int() { throw 42; }
+} ;
+
+
+int main()
+{
+ bool has_variant = HAVE_VARIANT ;
+
+ printf( "%d\n", has_variant ) ; // break here
+
+#if HAVE_VARIANT == 1
+ std::variant<int, double, char> v1;
+ std::variant<int, double, char> &v1_ref = v1;
+ std::variant<int, double, char> v2;
+ std::variant<int, double, char> v3;
+ std::variant<std::variant<int,double,char>> v_v1 ;
+ std::variant<int, double, char> v_no_value;
+
+ v1 = 12; // v contains int
+ v_v1 = v1 ;
+ int i = std::get<int>(v1);
+ printf( "%d\n", i ); // break here
+
+ v2 = 2.0 ;
+ double d = std::get<double>(v2) ;
+ printf( "%f\n", d );
+
+ v3 = 'A' ;
+ char c = std::get<char>(v3) ;
+ printf( "%d\n", c );
+
+ // Checking v1 above and here to make sure we done maintain the incorrect
+ // state when we change its value.
+ v1 = 2.0;
+ d = std::get<double>(v1) ;
+ printf( "%f\n", d ); // break here
+
+ try {
+ v_no_value.emplace<0>(S());
+ } catch( ... ) {}
+
+ printf( "%zu\n", v_no_value.index() ) ;
+#endif
+
+ return 0; // break here
+}
OpenPOWER on IntegriCloud