diff --git a/packages/flutter_tools/lib/src/ios/ios_deploy.dart b/packages/flutter_tools/lib/src/ios/ios_deploy.dart index 1d9a1a55ff..228823d898 100644 --- a/packages/flutter_tools/lib/src/ios/ios_deploy.dart +++ b/packages/flutter_tools/lib/src/ios/ios_deploy.dart @@ -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 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 debuggerCompleter = Completer(); try { _iosDeployProcess = await _processUtils.start( @@ -336,10 +342,30 @@ class IOSDeployDebugger { .transform(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; diff --git a/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart b/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart index 855ea5029a..bd9dd9c761 100644 --- a/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart +++ b/packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart @@ -93,6 +93,22 @@ void main () { logger = BufferLogger.test(); }); + testWithoutContext('custom lldb prompt', () async { + final StreamController> stdin = StreamController>(); + final FakeProcessManager processManager = FakeProcessManager.list([ + FakeCommand( + command: const ['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> stdin = StreamController>(); final FakeProcessManager processManager = FakeProcessManager.list([