agentleFS
moasqmoasq/ios-dev-agent/.agents/skills/debugging/SKILL.md

debugging

Skill4 starsChanged 6 months agoMITView on GitHub

Use when diagnosing runtime crashes, SwiftUI render errors, concurrency violations, or unexpected behavior. Covers crash investigation methodology, LLDB debugging via XcodeBuildMCP, common iOS crash patterns, and the async renderer color crash.

116 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use Problem-Solving Techniques, media-processing and 10 more.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • truongtv22Skill

    Problem-Solving Techniques

    Apply systematic problem-solving techniques for complexity spirals (simplification cascades), innovation blocks (collision-zone thinking), recurring patterns (meta-pattern recognition), assumption constraints (inversion exercise), scale uncertainty (scale game), and dispatch when stuck. Techniques derived from Microsoft Amplifier project patterns adapted for immediate application.

    Also in 4 projects that use this

  • mrgoonieSkill

    media-processing

    Process multimedia files with FFmpeg (video/audio encoding, conversion, streaming, filtering, hardware acceleration) and ImageMagick (image manipulation, format conversion, batch processing, effects, composition). Use when converting media formats, encoding videos with specific codecs (H.264, H.265, VP9), resizing/cropping images, extracting audio from video, applying filters and effects, optimizing file sizes, creating streaming manifests (HLS/DASH), generating thumbnails, batch processing images, creating composite images, or implementing media processing pipelines. Supports 100+ formats, hardware acceleration (NVENC, QSV), and complex filtergraphs.

    Also in 6 projects that use this

  • JetBrainsSkill

    ssr

    Guide for using Structural Search and Replace in IntelliJ. Use when creating or modifying SSR inspections or search patterns.

    Also in 3 projects that use this

  • mrgoonieSkill

    web-frameworks

    Build modern full-stack web applications with Next.js (App Router, Server Components, RSC, PPR, SSR, SSG, ISR), Turborepo (monorepo management, task pipelines, remote caching, parallel execution), and RemixIcon (3100+ SVG icons in outlined/filled styles). Use when creating React applications, implementing server-side rendering, setting up monorepos with multiple packages, optimizing build performance and caching strategies, adding icon libraries, managing shared dependencies, or working with TypeScript full-stack projects.

    Also in 6 projects that use this

  • DevNewbie1826Skill

    remove-ai-slops

    Remove AI-generated code slop from branch changes or an explicit file list while preserving behavior, including junk tests (prose pins, source greps, copied inventories, mock echoes), each proven by its class rule before a cut. Use when asked to remove slop, clean AI code, deslop, clean up generated code, strip slop, prune junk tests, or review generated-code cleanup. Start by locking behavior with regression tests, then use the category and workflow references.

    Also in 3 projects that use this

  • DevNewbie1826Skill

    programming

    MUST USE for work on Python, Rust, TypeScript, JavaScript, or Go source files and project manifests, and whenever a test or spec file is written, reshaped, reviewed, or deleted. Triggers: write or edit code; add, change, or delete a test; test authoring gate; junk tests; new project; Go HTTP service (gin lane); Bubble Tea TUI; CJK IME; Connect-Go RPC; sqlc or pgx; branded IDs; exhaustive matching; unsafe Rust; Miri; oversized file; refactoring; logging, log levels, structured logging, or observability; arena, allocator, bumpalo, const fn, const generics, compile-time programming, zero-allocation APIs, bitfields, repr, scope guards, errdefer-style cleanup, Zig-like patterns, zero-copy parsing, packed data, or FFI; Rust public API design or macros.

    Also in 3 projects that use this

  • +6 more from mrgoonie

The file

We split this skill into the rules it gives an agent

12 rules. 0 are common, 6 are distinctive, and 6 are very specific to this project.

  • 0

    Common

    Most of the 104 edited versions we read keep these.

  • 6

    Distinctive

    This author's own choices. Worth a look.

  • 6

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Use this guide when diagnosing runtime crashes, render errors, or unexpected behavior.

    line 8
  2. Distinctive:

    If XcodeBuildMCP is available:

    line 86
  3. Distinctive:

    If only Apple Xcode MCP: ask the user to copy the backtrace from Xcode's Debug Navigator.

    line 92
  4. Distinctive:

    Read the stack from bottom to top.

    line 95
  5. Very specific:

    Fix: Use static Color(hex:) instead of Color(light:dark:) with UIColor provider

    line 124
  6. Very specific:

    Fix: Ensure all UI-bound state is @MainActor.

    line 129
  7. Very specific:

    Fix: Use AVAudioApplication.requestRecordPermission() (iOS 17+ async).

    line 134
  8. Very specific:

    Fix: Use @ModelActor for background contexts, @MainActor for UI contexts.

    line 139
  9. Very specific:

    Fix: Use Identifiable conformance or stable id: keypath.

    line 144
  10. Distinctive:

    Always get the backtrace first — don't guess

    line 183
  11. Distinctive:

    Check the crashing thread, not Thread 1

    line 184
  12. Very specific:

    Use OSLog (not print()) for debugging

    line 186

“Common” is measured: kept by at least 6 in 10 of the 104 edited versions of this file we could read. “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

iOS Debugging & Crash Investigation

Use this guide when diagnosing runtime crashes, render errors, or unexpected behavior.

MCP Tool Selection — Check What's Available

At the start of a debugging session, check which MCP servers are loaded. Use ToolSearch to probe:

ToolSearch("XcodeBuildMCP")   → if found: full LLDB + simulator + build
ToolSearch("mcp__xcode__")    → if found: build + preview + test (no LLDB)

Priority order:

  1. Apple Xcode MCP (mcp__xcode__*) — use for build, preview, test, issues, build log
  2. XcodeBuildMCP (mcp__XcodeBuildMCP__*) — use ONLY for what Apple Xcode MCP cannot do: LLDB debugging, simulator log capture, screenshots, UI snapshots, video recording

What Apple Xcode MCP handles (prefer these when available):

CapabilityTool
Buildmcp__xcode__BuildProject
Previewmcp__xcode__RenderPreview
Run testsmcp__xcode__RunSomeTests / RunAllTests
Navigator issuesmcp__xcode__XcodeListNavigatorIssues
Build logmcp__xcode__GetBuildLog
Read filesmcp__xcode__XcodeRead
Search codemcp__xcode__XcodeGrep
Find filesmcp__xcode__XcodeGlob
Code diagnosticsmcp__xcode__XcodeRefreshCodeIssuesInFile
Execute snippetmcp__xcode__ExecuteSnippet

What ONLY XcodeBuildMCP can do (fallback to these):

CapabilityTool
LLDB attachmcp__XcodeBuildMCP__debugging__attach
Backtracemcp__XcodeBuildMCP__debugging__stack
Frame variablesmcp__XcodeBuildMCP__debugging__variables
Run LLDB commandmcp__XcodeBuildMCP__debugging__lldb_command
Add breakpointmcp__XcodeBuildMCP__debugging__add_breakpoint
Remove breakpointmcp__XcodeBuildMCP__debugging__remove_breakpoint
Continue executionmcp__XcodeBuildMCP__debugging__continue
Detach debuggermcp__XcodeBuildMCP__debugging__detach
Simulator log capturemcp__XcodeBuildMCP__simulator__start_simulator_log_capture / stop_simulator_log_capture
Launch with logsmcp__XcodeBuildMCP__simulator__launch_app_with_logs
Screenshotmcp__XcodeBuildMCP__simulator__screenshot
UI hierarchy snapshotmcp__XcodeBuildMCP__simulator__snapshot_ui
Record videomcp__XcodeBuildMCP__simulator__record_video
Build & run (sim)mcp__XcodeBuildMCP__simulator__build_and_run

Install XcodeBuildMCP: claude mcp add XcodeBuildMCP -- npx -y xcodebuildmcp@latest mcp

LLDB Crash Debugging Workflow (XcodeBuildMCP required)

1. Build & run:    mcp__XcodeBuildMCP__simulator__build_and_run
2. Set breakpoint: mcp__XcodeBuildMCP__debugging__add_breakpoint
3. When paused:    mcp__XcodeBuildMCP__debugging__stack          → backtrace
4. Inspect vars:   mcp__XcodeBuildMCP__debugging__variables      → local state
5. Run LLDB:       mcp__XcodeBuildMCP__debugging__lldb_command   → "po myVariable"
6. Continue:       mcp__XcodeBuildMCP__debugging__continue
7. Detach:         mcp__XcodeBuildMCP__debugging__detach

IMPORTANT: XcodeBuildMCP manages its OWN debug session. Do NOT run the app from Xcode at the same time — only one debugger can attach. Use build_and_run from XcodeBuildMCP, then attach.

Decision Logic

NeedUse
Build the projectApple Xcode MCP (BuildProject)
Runtime crash / backtraceXcodeBuildMCP (LLDB)
Build errors / diagnosticsApple Xcode MCP (GetBuildLog, XcodeListNavigatorIssues)
UI rendering previewApple Xcode MCP (RenderPreview)
Run testsApple Xcode MCP (RunSomeTests)
Console logs at runtimeXcodeBuildMCP (launch_app_with_logs)
ScreenshotApple Xcode MCP or XcodeBuildMCP
View hierarchyXcodeBuildMCP (snapshot_ui)

Crash Investigation Methodology

Step 1: Get the Backtrace (FIRST thing to do)

If XcodeBuildMCP is available:

→ mcp__XcodeBuildMCP__debugging__stack

This gives the full backtrace from all threads. Find the crashing thread.

If only Apple Xcode MCP: ask the user to copy the backtrace from Xcode's Debug Navigator.

Step 2: Find the First App Frame

Read the stack from bottom to top. The first frame in YOUR code (not Apple/system frames) is the root cause.

Step 3: Inspect State

→ mcp__XcodeBuildMCP__debugging__variables    (local vars)
→ mcp__XcodeBuildMCP__debugging__lldb_command  "po self"
→ mcp__XcodeBuildMCP__debugging__lldb_command  "po someProperty"

Step 4: Set Breakpoints for Next Run

→ mcp__XcodeBuildMCP__debugging__add_breakpoint  file:line or function name
→ mcp__XcodeBuildMCP__debugging__continue

Step 5: Fix and Re-run

Edit the code, rebuild:

→ mcp__xcode__BuildProject                         (preferred — uses Xcode)
→ mcp__XcodeBuildMCP__simulator__build_and_run      (fallback — standalone)

Known Crash Patterns

AsyncRenderer Color Crash (CRITICAL)

See reference/async-renderer-crash.md for the full investigation.

Pattern: EXC_BREAKPOINT on com.apple.SwiftUI.AsyncRenderer with _dispatch_assert_queue_fail Cause: UIKit dynamic color providers (UIColor { traits in ... }) resolved off main queue Fix: Use static Color(hex:) instead of Color(light:dark:) with UIColor provider

Swift 6 Concurrency Violations

Pattern: EXC_BREAKPOINT with _swift_task_checkIsolatedSwift Cause: @MainActor-isolated code accessed from non-isolated context Fix: Ensure all UI-bound state is @MainActor. Snapshot values before crossing isolation boundaries.

AVFoundation on Simulator

Pattern: Crash in AVAudioSession or AVAudioRecorder init Cause: Deprecated APIs (e.g., requestRecordPermission callback-based), simulator audio routing issues, @Sendable Timer closures capturing @MainActor state Fix: Use AVAudioApplication.requestRecordPermission() (iOS 17+ async). Use Task loops instead of Timer.scheduledTimer for metering. Guard recorder.record() return value.

SwiftData Thread Safety

Pattern: Crash on ModelContext access from background thread Cause: ModelContext is not Sendable Fix: Use @ModelActor for background contexts, @MainActor for UI contexts.

ForEach Identity Crash

Pattern: Index out of bounds during list mutation Cause: Using .indices or unstable identity with ForEach Fix: Use Identifiable conformance or stable id: keypath.

Xcode Debugging Tools (Manual)

Breakpoints

  • Exception Breakpoint: Catches all runtime exceptions
  • Symbolic Breakpoint: _dispatch_assert_queue_fail — catches queue violations
  • Swift Error Breakpoint: Catches all thrown Swift errors

Runtime Sanitizers (Scheme → Diagnostics)

SanitizerDetectsCost
Thread SanitizerData races2-5x
Address SanitizerBuffer overflows, use-after-free2-3x
Main Thread CheckerUIKit calls from backgroundMinimal

Always enable Main Thread Checker.

Console Logging

import OSLog
let logger = Logger(subsystem: "com.example.app", category: "debugging")
logger.debug("State: \(String(describing: newValue))")

CLI Debugging

# Launch with console output
xcrun simctl launch --console booted com.example.app

# Find crash logs
find ~/Library/Logs/DiagnosticReports -name "<AppName>*" -type f

# Symbolicate
atos -arch arm64 -o <AppName>.app/<AppName> -l 0x100000000 0x100012345

Rules

  • Always get the backtrace first — don't guess
  • Check the crashing thread, not Thread 1
  • Trust the first app frame in the stack
  • Use OSLog (not print()) for debugging
  • XcodeBuildMCP owns the debug session — don't also run from Xcode

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.