Debug Code With AI: Stack Traces, Logs and iOS Crash Reports
Step-by-step how to debug code with AI: what to paste, prompts for stack traces, logs and iOS crash reports, and how to verify the answer before you ship.
For Engineering

How do you debug code with AI?
Give the AI the evidence, not just the symptom. Paste the full error or stack trace, the code around the line it points to, what you expected to happen, what happened instead, and your environment (language, framework, OS and app version). Then ask for ranked hypotheses with a test that would confirm or rule out each one, instead of asking for "the fix". Run the test yourself before changing any code.
That is the whole method. The rest of this post shows how to do it for stack traces, application logs and iOS crash reports, with prompts you can paste.
TL;DR
- Context beats cleverness. The quality of the answer depends mostly on what you paste: the complete trace, the relevant code, and the exact version of your app and OS.
- Ask for hypotheses, not fixes. A ranked list of likely causes, each with a way to check it, is more reliable than one confident answer.
- For iOS crashes, symbolicate first. A crash report full of hex addresses gives the AI nothing to work with. Match it with the right dSYM so function names and line numbers appear.
- Verify every claim. AI will sometimes cite a function, flag or API that does not exist. Reproduce the bug, apply the change, and confirm the failure is gone.
- Redact before you paste. Strip tokens, customer data, internal hostnames and anything your company's policy forbids sending to an outside tool.
- Finish with a regression test. Ask the AI to write one that fails before the fix and passes after.
What should you gather before asking AI to debug?
Most bad AI debugging sessions start with a one-line message like "my app crashes, why?". The model has to guess, and it will guess confidently. Spend two minutes collecting this first:
| Item | Why it matters |
|---|---|
| Full error text or stack trace | The top frame is rarely the whole story. Keep every line, including "caused by" chains. |
| The code at and around the failing line | Include the function, plus the callers if the trace shows them. |
| Expected vs. actual behavior | Tells the AI what "fixed" looks like. |
| Steps to reproduce, or "only happens sometimes" | Intermittent bugs point toward threading, timing or bad data, and the AI should know. |
| Versions | Language, framework, OS, device, app build number. Many bugs exist only in one release. |
| What changed recently | A new dependency, an OS update or a merged pull request is often the cause. |
| What you already tried | Stops the AI from suggesting the same dead ends. |
If the log file is huge, do not paste all of it. Take the 20 to 50 lines before the first error, the error itself, and a few lines after. The cause often sits just before the first failure, and the later errors are usually fallout.
How do you debug a stack trace with AI?
A stack trace is a list of the function calls that were active when something failed, newest first in most languages (Python prints the most recent call last, which trips people up). The AI is good at reading these because the format is regular and the error messages are well documented.
Step 1. Capture the whole trace. Copy from the first line of the error to the last, including any "Caused by" sections. Truncated traces lead to wrong answers.
Step 2. Add the code. Paste the function named in the first frame that belongs to your code (not a library). If the trace passes through three of your files, include the relevant part of each.
Step 3. Use a prompt that asks for reasoning and checks.
You are helping me debug. Do not rewrite my code yet.
Language/framework: [e.g. Python 3.11, Django 4.2]
What I expected: [one sentence]
What happened: [one sentence]
Happens: [always / intermittently / only in production / after a recent change]
Stack trace:
[paste full trace]
Relevant code:
[paste function(s)]
1. Explain in plain English what this error means.
2. Point to the exact frame where my code is involved.
3. Give the 3 most likely causes, ranked, with the evidence in the
trace or code that supports each.
4. For each cause, tell me one quick check (a log line, a print, a
breakpoint, a test) that would confirm or rule it out.
5. Tell me what information you are missing that would change your ranking.
Step 4. Run the checks. Add the log line or breakpoint the AI suggests. Report the result back in the same conversation: "Cause 1 ruled out, the value is not null. Here is the new output." This back-and-forth is where AI debugging saves time. You are using it like a colleague who is good at spotting patterns.
Step 5. Only then ask for the fix. "Now propose the smallest change that fixes cause 2, and explain what else it could affect."
How do you debug logs with AI?
Logs are harder than stack traces because they are long, noisy and out of order when many requests run at once. AI helps most with three jobs: finding the first real failure, grouping repeated errors, and building a timeline.
Try this prompt with a trimmed excerpt:
Here are logs from [service name] covering [time window]. Timestamps are [UTC / local].
[paste logs]
1. Identify the first error that is not just a consequence of an earlier one.
2. Group the remaining errors by likely shared cause.
3. Build a short timeline of what happened, in order.
4. List what you can say with confidence and what is only a guess.
5. Suggest what additional logging would make this diagnosable next time.
Two cautions. First, models are weak at counting and at precise arithmetic over large pastes. If you need "how many requests failed", use your log tool's query, not the AI's tally. Second, if you filter logs before pasting, say so. Otherwise the AI may read a gap as "nothing happened".
For very large volumes, use AI to write the query instead of reading the logs: "Write a query for [your log tool] that shows 5xx responses grouped by endpoint for the last hour." Check the syntax against your tool's documentation, since query languages differ and models mix them up.
How do you debug iOS crash logs with AI?
iOS crash reports look intimidating, but they follow a fixed structure, and that is why an AI handles them well once you give it the right version of the file.
Step 1: Get the crash report
Common sources:
- Xcode Organizer (Window, then Organizer, then Crashes) for released builds, including TestFlight and App Store builds when users have shared diagnostics.
- Devices and Simulators in Xcode, where you can view logs from a connected device.
- Your crash reporting tool, if you use one. Many of these already symbolicate for you.
- A tester's device, where crash logs appear under Settings, Privacy and Security, Analytics and Improvements, Analytics Data.
Step 2: Symbolicate it
An unsymbolicated report shows memory addresses where function names should be, like MyApp 0x0000000102a4f3c0 0x102a30000 + 127936. Neither you nor the AI can reason about that. Symbolication translates those addresses into function names and line numbers using the dSYM file produced when that exact build was archived. The dSYM must match the build's UUID. A dSYM from a different build gives wrong or empty results.
Xcode symbolicates automatically when the matching dSYM is available (for example, in Organizer if you uploaded symbols). Crash reporting tools need the dSYMs uploaded. If you ship through CI, make uploading dSYMs a build step so you never have to hunt for them later.
Do not ask the AI to "symbolicate" a raw report by guessing. It cannot read your binary, and any function names it produces would be invented.
Step 3: Paste the right parts
You do not need the whole report. Include:
- The header: app version and build, OS version, device model
- Exception Type, Exception Codes and Termination Reason
- Triggered by Thread and that thread's full backtrace
- Backtraces of other threads only if you suspect a deadlock or a race
- The source of the first frame that is your code
Here is a short, illustrative excerpt (made up for this example):
Exception Type: EXC_BREAKPOINT (SIGTRAP)
Termination Reason: SIGNAL 5 Trace/BPT trap: 5
Triggered by Thread: 0
Thread 0 Crashed:
0 MyApp OrderViewController.updateTotal() (OrderViewController.swift:148)
1 MyApp OrderViewController.viewWillAppear(_:) (OrderViewController.swift:61)
2 UIKitCore -[UIViewController _setViewAppearState:isAnimating:]
Step 4: Use a crash-specific prompt
I'm an iOS developer debugging a crash from a released build.
App version/build: [x.y.z (build)]
iOS version and device: [e.g. iOS 17.x, iPhone model]
Frequency: [one user / many users / only on certain OS versions]
Symbolicated crash report (relevant parts):
[paste header, exception info, crashed thread]
Source of the crashing function:
[paste code]
1. Explain what the Exception Type and Termination Reason mean here.
2. Based on the crashed thread, what was the app doing?
3. Give ranked hypotheses for the root cause, each with the evidence.
4. For each, tell me how to reproduce or confirm it (a breakpoint,
a unit test, a scheme setting such as Address Sanitizer or
Thread Sanitizer, or a specific device state).
5. Do not invent symbols or line numbers not shown above.
What the common crash types usually mean
Treat this as a starting point, and ask the AI to explain how it applies to your trace.
| What you see | Usual meaning |
|---|---|
EXC_BAD_ACCESS (often SIGSEGV or SIGBUS) | The code touched memory it should not have: a dangling pointer, use after free, or a bad unsafe pointer. Address Sanitizer helps find it. |
EXC_BREAKPOINT (SIGTRAP) in Swift code | A Swift runtime check failed, such as force-unwrapping nil, an array index out of range, or an arithmetic overflow. The message is often in the report's application-specific information. |
EXC_CRASH (SIGABRT) | The app deliberately aborted, frequently because of an uncaught Objective-C exception or a failed assertion. Look for the exception reason. |
Termination code 0x8badf00d | The system's watchdog killed the app because it took too long, for instance blocking the main thread at launch or while resuming. |
| Crash with no obvious crashing frame, or "terminated due to memory" style reports | Memory pressure. Look at memory usage, large images and leaks, not the last line of code. |
If your trace shows a crash on a background thread with the main thread in the middle of a UI update, say so in the prompt. Threading bugs are where the AI most needs the extra threads' backtraces.
How do you check that the AI's answer is right?
This is the step people skip, and it is where trust gets lost. Do these in order:
- Reproduce first. If you cannot trigger the bug, you cannot know a fix worked. Ask the AI for the narrowest reproduction it can think of, and try it.
- Confirm the diagnosis before the fix. Run the check the AI proposed. If the evidence does not match, tell it and ask for the next hypothesis.
- Verify that APIs and flags exist. Look up any function, build setting or library call you do not recognize in the official documentation. Models sometimes blend versions or invent names.
- Read the change as if a colleague wrote it. Does it fix the cause, or just hide the symptom with a nil check, a try/catch or a delay? Silencing an error is rarely the fix.
- Write a regression test. Prompt: "Write a test that fails with the original code and passes with your fix. Explain what it covers and what it does not."
- Run your existing tests and test the neighboring behavior the change could affect.
What should AI not be trusted with when debugging?
- Anything it cannot see. It does not know your production data, your infrastructure or your binary. If a claim depends on those, treat it as a guess.
- Exact counts and timing math across long logs.
- Security-sensitive fixes. Authentication, encryption and permission bugs deserve a human reviewer, whatever the AI says.
- Invented specifics. Line numbers, symbol names, version numbers and release notes it cites from memory need checking.
- Your private data. Before pasting, remove API keys, session tokens, passwords, personal data in log lines (emails, names, device identifiers) and internal URLs. Check your company's policy on which AI tools are approved for code and logs. If you are unsure, ask your security team, and prefer an approved internal tool.
What are common mistakes when debugging with AI?
- Pasting only the last line of the error. The cause is usually higher in the trace or earlier in the log.
- Asking "fix this" with no expected behavior. The AI will optimize for making the error disappear.
- Accepting the first answer. Ask "what else could cause this?" and "what would prove you wrong?"
- Switching context mid-thread. Long conversations drift. Once you have a diagnosis, start a fresh chat with a short summary of what is confirmed.
- Skipping symbolication on iOS. This is the single most common reason crash analysis goes nowhere.
- Letting the AI refactor while debugging. Keep the change small so you can tell what fixed it.
Can you build a small tool to triage bugs and crash reports?
If your team keeps pasting crash logs into chat threads and spreadsheets, a small internal tool can do better: a form where anyone submits a crash or error report, a place to store the trace and build number, fields for status and owner, and an AI step that summarizes each report and flags likely duplicates. Remy builds this kind of app from a plain-English description, with a database, sign-in and a live URL included, so you describe the workflow and your team gets a working triage board instead of another subscription. Remy builds web apps, not native iOS apps, so it suits the tracking and triage side of the job, not the app that is crashing. You own the code it produces.
Frequently Asked Questions
Can AI read an iOS crash log?
Yes, if the log is symbolicated. AI can explain the exception type, read the crashed thread's backtrace and suggest causes. It cannot symbolicate a raw report for you, because that requires the matching dSYM file from your build. Symbolicate in Xcode or your crash reporting tool first, then paste the result.
Which AI is best for debugging code?
Several general-purpose chat assistants and coding tools handle stack traces well, and the gap between them matters less than what you give them. Complete context, a clear expected behavior and a verification step improve results more than switching tools. Use whichever your company has approved, and compare two if a bug resists the first.
Is it safe to paste logs and stack traces into an AI tool?
Only after you remove secrets and personal data, and only in a tool your company allows. Logs often contain tokens, email addresses, user IDs and internal hostnames without anyone noticing. Redact them, and check your security or IT policy if you are unsure.
Will AI replace debugging skills for junior developers?
It speeds up the reading and hypothesis steps, but you still need to reproduce bugs, judge whether a fix addresses the cause and know when the AI is wrong. Developers who learn to run the checks and read the output understand their systems faster. Those who paste fixes without understanding them tend to ship the same bug twice.
What if the AI's fix does not work?
Report exactly what happened: the new error, or the unchanged behavior. Ask which hypothesis that rules out and what the next most likely one is. If two rounds go nowhere, start a new chat with a clean summary of what you have confirmed, or step away and add logging at the point where reality diverges from your expectations.
Useful for
How we source, write, and correct our articles. Editorial standards
Related articles

RAG vs Fine-Tuning: How to Build a RAG Pipeline That Works

Technical Design Doc and RFC Template (With ADR Example)

How to Roll Out AI Coding Assistants Across an Engineering Org
