Unverified Commit 832d776b authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Stop debugger when iOS app crashes (#68844)

parent f3562c6f
......@@ -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) {
......
......@@ -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, <String>['Log on attach']);
expect(receivedLogLines, <String>[
'Log on attach',
'Log after process exit',
]);
});
testWithoutContext('app crash', () async {
final FakeProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['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<String> receivedLogLines = <String>[];
final Stream<String> logLines = iosDeployDebugger.logLines
..listen(receivedLogLines.add);
expect(await iosDeployDebugger.launchAndAttach(), isTrue);
await logLines.toList();
expect(receivedLogLines, <String>[
'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(<FakeCommand>[
const FakeCommand(
command: <String>['ios-deploy'],
......
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