Skip to content

fix(debug): debug-brk option does not work for iOS Simulator #3340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/common
50 changes: 25 additions & 25 deletions lib/services/ios-debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
private $iOSNotification: IiOSNotification,
private $iOSSocketRequestExecutor: IiOSSocketRequestExecutor,
private $processService: IProcessService,
private $socketProxyFactory: ISocketProxyFactory) {
private $socketProxyFactory: ISocketProxyFactory,
private $net: INet) {
super(device, $devicesService);
this.$processService.attachToProcessExitSignals(this, this.debugStop);
this.$socketProxyFactory.on(CONNECTION_ERROR_EVENT_NAME, (e: Error) => this.emit(CONNECTION_ERROR_EVENT_NAME, e));
Expand Down Expand Up @@ -125,29 +126,28 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS
const lineStream = byline(child_process.stdout);
this._childProcess = child_process;

await new Promise((resolve: () => void, reject) => {
lineStream.on('data', (line: NodeBuffer) => {
const lineText = line.toString();
if (lineText && _.startsWith(lineText, debugData.applicationIdentifier)) {
const pid = getPidFromiOSSimulatorLogs(debugData.applicationIdentifier, lineText);
if (!pid) {
this.$logger.trace(`Line ${lineText} does not contain PID of the application ${debugData.applicationIdentifier}.`);
return;
}

this._lldbProcess = this.$childProcess.spawn("lldb", ["-p", pid]);
if (log4js.levels.TRACE.isGreaterThanOrEqualTo(this.$logger.getLevel())) {
this._lldbProcess.stdout.pipe(process.stdout);
}
this._lldbProcess.stderr.pipe(process.stderr);
this._lldbProcess.stdin.write("process continue\n");
this.connectToApplicationOnEmulator(debugData.deviceIdentifier).then(resolve, reject);
} else {
process.stdout.write(line + "\n");
lineStream.on('data', (line: NodeBuffer) => {
const lineText = line.toString();
if (lineText && _.startsWith(lineText, debugData.applicationIdentifier)) {
const pid = getPidFromiOSSimulatorLogs(debugData.applicationIdentifier, lineText);
if (!pid) {
this.$logger.trace(`Line ${lineText} does not contain PID of the application ${debugData.applicationIdentifier}.`);
return;
}
});

this._lldbProcess = this.$childProcess.spawn("lldb", ["-p", pid]);
if (log4js.levels.TRACE.isGreaterThanOrEqualTo(this.$logger.getLevel())) {
this._lldbProcess.stdout.pipe(process.stdout);
}
this._lldbProcess.stderr.pipe(process.stderr);
this._lldbProcess.stdin.write("process continue\n");
} else {
process.stdout.write(line + "\n");
}
});

await this.waitForBackendPortToBeOpened(debugData.deviceIdentifier);

return this.wireDebuggerClient(debugData, debugOptions);
}

Expand All @@ -158,13 +158,13 @@ export class IOSDebugService extends DebugServiceBase implements IPlatformDebugS

const iOSEmulatorService = <Mobile.IiOSSimulatorService>this.$iOSEmulatorServices;
await iOSEmulatorService.postDarwinNotification(attachRequestMessage);
await this.connectToApplicationOnEmulator(debugData.deviceIdentifier);
await this.waitForBackendPortToBeOpened(debugData.deviceIdentifier);
return result;
}

private async connectToApplicationOnEmulator(deviceIdentifier: string): Promise<void> {
const socket = await this.$iOSEmulatorServices.connectToPort({ port: inspectorBackendPort });
if (!socket) {
private async waitForBackendPortToBeOpened(deviceIdentifier: string): Promise<void> {
const portListens = await this.$net.waitForPortToListen({ port: inspectorBackendPort, timeout: 10000, interval: 200 });
if (!portListens) {
const error = <Mobile.IDeviceError>new Error("Unable to connect to application. Ensure application is running on simulator.");
error.deviceIdentifier = deviceIdentifier;
throw error;
Expand Down
8 changes: 5 additions & 3 deletions test/services/ios-debug-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class IOSDebugServiceInheritor extends IOSDebugService {
$iOSNotification: IiOSNotification,
$iOSSocketRequestExecutor: IiOSSocketRequestExecutor,
$processService: IProcessService,
$socketProxyFactory: ISocketProxyFactory) {
$socketProxyFactory: ISocketProxyFactory,
$net: INet) {
super(<any>{}, $devicesService, $platformService, $iOSEmulatorServices, $childProcess, $hostInfo, $logger, $errors,
$npmInstallationManager, $iOSNotification, $iOSSocketRequestExecutor, $processService, $socketProxyFactory);
$npmInstallationManager, $iOSNotification, $iOSSocketRequestExecutor, $processService, $socketProxyFactory, $net);
}

public getChromeDebugUrl(debugOptions: IDebugOptions, port: number): string {
Expand Down Expand Up @@ -49,7 +50,8 @@ const createTestInjector = (): IInjector => {
});

testInjector.register("net", {
getAvailablePortInRange: async (startPort: number, endPort?: number): Promise<number> => 41000
getAvailablePortInRange: async (startPort: number, endPort?: number): Promise<number> => 41000,
waitForPortToListen: async (opts: { port: number, timeout: number, interval?: number }): Promise<boolean> => true
});

return testInjector;
Expand Down