[debuginfo-tests] 60346bd - Add test for GDB pretty printers.

Christian Sigg via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 11 00:17:29 PST 2020


Author: Christian Sigg
Date: 2020-01-11T09:17:15+01:00
New Revision: 60346bdbd73da9c944d50ea5dcecad71a05105ac

URL: https://github.com/llvm/llvm-project/commit/60346bdbd73da9c944d50ea5dcecad71a05105ac
DIFF: https://github.com/llvm/llvm-project/commit/60346bdbd73da9c944d50ea5dcecad71a05105ac.diff

LOG: Add test for GDB pretty printers.

Reviewers: dblaikie, aprantl, davide, JDevlieghere

Reviewed By: aprantl

Subscribers: jmorse, aprantl, merge_guards_bot, mgorny, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D72321

Added: 
    debuginfo-tests/llvm-prettyprinters/gdb/lit.local.cfg
    debuginfo-tests/llvm-prettyprinters/gdb/prettyprinters.cpp
    debuginfo-tests/llvm-prettyprinters/gdb/prettyprinters.gdb

Modified: 
    debuginfo-tests/CMakeLists.txt
    debuginfo-tests/lit.cfg.py

Removed: 
    


################################################################################
diff  --git a/debuginfo-tests/CMakeLists.txt b/debuginfo-tests/CMakeLists.txt
index 36863e030b7f..c122d9b27a8a 100644
--- a/debuginfo-tests/CMakeLists.txt
+++ b/debuginfo-tests/CMakeLists.txt
@@ -2,6 +2,11 @@
 # various types of debug info, and then run those programs under a debugger
 # such as GDB or LLDB to verify the results.
 
+add_llvm_executable(prettyprinters
+        llvm-prettyprinters/gdb/prettyprinters.cpp
+)
+target_link_libraries(prettyprinters PRIVATE LLVMSupport)
+
 set(DEBUGINFO_TESTS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
 set(DEBUGINFO_TESTS_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
 
@@ -11,6 +16,7 @@ set(DEBUGINFO_TEST_DEPS
   count
   llvm-objdump
   not
+  prettyprinters
   )
 
 # The Windows builder scripts pass -fuse-ld=lld.

diff  --git a/debuginfo-tests/lit.cfg.py b/debuginfo-tests/lit.cfg.py
index f5a96c69c4d2..837c930ac7fd 100644
--- a/debuginfo-tests/lit.cfg.py
+++ b/debuginfo-tests/lit.cfg.py
@@ -44,6 +44,8 @@
 tools = [
     ToolSubst('%test_debuginfo', command=os.path.join(
         config.debuginfo_tests_src_root, 'llgdb-tests', 'test_debuginfo.pl')),
+    ToolSubst("%llvm_src_root", config.llvm_src_root),
+    ToolSubst("%llvm_tools_dir", config.llvm_tools_dir),
 ]
 
 def get_required_attr(config, attr_name):

diff  --git a/debuginfo-tests/llvm-prettyprinters/gdb/lit.local.cfg b/debuginfo-tests/llvm-prettyprinters/gdb/lit.local.cfg
new file mode 100644
index 000000000000..be053e06f59e
--- /dev/null
+++ b/debuginfo-tests/llvm-prettyprinters/gdb/lit.local.cfg
@@ -0,0 +1,9 @@
+import lit.util
+
+# debuginfo-tests are not expected to pass in a cross-compilation setup.
+if 'native' not in config.available_features or lit.util.which('gdb') is None:
+    config.unsupported = True
+
+config.suffixes = ['.gdb']
+
+

diff  --git a/debuginfo-tests/llvm-prettyprinters/gdb/prettyprinters.cpp b/debuginfo-tests/llvm-prettyprinters/gdb/prettyprinters.cpp
new file mode 100644
index 000000000000..03cef4d977d5
--- /dev/null
+++ b/debuginfo-tests/llvm-prettyprinters/gdb/prettyprinters.cpp
@@ -0,0 +1,25 @@
+#include "llvm/ADT/ArrayRef.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/Optional.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Twine.h"
+#include "llvm/Support/Error.h"
+
+int Array[] = {1, 2, 3};
+
+llvm::ArrayRef<int> ArrayRef(Array);
+llvm::MutableArrayRef<int> MutableArrayRef(Array);
+llvm::DenseMap<int, int> DenseMap = {{4, 5}, {6, 7}};
+llvm::Expected<int> ExpectedValue(8);
+llvm::Expected<int> ExpectedError(llvm::createStringError({}, ""));
+llvm::Optional<int> OptionalValue(9);
+llvm::Optional<int> OptionalNone(llvm::None);
+llvm::SmallVector<int, 5> SmallVector = {10, 11, 12};
+llvm::SmallString<5> SmallString("foo");
+llvm::StringRef StringRef = "bar";
+llvm::Twine Twine = llvm::Twine(SmallString) + StringRef;
+
+int main() {
+  return 0;
+}

diff  --git a/debuginfo-tests/llvm-prettyprinters/gdb/prettyprinters.gdb b/debuginfo-tests/llvm-prettyprinters/gdb/prettyprinters.gdb
new file mode 100644
index 000000000000..94213f941436
--- /dev/null
+++ b/debuginfo-tests/llvm-prettyprinters/gdb/prettyprinters.gdb
@@ -0,0 +1,41 @@
+# RUN: gdb -q -batch -n -iex 'source %llvm_src_root/utils/gdb-scripts/prettyprinters.py' -x %s %llvm_tools_dir/prettyprinters | FileCheck %s
+
+break main
+run
+
+# CHECK: llvm::ArrayRef of length 3 = {1, 2, 3}
+p ArrayRef
+
+# CHECK: llvm::ArrayRef of length 3 = {1, 2, 3}
+p MutableArrayRef
+
+# CHECK: llvm::DenseMap with 2 elements = {
+# CHECK:   [4] = 5,
+# CHECK:   [6] = 7,
+# CHECK: }
+p DenseMap
+
+# CHECK: llvm::Expected = {value = 8}
+p ExpectedValue
+
+# CHECK: llvm::Expected is error
+p ExpectedError
+
+# CHECK: llvm::Optional = {value = 9}
+p OptionalValue
+
+# CHECK: llvm::Optional is not initialized
+p OptionalNone
+
+# CHECK: llvm::SmallVector of Size 3, Capacity 5 = {10, 11, 12}
+p SmallVector
+
+# CHECK: "foo"
+p SmallString
+
+# CHECK: "bar"
+p StringRef
+
+# CHECK: "\"foo\"\"bar\""
+p Twine
+


        


More information about the llvm-commits mailing list