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
This commit is contained in:
Christian Sigg 2020-01-11 08:47:41 +01:00
parent c2ddfa876f
commit 60346bdbd7
5 changed files with 83 additions and 0 deletions

View File

@ -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.

View File

@ -44,6 +44,8 @@ llvm_config.use_default_substitutions()
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):

View File

@ -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']

View File

@ -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;
}

View File

@ -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