Skip to content

Conversation

Copy link

Copilot AI commented Aug 20, 2025

Fixes issue #114 where the debugger would terminate immediately after app launch when debugging iOS applications on physical devices, despite successful app installation and launch.

Problem

When using the "debugging-launch" task to debug iOS apps on physical devices, users experienced:

  • App builds and installs successfully on device
  • App launches correctly on device
  • LLDB attaches to process but immediately shows "Process exited with code -1"
  • Debug adapter exits, preventing any debugging

The same workflow worked perfectly on iOS Simulator, indicating a device-specific issue.

Root Cause

The issue was caused by the --console flag in the devicectl device process launch command. When this flag is used:

  • devicectl attaches to the application console and waits for it to exit
  • This causes the process to complete immediately after launching
  • The debugger cannot attach to a process that has already exited
// Previous code - always used --console when available
const launchArgs = [
  "devicectl", "device", "process", "launch",
  isConsoleOptionSupported ? "--console" : null,  // This caused the issue
  "--json-output", jsonPath,
  "--terminate-existing",
  "--device", deviceId,
  bundleId
].filter(arg => arg !== null);

Solution

Modified the device launch logic to conditionally exclude the --console flag when launching in debug mode:

// New code - excludes --console in debug mode
const launchArgs = [
  "devicectl", "device", "process", "launch", 
  isConsoleOptionSupported && !option.debug ? "--console" : null,  // Fixed
  "--json-output", jsonPath,
  "--terminate-existing", 
  "--device", deviceId,
  bundleId
].filter(arg => arg !== null);

Changes Made

  1. Added debug parameter: Added optional debug?: boolean to runOniOSDevice() function signature
  2. Updated launch logic: Modified devicectl arguments to exclude --console when debug=true
  3. Propagated debug flag: Updated all callers in provider.ts and commands.ts to pass the debug flag
  4. Added comprehensive tests: Unit tests validate the console flag handling logic

Behavior After Fix

  • Debug mode (debugging-launch task): Launches without --console, keeping process alive for debugger attachment
  • Normal mode (launch task): Uses --console as before for console output capture
  • Legacy Xcode (< v16): Maintains existing behavior since --console wasn't supported

Testing

Added unit tests covering:

  • Console flag excluded when debug=true
  • Console flag included when debug=false
  • Backward compatibility with older Xcode versions
  • Proper null argument filtering

All tests pass, TypeScript compilation successful, no linting issues.

Impact

  • ✅ Fixes device debugging for iOS physical devices
  • ✅ Preserves existing functionality for non-debug launches
  • ✅ Maintains backward compatibility
  • ✅ No breaking changes to public APIs

Closes #114


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Add debug parameter to runOniOSDevice function
- Modify devicectl launch arguments to exclude --console when debug=true
- Update all runOniOSDevice calls to pass debug flag from options
- Fix issue where --console flag caused process to exit immediately preventing debugger attachment

Co-authored-by: hyzyla <[email protected]>
@hyzyla
Copy link
Collaborator

hyzyla commented Aug 20, 2025

Root Cause: The --console flag in devicectl device process launch causes the process to wait for the app to exit, which terminates the process immediately after launch. This prevents the debugger from attaching properly.

Find in the internet proof for that? @copilot

Copilot AI and others added 2 commits August 20, 2025 19:05
- Add comprehensive unit tests for console flag handling logic
- Add documentation explaining the root cause and solution
- Verify all tests pass and TypeScript compilation works

Co-authored-by: hyzyla <[email protected]>
Copilot AI changed the title [WIP] Fix this issue: @sweetpad-dev/sweetpad/issues/114 Fix debugger terminating immediately on iOS device debugging Aug 20, 2025
Copilot AI requested a review from hyzyla August 20, 2025 19:09
@jdaites
Copy link

jdaites commented Aug 27, 2025

Nice, are there plans for this to go in soon?

@hyzyla
Copy link
Collaborator

hyzyla commented Aug 27, 2025

Nice, are there plans for this to go in soon?

I would like to move forward with this issue, but I'm not sure if Copilot hallucinated that solution or not

@jdaites
Copy link

jdaites commented Aug 28, 2025

Nice, are there plans for this to go in soon?

I would like to move forward with this issue, but I'm not sure if Copilot hallucinated that solution or not

Based on my analysis it looks like a legit solution. The --console flag cuases it to be dependent on the console, but separating them out allows the debugger to attach independently of the console. I didn't test this out, but in theory it should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Debugger terminates immediately after app launch on physical iOS device

3 participants