Skip to content
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

Unable to debug on physical device #41

Open
wr-fenglei opened this issue Sep 19, 2024 · 10 comments
Open

Unable to debug on physical device #41

wr-fenglei opened this issue Sep 19, 2024 · 10 comments

Comments

@wr-fenglei
Copy link

wr-fenglei commented Sep 19, 2024

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
Copy link
Collaborator

hyzyla commented Sep 19, 2024

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
Copy link
Author

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
Copy link

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

@hyzyla
Copy link
Collaborator

hyzyla commented Sep 21, 2024

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: flutter/flutter#133465 (comment). 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

@kvaster
Copy link
Contributor

kvaster commented Nov 30, 2024

I'm able to debug app using folowing patch and vscode-ios-debug extension (patched for Xcode 16): #76

@wr-fenglei
Copy link
Author

@kvaster This is great! I'll upgrade to Xcode 16 soon and give it a try.

@bingli-minimax
Copy link

bingli-minimax commented Dec 3, 2024

@kvaster i've tried but still not working, with a toast could not find pid for <Bundle ID>.

  1. part of my launch.json with bundle id copied from plist file
    image
  2. running app from sweeptpad extension
  3. F5 to run above attach command
    Is any thing i missed ?

@wr-fenglei
Copy link
Author

@bingli-minimax Try replacing with your app's actual Bundle ID, for example: com.example.myapp

@bingli-minimax
Copy link

bingli-minimax commented Dec 5, 2024

@bingli-minimax Try replacing with your app's actual Bundle ID, for example: com.example.myapp

Actually, i have set my own app Bundle ID and still not working. The Bundle Id in post above is for example because i do not want to show the app info.

@kvaster
Copy link
Contributor

kvaster commented Dec 9, 2024

How it works at my place.

You need to install latest sweetpad and vscode-ios-debug. If you're using iOS >= 17 (Xcode >= 16) then you need to install patched version of vscode-ios-debug. Patch is here: nisargjhaveri/vscode-ios-debug#25

Open your project, choose proper schema and configuration and press build and run in sweetpad pane. Make sure you device is unlocked in that moment.

After app will be launched and you'll be able to see app's logs, start debugging from Run and Debug pane. Please make sure your app is running and device is unlocked in that moment.

This is how it works at my place. And I'm using Xcode 16.1, tested also on Xcode 16. And I've not tested it without patch and on Xcode < 16 (iOS < 17).

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

No branches or pull requests

5 participants