# Run and Debug

Source: https://athas.dev/docs/debugger

Start a debug session, step through your program, and read threads, call stack, variables, watches and breakpoints.

Athas debugs through the Debug Adapter Protocol, the same protocol VS Code uses, so an adapter you
already have installed works here too.

## Open it

Run **View: Show Run and Debug** from the command palette, or pick **Run and Debug** in the View
menu. The view opens as a tab beside the editor.

## Launch configurations

Athas reads `.vscode/launch.json` from the project, including comments and trailing commas. It
also offers generated configurations for what it finds in the project, so a simple program needs
no file at all.

Pick a configuration from the view's picker, then start the session.

## Commands

| Command                      | Default              |
| ---------------------------- | -------------------- |
| **Debug: Start**             | `F5` inside the view |
| **Debug: Stop**              | `Shift+F5`           |
| **Debug: Restart**           | `Cmd/Ctrl+Shift+F5`  |
| **Debug: Toggle Breakpoint** | —                    |

Inside the view, `F6` pauses, `F10` steps over, `F11` steps into and `Shift+F11` steps out.

**Debug: Toggle Breakpoint** works on the editor's cursor line, so it is worth binding in
[keymaps](https://athas.dev/docs/keymaps). Breakpoints are shared across the session and the editor gutter.

## While a session runs

The view lists the program's threads and, for the selected one, its call stack. Selecting a frame
opens that file at the line. Below it are the frame's variables, the watch expressions you add,
every breakpoint in the project, and the adapter's console.

## Adapters

Athas finds the adapter from the configuration's `type`. These are recognised:

| `type`                                                             | Adapter                 | Where it comes from                                                                   |
| ------------------------------------------------------------------ | ----------------------- | ------------------------------------------------------------------------------------- |
| `python`, `debugpy`                                                | debugpy                 | `python -m pip install debugpy`                                                       |
| `go`, `delve`                                                      | Delve                   | `go install github.com/go-delve/delve/cmd/dlv@latest`                                 |
| `lldb`, `rust`, `codelldb`, `lldb-dap`                             | CodeLLDB, or `lldb-dap` | A CodeLLDB install, or the LLVM toolchain                                             |
| `gdb`                                                              | GDB                     | GDB 14 or newer on `PATH`                                                             |
| `cppdbg`                                                           | GDB or `lldb-dap`       | Follows `MIMode`                                                                      |
| `node`, `pwa-node`, `chrome`, `pwa-chrome`, `msedge`, `pwa-msedge` | js-debug                | `js-debug-adapter` on `PATH`, or `ATHAS_JS_DEBUG` pointing at its `dapDebugServer.js` |

Athas also looks through `~/.vscode/extensions` for an adapter you installed there.

Java is the exception: it starts through the Java language server, so open a Java file and let
`jdtls` come up first.

For anything else, set `adapterCommand` or `debugServer` in `launch.json` and Athas will use it.

## The adapter is not found

The error names what is missing and how to install it. If the adapter is installed somewhere
unusual, point at it directly with `adapterCommand` in the configuration rather than relying on
discovery.
