Debug iOS Apps on iPhone in VS Code: F5, Breakpoints, Attach
Three ways to start (Build & Run, Run and Attach), what you see if a step fails after F5, panels and output during a debug session, launch.json fields and Dart debugging for Flutter.
Last updated
To debug iOS apps on iPhone in VS Code, select your iPhone, set a breakpoint in your code and press F5. The extension builds, signs, installs and launches the app, then attaches the debugger, with no launch.json needed. When a breakpoint hits, the standard VS Code debug view shows variables and the call stack. Breakpoints work in Swift, Objective-C, C / C++ and Kotlin, and Flutter projects debug Dart at the same time. Here's an app running and debugging on a device from Windows.
What are the ways to start debugging an iOS app in VS Code?
| Mode | Where | What it does |
|---|---|---|
| Build & Run | F5, ▶ in the view title bar, or the target row button | Builds with the current configuration, signs, installs on the selected device, launches and attaches the debugger |
| Run | KXBuild: Run, or the target row button | Skips the build. Installs the most recent build and launches it. |
| Attach | KXBuild: Attach to Running App | Lists the apps running on the iPhone and attaches the debugger to the one you pick |
The build runs before the debug session starts, so the Restart button on the debug toolbar doesn't recompile. After changing code, stop and press F5 again.
What do I do when F5 shows an error?
Every step after the build shows a progress notification you can cancel. If a step fails, the message names that step. Click Show Output for the full log.
| Message | Fix |
|---|---|
| No iOS device selected | Select a device in the KXBuild view |
| Developer Mode is off | Turn on Developer Mode on the iPhone and restart it |
| Developer Disk Image is not mounted | Reconnect the iPhone or run doctor |
| The device is not paired/trusted | Unlock the iPhone and tap Trust |
| Not enough free space on the device | Free up storage on the iPhone and try again |
| No valid provisioning profile, or the device is not in the provisioning profile | See sign iOS apps on Windows |
| did not report the app as launched in time | Unlock the iPhone and check the connection |
| didn't start in time | The app may be crashing on launch. Check the device log. |
Which breakpoints and debugging features work on the iPhone?
You can set breakpoints in Swift, Objective-C, C / C++ and the Kotlin code of Kotlin Multiplatform projects. Stepping, variables, the call stack, watch expressions and the Debug Console all work as in any VS Code debug session, and you can type lldb commands in the Debug Console. When you stop somewhere without source, open the assembly view.
While you debug, app output from print and NSLog goes to Output > KXBuild Console and the build log to Output > KXBuild. Stopping the session also quits the app on the iPhone; press F5 to start it again.
To see how the UI is layered while you debug, run kxdevice web and capture the app under View debugger. A Debug build can be read while it is being debugged, without interrupting it. See View hierarchy.
Do I need a launch.json, and which fields does it take?
F5 works without a launch.json. Add one only when you want to pin a device, target or build configuration. Set the debugger type to kxbuild. Here's an example and the available fields.
{
"version": "0.2.0",
"configurations": [
{ "type": "kxbuild", "request": "launch", "name": "KXBuild: Build & Run", "build": true },
{ "type": "kxbuild", "request": "launch", "name": "KXBuild: Run", "build": false },
{ "type": "kxbuild", "request": "attach", "name": "KXBuild: Attach", "attachPid": 0 }
]
}| Field | Description |
|---|---|
| build | true builds before installing. false installs the most recent build. |
| device | Device UDID. Omit to use the device selected in the view. |
| bundle | Bundle ID of the app target to run. Omit to use the project's only app target. If there are several, you're asked to pick one. |
| configuration | Debug or Release. Omit to use the one selected in the view. |
| attachPid | Process ID to attach to. 0 shows a list to pick from when the session starts. |
How do I debug Dart and native code together in a Flutter project?
In Flutter projects, F5 debugs the native Objective-C and Swift code right away. Debugging Dart code needs the VS Code Dart extension. If KXBuild detects a Flutter project without it, you're offered a one-click install. Afterwards run Build & Run again, and native and Dart breakpoints both work, with hot reload.
How do I debug the JS code of React Native, Expo and uni-app?
For React Native and Expo, KXBuild debugs the native side. For JS breakpoints, use the Metro / Hermes debugger. An exported uni-app project is a native shell around a WebView. Debug the native part in KXBuild and the page JS with the tools built into HBuilderX.
Whatever the project type, the native side goes through the same F5 flow to debug iOS apps on iPhone in VS Code. If your computer doesn't see the phone yet, first connect an iPhone to Windows for debugging: install the driver, trust the computer and turn on Developer Mode.
Next steps
Code completion and indexing
Completion, go to definition and error checking for Swift, Objective-C and C/C++, ready as soon as you open the project. When you need to build once first, and what to do when completion misbehaves.
Troubleshooting
Run kxbuild doctor first. Then look up your error message by category: install, project, signing, device, release or extension. Also covers where to find the logs.