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.

81 other projects use a version of this.

Adopted by

Most recently taken up by

Used with

Projects with it also use media-processing, databases 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.
  • 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 4 projects that use this

  • mrgoonieSkill

    databases

    Work with MongoDB (document database, BSON documents, aggregation pipelines, Atlas cloud) and PostgreSQL (relational database, SQL queries, psql CLI, pgAdmin). Use when designing database schemas, writing queries and aggregations, optimizing indexes for performance, performing database migrations, configuring replication and sharding, implementing backup and restore strategies, managing database users and permissions, analyzing query performance, or administering production databases.

    Also in 5 projects that use this

  • pproencaSkill

    refactoring

    Code refactoring best practices based on Martin Fowler's catalog and Clean Code principles. This skill should be used when refactoring existing code, improving code structure, reducing complexity, eliminating code smells, or reviewing code for maintainability. Triggers on tasks involving extract method, rename, decompose conditional, reduce coupling, or improve readability.

    Also in 17 projects that use this

  • ShopifySkill

    profiling

    Profile Rubydex indexer performance — CPU flamegraphs, memory usage, phase-level timing. Use this skill whenever the user mentions profiling, performance, flamegraphs, benchmarking, "why is X slow", bottlenecks, hot paths, memory usage, or wants to understand where time is spent during indexing/resolution. Also trigger when comparing performance before/after a change.

    Also in 3 projects that use this

  • sarveshtaleleSkill

    test-generation

    Generate a test strategy and starter test stubs for given modules across unit, integration, and e2e layers (pytest/jest/playwright). Trigger on: generate tests, test plan, test strategy, coverage plan, test scaffolding.

    Also in 3 projects that use this

  • MicrosoftSkill

    using-skills

    Describes how to use abilities. Read before any conversation.

    Also in 3 projects that use this

  • +5 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 73 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 73 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.