-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix a bug with cancelling "attach -w" after you have run a process previously #65822
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
|
||
import os | ||
import threading | ||
import lldb | ||
import shutil | ||
from lldbsuite.test.decorators import * | ||
|
@@ -127,3 +128,65 @@ def tearDown(self): | |
|
||
# Call super's tearDown(). | ||
TestBase.tearDown(self) | ||
|
||
def test_run_then_attach_wait_interrupt(self): | ||
# Test that having run one process doesn't cause us to be unable | ||
# to interrupt a subsequent attach attempt. | ||
self.build() | ||
exe = self.getBuildArtifact(exe_name) | ||
|
||
target = lldbutil.run_to_breakpoint_make_target(self, exe_name, True) | ||
launch_info = target.GetLaunchInfo() | ||
launch_info.SetArguments(["q"], True) | ||
error = lldb.SBError() | ||
target.Launch(launch_info, error) | ||
self.assertSuccess(error, "Launched a process") | ||
self.assertState(target.process.state, lldb.eStateExited, "and it exited.") | ||
|
||
# Okay now we've run a process, try to attach/wait to something | ||
# and make sure that we can interrupt that. | ||
|
||
options = lldb.SBCommandInterpreterRunOptions() | ||
options.SetPrintResults(True) | ||
options.SetEchoCommands(False) | ||
|
||
self.stdin_path = self.getBuildArtifact("stdin.txt") | ||
|
||
with open(self.stdin_path, "w") as input_handle: | ||
input_handle.write("process attach -w -n noone_would_use_this_name\nquit") | ||
|
||
# Python will close the file descriptor if all references | ||
# to the filehandle object lapse, so we need to keep one | ||
# around. | ||
self.filehandle = open(self.stdin_path, "r") | ||
self.dbg.SetInputFileHandle(self.filehandle, False) | ||
|
||
# No need to track the output | ||
self.stdout_path = self.getBuildArtifact("stdout.txt") | ||
self.out_filehandle = open(self.stdout_path, "w") | ||
self.dbg.SetOutputFileHandle(self.out_filehandle, False) | ||
self.dbg.SetErrorFileHandle(self.out_filehandle, False) | ||
|
||
n_errors, quit_req, crashed = self.dbg.RunCommandInterpreter( | ||
True, True, options, 0, False, False) | ||
|
||
while 1: | ||
time.sleep(1) | ||
if target.process.state == lldb.eStateAttaching: | ||
break | ||
|
||
self.dbg.DispatchInputInterrupt() | ||
self.dbg.DispatchInputInterrupt() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this done twice? |
||
|
||
self.out_filehandle.flush() | ||
reader = open(self.stdout_path, "r") | ||
results = reader.readlines() | ||
found_result = False | ||
for line in results: | ||
if "Cancelled async attach" in line: | ||
found_result = True | ||
break | ||
self.assertTrue(found_result, "Found async error in results") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This fails if
When the test works the results contain:
Running it in a loop it took ~40 runs to get a failing one. I wonder if that is because the attach happens to finish a lot faster sometimes, so there's no time to cancel it? If that's down to the OS and machine load, I'm not sure how we'd make this predictable. The ugly option is to say if the results are empty, pass the test and assume the other 39 runs will check for the bug. |
||
# We shouldn't still have a process in the "attaching" state: | ||
state = self.dbg.GetSelectedTarget().process.state | ||
self.assertState(state, lldb.eStateExited, "Process not exited after attach cancellation") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion/Bikeshedding: Flip the condition and you can reduce one level of indentation in this method. That's just my preference though, doesn't make a difference either way.