-
-
Notifications
You must be signed in to change notification settings - Fork 188
/
run-lldb-tests.sh
executable file
·132 lines (113 loc) · 4.38 KB
/
run-lldb-tests.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/sh
#
# Copyright (c) 2022 Martin Storsjo
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
set -ex
if [ $# -lt 1 ]; then
echo $0 prefix
exit 1
fi
PREFIX="$1"
PREFIX="$(cd "$PREFIX" && pwd)"
export PATH=$PREFIX/bin:$PATH
# We use tool names with explicit .exe suffixes here, so that it works both
# in msys2 bash and in bash in WSL.
: ${CXX:=clang++.exe}
: ${LLDB:=lldb.exe}
: ${OBJCOPY:=objcopy.exe}
TARGET=$(clang.exe --version | grep Target: | awk '{print $2}')
ARCH="${TARGET%%-*}"
cd test
TEST_DIR="$ARCH"
[ -z "$CLEAN" ] || rm -rf $TEST_DIR
mkdir -p $TEST_DIR
# Build an executable with DWARF debug info
$CXX hello-exception.cpp -o $TEST_DIR/hello-exception-dwarf.exe -g
# Build an executable with PDB debug info. Strip out any bundled DWARF debug info.
$CXX hello-exception.cpp -o $TEST_DIR/hello-exception-pdb.exe -g -gcodeview -Wl,--pdb= -Wl,-s
# Make a DWARF split debug info file with gnu debuglink.
cp $TEST_DIR/hello-exception-dwarf.exe $TEST_DIR/hello-exception-split.exe
$OBJCOPY --only-keep-debug $TEST_DIR/hello-exception-split.exe $TEST_DIR/hello-exception-split.dbg
$OBJCOPY --strip-all $TEST_DIR/hello-exception-split.exe
$OBJCOPY --add-gnu-debuglink=$TEST_DIR/hello-exception-split.dbg $TEST_DIR/hello-exception-split.exe
for i in libc++ libunwind; do
if [ -f $PREFIX/$ARCH-w64-mingw32/bin/$i.dll ]; then
cp $PREFIX/$ARCH-w64-mingw32/bin/$i.dll $TEST_DIR
fi
done
# Test debugging a crashing executable, and check the backtrace of
# the crash.
OUT=lldb-test-out
SCRIPT=lldb-test-script
cat > $SCRIPT <<EOF
run
bt
EOF
for exe in hello-exception-dwarf.exe hello-exception-pdb.exe hello-exception-split.exe; do
$LLDB -b -s $SCRIPT -- $TEST_DIR/$exe -crash < /dev/null > $OUT 2>/dev/null
cat $OUT
grep -q "Access violation" $OUT
if [ "$ARCH" != "armv7" ] || [ "$exe" = "hello-exception-pdb.exe" ]; then
grep -q "volatile int.*NULL.*0x42" $OUT
fi
if [ "$ARCH" != "armv7" ]; then
# armv7 pdb gives "val=<unavailable>".
grep -q "frame #0: .*hello-exception.*.exe.recurse(val=0) at hello-exception.cpp:" $OUT
grep -q "hello-exception.*.exe.recurse(val=10) at hello-exception.cpp:" $OUT
fi
done
exe=hello-exception-dwarf.exe
if [ "$ARCH" = "armv7" ]; then
# LLDB works better on ARM with PDB than with DWARF.
exe=hello-exception-pdb.exe
fi
# Test running into a programmatic breakpoint (__debugbreak), check the
# backtrace from there, and check that we can continue from it.
cat > $SCRIPT <<EOF
run
bt
cont
EOF
$LLDB -b -s $SCRIPT -- $TEST_DIR/$exe -breakpoint < /dev/null > $OUT 2>/dev/null
cat $OUT
grep -q "stop reason = Exception 0x80000003" $OUT
# Not checking that __debugbreak is "frame #0"; on arm/aarch64, the program
# counter points into the __debugbreak function, while on x86, it points to
# the calling recurse function.
grep -q "__debugbreak" $OUT
if [ "$ARCH" != "armv7" ]; then
grep -q "hello-exception.*.exe.recurse(val=10) at hello-exception.cpp:" $OUT
fi
grep -q "exited with status = 0" $OUT
# Test setting a breakpoint in LLDB, checking the backtrace when we hit it,
# stepping from the breakpoint, and running to completion.
cat > $SCRIPT <<EOF
b done
run
bt
finish
cont
EOF
$LLDB -b -s $SCRIPT -- $TEST_DIR/$exe -noop < /dev/null > $OUT 2>/dev/null
cat $OUT
grep -q "Breakpoint 1: where = hello-exception.*.exe.done.* at hello-exception.cpp:" $OUT
grep -q "stop reason = breakpoint" $OUT
grep -q "frame #0: .*hello-exception.*.exe.done.* at hello-exception.cpp:" $OUT
if [ "$ARCH" != "armv7" ]; then
grep -q "frame #0: .*hello-exception.*.exe.recurse(val=0) at hello-exception.cpp:" $OUT
grep -q "hello-exception.*.exe.recurse(val=10) at hello-exception.cpp:" $OUT
fi
grep -q "exited with status = 0" $OUT
rm -f $OUT $SCRIPT
echo All tests succeeded