11import os
22import itertools
33import platform
4+ import re
45import subprocess
56import sys
67
78import lit .util
9+ from lit .formats import ShTest
810from lit .llvm import llvm_config
911from lit .llvm .subst import FindTool
1012from lit .llvm .subst import ToolSubst
@@ -22,6 +24,55 @@ def _disallow(config, execName):
2224 config .substitutions .append ((" {0} " .format (execName ), warning .format (execName )))
2325
2426
27+ def get_lldb_args (config , suffix = None ):
28+ lldb_args = []
29+ if "remote-linux" in config .available_features :
30+ lldb_args += [
31+ "-O" ,
32+ '"platform select remote-linux"' ,
33+ "-O" ,
34+ f'"platform connect { config .lldb_platform_url } "' ,
35+ ]
36+ if config .lldb_platform_working_dir :
37+ dir = f"{ config .lldb_platform_working_dir } /shell"
38+ if suffix :
39+ dir += f"/{ suffix } "
40+ lldb_args += [
41+ "-O" ,
42+ f'"platform shell mkdir -p { dir } "' ,
43+ "-O" ,
44+ f'"platform settings -w { dir } "' ,
45+ ]
46+ lldb_args += ["--no-lldbinit" , "-S" , _get_lldb_init_path (config )]
47+ return lldb_args
48+
49+
50+ class ShTestLldb (ShTest ):
51+ def __init__ (
52+ self , execute_external = False , extra_substitutions = [], preamble_commands = []
53+ ):
54+ super ().__init__ (execute_external , extra_substitutions , preamble_commands )
55+
56+ def execute (self , test , litConfig ):
57+ for i , t in enumerate (test .config .substitutions ):
58+ try :
59+ if re .match (t [0 ], "%lldb" ):
60+ cmd = t [1 ]
61+ if '-O "platform settings -w ' in cmd :
62+ args_def = " " .join (get_lldb_args (test .config ))
63+ args_unique = " " .join (
64+ get_lldb_args (test .config , "/" .join (test .path_in_suite ))
65+ )
66+ test .config .substitutions [i ] = (
67+ t [0 ],
68+ cmd .replace (args_def , args_unique ),
69+ )
70+ break
71+ except :
72+ pass
73+ return super ().execute (test , litConfig )
74+
75+
2576def use_lldb_substitutions (config ):
2677 # Set up substitutions for primary tools. These tools must come from config.lldb_tools_dir
2778 # which is basically the build output directory. We do not want to find these in path or
@@ -34,7 +85,9 @@ def use_lldb_substitutions(config):
3485 build_script = os .path .join (build_script , "build.py" )
3586 build_script_args = [
3687 build_script ,
37- "--compiler=any" , # Default to best compiler
88+ (
89+ "--compiler=clang" if config .enable_remote else "--compiler=any"
90+ ), # Default to best compiler
3891 "--arch=" + str (config .lldb_bitness ),
3992 ]
4093 if config .lldb_lit_tools_dir :
@@ -56,7 +109,7 @@ def use_lldb_substitutions(config):
56109 ToolSubst (
57110 "%lldb" ,
58111 command = FindTool ("lldb" ),
59- extra_args = [ "--no-lldbinit" , "-S" , lldb_init ] ,
112+ extra_args = get_lldb_args ( config ) ,
60113 unresolved = "fatal" ,
61114 ),
62115 ToolSubst (
@@ -138,7 +191,7 @@ def use_support_substitutions(config):
138191 # Set up substitutions for support tools. These tools can be overridden at the CMake
139192 # level (by specifying -DLLDB_LIT_TOOLS_DIR), installed, or as a last resort, we can use
140193 # the just-built version.
141- host_flags = ["--target=" + config .host_triple ]
194+ host_flags = ["--target=" + config .target_triple ]
142195 if platform .system () in ["Darwin" ]:
143196 try :
144197 out = subprocess .check_output (["xcrun" , "--show-sdk-path" ]).strip ()
@@ -165,6 +218,14 @@ def use_support_substitutions(config):
165218 if config .cmake_sysroot :
166219 host_flags += ["--sysroot={}" .format (config .cmake_sysroot )]
167220
221+ if config .enable_remote and config .has_libcxx :
222+ host_flags += [
223+ "-L{}" .format (config .libcxx_libs_dir ),
224+ "-Wl,-rpath,{}" .format (config .libcxx_libs_dir ),
225+ "-lc++" ,
226+ "-lc++abi" ,
227+ ]
228+
168229 host_flags = " " .join (host_flags )
169230 config .substitutions .append (("%clang_host" , "%clang " + host_flags ))
170231 config .substitutions .append (("%clangxx_host" , "%clangxx " + host_flags ))
0 commit comments