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 + gdb-tests/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/gdb-tests/lit.local.cfg b/debuginfo-tests/gdb-tests/lit.local.cfg new file mode 100644 --- /dev/null +++ b/debuginfo-tests/gdb-tests/lit.local.cfg @@ -0,0 +1,7 @@ +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 + + diff --git a/debuginfo-tests/gdb-tests/prettyprinters.cpp b/debuginfo-tests/gdb-tests/prettyprinters.cpp new file mode 100644 --- /dev/null +++ b/debuginfo-tests/gdb-tests/prettyprinters.cpp @@ -0,0 +1,57 @@ +// RUN: env DEBUGGER=gdb %test_debuginfo %s %llvm_tools_dir/prettyprinters "-iex 'source %llvm_src_root/utils/gdb-scripts/prettyprinters.py'" + +// DEBUGGER: delete breakpoints +// DEBUGGER: break break_hook +// DEBUGGER: run +// DEBUGGER: up +// DEBUGGER: info locals + +#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" + +void break_hook() {} +int array[] = {1, 2, 3}; + +int __attribute__((optimize("O0"))) main() { + // CHECK: arrayRef = llvm::ArrayRef of length 3 = {1, 2, 3} + llvm::ArrayRef arrayRef(array); + // CHECK: mutableArrayRef = llvm::ArrayRef of length 3 = {1, 2, 3} + llvm::MutableArrayRef mutableArrayRef(array); + + // CHECK: denseMap = llvm::DenseMap with 2 elements = { + // CHECK: [4] = 5, + // CHECK: [6] = 7, + // CHECK: } + llvm::DenseMap denseMap({{4, 5}, {6, 7}}); + + // CHECK: expectedValue = llvm::Expected = {value = 8} + llvm::Expected expectedValue(8); + // CHECK: expectedError = llvm::Expected is error + llvm::Expected expectedError(llvm::createStringError({}, "")); + + // CHECK: optionalValue = llvm::Optional = {value = 9} + llvm::Optional optionalValue(9); + // CHECK: optionalNone = llvm::Optional is not initialized + llvm::Optional optionalNone(llvm::None); + + // CHECK: smallVector = llvm::SmallVector of Size 3, Capacity 5 = {10, 11, 12} + llvm::SmallVector smallVector = {10, 11, 12}; + + // CHECK: smallString = "foo" + llvm::SmallString<5> smallString("foo"); + + // CHECK: stringRef = "bar" + llvm::StringRef stringRef = "bar"; + + // CHECK: twine = "\"foo\"\"bar\"" + llvm::Twine twine = llvm::Twine(smallString) + stringRef; + (void)twine; + + break_hook(); + return 0; +} 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/llgdb-tests/test_debuginfo.pl b/debuginfo-tests/llgdb-tests/test_debuginfo.pl --- a/debuginfo-tests/llgdb-tests/test_debuginfo.pl +++ b/debuginfo-tests/llgdb-tests/test_debuginfo.pl @@ -19,8 +19,8 @@ use Config; use Cwd; -my $testcase_file = $ARGV[0]; -my $executable_file = $ARGV[1]; +my $testcase_file = shift or die "no testcase file specified"; +my $executable_file = shift or die "no executable specified"; my $input_filename = basename $testcase_file; my $output_dir = dirname $executable_file; @@ -67,7 +67,7 @@ my $debugger_options = "-q -batch -n -x"; # run debugger and capture output. -system("$my_debugger $debugger_options $debugger_script_file $executable_file > $output_file 2>&1"); +system("$my_debugger @ARGV $debugger_options $debugger_script_file $executable_file > $output_file 2>&1"); # validate output. system("FileCheck", "-input-file", "$output_file", "$testcase_file"); diff --git a/llvm/utils/gdb-scripts/prettyprinters.py b/llvm/utils/gdb-scripts/prettyprinters.py --- a/llvm/utils/gdb-scripts/prettyprinters.py +++ b/llvm/utils/gdb-scripts/prettyprinters.py @@ -319,7 +319,7 @@ pp.add_printer('llvm::SmallString', '^llvm::SmallString<.*>$', SmallStringPrinter) pp.add_printer('llvm::StringRef', '^llvm::StringRef$', StringRefPrinter) pp.add_printer('llvm::SmallVectorImpl', '^llvm::SmallVector(Impl)?<.*>$', SmallVectorPrinter) -pp.add_printer('llvm::ArrayRef', '^llvm::(Const)?ArrayRef<.*>$', ArrayRefPrinter) +pp.add_printer('llvm::ArrayRef', '^llvm::(Mutable)?ArrayRef<.*>$', ArrayRefPrinter) pp.add_printer('llvm::Expected', '^llvm::Expected<.*>$', ExpectedPrinter) pp.add_printer('llvm::Optional', '^llvm::Optional<.*>$', OptionalPrinter) pp.add_printer('llvm::DenseMap', '^llvm::DenseMap<.*>$', DenseMapPrinter)