From 832d776b1562dbae76b56d55087d07057f99971b Mon Sep 17 00:00:00 2001 From: Jenn Magder Date: Fri, 23 Oct 2020 14:12:04 -0700 Subject: [PATCH] Stop debugger when iOS app crashes (#68844) --- .../flutter_tools/lib/src/ios/ios_deploy.dart | 15 ++++---- .../general.shard/ios/ios_deploy_test.dart | 36 +++++++++++++++++-- 2 files changed, 41 insertions(+), 10 deletions(-) diff --git a/packages/flutter_tools/lib/src/ios/ios_deploy.dart b/packages/flutter_tools/lib/src/ios/ios_deploy.dart index 8db8b6563d..5e492eaf88 100644 --- a/packages/flutter_tools/lib/src/ios/ios_deploy.dart +++ b/packages/flutter_tools/lib/src/ios/ios_deploy.dart @@ -272,6 +272,9 @@ class IOSDeployDebugger { // https://github.com/ios-control/ios-deploy/blob/1.11.2-beta.1/src/ios-deploy/ios-deploy.m#L51 static final RegExp _lldbProcessExit = RegExp(r'Process \d* exited with status ='); + // (lldb) Process 6152 stopped + static final RegExp _lldbProcessStopped = RegExp(r'Process \d* stopped'); + /// Launch the app on the device, and attach the debugger. /// /// Returns whether or not the debugger successfully attached. @@ -311,14 +314,12 @@ class IOSDeployDebugger { } if (line.contains('PROCESS_STOPPED') || line.contains('PROCESS_EXITED') || - _lldbProcessExit.hasMatch(line)) { - // The app exited or crashed, so stop echoing the output. - // Don't pass any further ios-deploy debugging messages to the log reader after it exits. - _debuggerState = _IOSDeployDebuggerState.detached; + _lldbProcessExit.hasMatch(line) || + _lldbProcessStopped.hasMatch(line)) { + // The app exited or crashed, so exit. Continue passing debugging + // messages to the log reader until it exits to capture crash dumps. _logger.printTrace(line); - if (!debuggerCompleter.isCompleted) { - debuggerCompleter.complete(false); - } + exit(); return; } if (_debuggerState != _IOSDeployDebuggerState.attached) { 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 6449061ae6..38db1f055e 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 @@ -104,7 +104,10 @@ void main () { 'success', // ignore first "success" from lldb, but log subsequent ones from real logging. 'Log on attach1', 'Log on attach2', - '', '']); + '', + '', + 'Log after process exit', + ]); }); testWithoutContext('app exit', () async { @@ -124,7 +127,34 @@ void main () { expect(await iosDeployDebugger.launchAndAttach(), isTrue); await logLines.toList(); - expect(receivedLogLines, ['Log on attach']); + expect(receivedLogLines, [ + 'Log on attach', + 'Log after process exit', + ]); + }); + + testWithoutContext('app crash', () async { + final FakeProcessManager processManager = FakeProcessManager.list([ + const FakeCommand( + command: ['ios-deploy'], + stdout: + '(lldb) run\r\nsuccess\r\nLog on attach\r\n(lldb) Process 6156 stopped\r\n* thread #1, stop reason = Assertion failed:', + ), + ]); + final IOSDeployDebugger iosDeployDebugger = IOSDeployDebugger.test( + processManager: processManager, + logger: logger, + ); + final List receivedLogLines = []; + final Stream logLines = iosDeployDebugger.logLines + ..listen(receivedLogLines.add); + + expect(await iosDeployDebugger.launchAndAttach(), isTrue); + await logLines.toList(); + expect(receivedLogLines, [ + 'Log on attach', + '* thread #1, stop reason = Assertion failed:', + ]); }); testWithoutContext('attach failed', () async { @@ -196,7 +226,7 @@ void main () { expect(logger.errorText, contains('Your device is locked.')); }); - testWithoutContext('device locked', () async { + testWithoutContext('unknown app launch error', () async { final FakeProcessManager processManager = FakeProcessManager.list([ const FakeCommand( command: ['ios-deploy'],