Skip to main content
On this page

Debug iOS apps on a real iPhone in VS Code with breakpoints

Breakpoints, variables and the console, attaching to a running app, launch arguments, and slow first sessions on a device.

Last updated

Debug iOS apps on a real iPhone or a simulator in VS Code with no configuration at all. With KXApp, pick an iPhone or a simulator, set breakpoints in your source and press Cmd+R or F5: the extension builds, installs and launches the app and attaches the debugger. Breakpoints work in Swift, Objective-C, C and C++, variables, call stack and threads are in VS Code's standard debug view, and the app's print / NSLog output is in Output › kxapp Console.

The debug view stopped at a breakpoint

What can I do while debugging an iOS app in VS Code?

  • Breakpoints work in Swift, Objective-C, C and C++, including conditional breakpoints and logpoints.
  • Variables, watch, call stack and threads are in VS Code's standard debug view.
  • The Debug Console accepts lldb commands such as po self and bt.
  • The app's print / NSLog output is in Output › kxapp Console.
  • Stopping the session ends the app, as in Xcode. To keep the app running, turn off kxapp.debug.killAppOnStop.

Restart on the debug toolbar doesn't relaunch the app; it points you to Build & Run instead. After changing code, press Cmd+. to stop, then Cmd+R to build and run again (Cmd+R doesn't work while a debug session is running), or click Build & Run in the Xcode Project view's title bar.

How do I attach to a running app?

Run "Attach to Running App…" from the Command Palette and pick an app running on the device (shown with its name, pid and bundle id). The app keeps running after you detach.

How do I pin a scheme or pass launch arguments in launch.json?

To pin a scheme or device, or to pass launch arguments, add a configuration of type kxapp to .vscode/launch.json:

{ "version": "0.2.0", "configurations": [ { "type": "kxapp", "request": "launch", "name": "kxapp: Build & Run", "build": true }, { "type": "kxapp", "request": "launch", "name": "kxapp: Run", "build": false }, { "type": "kxapp", "request": "attach", "name": "kxapp: Attach" } ] }
FieldDescription
schemeScheme to build and run; defaults to the current selection
configurationBuild configuration; defaults to the current selection
deviceUDID or name of the simulator or device; defaults to the run destination
buildBuild before running; defaults to true
argsLaunch arguments for the app
envEnvironment variables for the app
pid(attach) Process to attach to; pick from running apps when omitted

Why is the first debug session on an iPhone slow?

After an iPhone updates its OS, Xcode has to prepare it once, otherwise the first debug session starts very slowly. When that happens the extension tells you: open Xcode's Window › Devices and Simulators, connect the device once and let Xcode finish preparing it. After that, breakpoints hit within seconds.

For other launch failures when you debug iOS apps on a real iPhone (locked device, signing problems and so on) the extension shows the actual reason; fixes are in common iOS build errors in VS Code.

Frequently asked questions

Is debugging on a simulator different from a device?

No, only the run destination changes. A device must be unlocked, trust this Mac, have Developer Mode on and have been prepared by Xcode once; see build and run iOS apps in VS Code.

Can I type lldb commands in the Debug Console?

Yes. Type them straight into the Debug Console, for example po self to print an object or bt for the call stack.

Can the app keep running after I stop debugging?

Yes, turn off kxapp.debug.killAppOnStop; by default stopping ends the app, as in Xcode. An app you joined with "Attach to Running App…" keeps running after you detach anyway.

What's the difference between a logpoint and a breakpoint?

A logpoint prints a line without stopping; a breakpoint pauses the app so you can inspect variables and the call stack. Both work in Swift and Objective-C.

Next steps