|
3 | 3 | import re
|
4 | 4 | import subprocess
|
5 | 5 | import sys
|
| 6 | +from distutils.version import StrictVersion |
6 | 7 |
|
7 | 8 | import lit.formats
|
8 | 9 | import lit.util
|
@@ -200,6 +201,54 @@ def can_target_host():
|
200 | 201 | if apple_lldb_vers < 1000:
|
201 | 202 | config.available_features.add('apple-lldb-pre-1000')
|
202 | 203 |
|
| 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 | + |
203 | 252 | llvm_config.feature_config(
|
204 | 253 | [('--build-mode', {'Debug|RelWithDebInfo': 'debug-info'})]
|
205 | 254 | )
|
0 commit comments