Skip to content

Commit 5257efd

Browse files
committed
[cross-project-tests] XFAIL llgdb-tests when gdb can't read clang's DWARF
Tests in the `cross-project-tests/debuginfo-tests/llgdb-tests` directory run gdb on non-darwin platforms. gdb versions less than 10.1 cannot parse the DWARF v5 emitted by clang, and DWARF v5 is now the default, so these tests fail on Linux with gdb versions less than 10.1. This patch lets us XFAIL the tests under these conditions. Add `gdb-clang-incompatibility` to the `available_features` in `cross-project-tests/lit.cfg.py` when clang's default DWARF version is 5 or greater and the gdb (if found) version is less than 10.1. Discourse discussion: https://llvm.discourse.group/t/gdb-10-1-cant-read-clangs-dwarf-v5/6035 Reviewed By: jmorse Differential Revision: https://reviews.llvm.org/D118468
1 parent e3ba831 commit 5257efd

File tree

10 files changed

+68
-13
lines changed

10 files changed

+68
-13
lines changed

cross-project-tests/debuginfo-tests/llgdb-tests/asan-blocks.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
// REQUIRES: !asan, system-darwin
55
// Zorg configures the ASAN stage2 bots to not build the asan
66
// compiler-rt. Only run this test on non-asanified configurations.
7+
// XFAIL: !system-darwin && gdb-clang-incompatibility
8+
79
void b();
810
struct S {
911
int a[8];
1012
};
1113

1214
int f(struct S s, unsigned i) {
13-
// DEBUGGER: break 17
15+
// DEBUGGER: break 19
1416
// DEBUGGER: r
1517
// DEBUGGER: p s
1618
// CHECK: a = ([0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7)
@@ -20,7 +22,7 @@ int f(struct S s, unsigned i) {
2022
int main(int argc, const char **argv) {
2123
struct S s = {{0, 1, 2, 3, 4, 5, 6, 7}};
2224
if (f(s, 4) == 4) {
23-
// DEBUGGER: break 27
25+
// DEBUGGER: break 29
2426
// DEBUGGER: c
2527
// DEBUGGER: p s
2628
// CHECK: a = ([0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7)
@@ -32,7 +34,7 @@ int main(int argc, const char **argv) {
3234
void c() {}
3335

3436
void b() {
35-
// DEBUGGER: break 40
37+
// DEBUGGER: break 42
3638
// DEBUGGER: c
3739
// DEBUGGER: p x
3840
// CHECK: 42

cross-project-tests/debuginfo-tests/llgdb-tests/asan-deque.cpp

+6-4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// Zorg configures the ASAN stage2 bots to not build the asan
55
// compiler-rt. Only run this test on non-asanified configurations.
66
// UNSUPPORTED: apple-lldb-pre-1000
7+
// XFAIL: !system-darwin && gdb-clang-incompatibility
8+
79
#include <deque>
810

911
struct A {
@@ -23,24 +25,24 @@ int main() {
2325
log.push_back(1234);
2426
log.push_back(56789);
2527
escape(log);
26-
// DEBUGGER: break 25
28+
// DEBUGGER: break 27
2729
while (!log.empty()) {
2830
auto record = log.front();
2931
log.pop_front();
3032
escape(log);
31-
// DEBUGGER: break 30
33+
// DEBUGGER: break 32
3234
}
3335
}
3436

3537
// DEBUGGER: r
3638

37-
// (at line 25)
39+
// (at line 27)
3840
// DEBUGGER: p log
3941
// CHECK: 1234
4042
// CHECK: 56789
4143

4244
// DEBUGGER: c
4345

44-
// (at line 30)
46+
// (at line 32)
4547
// DEBUGGER: p log
4648
// CHECK: 56789

cross-project-tests/debuginfo-tests/llgdb-tests/asan.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// REQUIRES: !asan
44
// Zorg configures the ASAN stage2 bots to not build the asan
55
// compiler-rt. Only run this test on non-asanified configurations.
6-
//
6+
// XFAIL: !system-darwin && gdb-clang-incompatibility
77

88
struct S {
99
int a[8];

cross-project-tests/debuginfo-tests/llgdb-tests/nested-struct.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o
22
// RUN: %test_debuginfo %s %t.o
3+
// XFAIL: !system-darwin && gdb-clang-incompatibility
34
// Radar 9440721
45
// If debug info for my_number() is emitted outside function foo's scope
56
// then a debugger may not be able to handle it. At least one version of

cross-project-tests/debuginfo-tests/llgdb-tests/nrvo-string.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// RUN: %test_debuginfo %s %t.out
66
// RUN: %clangxx -O1 -fno-exceptions %target_itanium_abi_host_triple %s -o %t.out -g
77
// RUN: %test_debuginfo %s %t.out
8-
//
8+
// XFAIL: !system-darwin && gdb-clang-incompatibility
99
// PR34513
1010
volatile int sideeffect = 0;
1111
void __attribute__((noinline)) stop() { sideeffect++; }

cross-project-tests/debuginfo-tests/llgdb-tests/safestack.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// Zorg configures the ASAN stage2 bots to not build the
66
// safestack compiler-rt. Only run this test on
77
// non-asanified configurations.
8-
8+
// XFAIL: !system-darwin && gdb-clang-incompatibility
99
struct S {
1010
int a[8];
1111
};

cross-project-tests/debuginfo-tests/llgdb-tests/sret.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o
22
// RUN: %clangxx %target_itanium_abi_host_triple %t.o -o %t.out
33
// RUN: %test_debuginfo %s %t.out
4+
// XFAIL: !system-darwin && gdb-clang-incompatibility
45
// Radar 8775834
5-
// DEBUGGER: break 62
6+
// DEBUGGER: break 63
67
// DEBUGGER: r
78
// DEBUGGER: p a
89
// CHECK: ${{[0-9]+}} =

cross-project-tests/debuginfo-tests/llgdb-tests/static-member-2.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// RUN: %test_debuginfo %s %t.out
44

55
// FIXME: LLDB finds the wrong symbol for "C". rdar://problem/14933867
6-
// XFAIL: darwin
6+
// XFAIL: darwin, gdb-clang-incompatibility
77

88
// DEBUGGER: delete breakpoints
99
// DEBUGGER: break static-member.cpp:33

cross-project-tests/debuginfo-tests/llgdb-tests/static-member.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -o %t -c
22
// RUN: %clangxx %target_itanium_abi_host_triple %t -o %t.out
33
// RUN: %test_debuginfo %s %t.out
4-
4+
// XFAIL: !system-darwin && gdb-clang-incompatibility
55
// DEBUGGER: delete breakpoints
66
// DEBUGGER: break static-member.cpp:33
77
// DEBUGGER: r

cross-project-tests/lit.cfg.py

+49
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import re
44
import subprocess
55
import sys
6+
from distutils.version import StrictVersion
67

78
import lit.formats
89
import lit.util
@@ -200,6 +201,54 @@ def can_target_host():
200201
if apple_lldb_vers < 1000:
201202
config.available_features.add('apple-lldb-pre-1000')
202203

204+
def get_gdb_version_string():
205+
"""Return gdb's version string, or None if gdb cannot be found or the
206+
--version output is formatted unexpectedly.
207+
"""
208+
# See if we can get a gdb version, e.g.
209+
# $ gdb --version
210+
# GNU gdb (GDB) 10.2
211+
# ...More stuff...
212+
try:
213+
gdb_vers_lines = subprocess.check_output(['gdb', '--version']).decode().splitlines()
214+
except:
215+
return None # We coudln't find gdb or something went wrong running it.
216+
if len(gdb_vers_lines) < 1:
217+
print("Unkown GDB version format (too few lines)", file=sys.stderr)
218+
return None
219+
string = gdb_vers_lines[0].strip().partition('GNU gdb (GDB) ')[2]
220+
if len(string) == 0:
221+
print("Unkown GDB version format", file=sys.stderr)
222+
return None
223+
return string
224+
225+
def get_clang_default_dwarf_version_string(triple):
226+
"""Return the default dwarf version string for clang on this (host) platform
227+
or None if we can't work it out.
228+
"""
229+
# Get the flags passed by the driver and look for -dwarf-version.
230+
cmd = f'{llvm_config.use_llvm_tool("clang")} -g -xc -c - -v -### --target={triple}'
231+
stderr = subprocess.run(cmd.split(), stderr=subprocess.PIPE).stderr.decode()
232+
match = re.search('-dwarf-version=(\d+)', stderr)
233+
if match is None:
234+
print("Cannot determine default dwarf version", file=sys.stderr)
235+
return None
236+
return match.group(1)
237+
238+
# Some cross-project-tests use gdb, but not all versions of gdb are compatible
239+
# with clang's dwarf. Add feature `gdb-clang-incompatibility` to signal that
240+
# there's an incompatibility between clang's default dwarf version for this
241+
# platform and the installed gdb version.
242+
dwarf_version_string = get_clang_default_dwarf_version_string(config.host_triple)
243+
gdb_version_string = get_gdb_version_string()
244+
if dwarf_version_string and gdb_version_string:
245+
if int(dwarf_version_string) >= 5:
246+
if StrictVersion(gdb_version_string) < StrictVersion('10.1'):
247+
# Example for llgdb-tests, which use lldb on darwin but gdb elsewhere:
248+
# XFAIL: !system-darwin && gdb-clang-incompatibility
249+
config.available_features.add('gdb-clang-incompatibility')
250+
print("XFAIL some tests: use gdb version >= 10.1 to restore test coverage", file=sys.stderr)
251+
203252
llvm_config.feature_config(
204253
[('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})]
205254
)

0 commit comments

Comments
 (0)