Skip to main content
On this page

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

Pick your iPhone, set a breakpoint and press F5: inspect variables and the call stack, step with F10, run lldb commands in the Debug Console, read print output in KXBuild Console, and attach to an app already running on the phone.

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.

The debug view stopped at a breakpoint

What are the ways to start debugging an iOS app in VS Code?

ModeWhereWhat it does
Build & RunF5, ▶ in the view title bar, or the target row buttonBuilds with the current configuration, signs, installs on the selected device, launches and attaches the debugger
RunKXBuild: Run, or the target row buttonSkips the build. Installs the most recent build and launches it.
AttachKXBuild: Attach to Running AppLists 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.

MessageFix
No iOS device selectedSelect a device in the KXBuild view
Developer Mode is offTurn on Developer Mode on the iPhone and restart it
Developer Disk Image is not mountedReconnect the iPhone or run doctor
The device is not paired/trustedUnlock the iPhone and tap Trust
Not enough free space on the deviceFree up storage on the iPhone and try again
No valid provisioning profile, or the device is not in the provisioning profileSee sign iOS apps on Windows
did not report the app as launched in timeUnlock the iPhone and check the connection
didn't start in timeThe 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 } ] }
FieldDescription
buildtrue builds before installing. false installs the most recent build.
deviceDevice UDID. Omit to use the device selected in the view.
bundleBundle 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.
configurationDebug or Release. Omit to use the one selected in the view.
attachPidProcess 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