Skip to content

Commit 60346bd

Browse files
committed
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
1 parent c2ddfa8 commit 60346bd

File tree

5 files changed

+83
-0
lines changed

5 files changed

+83
-0
lines changed

debuginfo-tests/CMakeLists.txt

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
# various types of debug info, and then run those programs under a debugger
33
# such as GDB or LLDB to verify the results.
44

5+
add_llvm_executable(prettyprinters
6+
llvm-prettyprinters/gdb/prettyprinters.cpp
7+
)
8+
target_link_libraries(prettyprinters PRIVATE LLVMSupport)
9+
510
set(DEBUGINFO_TESTS_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
611
set(DEBUGINFO_TESTS_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
712

@@ -11,6 +16,7 @@ set(DEBUGINFO_TEST_DEPS
1116
count
1217
llvm-objdump
1318
not
19+
prettyprinters
1420
)
1521

1622
# The Windows builder scripts pass -fuse-ld=lld.

debuginfo-tests/lit.cfg.py

+2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
tools = [
4545
ToolSubst('%test_debuginfo', command=os.path.join(
4646
config.debuginfo_tests_src_root, 'llgdb-tests', 'test_debuginfo.pl')),
47+
ToolSubst("%llvm_src_root", config.llvm_src_root),
48+
ToolSubst("%llvm_tools_dir", config.llvm_tools_dir),
4749
]
4850

4951
def get_required_attr(config, attr_name):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import lit.util
2+
3+
# debuginfo-tests are not expected to pass in a cross-compilation setup.
4+
if 'native' not in config.available_features or lit.util.which('gdb') is None:
5+
config.unsupported = True
6+
7+
config.suffixes = ['.gdb']
8+
9+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#include "llvm/ADT/ArrayRef.h"
2+
#include "llvm/ADT/DenseMap.h"
3+
#include "llvm/ADT/Optional.h"
4+
#include "llvm/ADT/SmallString.h"
5+
#include "llvm/ADT/SmallVector.h"
6+
#include "llvm/ADT/Twine.h"
7+
#include "llvm/Support/Error.h"
8+
9+
int Array[] = {1, 2, 3};
10+
11+
llvm::ArrayRef<int> ArrayRef(Array);
12+
llvm::MutableArrayRef<int> MutableArrayRef(Array);
13+
llvm::DenseMap<int, int> DenseMap = {{4, 5}, {6, 7}};
14+
llvm::Expected<int> ExpectedValue(8);
15+
llvm::Expected<int> ExpectedError(llvm::createStringError({}, ""));
16+
llvm::Optional<int> OptionalValue(9);
17+
llvm::Optional<int> OptionalNone(llvm::None);
18+
llvm::SmallVector<int, 5> SmallVector = {10, 11, 12};
19+
llvm::SmallString<5> SmallString("foo");
20+
llvm::StringRef StringRef = "bar";
21+
llvm::Twine Twine = llvm::Twine(SmallString) + StringRef;
22+
23+
int main() {
24+
return 0;
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# RUN: gdb -q -batch -n -iex 'source %llvm_src_root/utils/gdb-scripts/prettyprinters.py' -x %s %llvm_tools_dir/prettyprinters | FileCheck %s
2+
3+
break main
4+
run
5+
6+
# CHECK: llvm::ArrayRef of length 3 = {1, 2, 3}
7+
p ArrayRef
8+
9+
# CHECK: llvm::ArrayRef of length 3 = {1, 2, 3}
10+
p MutableArrayRef
11+
12+
# CHECK: llvm::DenseMap with 2 elements = {
13+
# CHECK: [4] = 5,
14+
# CHECK: [6] = 7,
15+
# CHECK: }
16+
p DenseMap
17+
18+
# CHECK: llvm::Expected = {value = 8}
19+
p ExpectedValue
20+
21+
# CHECK: llvm::Expected is error
22+
p ExpectedError
23+
24+
# CHECK: llvm::Optional = {value = 9}
25+
p OptionalValue
26+
27+
# CHECK: llvm::Optional is not initialized
28+
p OptionalNone
29+
30+
# CHECK: llvm::SmallVector of Size 3, Capacity 5 = {10, 11, 12}
31+
p SmallVector
32+
33+
# CHECK: "foo"
34+
p SmallString
35+
36+
# CHECK: "bar"
37+
p StringRef
38+
39+
# CHECK: "\"foo\"\"bar\""
40+
p Twine
41+

0 commit comments

Comments
 (0)