sweetpad-dev / sweetpad

Develop Swift/iOS projects using VSCode
https://marketplace.visualstudio.com/items?itemName=sweetpad.sweetpad
MIT License
586 stars 19 forks source link

Unable to debug on physical device #41

Open wr-fenglei opened 2 months ago

wr-fenglei commented 2 months ago

Thank you very much for creating this plugin. I really like it.

However, I've found that I can't debug on a physical device. Is there something wrong with my configuration?

My plugin version is 0.1.33.

I'm using Xcode 15.2, and my phone's system is iOS 17.6.1.

My launch.json configuration is as follows:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "sweetpad-lldb",
            "request": "launch",
            "name": "Attach to running app (SweetPad)",
            "preLaunchTask": "sweetpad: launch",
        },
    ],
}

When I use VSCode's debug feature, the Terminal outputs:

Result bundle written to path:
Build Succeeded

🚀 Executing command:
xcrun devicectl device install app --device iosdevice-00008020-000B34D6012A003F /Users/myname/Library/Developer/Xcode/DerivedData/myapp-djwiypcpaflfvkbkckuttoyimesk/Build/Products/Debug-iphoneos/myapp.app

ERROR: The specified device was not found. (com.apple.dt.CoreDeviceError error 1000.)

🚫 Command returned non-zero exit code

When I use the command: SweetPad: Build & Run (Launch), the Terminal outputs:

Result bundle written to path:
Build Succeeded

🚀 Executing command:
xcrun devicectl device install app --device 00008020-000B34D6012A003F /Users/myname/Library/Developer/Xcode/DerivedData/myapp-djwiypcpaflfvkbkckuttoyimesk/Build/Products/Debug-iphoneos/myapp.app

21:59:41  Acquired tunnel connection to device.
21:59:41  Enabling developer disk image services.
21:59:41  Acquired usage assertion.
1%... 2%... 3%... 4%... 5%... 6%... 7%... 8%... 9%... 10%... 11%... 12%... 13%... 14%... 15%... 16%... 18%... 19%... 20%... 21%... 22%... 23%... 24%... 25%... 26%... 27%... 28%... 30%... 31%... 32%... 33%... 34%... 35%... 36%... 37%... 38%... 39%... 40%... 41%... 42%... 43%... 44%... 45%... 46%... 47%... 48%... 49%... 50%... 51%... 52%... 53%... 54%... 55%... 56%... 57%... 59%... 60%... 62%... 66%... 68%... 72%... 74%... 76%... 80%... 84%... 88%... 92%... 96%... Complete!
App installed:
? bundleID: com.myapp.ios
? installationURL: file:///private/var/containers/Bundle/Application/689DB382-C1B9-4626-B4D7-56ADEA7B5021/myapp.app/
? launchServicesIdentifier: unknown
? databaseUUID: E1D4A799-1D0D-4931-A385-74A49B4B3FD7
? databaseSequenceNumber: 1268
? options: 

🚀 Executing command:
xcrun devicectl device process launch --json-output '/Users/myname/Library/Application Support/Cursor/User/workspaceStorage/f8d9db3c1fcf7403dae4fe89e60093e3/sweetpad.sweetpad/_temp/json_f54f27f0' --terminate-existing --device 00008020-000B34D6012A003F com.myapp.ios

22:00:12  Acquired tunnel connection to device.
22:00:13  Enabling developer disk image services.
22:00:13  Acquired usage assertion.
Launched application with com.myapp.ios bundle identifier.

App launched on device with PID: 872
✅ Task completed

When using VSCode's debug feature, the --device parameter is: iosdevice-00008020-000B34D6012A003F (may be wrong)

When using SweetPad's debug feature, the --device parameter is: 00008020-000B34D6012A003F

Additionally, when I use SweetPad: Get app path for debugging, it pops up an error:

Sweetpad: No last launched app path found, please launch the app first using the extension

I've noticed that when running on a physical device, build.lastLaunchedAppPath is not updated. I'm not sure if this is related.

I would greatly appreciate if you could look into this issue. I'm really looking forward to debugging on a physical device.

hyzyla commented 2 months ago

Hi! Actually debugging currently doesn't work on physical devices. You can only launch app on physical devices.

To fix error that you've mentioned please update the extension to the latest version and try to launch using ▶️ button on the extension panel.

https://sweetpad.hyzyla.dev/docs/devices

wr-fenglei commented 2 months ago

Thank you very much, I can run it on a physical device.

I would be extremely grateful if you could explain the challenges of debugging on a physical device.

I'd like to try implementing this feature and hope to be of some help.

rudrankriyam commented 2 months ago

That would be amazing @wr-fenglei! I was trying to run it on the device today, and having debug support would be wonderful!

hyzyla commented 2 months ago

In the latest version (0.1.34), I've added the --console option for launching on physical devices. This option will redirect stdout to the extension, allowing you to print debug information on a physical device.

--console — Attaches the application to the console and waits for it to exit. devicectl will wait for the app to terminate. Catchable signals sent to devicectl are forwarded to the app. If the app is not already running, its standard streams will be connected to devicectl's standard streams.


I'd like to try implementing this feature and hope to be of some help.

Thank you! That would be amazing! 💜

I think a good starting point for configuring proper debugging with LLDB is to check this comment in the Flutter project: https://github.com/flutter/flutter/issues/133465#issuecomment-2159512125. From my understanding, launching an LLDB session with devicectl works only with Xcode 16 and requires running these commands in the LLDB session.

(lldb) device select <device-identifier>
(lldb) device process attach --pid <pid>

In my extension, I heavily rely on the CodeLLDB extension for LLDB debugging and my extension just provide the correct options to this extension based on project information. Most of the logic is located in the DebuggerConfigurationProvider class. Additionally, I’ve prepared a document on how to debug the extension on a local machine. This is also applicable for development, but rememeber to fork the project instead of just cloning it: Debugging extension.

If you have any other questions or ideas, don't hesitate to contact me