Unable to debug on physical device
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.
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
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.
That would be amazing @wr-fenglei! I was trying to run it on the device today, and having debug support would be wonderful!
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
I'm able to debug app using folowing patch and vscode-ios-debug extension (patched for Xcode 16): https://github.com/sweetpad-dev/sweetpad/pull/76
@kvaster This is great! I'll upgrade to Xcode 16 soon and give it a try.
@kvaster i've tried but still not working, with a toast could not find pid for <Bundle ID>.
- part of my
launch.jsonwith bundle id copied from plist file - running app from sweeptpad extension
-
F5to run aboveattachcommand Is any thing i missed ?
@bingli-minimax Try replacing <Bundle ID> with your app's actual Bundle ID, for example: com.example.myapp
@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.
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: https://github.com/nisargjhaveri/vscode-ios-debug/pull/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).
I've attempted and released a fix in v0.4.1 of vscode-ios-debug for iOS 17+ (with Xcode 16+) support. Thought it might be useful here.
Great! It's really easy now to launch debug. With following config you may install, launch and debug:
{
"version": "0.2.0",
"configurations": [
{
"name": "iOS Debug",
"type": "lldb",
"request": "launch",
"program": "${command:sweetpad.debugger.getAppPath}",
"iosBundleId": "YOUR BUNDLE ID",
"iosTarget": "select",
"preLaunchTask": "sweetpad: build"
}
]
}
@nisargjhaveri , I don’t know how you do this, but it works like magic! 🤩
I’ve added the same logic to the Sweetpad extension https://github.com/sweetpad-dev/sweetpad/blob/main/src/debugger/provider.ts#L77C7-L102C12. Could someone test how it works on your projects and devices (v0.1.49) ? It works on my iPad but randomly fails on my iPhone.
@hyzyla I tried 0.1.49 on vscode and cursor, it works.
@hyzyla , thanks a lot!
Just for notice: new changes allows to attach to running application on ios device and this is great, but there is one use case where you will still need vscode-ios-debug. If you your app crashes right after start or you need to debug app initialization - you will need to use vscode-ios-debug, cause it allows to launch and pause app right at the start.
@hyzyla I'm curious, why not take a dependency on vscode-ios-debug directly? I was having a high-level look, and the work you did looks impressive, and it should be possible to directly use vscode-ios-debug for the debugging parts. We'd not have to maintain two projects with almost same logic. I'd be happy to collaborate and expose any APIs if needed as well for better integration if required.
I've upgraded to Xcode 16.2, and both the console and debugging are working perfectly now - this is fantastic! Thank you so much!
Here's my environment setup:
- SweetPad 0.1.49
- Xcode 16.2
- iPhone XR iOS 17.6
I'm including my configuration files for reference:
task.json:
{
"version": "2.0.0",
"tasks": [
{
"type": "sweetpad",
"action": "launch",
"problemMatcher": [
"$sweetpad-watch",
"$sweetpad-xcodebuild-default",
"$sweetpad-xcbeautify-errors",
"$sweetpad-xcbeautify-warnings"
],
"label": "sweetpad: launch",
"detail": "Build and Launch the app",
"isBackground": true
}
]
}
launch.json:
{
"version": "0.2.0",
"configurations": [
{
"type": "sweetpad-lldb",
"request": "attach",
"name": "Attach to running app (SweetPad)",
"preLaunchTask": "sweetpad: launch"
}
]
}
I think we can close this issue now.
I can run on real device and see logs, but pause and breakpoints are not working..
{
"type": "sweetpad-lldb",
"request": "attach",
"name": "Debug TWorld DEV",
"preLaunchTask": "sweetpad: debug TWorld DEV"
},
{
"type": "sweetpad",
"action": "launch",
"label": "sweetpad: debug TWorld DEV",
"detail": "Build and Launch the app (TWorld DEV)",
"isBackground": false,
"problemMatcher": [
"$sweetpad-watch",
"$sweetpad-xcodebuild-default",
"$sweetpad-xcbeautify-errors",
"$sweetpad-xcbeautify-warnings"
],
"scheme": "TWorld고도화 DEV",
"configuration": "Dev.debug",
"launchArgs": [],
"launchEnv": {}
},
I can't see process in CALL STACK. Sometimes I can see it, however neigther didn't work
@2sem I'm not very clear about this either.
You can try reading this documentation: https://sweetpad.hyzyla.dev/docs/debug
The documentation mentions:
"isBackground": true, // Important: lets VS Code know when the task is ready
Just for notice: new changes allows to attach to running application on ios device and this is great, but there is one use case where you will still need vscode-ios-debug.
@kvaster I am not able to attach to app running on device. Getting the following error:
My launch.json entry:
{
"type": "sweetpad-lldb",
"request": "attach",
"name": "Attach to running app (SweetPad)",
"preLaunchTask": "sweetpad: launch"
}
If you your app crashes right after start or you need to debug app initialization - you will need to use vscode-ios-debug, cause it allows to launch and pause app right at the start.
I think that would be because when starting the app --start-stopped flag is not passed to devicectl device process launch.
@soumyamahunt Yeah, I'm getting the same issue. Did you find a way to solve it?
@nisargjhaveri I'm getting the same issue too. Did you find a way to solve it?
Just for notice: new changes allows to attach to running application on ios device and this is great, but there is one use case where you will still need vscode-ios-debug.
@kvaster I am not able to attach to app running on device. Getting the following error:
My launch.json entry:
{ "type": "sweetpad-lldb", "request": "attach", "name": "Attach to running app (SweetPad)", "preLaunchTask": "sweetpad: launch" }
If you your app crashes right after start or you need to debug app initialization - you will need to use vscode-ios-debug, cause it allows to launch and pause app right at the start.
I think that would be because when starting the app
--start-stoppedflag is not passed todevicectl device process launch.
@YangCodeHub @dtln820 Could you try adding the following line to .vscode/settings.json and try again?
{
"lldb.library": "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/LLDB"
}
This line ensures that LLDB from Xcode is used instead of the default LLDB.
If it doesn't work, I would like to ask you to add "lldb.verboseLogging": true to the .vscode/settings.json and then share the full output from the Output > LLDB panel to identify the cause of the problem.
@YangCodeHub @dtln820 Could you try adding the following line to .vscode/settings.json and try again?
{ "lldb.library": "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/LLDB" }
This line ensures that LLDB from Xcode is used instead of the default LLDB.
If it doesn't work, I would like to ask you to add
"lldb.verboseLogging": trueto the.vscode/settings.jsonand then share the full output from the Output > LLDB panel to identify the cause of the problem.
@hyzyla @kvaster @nisargjhaveri Hi, after i added "lldb.verboseLogging": true to the .vscode/settings.json, it just works few times.
my launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "iOS Debug",
"type": "lldb",
"request": "launch",
"program": "${command:sweetpad.debugger.getAppPath}",
"iosBundleId": "com.xxx.xx",
"iosTarget": "select",
"preLaunchTask": "sweetpad: build"
}
]
}
my settings.json
{
"lldb.library": "/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/LLDB",
"lldb.verboseLogging": true
}
OUTPUT->LLDB
[DEBUG codelldb::dap_codec] --> {"command":"configurationDone","type":"request","seq":8}
[DEBUG codelldb::debug_session::launch] launch env: []
[DEBUG codelldb::dap_codec] <-- {"seq":14,"type":"event","event":"output","body":{"category":"console","output":"Executing script: preRunCommands\n"}}
[DEBUG codelldb::debug_session] script lldb.target.module[0].SetPlatformFileSpec(lldb.SBFileSpec('/private/var/containers/Bundle/Application/87AC57D1-3823-412C-8B39-D990C6D083CC/X.app')) -> SuccessFinishNoResult, Error: Success
Output Message:
True
[DEBUG codelldb::dap_codec] <-- {"seq":15,"type":"event","event":"output","body":{"category":"console","output":"True\n"}}
[DEBUG codelldb::dap_codec] <-- {"seq":16,"type":"event","event":"output","body":{"category":"console","output":"True\n\n"}}
[DEBUG codelldb::dap_codec] <-- {"seq":17,"type":"event","event":"output","body":{"category":"console","output":"Launching: /Users/yang/Library/Developer/Xcode/DerivedData/XiOSProject-cgibobmyfmookogvfpfhylmvmlvm/Build/Products/Debug-iphoneos/X.app/X\n"}}
[DEBUG codelldb::dap_codec] <-- {"seq":18,"type":"event","event":"output","body":{"category":"console","output":"Executing script: processCreateCommands\n"}}
timed out waiting for shell command to complete[DEBUG codelldb::debug_session] script lldb.debugger.HandleCommand("device select 00008130-001C783C3803401C") -> SuccessFinishNoResult, Error: Success
no device selected: use 'device select <identifier>' to select a device.[DEBUG codelldb::debug_session] script lldb.debugger.HandleCommand("device process attach -c --pid 21115") -> SuccessFinishNoResult, Error: Success
[ERROR codelldb::debug_session] Process is not valid.
[DEBUG codelldb::dap_codec] <-- {"seq":19,"type":"response","request_seq":2,"success":false,"command":"","message":"Process is not valid.","show_user":true}
[DEBUG codelldb::dap_codec] <-- {"seq":20,"type":"response","request_seq":8,"success":true,"command":"configurationDone"}
[DEBUG codelldb::dap_codec] --> {"command":"disconnect","arguments":{"restart":false},"type":"request","seq":9}
[DEBUG codelldb::dap_codec] <-- {"seq":21,"type":"response","request_seq":9,"success":true,"command":"disconnect"}
[DEBUG codelldb::dap_session] The client has disconnected
[DEBUG codelldb::debug_session] End of the requests stream
[DEBUG codelldb::debug_session] DebugSession::drop()
[DEBUG codelldb] End of the debug session
[DEBUG codelldb] Exiting
Debug adapter exit code=0, signal=null.
My launch.json entry: