Noninteractive iOS debugger session (#68145)
This commit is contained in:
@@ -468,12 +468,10 @@ class IOSDevice extends Device {
|
||||
packageName: FlutterProject.current().manifest.appName,
|
||||
);
|
||||
if (localUri == null) {
|
||||
iosDeployDebugger?.detach();
|
||||
return LaunchResult.failed();
|
||||
}
|
||||
return LaunchResult.succeeded(observatoryUri: localUri);
|
||||
} on ProcessException catch (e) {
|
||||
iosDeployDebugger?.detach();
|
||||
_logger.printError(e.message);
|
||||
return LaunchResult.failed();
|
||||
} finally {
|
||||
@@ -486,12 +484,7 @@ class IOSDevice extends Device {
|
||||
IOSApp app, {
|
||||
String userIdentifier,
|
||||
}) async {
|
||||
// If the debugger is not attached, killing the ios-deploy process won't stop the app.
|
||||
if (iosDeployDebugger!= null && iosDeployDebugger.debuggerAttached) {
|
||||
// Avoid null.
|
||||
return iosDeployDebugger?.exit() == true;
|
||||
}
|
||||
return false;
|
||||
return iosDeployDebugger?.exit();
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -723,8 +716,8 @@ class IOSDeviceLogReader extends DeviceLogReader {
|
||||
}
|
||||
|
||||
void logMessage(vm_service.Event event) {
|
||||
if (_iosDeployDebugger != null && _iosDeployDebugger.debuggerAttached) {
|
||||
// Prefer the more complete logs from the attached debugger.
|
||||
if (_iosDeployDebugger != null) {
|
||||
// Prefer the more complete logs from the debugger.
|
||||
return;
|
||||
}
|
||||
final String message = processVmServiceMessage(event);
|
||||
@@ -739,7 +732,7 @@ class IOSDeviceLogReader extends DeviceLogReader {
|
||||
]);
|
||||
}
|
||||
|
||||
/// Log reader will listen to [debugger.logLines] and will detach debugger on dispose.
|
||||
/// Log reader will listen to [debugger.logLines].
|
||||
set debuggerStream(IOSDeployDebugger debugger) {
|
||||
// Logging is gathered from syslog on iOS 13 and earlier.
|
||||
if (_majorSdkVersion < minimumUniversalLoggingSdkVersion) {
|
||||
@@ -818,7 +811,6 @@ class IOSDeviceLogReader extends DeviceLogReader {
|
||||
loggingSubscription.cancel();
|
||||
}
|
||||
_idevicesyslogProcess?.kill();
|
||||
_iosDeployDebugger?.detach();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -118,14 +118,13 @@ class IOSDeploy {
|
||||
/// Returns [IOSDeployDebugger] wrapping attached debugger logic.
|
||||
///
|
||||
/// This method does not install the app. Call [IOSDeployDebugger.launchAndAttach()]
|
||||
/// to install and attach the debugger to the specified app bundle.
|
||||
/// to install the specified app bundle.
|
||||
IOSDeployDebugger prepareDebuggerForLaunch({
|
||||
@required String deviceId,
|
||||
@required String bundlePath,
|
||||
@required List<String> launchArguments,
|
||||
@required IOSDeviceInterface interfaceType,
|
||||
}) {
|
||||
// Interactive debug session to support sending the lldb detach command.
|
||||
final List<String> launchCommand = <String>[
|
||||
'script',
|
||||
'-t',
|
||||
@@ -137,6 +136,7 @@ class IOSDeploy {
|
||||
'--bundle',
|
||||
bundlePath,
|
||||
'--debug',
|
||||
'--noninteractive',
|
||||
if (interfaceType != IOSDeviceInterface.network)
|
||||
'--no-wifi',
|
||||
if (launchArguments.isNotEmpty) ...<String>[
|
||||
@@ -224,7 +224,7 @@ enum _IOSDeployDebuggerState {
|
||||
attached,
|
||||
}
|
||||
|
||||
/// Wrapper to launch app and attach the debugger with ios-deploy.
|
||||
/// Wrapper to launch app with the debugger with ios-deploy.
|
||||
class IOSDeployDebugger {
|
||||
IOSDeployDebugger({
|
||||
@required Logger logger,
|
||||
@@ -264,15 +264,16 @@ class IOSDeployDebugger {
|
||||
Stream<String> get logLines => _debuggerOutput.stream;
|
||||
final StreamController<String> _debuggerOutput = StreamController<String>.broadcast();
|
||||
|
||||
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) run
|
||||
// https://github.com/ios-control/ios-deploy/blob/1.11.2-beta.1/src/ios-deploy/ios-deploy.m#L51
|
||||
// (lldb) autoexit
|
||||
// hhttps://github.com/ios-control/ios-deploy/blob/1.11.2-beta.1/src/ios-deploy/ios-deploy.m#L61
|
||||
static final RegExp _lldbAutoexit = RegExp(r'\(lldb\)\s*autoexit');
|
||||
|
||||
// From lldb on exit.
|
||||
static final RegExp _lldbProcessExit = RegExp(r'Process \d* exited with status =');
|
||||
|
||||
/// Launch the app on the device, and attach the debugger.
|
||||
@@ -295,6 +296,7 @@ class IOSDeployDebugger {
|
||||
|
||||
// (lldb) run
|
||||
// success
|
||||
// (lldb) autoexit
|
||||
// 2020-09-15 13:42:25.185474-0700 Runner[477:181141] flutter: Observatory listening on http://127.0.0.1:57782/
|
||||
if (_lldbRun.hasMatch(line)) {
|
||||
_logger.printTrace(line);
|
||||
@@ -324,7 +326,7 @@ class IOSDeployDebugger {
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (_debuggerState != _IOSDeployDebuggerState.attached) {
|
||||
if (_debuggerState != _IOSDeployDebuggerState.attached || _lldbAutoexit.hasMatch(line)) {
|
||||
_logger.printTrace(line);
|
||||
return;
|
||||
}
|
||||
@@ -378,21 +380,6 @@ class IOSDeployDebugger {
|
||||
_iosDeployProcess = null;
|
||||
return success;
|
||||
}
|
||||
|
||||
void detach() {
|
||||
if (!debuggerAttached) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
// Detach lldb from the app process.
|
||||
_iosDeployProcess?.stdin?.writeln('process detach');
|
||||
_debuggerState = _IOSDeployDebuggerState.detached;
|
||||
} on SocketException catch (error) {
|
||||
// Best effort, try to detach, but maybe the app already exited or already detached.
|
||||
_logger.printTrace('Could not detach from debugger: $error');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Maps stdout line stream. Must return original line.
|
||||
|
||||
Reference in New Issue
Block a user