-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Stream logging from attached debugger on iOS #66092
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
Conversation
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.
The change in this file switches the order of fallbacks, which confused git. Now it first tries log scanning, and only if that fails, falls back to mDNS discovery.
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.
This was previously waiting and buffering for duration before sending the first message. The observatory URL was discovered faster than 200 ms in my tests, so let's not wait to process it.
2128ca7 to
7d56f57
Compare
7d56f57 to
e91e25e
Compare
jonahwilliams
left a comment
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.
If this is successful should we remove the mDNS fallback entirely? Could we also remove the provisioning logic for the mDNS permissions?
| // (lldb) run | ||
| // success | ||
| // 2020-09-15 13:42:25.185474-0700 Runner[477:181141] flutter: Observatory listening on http://127.0.0.1:57782/ | ||
| if (line == '(lldb) run') { |
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.
this might deserve a const, with a doc describing where you found it.
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.
Done.
| _logger.printTrace('ios-deploy failed: $exception'); | ||
| _debuggerAttached = false; | ||
| _debuggerOutput.addError(exception, stackTrace); | ||
| } on ArgumentError catch (exception, stackTrace) { |
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.
This will fail if ios-deploy is missing right? should we catch the error or let it crash here and solve the problem elsewhere? i.e. startup checks
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.
I think we already have those checks in place with the stamp/artifact download logic, since ios-deploy is an artifact we ship ourselves idevicesyslog. Unlike the Xcode tooling where we do lots of install checks.
| // (lldb) run | ||
| // success | ||
| // 2020-09-15 13:42:25.185474-0700 Runner[477:181141] flutter: Observatory listening on http://127.0.0.1:57782/ | ||
| if (line == '(lldb) run') { |
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.
Is there any way to make this test and the test for 'success' more resilient to changes in output from lldb? Maybe ignore whitespace or unexpected lines between here and 'success'?
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.
run is coming from ios-deploy, and success is coming from lldb. I will make this a regex to handle whitespace differences.
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.
Added more comments and tests.
| debuggerCompleter.complete(false); | ||
| return; | ||
| } | ||
| if (!debuggerAttached) { |
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.
Oh, okay. The very next line after the lldb run line doesn't have to be 'success'. We'll wait until it is. Consider updating the comment above.
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.
It does have to be "success" (lldbRunCalled logic where it's being set to false if the next line isn't "success"), unless I have a bug in here.
Maybe I should change this to fail if the next line isn't "success" so it doesn't hang forever on something unexpected instead of special-casing "error: process launch failed" (and example of a non-success next line).
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.
Ah, okay. I misread the code. My suggestion for a cleanup would be to structure this explicitly as a state machine, with an enum setting out explicitly what the states are, and a big comment explaining what/when the transitions are.
That might also make testing this code easier. I think I see below that the error paths in here could use some coverage.
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.
Added an enum, hopefully it's clearer now.
| _logger.printTrace('ios-deploy exited with code $exitCode'); | ||
| _debuggerAttached = false; | ||
| unawaited(stdoutSubscription.cancel()); | ||
| unawaited(stderrSubscription.cancel()); |
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.
Does ios-deploy have anything interesting on its stderr when it exits with an error?
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.
Some stuff:
https://github.com/ios-control/ios-deploy/blob/master/src/ios-deploy/ios-deploy.m#L1741
Though nothing that's probably actionable to the developer. It's being printTraced a few lines above this.
https://github.com/flutter/flutter/pull/66092/files/e91e25e01ffa596f7e60c861b435a9c672a9a29e#diff-8d108d6a887a4f5b74f7c7d77003e795R326
They seem to put actionable errors to stdout (see _monitorIOSDeployFailure parsing below, which existed before this PR).
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.
Added _monitorIOSDeployFailure to the stderr processing in case they move how that's output. Will add a test.
| debuggerCompleter.complete(false); | ||
| return; | ||
| } | ||
| if (!debuggerAttached) { |
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.
Ah, okay. I misread the code. My suggestion for a cleanup would be to structure this explicitly as a state machine, with an enum setting out explicitly what the states are, and a big comment explaining what/when the transitions are.
That might also make testing this code easier. I think I see below that the error paths in here could use some coverage.
| final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[ | ||
| const FakeCommand( | ||
| command: <String>['ios-deploy'], | ||
| stdout: '(lldb) run\r\nsuccess\r\nLog on attach1\r\n\r\nLog on attach2\r\n\r\n\r\n\r\nPROCESS_STOPPED\r\nLog after process exit', |
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.
Test failure modes on unexpected stdout.
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.
Done.
jonahwilliams
left a comment
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.
LGTM if LG to @zanderso
It's still used in the However it will allow us to remove the mDNS permission for |
zanderso
left a comment
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.
lgtm
|
Merging on red, hopefully this will deflake things (after a few reverts no doubt) |
This reverts commit 5c85803.
Description
As of iOS 13, the host can't directly read the device logs from the host. #43915 connected to the VM observatory and read the log lines from the logging services.
On
flutter runandflutter drive(notattachin this PR), instead of waiting to attach to the observatory, instead launch the app with the debugger and stay attached to stream in the logs fromlldb. See #54781 (comment) for details. This should also reduce devicelab flakes.This will give the tool access to:
print()stderr.writeln, other I/O sinksos_log,assertsetc)Notes
flutter attach. A follow up PR could attach the debugger in that scenario as well (without re-launching), and then the VM connection can be removed.idevicesyslog.Related Issues
Fixes #44717
Fixes #44718
Fixes #54781
#39240 (fixes
run/drive, notattach)#58078 (fixes
run/drive, notattach)Mitigate #46705 (
run/drive, notattach)Will allow us to turn off mDNS fallback for
driveon CI to solve iOS 14 issue #65207Note to self: check if this fixes #19196
Tests
Follow up with logging integration tests so this stops regressing.
Also, manually tested:
ios-deployprocesses aren't leakingChecklist
///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change