Unverified Commit ec524ed0 authored by 林洵锋's avatar 林洵锋 Committed by GitHub

Fix flutter_tools stuck when using custom LLDB prompt (#119443)

* Fix flutter_tools stuck when using custom LLDB prompt

* Remove trailing space character

* Fix local variable name

* Add comment

* Remove trailing space character

* Update packages/flutter_tools/lib/src/ios/ios_deploy.dart
Co-authored-by: 's avatarJenn Magder <magder@google.com>

* Update packages/flutter_tools/lib/src/ios/ios_deploy.dart
Co-authored-by: 's avatarJenn Magder <magder@google.com>

* Remove trailing space character

---------
Co-authored-by: 's avatarJenn Magder <magder@google.com>
parent 40b5e4cb
......@@ -288,9 +288,10 @@ class IOSDeployDebugger {
bool get debuggerAttached => _debuggerState == _IOSDeployDebuggerState.attached;
_IOSDeployDebuggerState _debuggerState;
// (lldb) run
// https://github.com/ios-control/ios-deploy/blob/1.11.2-beta.1/src/ios-deploy/ios-deploy.m#L51
static final RegExp _lldbRun = RegExp(r'\(lldb\)\s*run');
// (lldb) platform select remote-'ios' --sysroot
// https://github.com/ios-control/ios-deploy/blob/1.11.2-beta.1/src/ios-deploy/ios-deploy.m#L33
// This regex is to get the configurable lldb prompt. By default this prompt will be "lldb".
static final RegExp _lldbPlatformSelect = RegExp(r"\s*platform select remote-'ios' --sysroot");
// (lldb) run
// https://github.com/ios-control/ios-deploy/blob/1.11.2-beta.1/src/ios-deploy/ios-deploy.m#L51
......@@ -324,6 +325,11 @@ class IOSDeployDebugger {
/// Returns whether or not the debugger successfully attached.
Future<bool> launchAndAttach() async {
// Return when the debugger attaches, or the ios-deploy process exits.
// (lldb) run
// https://github.com/ios-control/ios-deploy/blob/1.11.2-beta.1/src/ios-deploy/ios-deploy.m#L51
RegExp lldbRun = RegExp(r'\(lldb\)\s*run');
final Completer<bool> debuggerCompleter = Completer<bool>();
try {
_iosDeployProcess = await _processUtils.start(
......@@ -336,10 +342,30 @@ class IOSDeployDebugger {
.transform<String>(const LineSplitter())
.listen((String line) {
_monitorIOSDeployFailure(line, _logger);
// (lldb) platform select remote-'ios' --sysroot
// Use the configurable custom lldb prompt in the regex. The developer can set this prompt to anything.
// For example `settings set prompt "(mylldb)"` in ~/.lldbinit results in:
// "(mylldb) platform select remote-'ios' --sysroot"
if (_lldbPlatformSelect.hasMatch(line)) {
final String platformSelect = _lldbPlatformSelect.stringMatch(line) ?? '';
if (platformSelect.isEmpty) {
return;
}
final int promptEndIndex = line.indexOf(platformSelect);
if (promptEndIndex == -1) {
return;
}
final String prompt = line.substring(0, promptEndIndex);
lldbRun = RegExp(RegExp.escape(prompt) + r'\s*run');
_logger.printTrace(line);
return;
}
// (lldb) run
// success
// 2020-09-15 13:42:25.185474-0700 Runner[477:181141] flutter: The Dart VM service is listening on http://127.0.0.1:57782/
if (_lldbRun.hasMatch(line)) {
if (lldbRun.hasMatch(line)) {
_logger.printTrace(line);
_debuggerState = _IOSDeployDebuggerState.launching;
return;
......
......@@ -93,6 +93,22 @@ void main () {
logger = BufferLogger.test();
});
testWithoutContext('custom lldb prompt', () async {
final StreamController<List<int>> stdin = StreamController<List<int>>();
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
FakeCommand(
command: const <String>['ios-deploy'],
stdout: "(mylldb) platform select remote-'ios' --sysroot\r\n(mylldb) run\r\nsuccess\r\n",
stdin: IOSink(stdin.sink),
),
]);
final IOSDeployDebugger iosDeployDebugger = IOSDeployDebugger.test(
processManager: processManager,
logger: logger,
);
expect(await iosDeployDebugger.launchAndAttach(), isTrue);
});
testWithoutContext('debugger attached and stopped', () async {
final StreamController<List<int>> stdin = StreamController<List<int>>();
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment