Author: Pavel Labath Date: 2019-12-16T14:10:42+01:00 New Revision: 755a66ebdeda38669f5498565cbc6af331b47bad
URL: https://github.com/llvm/llvm-project/commit/755a66ebdeda38669f5498565cbc6af331b47bad DIFF: https://github.com/llvm/llvm-project/commit/755a66ebdeda38669f5498565cbc6af331b47bad.diff LOG: [lldb] Use file-based synchronization in TestVSCode_attach The is the best method we have at the moment for attach-style tests. Added: Modified: lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/attach/TestVSCode_attach.py lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/attach/main.c Removed: ################################################################################ diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/attach/TestVSCode_attach.py b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/attach/TestVSCode_attach.py index ed014392f598..cb2ac355df53 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/attach/TestVSCode_attach.py +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/attach/TestVSCode_attach.py @@ -79,19 +79,22 @@ def test_by_name(self): shutil.copyfile(orig_program, program) shutil.copymode(orig_program, program) + # Use a file as a synchronization point between test and inferior. + pid_file_path = lldbutil.append_to_process_working_directory(self, + "pid_file_%d" % (int(time.time()))) + def cleanup(): if os.path.exists(program): os.unlink(program) + self.run_platform_command("rm %s" % (pid_file_path)) # Execute the cleanup function during test case tear down. self.addTearDownHook(cleanup) - self.process = subprocess.Popen([program], - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE) - # Wait for a bit to ensure the process is launched, but not for so long - # that the process has already finished by the time we attach. - time.sleep(3) + popen = self.spawnSubprocess(program, [pid_file_path]) + self.addTearDownHook(self.cleanupSubprocesses) + + pid = lldbutil.wait_for_file_on_target(self, pid_file_path) + self.attach(program=program) self.set_and_hit_breakpoint(continueToExit=True) @@ -143,7 +146,7 @@ def test_commands(self): # and use it for debugging attachCommands = [ 'target create -d "%s"' % (program), - 'process launch -- arg1' + 'process launch' ] initCommands = ['target list', 'platform list'] preRunCommands = ['image list a.out', 'image dump sections a.out'] diff --git a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/attach/main.c b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/attach/main.c index 4f50f7546155..64d86583ada6 100644 --- a/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/attach/main.c +++ b/lldb/packages/Python/lldbsuite/test/tools/lldb-vscode/attach/main.c @@ -1,11 +1,20 @@ #include <stdio.h> #include <unistd.h> -int main(int argc, char const *argv[]) -{ - lldb_enable_attach(); +int main(int argc, char const *argv[]) { + lldb_enable_attach(); - printf("pid = %i\n", getpid()); - sleep(10); - return 0; // breakpoint 1 + if (argc >= 2) { + // Create the synchronization token. + FILE *f = fopen(argv[1], "wx"); + if (!f) + return 1; + fputs("\n", f); + fflush(f); + fclose(f); + } + + printf("pid = %i\n", getpid()); + sleep(10); + return 0; // breakpoint 1 } _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits