erhe C++ debugging (lldb on macOS / Linux, Visual Studio MCP on Windows)
Reproduce the failure under a debugger and read the real callstack plus the live
variable values at the fault site. Do NOT try to reason a crash out from
logs/log.txt plus a stripped console backtrace alone, and do not just stare at a
logs/editor_crash_*.dmp minidump -- they are a hypothesis, not the diagnosis.
This is the authoritative macOS/Linux lldb run-book. The Windows VS-MCP prose
(full tool list, typical flow, gotchas) lives in doc/agents/debugging.md.
Pick the platform path
- macOS / Linux -> lldb via a shell.
/usr/bin/lldbships with the
Command Line Tools (no install). The Debug builds have full symbols:
build_xcode_{metal,vulkan,metal_headless}/bin/Debug/editor.
On macOS, first run DevToolsSecurity -status. If developer mode is
disabled, do not start lldb (it blocks on an authorization dialog on the
user's screen); ask the user to run ! sudo DevToolsSecurity -enable once
(doc/agents/macos.md "Debugging").
- Windows -> the
visualstudioMCP server (mcp__visualstudio__*). It drives a
live VS instance: debugger_add_breakpoint -> debugger_launch -> poll
debugger_status until it breaks -> debugger_get_callstack /
debugger_get_locals / debugger_evaluate -> debugger_stop. Always
solution_info first to confirm which solution is loaded; for headless-only
repros open build_vs2026_vulkan_headless/erhe.slnx. (doc/agents/debugging.md has the full
tool list and flow.) lldb-mi/GDB-MI do not exist here; on Windows use VS-MCP.
macOS: which lldb interface (most efficient first)
- Python SB API emitting JSON -- DEFAULT for almost everything. Write a script
that drives the debugger and prints one JSON blob in a schema you control, then
run it in one batch call and parse stdout. You fetch exactly the fields you need
(minimal tokens), no protocol handshake, no scraping human-formatted bt text:
```bash
lldb --batch -o "command script import /tmp/probe.py" -o "quit"
```
probe.py defines def __lldb_init_module(debugger, internal_dict):, sets
debugger.SetAsync(False), does the work on the passed-in debugger, and
delimits the JSON with sentinels (print("JSON_BEGIN"+json.dumps(out)+"JSON_END"))
so you can extract it from lldb's own chatter. (lldb -P prints the SB-API module
path if you want to import lldb from a matching python.)
- lldb-dap (
xcrun -f lldb-dap) only when you need a persistent interactive
session across multiple tool calls (genuine step-debugging) -- run it backgrounded
on a socket (lldb-dap --connection listen://localhost:PORT) and send DAP
JSON-RPC requests (launch, setBreakpoints, stackTrace, scopes,
variables, evaluate, async stopped events; Content-Length framing, seq
correlation) so the debuggee stays stopped between inspections. More plumbing;
not for one-shot captures.
- Plain CLI (
lldb -b -o "..." -o "...") -- fine for a quick one-line peek. - lldb's built-in MCP server and GDB/MI are NOT worth it here. Inside lldb,
protocol-server start MCP listen://localhost:PORT starts an lldb-mcp server,
but it exposes exactly one tool (lldb_command, text back) over raw TCP --
plumbing for no structured-data gain. Apple ships no lldb-mi.
Canonical recipes (macOS, via the SB API / Bash)
- Reproduce-and-capture a crash / VERIFY / FATAL / C++ exception (macOS analog of
the Windows VS-MCP "launch -> break on unhandled exception -> dump callstack +
locals"): an SB-API script that creates the target, sets breakpoints (or relies on
the stop at the fatal signal/throw), Launches, and on stop walks SBProcess ->
threads -> frames -> SBValue variables, emitting JSON. One call, structured result.
- Snapshot a hung / deadlocked editor (attach to the already-running pid -- a
windowed launch is unaffected by attach): iterate every SBThread, dump each
frame's function/file/line to JSON, then detach. Quick text form:
lldb -b -o "attach -p <pid>" -o "thread backtrace all" -o "detach" -o "quit".
For deadlocks the root cause is usually on a different thread than the stuck one,
so always dump ALL threads, not just the apparent victim.
- Post-mortem:
ulimit -c unlimited, reproduce, then `lldb <editor> -c
/cores/core.<pid> (or target create + target.LoadCore` in the SB API).
Constraints
- The windowed editor needs a live display. A windowed launch under lldb
aborts at startup if the display is off/asleep; attaching to an already-running
editor is unaffected. When the display is off, debug a headless build instead:
build_vs2026_vulkan_headless on Windows, build_xcode_metal_headless
(scripts/configure_xcode_metal_headless.sh) on macOS.
- Building & launching to verify is self-serve -- you may build
build_xcode_metal/etc. and launch the editor on your own initiative (mind the
live-display requirement); only ask if the user told you to.
- Run erhe gtest suites serially, one failure at a time (
doc/testing.md); an
abort hides the rest of the run.
When NOT this skill
- "Renders nothing / renders wrong / wrong color / which texture or uniform holds
what" is a GPU question -> use erhe-renderdoc-gpu-debug (capture a frame, read
render targets and shader constant buffers). This skill is CPU-side: control flow,
crashes, hangs, and live C++ object state.