diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py index 19c766996292e..aea6b9fe36b2c 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-server/gdbremote_testcase.py @@ -444,13 +444,20 @@ def launch_process_for_attach( if not exe_path: exe_path = self.getBuildArtifact("a.out") - args = [] + # This file will be created once the inferior has enabled attaching. + sync_file_path = lldbutil.append_to_process_working_directory( + self, "process_ready" + ) + args = [f"syncfile:{sync_file_path}"] if inferior_args: args.extend(inferior_args) if sleep_seconds: args.append("sleep:%d" % sleep_seconds) - return self.spawnSubprocess(exe_path, args) + inferior = self.spawnSubprocess(exe_path, args) + lldbutil.wait_for_file_on_target(self, sync_file_path) + + return inferior def prep_debug_monitor_and_inferior( self, diff --git a/lldb/test/API/tools/lldb-server/main.cpp b/lldb/test/API/tools/lldb-server/main.cpp index 0e9323cce88cf..7e84552b0f25d 100644 --- a/lldb/test/API/tools/lldb-server/main.cpp +++ b/lldb/test/API/tools/lldb-server/main.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include #include @@ -265,7 +266,11 @@ int main(int argc, char **argv) { // Process command line args. for (int i = 1; i < argc; ++i) { std::string arg = argv[i]; - if (consume_front(arg, "stderr:")) { + if (consume_front(arg, "syncfile:")) { + // Write to this file to tell test framework that attaching is now + // possible. + std::ofstream(arg).close(); + } else if (consume_front(arg, "stderr:")) { // Treat remainder as text to go to stderr. fprintf(stderr, "%s\n", arg.c_str()); } else if (consume_front(arg, "retval:")) {