Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit ec524ed

Browse files
LinXunFengjmagman
andauthored
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: Jenn Magder <[email protected]> * Update packages/flutter_tools/lib/src/ios/ios_deploy.dart Co-authored-by: Jenn Magder <[email protected]> * Remove trailing space character --------- Co-authored-by: Jenn Magder <[email protected]>
1 parent 40b5e4c commit ec524ed

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

packages/flutter_tools/lib/src/ios/ios_deploy.dart

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,10 @@ class IOSDeployDebugger {
288288
bool get debuggerAttached => _debuggerState == _IOSDeployDebuggerState.attached;
289289
_IOSDeployDebuggerState _debuggerState;
290290

291-
// (lldb) run
292-
// https://github.com/ios-control/ios-deploy/blob/1.11.2-beta.1/src/ios-deploy/ios-deploy.m#L51
293-
static final RegExp _lldbRun = RegExp(r'\(lldb\)\s*run');
291+
// (lldb) platform select remote-'ios' --sysroot
292+
// https://github.com/ios-control/ios-deploy/blob/1.11.2-beta.1/src/ios-deploy/ios-deploy.m#L33
293+
// This regex is to get the configurable lldb prompt. By default this prompt will be "lldb".
294+
static final RegExp _lldbPlatformSelect = RegExp(r"\s*platform select remote-'ios' --sysroot");
294295

295296
// (lldb) run
296297
// 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 {
324325
/// Returns whether or not the debugger successfully attached.
325326
Future<bool> launchAndAttach() async {
326327
// Return when the debugger attaches, or the ios-deploy process exits.
328+
329+
// (lldb) run
330+
// https://github.com/ios-control/ios-deploy/blob/1.11.2-beta.1/src/ios-deploy/ios-deploy.m#L51
331+
RegExp lldbRun = RegExp(r'\(lldb\)\s*run');
332+
327333
final Completer<bool> debuggerCompleter = Completer<bool>();
328334
try {
329335
_iosDeployProcess = await _processUtils.start(
@@ -336,10 +342,30 @@ class IOSDeployDebugger {
336342
.transform<String>(const LineSplitter())
337343
.listen((String line) {
338344
_monitorIOSDeployFailure(line, _logger);
345+
346+
// (lldb) platform select remote-'ios' --sysroot
347+
// Use the configurable custom lldb prompt in the regex. The developer can set this prompt to anything.
348+
// For example `settings set prompt "(mylldb)"` in ~/.lldbinit results in:
349+
// "(mylldb) platform select remote-'ios' --sysroot"
350+
if (_lldbPlatformSelect.hasMatch(line)) {
351+
final String platformSelect = _lldbPlatformSelect.stringMatch(line) ?? '';
352+
if (platformSelect.isEmpty) {
353+
return;
354+
}
355+
final int promptEndIndex = line.indexOf(platformSelect);
356+
if (promptEndIndex == -1) {
357+
return;
358+
}
359+
final String prompt = line.substring(0, promptEndIndex);
360+
lldbRun = RegExp(RegExp.escape(prompt) + r'\s*run');
361+
_logger.printTrace(line);
362+
return;
363+
}
364+
339365
// (lldb) run
340366
// success
341367
// 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/
342-
if (_lldbRun.hasMatch(line)) {
368+
if (lldbRun.hasMatch(line)) {
343369
_logger.printTrace(line);
344370
_debuggerState = _IOSDeployDebuggerState.launching;
345371
return;

packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,22 @@ void main () {
9393
logger = BufferLogger.test();
9494
});
9595

96+
testWithoutContext('custom lldb prompt', () async {
97+
final StreamController<List<int>> stdin = StreamController<List<int>>();
98+
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
99+
FakeCommand(
100+
command: const <String>['ios-deploy'],
101+
stdout: "(mylldb) platform select remote-'ios' --sysroot\r\n(mylldb) run\r\nsuccess\r\n",
102+
stdin: IOSink(stdin.sink),
103+
),
104+
]);
105+
final IOSDeployDebugger iosDeployDebugger = IOSDeployDebugger.test(
106+
processManager: processManager,
107+
logger: logger,
108+
);
109+
expect(await iosDeployDebugger.launchAndAttach(), isTrue);
110+
});
111+
96112
testWithoutContext('debugger attached and stopped', () async {
97113
final StreamController<List<int>> stdin = StreamController<List<int>>();
98114
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[

0 commit comments

Comments
 (0)