Index: cross-project-tests/debuginfo-tests/llgdb-tests/asan-blocks.c =================================================================== --- cross-project-tests/debuginfo-tests/llgdb-tests/asan-blocks.c +++ cross-project-tests/debuginfo-tests/llgdb-tests/asan-blocks.c @@ -4,13 +4,15 @@ // REQUIRES: !asan, system-darwin // Zorg configures the ASAN stage2 bots to not build the asan // compiler-rt. Only run this test on non-asanified configurations. +// XFAIL: !system-darwin && gdb-clang-incompatibility + void b(); struct S { int a[8]; }; int f(struct S s, unsigned i) { - // DEBUGGER: break 17 + // DEBUGGER: break 19 // DEBUGGER: r // DEBUGGER: p s // CHECK: a = ([0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7) @@ -20,7 +22,7 @@ int main(int argc, const char **argv) { struct S s = {{0, 1, 2, 3, 4, 5, 6, 7}}; if (f(s, 4) == 4) { - // DEBUGGER: break 27 + // DEBUGGER: break 29 // DEBUGGER: c // DEBUGGER: p s // CHECK: a = ([0] = 0, [1] = 1, [2] = 2, [3] = 3, [4] = 4, [5] = 5, [6] = 6, [7] = 7) @@ -32,7 +34,7 @@ void c() {} void b() { - // DEBUGGER: break 40 + // DEBUGGER: break 42 // DEBUGGER: c // DEBUGGER: p x // CHECK: 42 Index: cross-project-tests/debuginfo-tests/llgdb-tests/asan-deque.cpp =================================================================== --- cross-project-tests/debuginfo-tests/llgdb-tests/asan-deque.cpp +++ cross-project-tests/debuginfo-tests/llgdb-tests/asan-deque.cpp @@ -4,6 +4,8 @@ // Zorg configures the ASAN stage2 bots to not build the asan // compiler-rt. Only run this test on non-asanified configurations. // UNSUPPORTED: apple-lldb-pre-1000 +// XFAIL: !system-darwin && gdb-clang-incompatibility + #include struct A { @@ -23,24 +25,24 @@ log.push_back(1234); log.push_back(56789); escape(log); - // DEBUGGER: break 25 + // DEBUGGER: break 27 while (!log.empty()) { auto record = log.front(); log.pop_front(); escape(log); - // DEBUGGER: break 30 + // DEBUGGER: break 32 } } // DEBUGGER: r -// (at line 25) +// (at line 27) // DEBUGGER: p log // CHECK: 1234 // CHECK: 56789 // DEBUGGER: c -// (at line 30) +// (at line 32) // DEBUGGER: p log // CHECK: 56789 Index: cross-project-tests/debuginfo-tests/llgdb-tests/asan.c =================================================================== --- cross-project-tests/debuginfo-tests/llgdb-tests/asan.c +++ cross-project-tests/debuginfo-tests/llgdb-tests/asan.c @@ -3,7 +3,7 @@ // REQUIRES: !asan // Zorg configures the ASAN stage2 bots to not build the asan // compiler-rt. Only run this test on non-asanified configurations. -// +// XFAIL: !system-darwin && gdb-clang-incompatibility struct S { int a[8]; Index: cross-project-tests/debuginfo-tests/llgdb-tests/nested-struct.cpp =================================================================== --- cross-project-tests/debuginfo-tests/llgdb-tests/nested-struct.cpp +++ cross-project-tests/debuginfo-tests/llgdb-tests/nested-struct.cpp @@ -1,5 +1,6 @@ // RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o // RUN: %test_debuginfo %s %t.o +// XFAIL: !system-darwin && gdb-clang-incompatibility // Radar 9440721 // If debug info for my_number() is emitted outside function foo's scope // then a debugger may not be able to handle it. At least one version of Index: cross-project-tests/debuginfo-tests/llgdb-tests/nrvo-string.cpp =================================================================== --- cross-project-tests/debuginfo-tests/llgdb-tests/nrvo-string.cpp +++ cross-project-tests/debuginfo-tests/llgdb-tests/nrvo-string.cpp @@ -5,7 +5,7 @@ // RUN: %test_debuginfo %s %t.out // RUN: %clangxx -O1 -fno-exceptions %target_itanium_abi_host_triple %s -o %t.out -g // RUN: %test_debuginfo %s %t.out -// +// XFAIL: !system-darwin && gdb-clang-incompatibility // PR34513 volatile int sideeffect = 0; void __attribute__((noinline)) stop() { sideeffect++; } Index: cross-project-tests/debuginfo-tests/llgdb-tests/safestack.c =================================================================== --- cross-project-tests/debuginfo-tests/llgdb-tests/safestack.c +++ cross-project-tests/debuginfo-tests/llgdb-tests/safestack.c @@ -5,7 +5,7 @@ // Zorg configures the ASAN stage2 bots to not build the // safestack compiler-rt. Only run this test on // non-asanified configurations. - +// XFAIL: !system-darwin && gdb-clang-incompatibility struct S { int a[8]; }; Index: cross-project-tests/debuginfo-tests/llgdb-tests/sret.cpp =================================================================== --- cross-project-tests/debuginfo-tests/llgdb-tests/sret.cpp +++ cross-project-tests/debuginfo-tests/llgdb-tests/sret.cpp @@ -1,8 +1,9 @@ // RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -c -o %t.o // RUN: %clangxx %target_itanium_abi_host_triple %t.o -o %t.out // RUN: %test_debuginfo %s %t.out +// XFAIL: !system-darwin && gdb-clang-incompatibility // Radar 8775834 -// DEBUGGER: break 62 +// DEBUGGER: break 63 // DEBUGGER: r // DEBUGGER: p a // CHECK: ${{[0-9]+}} = Index: cross-project-tests/debuginfo-tests/llgdb-tests/static-member-2.cpp =================================================================== --- cross-project-tests/debuginfo-tests/llgdb-tests/static-member-2.cpp +++ cross-project-tests/debuginfo-tests/llgdb-tests/static-member-2.cpp @@ -3,7 +3,7 @@ // RUN: %test_debuginfo %s %t.out // FIXME: LLDB finds the wrong symbol for "C". rdar://problem/14933867 -// XFAIL: darwin +// XFAIL: darwin, gdb-clang-incompatibility // DEBUGGER: delete breakpoints // DEBUGGER: break static-member.cpp:33 Index: cross-project-tests/debuginfo-tests/llgdb-tests/static-member.cpp =================================================================== --- cross-project-tests/debuginfo-tests/llgdb-tests/static-member.cpp +++ cross-project-tests/debuginfo-tests/llgdb-tests/static-member.cpp @@ -1,7 +1,7 @@ // RUN: %clangxx %target_itanium_abi_host_triple -O0 -g %s -o %t -c // RUN: %clangxx %target_itanium_abi_host_triple %t -o %t.out // RUN: %test_debuginfo %s %t.out - +// XFAIL: !system-darwin && gdb-clang-incompatibility // DEBUGGER: delete breakpoints // DEBUGGER: break static-member.cpp:33 // DEBUGGER: r Index: cross-project-tests/lit.cfg.py =================================================================== --- cross-project-tests/lit.cfg.py +++ cross-project-tests/lit.cfg.py @@ -3,6 +3,7 @@ import re import subprocess import sys +from distutils.version import StrictVersion import lit.formats import lit.util @@ -200,6 +201,51 @@ if apple_lldb_vers < 1000: config.available_features.add('apple-lldb-pre-1000') +def get_gdb_version_string(): + """Return gdb's version string, or None if gdb cannot be found or the + --version output is formatted unexpectedly. + """ + # See if we can get a gdb version, e.g. + # $ gdb --version + # GNU gdb (GDB) 10.2 + # ...More stuff... + try: + gdb_vers_lines = subprocess.check_output(['gdb', '--version']).decode().splitlines() + except: + return None # We coudln't find gdb or something went wrong running it. + + if len(gdb_vers_lines) < 1: + print('Unkown GDB version format (too few lines)', file=sys.stderr) + return None + return gdb_vers_lines[0].strip().partition('GNU gdb (GDB) ')[2] + +def get_clang_default_dwarf_version_string(triple): + """Return the default dwarf version string for clang on this (host) platform + or None if we can't work it out. + """ + # Get the flags passed by the driver and look for -dwarf-version. + cmd = f'{llvm_config.use_llvm_tool("clang")} -g -xc -c - -v -### --target={triple}' + stderr = subprocess.run(cmd.split(), stderr=subprocess.PIPE).stderr.decode() + match = re.search('-dwarf-version=(\d+)', stderr) + if match is None: + print("Cannot determine default dwarf version", file=sys.stderr) + return None + return match.group(1) + +# Some cross-project-tests use gdb, but not all versions of gdb are compatible +# with clang's dwarf. Add feature `gdb-clang-incompatibility` to signal that +# there's an incompatibility between clang's default dwarf version for this +# platform and the installed gdb version. +dwarf_version_string = get_clang_default_dwarf_version_string(config.host_triple) +gdb_version_string = get_gdb_version_string() +if dwarf_version_string and gdb_version_string: + if int(dwarf_version_string) >= 5: + if StrictVersion(gdb_version_string) < StrictVersion('10.1'): + # Example for llgdb-tests, which use lldb on darwin but gdb elsewhere: + # XFAIL: !system-darwin && gdb-clang-incompatibility + config.available_features.add('gdb-clang-incompatibility') + print("XFAIL some tests: use gdb version >= 10.1 to restore test coverage", file=sys.stderr) + llvm_config.feature_config( [('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})] )