How it works
This page describes what actually happens when you are running code.
The pieces
idb-repl(the driver). The CLI you run. It takes your Swift code, compiles it, and orchestrates the session. It does not talk to the target process directly.idb_companion(the server). A macOS process that manages simulators and exposes a gRPC API.idb-replbuilds on top of it — the companion is what actually injects and runs your code inside a process on the simulator. This is the same companion that powersidb's other features.- The target process. The process your code runs inside: an app, the simulator, or a test bundle (see Writing REPL code).
you ──▶ idb-repl ──(gRPC)──▶ idb companion ──▶ target process on the simulator
▲ (driver) (server) (app / simulator / test bundle)
└──────────────── result streamed back ──────────────────┘
What happens when you run a command
- Connect to a companion.
idb-replfinds or starts anidb_companionfor your target. - Prepare the target. Depending on the context, the companion attaches to a running app, (re)launches one with the REPL enabled, targets the simulator itself, or loads a test bundle.
- Compile. The driver compiles the Swift code you entered and sends it to the companion. (Remote compilation is coming soon.)
- Inject and execute. The companion loads the executable code into the target process and triggers execution.
- Return the result. The value you
returnis streamed back and printed.
Because the code runs inside the target process, it sees that process's memory and loaded frameworks directly — which is what makes live app inspection (app context), and running against a test bundle's own modules (test context), possible.
Sessions and persistence
- In the app context,
idb-replattaches to an already-running REPL for the same app by default, so successive commands hit the same live process and in-memory state persists across calls.--new-sessionforces a clean relaunch. See Writing REPL code → App context. - The simulator and test contexts are not reattachable — each run gets a fresh session.
For recording a session and re-running it later, see Reports and replay.