Skip to content

Commit 7df4eaa

Browse files
committed
[lldb/test] Automatically find debug servers to test
Our test configuration logic assumes that the tests can be run either with debugserver or with lldb-server. This is not entirely correct, since lldb server has two "personalities" (platform server and debug server) and debugserver is only a replacement for the latter. A consequence of this is that it's not possible to test the platform behavior of lldb-server on macos, as it is not possible to get a hold of the lldb-server binary. One solution to that would be to duplicate the server configuration logic to be able to specify both executables. However, that seems excessively redundant. A well-behaved lldb should be able to find the debug server on its own, and testing lldb with a different (lldb-|debug)server does not seem very useful (even in the out-of-tree debugserver setup, we copy the server into the build tree to make it appear "real"). Therefore, this patch deletes the configuration altogether and changes the low-level server retrieval functions to be able to both lldb-server and debugserver paths. They do this by consulting the "support executable" directory of the lldb under test. Differential Revision: https://reviews.llvm.org/D96202
1 parent 69f1a7a commit 7df4eaa

File tree

8 files changed

+10
-86
lines changed

8 files changed

+10
-86
lines changed

lldb/packages/Python/lldbsuite/test/dotest.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,6 @@ def parseOptionsAndInitTestdirs():
366366
args.executable)
367367
sys.exit(-1)
368368

369-
if args.server and args.out_of_tree_debugserver:
370-
logging.warning('Both --server and --out-of-tree-debugserver are set')
371-
372-
if args.server and not args.out_of_tree_debugserver:
373-
os.environ['LLDB_DEBUGSERVER_PATH'] = args.server
374-
375369
if args.excluded:
376370
for excl_file in args.excluded:
377371
parseExclusion(excl_file)

lldb/packages/Python/lldbsuite/test/dotest_args.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ def create_parser():
100100
'--executable',
101101
metavar='executable-path',
102102
help='The path to the lldb executable')
103-
group.add_argument(
104-
'--server',
105-
metavar='server-path',
106-
help='The path to the debug server executable to use')
107103
group.add_argument(
108104
'--out-of-tree-debugserver',
109105
dest='out_of_tree_debugserver',

lldb/packages/Python/lldbsuite/test/tools/lldb-server/lldbgdbserverutils.py

Lines changed: 6 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,12 @@
1515
from lldbsuite.test.lldbtest import *
1616
from lldbsuite.test import configuration
1717
from textwrap import dedent
18+
import shutil
1819

19-
def _get_debug_monitor_from_lldb(lldb_exe, debug_monitor_basename):
20-
"""Return the debug monitor exe path given the lldb exe path.
20+
def _get_support_exe(basename):
21+
support_dir = lldb.SBHostOS.GetLLDBPath(lldb.ePathTypeSupportExecutableDir)
2122

22-
This method attempts to construct a valid debug monitor exe name
23-
from a given lldb exe name. It will return None if the synthesized
24-
debug monitor name is not found to exist.
25-
26-
The debug monitor exe path is synthesized by taking the directory
27-
of the lldb exe, and replacing the portion of the base name that
28-
matches "lldb" (case insensitive) and replacing with the value of
29-
debug_monitor_basename.
30-
31-
Args:
32-
lldb_exe: the path to an lldb executable.
33-
34-
debug_monitor_basename: the base name portion of the debug monitor
35-
that will replace 'lldb'.
36-
37-
Returns:
38-
A path to the debug monitor exe if it is found to exist; otherwise,
39-
returns None.
40-
41-
"""
42-
if not lldb_exe:
43-
return None
44-
45-
exe_dir = os.path.dirname(lldb_exe)
46-
exe_base = os.path.basename(lldb_exe)
47-
48-
# we'll rebuild the filename by replacing lldb with
49-
# the debug monitor basename, keeping any prefix or suffix in place.
50-
regex = re.compile(r"lldb", re.IGNORECASE)
51-
new_base = regex.sub(debug_monitor_basename, exe_base)
52-
53-
debug_monitor_exe = os.path.join(exe_dir, new_base)
54-
if os.path.exists(debug_monitor_exe):
55-
return debug_monitor_exe
56-
57-
new_base = regex.sub(
58-
'LLDB.framework/Versions/A/Resources/' +
59-
debug_monitor_basename,
60-
exe_base)
61-
debug_monitor_exe = os.path.join(exe_dir, new_base)
62-
if os.path.exists(debug_monitor_exe):
63-
return debug_monitor_exe
64-
65-
return None
23+
return shutil.which(basename, path=support_dir.GetDirectory())
6624

6725

6826
def get_lldb_server_exe():
@@ -72,11 +30,8 @@ def get_lldb_server_exe():
7230
A path to the lldb-server exe if it is found to exist; otherwise,
7331
returns None.
7432
"""
75-
if "LLDB_DEBUGSERVER_PATH" in os.environ:
76-
return os.environ["LLDB_DEBUGSERVER_PATH"]
7733

78-
return _get_debug_monitor_from_lldb(
79-
lldbtest_config.lldbExec, "lldb-server")
34+
return _get_support_exe("lldb-server")
8035

8136

8237
def get_debugserver_exe():
@@ -86,15 +41,11 @@ def get_debugserver_exe():
8641
A path to the debugserver exe if it is found to exist; otherwise,
8742
returns None.
8843
"""
89-
if "LLDB_DEBUGSERVER_PATH" in os.environ:
90-
return os.environ["LLDB_DEBUGSERVER_PATH"]
91-
9244
if configuration.arch and configuration.arch == "x86_64" and \
9345
platform.machine().startswith("arm64"):
9446
return '/Library/Apple/usr/libexec/oah/debugserver'
9547

96-
return _get_debug_monitor_from_lldb(
97-
lldbtest_config.lldbExec, "debugserver")
48+
return _get_support_exe("debugserver")
9849

9950
_LOG_LINE_REGEX = re.compile(r'^(lldb-server|debugserver)\s+<\s*(\d+)>' +
10051
'\s+(read|send)\s+packet:\s+(.+)$')

lldb/test/API/CMakeLists.txt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,18 +108,8 @@ if(CMAKE_HOST_APPLE)
108108
message(STATUS "LLDB tests use out-of-tree debugserver: ${system_debugserver_path}")
109109
list(APPEND LLDB_TEST_COMMON_ARGS --out-of-tree-debugserver)
110110
add_lldb_test_dependency(debugserver)
111-
elseif(TARGET debugserver)
112-
set(debugserver_path ${LLVM_RUNTIME_OUTPUT_INTDIR}/debugserver)
113-
message(STATUS "LLDB Tests use just-built debugserver: ${debugserver_path}")
114-
set(LLDB_TEST_SERVER ${debugserver_path})
115-
add_lldb_test_dependency(debugserver)
116-
elseif(TARGET lldb-server)
117-
set(lldb_server_path ${LLVM_RUNTIME_OUTPUT_INTDIR}/lldb-server)
118-
message(STATUS "LLDB Tests use just-built lldb-server: ${lldb_server_path}")
119-
set(LLDB_TEST_SERVER ${lldb_server_path})
120-
add_lldb_test_dependency(lldb-server)
121111
else()
122-
message(WARNING "LLDB Tests enabled, but no server available")
112+
message(STATUS "LLDB Tests use just-built debug server")
123113
endif()
124114
endif()
125115

@@ -136,7 +126,6 @@ if(LLDB_BUILT_STANDALONE)
136126
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_EXECUTABLE "${LLDB_TEST_EXECUTABLE}")
137127
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_COMPILER "${LLDB_TEST_COMPILER}")
138128
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_DSYMUTIL "${LLDB_TEST_DSYMUTIL}")
139-
string(REPLACE ${LLVM_RUNTIME_OUTPUT_INTDIR} ${config_runtime_output_dir} LLDB_TEST_SERVER "${LLDB_TEST_SERVER}")
140129

141130
# Remaining ones must be paths to the provided LLVM build-tree.
142131
if(LLVM_CONFIGURATION_TYPES)
@@ -163,7 +152,6 @@ string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_BUILD_DI
163152
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_EXECUTABLE "${LLDB_TEST_EXECUTABLE}")
164153
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_COMPILER "${LLDB_TEST_COMPILER}")
165154
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_DSYMUTIL "${LLDB_TEST_DSYMUTIL}")
166-
string(REPLACE ${CMAKE_CFG_INTDIR} ${dotest_args_replacement} LLDB_TEST_SERVER "${LLDB_TEST_SERVER}")
167155

168156
# Configure the API test suite.
169157
configure_lit_site_cfg(

lldb/test/API/commands/platform/sdk/TestPlatformSDK.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from lldbsuite.test.decorators import *
44
from lldbsuite.test.lldbtest import *
55
from lldbsuite.test import lldbutil
6+
from lldbgdbserverutils import get_debugserver_exe
67

78
import os
89
import platform
@@ -28,7 +29,7 @@ class PlatformSDKTestCase(TestBase):
2829
TIMEOUT = 2
2930

3031
def no_debugserver(self):
31-
if os.getenv('LLDB_DEBUGSERVER_PATH') is None:
32+
if get_debugserver_exe() is None:
3233
return 'no debugserver'
3334
return None
3435

@@ -88,7 +89,7 @@ def cleanup():
8889
shutil.move(exe, exe_sdk_path)
8990

9091
# Attach to it with debugserver.
91-
debugserver = os.getenv('LLDB_DEBUGSERVER_PATH')
92+
debugserver = get_debugserver_exe()
9293
debugserver_args = [
9394
'localhost:{}'.format(self.PORT), '--attach={}'.format(pid)
9495
]

lldb/test/API/lit.site.cfg.py.in

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ config.lldb_executable = '@LLDB_TEST_EXECUTABLE@'
2929
config.test_arch = '@LLDB_TEST_ARCH@'
3030
config.test_compiler = '@LLDB_TEST_COMPILER@'
3131
config.dsymutil = '@LLDB_TEST_DSYMUTIL@'
32-
config.server = '@LLDB_TEST_SERVER@'
3332
# The API tests use their own module caches.
3433
config.lldb_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_LLDB@", "lldb-api")
3534
config.clang_module_cache = os.path.join("@LLDB_TEST_MODULE_CACHE_CLANG@", "lldb-api")
@@ -55,7 +54,6 @@ try:
5554
config.lldb_executable = config.lldb_executable % lit_config.params
5655
config.lldb_libs_dir = config.lldb_libs_dir % lit_config.params
5756
config.test_compiler = config.test_compiler % lit_config.params
58-
config.server = config.server % lit_config.params
5957
config.lldb_framework_dir = config.lldb_framework_dir % lit_config.params
6058
config.dotest_args_str = config.dotest_args_str % lit_config.params
6159
except KeyError as e:

lldb/utils/lldb-dotest/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ set(vars
1919
LLDB_TEST_EXECUTABLE
2020
LLDB_TEST_COMPILER
2121
LLDB_TEST_DSYMUTIL
22-
LLDB_TEST_SERVER
2322
LLDB_LIBS_DIR
2423
LLVM_TOOLS_DIR
2524
)

lldb/utils/lldb-dotest/lldb-dotest.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ arch = '@LLDB_TEST_ARCH@'
88
executable = '@LLDB_TEST_EXECUTABLE_CONFIGURED@'
99
compiler = '@LLDB_TEST_COMPILER_CONFIGURED@'
1010
dsymutil = '@LLDB_TEST_DSYMUTIL_CONFIGURED@'
11-
server = '@LLDB_TEST_SERVER_CONFIGURED@'
1211
lldb_build_dir = '@LLDB_TEST_BUILD_DIRECTORY_CONFIGURED@'
1312
lldb_build_intel_pt = "@LLDB_BUILD_INTEL_PT@"
1413
lldb_framework_dir = "@LLDB_FRAMEWORK_DIR_CONFIGURED@"
@@ -28,8 +27,6 @@ if __name__ == '__main__':
2827
cmd.extend(['--dsymutil', dsymutil])
2928
cmd.extend(['--lldb-libs-dir', lldb_libs_dir])
3029
cmd.extend(['--llvm-tools-dir', llvm_tools_dir])
31-
if server:
32-
cmd.extend(['--server', server])
3330
if lldb_framework_dir:
3431
cmd.extend(['--framework', lldb_framework_dir])
3532
if lldb_build_intel_pt == "1":

0 commit comments

Comments
 (0)