Skip to content

Commit

Permalink
[lldb] Use file-based synchronization in TestVSCode_attach
Browse files Browse the repository at this point in the history
The is the best method we have at the moment for attach-style tests.
  • Loading branch information
labath committed Dec 16, 2019
1 parent c72bff6 commit 755a66e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
Expand Up @@ -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)

Expand Down Expand Up @@ -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']
Expand Down
@@ -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
}

0 comments on commit 755a66e

Please sign in to comment.