diff --git a/debuginfo-tests/CMakeLists.txt b/debuginfo-tests/CMakeLists.txt --- 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 @@ 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 --- 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 --- /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 --- /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 ArrayRef(Array); +llvm::MutableArrayRef MutableArrayRef(Array); +llvm::DenseMap DenseMap = {{4, 5}, {6, 7}}; +llvm::Expected ExpectedValue(8); +llvm::Expected ExpectedError(llvm::createStringError({}, "")); +llvm::Optional OptionalValue(9); +llvm::Optional OptionalNone(llvm::None); +llvm::SmallVector 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 --- /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 +