Repository navigation
fix(ios): keep debug-brk apps alive on devices with a native debugger #6183
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
Open
rigor789
wants to merge
3
commits into
main
Choose a base branch
from
fix/ios-debug-brk-device
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
lib/common/test/unit-tests/mobile/ios-application-manager.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| import { assert } from "chai"; | ||
| import { EventEmitter } from "events"; | ||
| import { IOSApplicationManager } from "../../../mobile/ios/device/ios-application-manager"; | ||
|
|
||
| describe("IOSApplicationManager native debugger", () => { | ||
| const deviceId = "device"; | ||
| const appData = { appId: "org.app", projectName: "app", projectDir: "/app" }; | ||
|
|
||
| const setup = (pid?: number) => { | ||
| const lldbInput: string[] = []; | ||
| const lldbOutput = new EventEmitter(); | ||
| const spawned: string[][] = []; | ||
| const manager = new (<any>IOSApplicationManager)( | ||
| { trace: () => {}, info: () => {} }, | ||
| {}, | ||
| { | ||
| deviceInfo: { identifier: deviceId }, | ||
| destroyDebugSocket: async () => {}, | ||
| }, | ||
| {}, | ||
| {}, | ||
| { | ||
| start: async () => ({ [deviceId]: [{ deviceId, pid }] }), | ||
| stop: async () => ({}), | ||
| apps: async () => ({}), | ||
| }, | ||
| { justlaunch: true }, | ||
| new Proxy({}, { get: () => () => {} }), | ||
| { | ||
| spawn: (command: string, args: string[]) => { | ||
| spawned.push([command, ...args]); | ||
| return { | ||
| on: () => {}, | ||
| stdout: lldbOutput, | ||
| stdin: { | ||
| write: (text: string) => lldbInput.push(text), | ||
| end: () => {}, | ||
| }, | ||
| }; | ||
| }, | ||
| }, | ||
| ); | ||
| return { manager, lldbInput, lldbOutput, spawned }; | ||
| }; | ||
|
|
||
| it("attaches lldb to an app that waits for the JS debugger", async () => { | ||
| const { manager, lldbInput, spawned } = setup(42); | ||
|
|
||
| await manager.restartApplication({ ...appData, waitForDebugger: true }); | ||
|
|
||
| assert.deepEqual(spawned, [["xcrun", "lldb"]]); | ||
| assert.include(lldbInput[0], `device select ${deviceId}`); | ||
| assert.include(lldbInput[0], "device process attach -p 42"); | ||
| }); | ||
|
|
||
| it("continues the app once, after the attach stopped it", async () => { | ||
| const { manager, lldbInput, lldbOutput } = setup(42); | ||
|
|
||
| await manager.restartApplication({ ...appData, waitForDebugger: true }); | ||
| assert.lengthOf(lldbInput, 1); | ||
|
|
||
| lldbOutput.emit("data", Buffer.from("Process 42 sto")); | ||
| assert.lengthOf(lldbInput, 1); | ||
| lldbOutput.emit("data", Buffer.from("pped\n")); | ||
| lldbOutput.emit("data", Buffer.from("Process 42 stopped\n")); | ||
|
|
||
| assert.deepEqual(lldbInput.slice(1), ["process continue\n"]); | ||
| }); | ||
|
|
||
| it("doesn't attach to an app that doesn't wait", async () => { | ||
| const { manager, spawned } = setup(42); | ||
|
|
||
| await manager.restartApplication(appData); | ||
|
|
||
| assert.deepEqual(spawned, []); | ||
| }); | ||
|
|
||
| it("doesn't attach without a process id", async () => { | ||
| const { manager, spawned } = setup(-1); | ||
|
|
||
| await manager.restartApplication({ ...appData, waitForDebugger: true }); | ||
|
|
||
| assert.deepEqual(spawned, []); | ||
| }); | ||
|
|
||
| it("detaches when the app stops", async () => { | ||
| const { manager, lldbInput } = setup(42); | ||
|
|
||
| await manager.restartApplication({ ...appData, waitForDebugger: true }); | ||
| await manager.stopApplication(appData); | ||
|
|
||
| assert.include(lldbInput[lldbInput.length - 1], "process detach"); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import * as assert from "assert"; | ||
| import { IOSDeviceLiveSyncService } from "../../../lib/services/livesync/ios-device-livesync-service"; | ||
|
|
||
| describe("IOSDeviceLiveSyncService", () => { | ||
| const projectData: any = { | ||
| projectName: "app", | ||
| projectDir: "/app", | ||
| projectIdentifiers: { ios: "org.app" }, | ||
| }; | ||
|
|
||
| const restart = async (waitForDebugger: boolean) => { | ||
| const calls: string[] = []; | ||
| const ensureAppStartedValues: boolean[] = []; | ||
| const device: any = { | ||
| applicationManager: { | ||
| restartApplication: async () => { | ||
| calls.push("restart"); | ||
| }, | ||
| }, | ||
| getDebugSocket: async ( | ||
| _appId: string, | ||
| _projectName: string, | ||
| _projectDir: string, | ||
| ensureAppStarted: boolean | ||
| ) => { | ||
| calls.push("socket"); | ||
| ensureAppStartedValues.push(ensureAppStarted); | ||
| return { on: () => {}, removeAllListeners: () => {} }; | ||
| }, | ||
| }; | ||
| const service = new (<any>IOSDeviceLiveSyncService)( | ||
| { trace: () => {} }, | ||
| {}, | ||
| {}, | ||
| {}, | ||
| {}, | ||
| {}, | ||
| device | ||
| ); | ||
|
|
||
| await service.restartApplication(projectData, { | ||
| deviceAppData: { appIdentifier: "org.app" }, | ||
| useHotModuleReload: true, | ||
| waitForDebugger, | ||
| }); | ||
|
|
||
| return { calls, ensureAppStartedValues }; | ||
| }; | ||
|
|
||
| it("connects to the app it restarted without starting it again", async () => { | ||
| const { calls, ensureAppStartedValues } = await restart(false); | ||
|
|
||
| assert.deepStrictEqual(calls, ["restart", "socket"]); | ||
| assert.deepStrictEqual(ensureAppStartedValues, [false]); | ||
| }); | ||
|
|
||
| it("keeps an instance that waits for a debugger", async () => { | ||
| const { calls, ensureAppStartedValues } = await restart(true); | ||
|
|
||
| assert.deepStrictEqual(calls, ["restart", "socket"]); | ||
| assert.deepStrictEqual(ensureAppStartedValues, [false]); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Detach commands can fail silently after lldb exits.
If the lldb process already exited,
lldb.stdin.writecan emit anEPIPEerror on the stdin stream. This code attaches noerrorlistener tolldb.stdin. An unhandled streamerrorevent can crash the CLI. This is reachable whenxcrunis missing or lldb exits early.stopApplicationis called on every restart, so the crash can happen in a normal flow. The same applies to the writes inattachNativeDebugger. Add anerrorhandler onlldb.stdinwhen spawning.Proposed fix
lldb.on("error", (err: Error) => { this.$logger.trace("Unable to attach lldb to the application", err); }); + lldb.stdin?.on("error", (err: Error) => { + this.$logger.trace("Unable to write to lldb", err); + });