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

Commit

Permalink
Fix flutter_tools stuck when using custom LLDB prompt (#119443)
Browse files Browse the repository at this point in the history
* 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 <magder@google.com>

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

Co-authored-by: Jenn Magder <magder@google.com>

* Remove trailing space character

---------

Co-authored-by: Jenn Magder <magder@google.com>
  • Loading branch information
LinXunFeng and jmagman committed Feb 6, 2023
1 parent 40b5e4c commit ec524ed
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
34 changes: 30 additions & 4 deletions packages/flutter_tools/lib/src/ios/ios_deploy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand All @@ -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;
Expand Down
16 changes: 16 additions & 0 deletions packages/flutter_tools/test/general.shard/ios/ios_deploy_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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>[
Expand Down

0 comments on commit ec524ed

Please sign in to comment.