agentleFS
processmissionprocessmission/oh-my-qemu/skills/qemu-debug/SKILL.md

qemu-debug

Skill57 starsChanged 4 months agoMITView on GitHub

Use for debugging QEMU itself or guests under QEMU with host-side gdb/lldb, guest gdbstub, QEMU log flags, trace events, replay, one-insn-per-tb, and structured .oh-my-qemu artifacts.

The file

Show its rules and text

We split this skill into the rules it gives an agent

18 rules. About 0 are common, 10 are distinctive, and 8 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈10

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 8

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Before changing source or mutable artifacts, record the workspace root, revision, git status --short, pre-existing changes, goal, scope, …

    line 24
  2. Very specific:

    Keep QEMU builds under source-root builds/build-<target>/.

    line 31
  3. Distinctive:

    Do not assume a model bug before command line and image provenance are known.

    line 60
  4. Distinctive:

    ensure the relevant binary is built with debug info.

    line 70
  5. Very specific:

    put debugger transcripts and notes under .oh-my-qemu/<task-slug>/logs/.

    line 72
  6. Distinctive:

    keep guest logs/traces separate from host debugger notes.

    line 73
  7. Very specific:

    If guest execution must be paused while host debugging, combine host GDB with QEMU -S or an early qtest stop.

    line 101
  8. Very specific:

    Use -d item1,... with -D .oh-my-qemu/<task-slug>/logs/qemu.log.

    line 123
  9. Very specific:

    Use -dfilter when a target PC range is known.

    line 125
  10. Distinctive:

    Use trace events for structured evidence:

    line 127
  11. Distinctive:

    Add traces or qtest reproduction only after the host-side failure location is known.

    line 151
  12. Distinctive:

    Check reset state and interrupt-controller route.

    line 158
  13. Distinctive:

    Only then interpret full boot logs.

    line 159
  14. Very specific:

    Use one-insn-per-tb for instruction boundary issues.

    line 164
  15. Distinctive:

    Check frontend feature gates and PC/TB state.

    line 166
  16. Distinctive:

    Check backend constraints, optional flags, and emitted code.

    line 167
  17. Very specific:

    Write the report in .oh-my-qemu/<task-slug>/audit.md and include:

    line 171
  18. Distinctive:

    Stop only QEMU processes, debugger servers, and terminal sessions started for this task.

    line 182

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

QEMU Debug

Audit workflow

For non-trivial workspace writes, use a stable .oh-my-qemu/<task-slug>/ directory and create only needed entries:

.oh-my-qemu/<task-slug>/
├── audit.md      # Baseline, scope, decisions, evidence, verification, and gaps
├── commands.md   # Redacted commands, working directories, and results
├── logs/         # Decisive build, test, runtime, or diagnostic logs
├── scripts/      # Temporary scripts, probes, parsers, and harnesses
└── output/       # Generated deliverables, dependencies, and non-QEMU binaries

Before changing source or mutable artifacts, record the workspace root, revision, git status --short, pre-existing changes, goal, scope, and acceptance checks in audit.md. Log exact redacted commands and results in commands.md; record revisions, configurations, tool versions, and hashes when they affect reproducibility. Separate observations from inferences and edit source only when requested.

Keep QEMU builds under source-root builds/build-<target>/; put third-party dependencies and non-QEMU binaries in task output/. Before writing audit artifacts or configuring QEMU in a Git worktree, add .agents/, .oh-my-qemu/, and builds/ to the repository-local file from git rev-parse --git-path info/exclude; preserve existing entries and avoid duplicates. Never stage or commit those directories. At handoff, verify them absent from git status --short. Report the task directory and unresolved gaps.

QEMU upstream boundary

QEMU's official GitLab and mailing lists are upstream project channels. A patch becomes an upstream contribution when sent to the mailing-list recipients selected through MAINTAINERS; do not prepare or send agent-generated patches for that submission. Local branches, commits, patch files, pushes, and pull requests are not by themselves QEMU upstream contributions. Perform those Git actions only when requested and follow the workspace's Git policy.

Classify first

Identify the debug target:

  • guest code;
  • QEMU device model;
  • board topology/boot ABI;
  • QEMU core runtime;
  • TCG frontend;
  • TCG backend;
  • stale image/build/environment.

Do not assume a model bug before command line and image provenance are known.

Host-side debugging of the QEMU process

Host GDB controls the emulator process; the guest gdbstub controls guest CPU state. Use host GDB or LLDB for QEMU crashes, assertions, hangs, migration bugs, TCG backend emission, or qtest-spawned failures.

Before attaching:

  • ensure the relevant binary is built with debug info;
  • record the exact QEMU command in .oh-my-qemu/<task-slug>/commands.md;
  • put debugger transcripts and notes under .oh-my-qemu/<task-slug>/logs/;
  • keep guest logs/traces separate from host debugger notes.

Common launch patterns:

gdb --args builds/build-riscv64/qemu-system-riscv64 <qemu-options>
gdb -ex 'run' --args builds/build-riscv64/qemu-system-riscv64 <qemu-options>
lldb -- builds/build-riscv64/qemu-system-riscv64 <qemu-options>

Common attach patterns:

gdb -p <qemu-pid>
lldb -p <qemu-pid>

For qtest-spawned QEMU, use verbose qtest output to recover the exact command/environment. QTEST_STOP=1 can stop the spawned QEMU early so a host debugger can attach before the test continues.

Useful host-debugger checks:

  • backtrace of all threads;
  • current thread and frame around QEMU assertions;
  • breakpoints in device MMIO callbacks, reset hooks, realize paths, TCG translation, or qemu_ld/st helpers;
  • watchpoints on device state when corruption is suspected;
  • handle SIGPIPE nostop noprint and similar signal policy only after confirming it matches the failure;
  • thread names and event-loop state for hangs.

If guest execution must be paused while host debugging, combine host GDB with QEMU -S or an early qtest stop. Do not confuse a guest breakpoint with a host breakpoint.

Guest debugging with gdbstub

Use:

  • -s: listen on TCP port 1234;
  • -S: start paused;
  • -gdb dev: choose another backend, such as tcp::3117, unix socket, chardev, or stdio.

For multi-cluster machines, use GDB target extended-remote, add-inferior, inferior N, attach N, and set schedule-multiple on.

Useful GDB checks:

  • registers;
  • disassembly at PC;
  • virtual memory;
  • gdbstub physical memory mode;
  • QEMU single-step mask when IRQ/timer stepping matters.

QEMU logs and traces

Use -d item1,... with -D .oh-my-qemu/<task-slug>/logs/qemu.log. Use -d help on the target binary to discover log items.

Use -dfilter when a target PC range is known. Use -accel tcg,one-insn-per-tb=on to isolate guest-instruction boundaries.

Use trace events for structured evidence:

  • --trace "pattern" for quick checks;
  • --trace events=.oh-my-qemu/<task-slug>/scripts/trace-events.txt for repeatable runs;
  • local trace-events files for source-side event definitions.

Replay and determinism

For intermittent bugs, use record/replay when applicable:

  • record: -icount shift=auto,rr=record,rrfile=.oh-my-qemu/<task-slug>/logs/replay.bin;
  • replay: -icount shift=auto,rr=replay,rrfile=.oh-my-qemu/<task-slug>/logs/replay.bin.

Record QEMU binary, image hashes, machine options, and replay file path.

Debug ladders

QEMU process

  1. Reproduce with the same QEMU binary and command line.
  2. Build with debug info if symbols are missing.
  3. Launch under host GDB/LLDB for startup failures, or attach to the running PID for hangs.
  4. Capture all-thread backtrace and the crashing/asserting frame.
  5. Set source breakpoints at the suspected QEMU path and rerun.
  6. Add traces or qtest reproduction only after the host-side failure location is known.

Device/board

  1. Confirm image and command line.
  2. qtest the MMIO/IRQ path if possible.
  3. Enable targeted traces.
  4. Check reset state and interrupt-controller route.
  5. Only then interpret full boot logs.

TCG

  1. Reproduce under -accel tcg.
  2. Use one-insn-per-tb for instruction boundary issues.
  3. Compare guest instruction, TCG IR, and host code logs.
  4. Check frontend feature gates and PC/TB state.
  5. Check backend constraints, optional flags, and emitted code.

Debug report

Write the report in .oh-my-qemu/<task-slug>/audit.md and include:

  • command;
  • build directory and QEMU binary;
  • whether debugger target is host QEMU process or guest CPU state;
  • image hashes;
  • failure marker;
  • decisive log/trace paths;
  • classification;
  • next narrow check.

Stop only QEMU processes, debugger servers, and terminal sessions started for this task. Record cleanup and any target-state-changing operation.

Upstream references

  • QEMU code provenance and AI policy: docs/devel/code-provenance.rst.
  • GDB usage: docs/system/gdb.rst.
  • CLI debug options: qemu-options.hx.
  • Tracing: docs/devel/tracing.rst.
  • Replay: docs/system/replay.rst.
  • TCG internals: docs/devel/tcg.rst and docs/devel/tcg-ops.rst.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.