mirror of
https://github.com/hanzoai/skills.git
synced 2026-11-19 00:47:36 +00:00
Every page now loads /webmcp.js, scripts/webmcp.ts with its types stripped (npm run webmcp). Where the browser has document.modelContext it registers two read-only tools: search_skills over the published skills index, and get_skill, which returns a skill's markdown checked against the index digest. The markdown alternate link moves from build.py to site.py, so CI holds every page to it. The API catalog gains the site itself (llms.txt and the skills index) and hanzo.ai/agents; the live discovery check now fetches every catalog link. tests/site.mjs drives the tools through a recording modelContext, and checks a browser without one loads clean.
809 lines
32 KiB
HTML
809 lines
32 KiB
HTML
<!doctype html>
|
|
<html lang="en"><head>
|
|
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
<title>debugging-lldb-macos-debugging</title>
|
|
<meta name="color-scheme" content="dark">
|
|
<style>
|
|
/* Committed to one visual world: a dark instrument panel. No light variant —
|
|
the dot field and the hairline rules only read on black, and a naive
|
|
inversion would wash both out. Every colour is painted explicitly so the page
|
|
never borrows a host background. */
|
|
@font-face{font-family:'Zen';src:url('/fonts/Zen-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
|
|
@font-face{font-family:'Zen';src:url('/fonts/Zen-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
|
|
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Variable.woff2') format('woff2');font-weight:100 900;font-style:normal;font-display:swap}
|
|
@font-face{font-family:'Zen Mono';src:url('/fonts/ZenMono-Italic-Variable.woff2') format('woff2');font-weight:100 900;font-style:italic;font-display:swap}
|
|
@font-face{font-family:'Zen Pixel Square';src:url('/fonts/ZenPixel-Square.woff2') format('woff2');font-style:normal;font-display:swap}
|
|
|
|
:root{
|
|
--ink:#f4f4f2; --soft:#9c9c98; --faint:#6a6a66; --ground:#000; --panel:#0a0a0a;
|
|
--line:#232323; --line-hi:#3a3a3a; --accent:#f4f4f2;
|
|
--font-zen-sans:'Zen',-apple-system,BlinkMacSystemFont,"Segoe UI",Helvetica,Arial,sans-serif;
|
|
--font-zen-mono:'Zen Mono',ui-monospace,"SF Mono",SFMono-Regular,Menlo,Consolas,monospace;
|
|
--font-zen-pixel-square:'Zen Pixel Square',monospace;
|
|
--mono:var(--font-zen-mono);
|
|
--sans:var(--font-zen-sans);
|
|
/* Controls are pills and surfaces are soft, as on hanzo.ai. */
|
|
--r:999px; --r-soft:14px;
|
|
}
|
|
*{box-sizing:border-box}
|
|
html{-webkit-text-size-adjust:100%}
|
|
body{margin:0;background:var(--ground);color:var(--ink);font-family:var(--sans);
|
|
font-size:16px;line-height:1.65;-webkit-font-smoothing:antialiased}
|
|
.wrap{max-width:60rem;margin:0 auto;padding:0 1.75rem}
|
|
|
|
/* The dot field. A halftone made of one repeating radial-gradient, faded out
|
|
along the diagonal by a mask so it reads as a wave rather than wallpaper. */
|
|
/* No overflow clip here: the dot field is inset to the box already, and a clip
|
|
would cut off the copy-prompt menu. */
|
|
.hero{position:relative;border-bottom:1px solid var(--line)}
|
|
.hero::before{content:"";position:absolute;inset:0;
|
|
background-image:radial-gradient(var(--line-hi) 1px, transparent 1px);
|
|
background-size:7px 7px;
|
|
-webkit-mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
|
|
mask-image:linear-gradient(115deg,#000 0%,rgba(0,0,0,.55) 38%,transparent 72%);
|
|
pointer-events:none}
|
|
.hero .wrap{position:relative;padding-top:5.5rem;padding-bottom:4rem}
|
|
|
|
nav{border-bottom:1px solid var(--line)}
|
|
nav .in{max-width:60rem;margin:0 auto;padding:1.1rem 1.75rem;display:flex;
|
|
justify-content:space-between;align-items:center;gap:1rem}
|
|
.brand{font-family:var(--mono);font-size:.85rem;letter-spacing:.14em;
|
|
text-transform:uppercase;color:var(--ink);text-decoration:none;
|
|
display:inline-flex;align-items:center;gap:.6rem}
|
|
.brand i{font-style:normal;color:var(--faint)}
|
|
.mark{width:1.15em;height:1.15em;display:block;flex:0 0 auto}
|
|
nav a.up{font-family:var(--mono);font-size:.72rem;letter-spacing:.14em;
|
|
text-transform:uppercase;color:var(--soft);text-decoration:none}
|
|
nav a.up:hover{color:var(--ink)}
|
|
|
|
h1{font-family:var(--mono);font-size:clamp(2rem,5.4vw,3.4rem);line-height:1.12;
|
|
letter-spacing:-.02em;margin:0 0 1.1rem;font-weight:500;text-wrap:balance}
|
|
h1 em{font-style:normal;color:var(--faint)}
|
|
.lede{color:var(--soft);font-size:1.05rem;max-width:52ch;margin:0 0 2.25rem}
|
|
|
|
.btns{display:flex;flex-wrap:wrap;gap:.7rem;margin:0 0 .5rem;align-items:center}
|
|
.btn{display:inline-flex;align-items:center;gap:.5rem;font-family:var(--mono);
|
|
font-size:.72rem;letter-spacing:.14em;text-transform:uppercase;
|
|
padding:.8rem 1.4rem;border:1px solid var(--line-hi);border-radius:var(--r);
|
|
color:var(--ink);text-decoration:none;background:transparent;cursor:pointer;
|
|
line-height:1.2;font-weight:400}
|
|
.btn:hover{background:#141414;text-decoration:none;border-color:var(--soft)}
|
|
.btn.solid{background:var(--ink);color:#000;border-color:var(--ink)}
|
|
.btn.solid:hover{background:#d8d8d4}
|
|
.btn .chev{width:.7em;height:.7em;flex:0 0 auto;transition:transform .15s ease}
|
|
.btn[aria-expanded="true"] .chev{transform:rotate(180deg)}
|
|
|
|
/* Copy-prompt selector. Each row copies the prompt for its own target. */
|
|
.copy{position:relative;display:inline-flex}
|
|
.menu{position:absolute;top:calc(100% + .5rem);left:0;z-index:20;min-width:21rem;
|
|
background:var(--panel);border:1px solid var(--line-hi);border-radius:var(--r-soft);
|
|
padding:.4rem;display:flex;flex-direction:column;
|
|
box-shadow:0 12px 32px rgba(0,0,0,.75)}
|
|
.menu[hidden]{display:none}
|
|
.mi{display:flex;align-items:center;gap:.7rem;width:100%;text-align:left;
|
|
padding:.62rem .8rem;border:0;border-radius:calc(var(--r-soft) - .35rem);
|
|
background:transparent;color:var(--ink);font-family:var(--mono);font-size:.76rem;
|
|
letter-spacing:.04em;text-decoration:none;cursor:pointer;line-height:1.3;
|
|
white-space:nowrap}
|
|
.mi:hover,.mi:focus-visible{background:#181818;outline:none}
|
|
.mi .mark{width:1.05rem;height:1.05rem;color:var(--soft)}
|
|
.mi:hover .mark{color:var(--ink)}
|
|
.mi u{margin-left:auto;color:var(--faint);text-decoration:none;font-size:.68rem;
|
|
letter-spacing:.1em;text-transform:uppercase}
|
|
|
|
/* Works-with bar: one scrolling row, name and mark per agent. */
|
|
.strip{border-bottom:1px solid var(--line);background:var(--panel)}
|
|
.strip .in{max-width:60rem;margin:0 auto;padding:.9rem 1.75rem;display:flex;
|
|
align-items:center;gap:1.25rem;font-family:var(--mono);font-size:.72rem;
|
|
letter-spacing:.1em;text-transform:uppercase;color:var(--faint)}
|
|
.strip b{color:var(--soft);font-weight:400;flex:0 0 auto;
|
|
border-right:1px solid var(--line);padding-right:1.25rem;align-self:stretch;
|
|
display:flex;align-items:center}
|
|
.bar{display:flex;align-items:center;gap:.5rem;flex:1 1 auto;min-width:0;
|
|
overflow-x:auto;scrollbar-width:none;scroll-snap-type:x proximity;
|
|
-webkit-overflow-scrolling:touch;
|
|
-webkit-mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent);
|
|
mask-image:linear-gradient(90deg,#000 calc(100% - 3rem),transparent)}
|
|
.bar::-webkit-scrollbar{display:none}
|
|
.agent{display:inline-flex;align-items:center;gap:.45rem;flex:0 0 auto;
|
|
padding:.4rem .85rem;border:1px solid var(--line);border-radius:var(--r);
|
|
color:var(--soft);white-space:nowrap;scroll-snap-align:start;
|
|
text-decoration:none;background:var(--ground)}
|
|
.agent:hover{color:var(--ink);border-color:var(--line-hi);text-decoration:none}
|
|
.agent .mark{width:.95rem;height:.95rem}
|
|
|
|
h2{font-family:var(--mono);font-size:1.1rem;letter-spacing:-.01em;margin:2.75rem 0 .75rem;font-weight:500}
|
|
h3{font-size:1rem;margin:2rem 0 .5rem;font-weight:600}
|
|
h4,h5,h6{font-size:.94rem;margin:1.5rem 0 .5rem;font-weight:600}
|
|
p{margin:0 0 1rem;max-width:70ch}
|
|
ul,ol{margin:0 0 1rem;padding-left:1.35rem;max-width:70ch}
|
|
li{margin:.22rem 0}
|
|
a{color:var(--ink);text-decoration:underline;text-underline-offset:3px;
|
|
text-decoration-color:var(--line-hi)}
|
|
a:hover{text-decoration-color:var(--ink)}
|
|
a:focus-visible{outline:1px solid var(--ink);outline-offset:3px}
|
|
code{font-family:var(--mono);font-size:.85em;background:var(--panel);
|
|
border:1px solid var(--line);border-radius:5px;padding:.1em .36em}
|
|
pre{background:var(--panel);border:1px solid var(--line);padding:1rem 1.1rem;
|
|
border-radius:var(--r-soft);overflow-x:auto;margin:0 0 1.25rem}
|
|
pre code{background:none;border:0;padding:0;font-size:.82rem;line-height:1.7}
|
|
blockquote{margin:0 0 1rem;padding-left:1rem;border-left:1px solid var(--line-hi);color:var(--soft)}
|
|
hr{border:0;border-top:1px solid var(--line);margin:2.5rem 0}
|
|
table{border-collapse:collapse;width:100%;margin:0 0 1.25rem;font-size:.92rem;
|
|
display:block;overflow-x:auto}
|
|
th,td{border:1px solid var(--line);padding:.5rem .7rem;text-align:left}
|
|
|
|
.curl{display:block;background:var(--panel);border:1px solid var(--line);
|
|
border-radius:var(--r-soft);padding:.95rem 1.1rem;font-family:var(--mono);
|
|
font-size:.8rem;color:var(--soft);overflow-x:auto;margin:0 0 2.5rem;
|
|
white-space:pre;line-height:1.9}
|
|
.curl b{color:var(--ink);font-weight:400}
|
|
.curl i{font-style:normal;color:var(--faint)}
|
|
|
|
/* index */
|
|
#q{width:100%;padding:.85rem 1.2rem;font-family:var(--mono);font-size:.85rem;color:var(--ink);
|
|
background:var(--panel);border:1px solid var(--line);border-radius:var(--r);margin:0 0 .6rem}
|
|
#q::placeholder{color:var(--faint);text-transform:uppercase;letter-spacing:.1em;font-size:.72rem}
|
|
#q:focus{outline:none;border-color:var(--soft)}
|
|
#count{color:var(--faint);font-family:var(--mono);font-size:.72rem;letter-spacing:.1em;
|
|
text-transform:uppercase;margin:0 0 2rem}
|
|
.cat{margin:2.5rem 0 .5rem;font-family:var(--mono);font-size:.7rem;letter-spacing:.16em;
|
|
text-transform:uppercase;color:var(--faint);border-bottom:1px solid var(--line);
|
|
padding-bottom:.45rem}
|
|
.row{display:block;padding:.6rem .9rem;margin:0 -.9rem;border-bottom:1px solid var(--line);
|
|
border-radius:var(--r-soft);text-decoration:none}
|
|
.row:hover{background:#0a0a0a}
|
|
.nm{font-family:var(--mono);font-size:.84rem;color:var(--ink);display:block}
|
|
.ds{color:var(--soft);font-size:.9rem;display:block;margin-top:.12rem}
|
|
footer{margin-top:4rem;padding:2rem 0 4rem;border-top:1px solid var(--line);
|
|
color:var(--faint);font-size:.85rem}
|
|
footer a{color:var(--soft)}
|
|
.fmap{display:grid;gap:1.75rem;grid-template-columns:repeat(auto-fit,minmax(11rem,1fr));
|
|
margin:0 0 2rem;font-size:.85rem}
|
|
.fmap b{display:block;font-family:var(--mono);font-size:.68rem;letter-spacing:.16em;
|
|
text-transform:uppercase;color:var(--faint);font-weight:400;margin:0 0 .6rem;
|
|
border-bottom:1px solid var(--line);padding-bottom:.4rem}
|
|
.fmap a{display:inline-block;color:var(--ink);text-decoration:none;margin:.3rem .35rem 0 0}
|
|
.fmap a:hover{text-decoration:underline}
|
|
.fmap div{color:var(--faint);line-height:1.5}
|
|
.fend{border-top:1px solid var(--line);padding-top:1.25rem;font-size:.82rem}
|
|
|
|
@media (max-width:640px){
|
|
.hero .wrap{padding-top:3.25rem;padding-bottom:2.75rem}
|
|
.btns{gap:.5rem}
|
|
.btn{padding:.75rem 1.15rem;font-size:.68rem}
|
|
.copy,.copy .btn{width:100%;justify-content:center}
|
|
.menu{left:0;right:0;min-width:0}
|
|
.strip .in{flex-direction:column;align-items:flex-start;gap:.6rem;padding:.9rem 1.75rem}
|
|
.strip b{border-right:0;padding-right:0}
|
|
.bar{width:100%}
|
|
}
|
|
</style>
|
|
<link rel="icon" href="/favicon.svg">
|
|
<link rel="canonical" href="https://hanzoskills.com/debugging-lldb-macos-debugging">
|
|
<link rel="alternate" type="text/markdown" href="/debugging-lldb-macos-debugging.md">
|
|
<script type="module" src="/webmcp.js"></script>
|
|
</head>
|
|
<!-- Reading this with a machine? Every page here is also plain markdown.
|
|
This one: https://hanzoskills.com/debugging-lldb-macos-debugging.md
|
|
Index: https://hanzoskills.com/llms.txt
|
|
Corpus: https://hanzoskills.com/all.md
|
|
Append .md to any path for the markdown twin. -->
|
|
<body>
|
|
<nav><div class="in">
|
|
<a class="brand" href="/"><svg class="mark" viewBox="0 0 67 67" fill="currentColor" aria-hidden="true"><path d="M22.21 67V44.6369H0V67H22.21Z"/><path d="M66.7038 22.3184H22.2534L0.0878906 44.6367H44.4634L66.7038 22.3184Z"/><path d="M22.21 0H0V22.3184H22.21V0Z"/><path d="M66.7198 0H44.5098V22.3184H66.7198V0Z"/><path d="M66.7198 67V44.6369H44.5098V67H66.7198Z"/></svg> HANZO<i>SKILLS</i></a>
|
|
<a class="up" href="/">All skills</a>
|
|
</div></nav>
|
|
|
|
<div class="wrap">
|
|
<h1>debugging-lldb-macos-debugging</h1><p class="lede">Comprehensive guide to LLDB debugger for macOS/iOS development. Covers LLDB vs GDB differences, Swift/Objective-C debugging, Xcode integration, command-line usage, breakpoint expressions, watchpoints, Python scripting, and performance improvements (50x faster step-over in 2025).</p><h1>LLDB macOS Debugging</h1>
|
|
<p><strong>Last Updated</strong>: 2025-10-26</p>
|
|
<h2>Overview</h2>
|
|
<p>LLDB is the default debugger for macOS, iOS, and Apple platforms. It's the backend for Xcode's debugger and provides superior Swift/Objective-C debugging compared to GDB. As of 2025, LLDB features 50x faster step-over performance for optimized Swift code.</p>
|
|
<h2>Core Concepts</h2>
|
|
<h3>LLDB vs GDB</h3>
|
|
<p>| Feature | GDB | LLDB | |---------|-----|------| | Swift debugging | Limited | Native | | Objective-C | Basic | Excellent | | macOS integration | Poor | Native | | Xcode backend | No | Yes | | Command syntax | Abbreviated | Structured | | Performance (2025) | Baseline | 50x faster step-over |</p>
|
|
<h3>LLDB Architecture</h3>
|
|
<pre><code>Debuggee (App/Binary)
|
|
↓
|
|
debugserver (macOS/iOS)
|
|
↓
|
|
LLDB (debugger)
|
|
↓
|
|
Xcode UI / Command Line</code></pre>
|
|
<hr>
|
|
<h2>Installation & Setup</h2>
|
|
<h3>Verify Installation</h3>
|
|
<pre><code class="lang-bash"># Check LLDB version
|
|
lldb --version
|
|
# lldb-1600.0.0 (2025 version)
|
|
|
|
# Check Xcode Command Line Tools
|
|
xcode-select -p
|
|
|
|
# Install if missing
|
|
xcode-select --install</code></pre>
|
|
<h3>Command-Line Launch</h3>
|
|
<pre><code class="lang-bash"># Launch LLDB with binary
|
|
lldb ./my_program
|
|
|
|
# Launch with arguments
|
|
lldb -- ./my_program arg1 arg2
|
|
|
|
# Attach to running process
|
|
lldb -p <pid>
|
|
lldb -n ProcessName
|
|
|
|
# Load and run immediately
|
|
lldb -o "run" ./my_program</code></pre>
|
|
<hr>
|
|
<h2>Command Syntax: LLDB vs GDB</h2>
|
|
<h3>Structured Commands</h3>
|
|
<p>LLDB uses structured syntax: <code><command> <subcommand> [options]</code></p>
|
|
<pre><code>GDB → LLDB
|
|
────────────────────────────────────────────────
|
|
break main → breakpoint set -n main
|
|
break file.c:42 → breakpoint set -f file.c -l 42
|
|
continue → continue (same)
|
|
step → thread step-in
|
|
next → thread step-over
|
|
finish → thread step-out
|
|
backtrace → thread backtrace
|
|
print var → expr var / p var
|
|
run → process launch / run
|
|
attach <pid> → process attach -p <pid>
|
|
info breakpoints → breakpoint list</code></pre>
|
|
<h3>Aliases</h3>
|
|
<p>LLDB provides GDB-compatible aliases:</p>
|
|
<pre><code class="lang-lldb">(lldb) run # Alias for process launch
|
|
(lldb) r # Short form
|
|
(lldb) step # Alias for thread step-in
|
|
(lldb) s # Short form
|
|
(lldb) next # Alias for thread step-over
|
|
(lldb) n # Short form
|
|
(lldb) continue # Same as GDB
|
|
(lldb) c # Short form</code></pre>
|
|
<hr>
|
|
<h2>Breakpoints</h2>
|
|
<h3>Setting Breakpoints</h3>
|
|
<p><strong>Function breakpoints</strong>:</p>
|
|
<pre><code class="lang-lldb"># Swift function
|
|
(lldb) breakpoint set -n MyClass.myMethod
|
|
(lldb) br s -n MyClass.myMethod
|
|
(lldb) b MyClass.myMethod
|
|
|
|
# Objective-C method
|
|
(lldb) breakpoint set -n "-[MyClass myMethod:]"
|
|
(lldb) b -[MyClass myMethod:]
|
|
|
|
# C function
|
|
(lldb) breakpoint set -n main
|
|
(lldb) b main
|
|
|
|
# Regex breakpoint
|
|
(lldb) breakpoint set -r 'MyClass.*'
|
|
(lldb) rb 'calculate.*'</code></pre>
|
|
<p><strong>File and line breakpoints</strong>:</p>
|
|
<pre><code class="lang-lldb"># Break at file:line
|
|
(lldb) breakpoint set -f ViewController.swift -l 42
|
|
(lldb) br s -f ViewController.swift -l 42
|
|
(lldb) b ViewController.swift:42
|
|
|
|
# Break in current file
|
|
(lldb) breakpoint set -l 100</code></pre>
|
|
<p><strong>Conditional breakpoints</strong>:</p>
|
|
<pre><code class="lang-lldb"># Break if condition true
|
|
(lldb) breakpoint set -n process_data -c 'count > 100'
|
|
(lldb) br s -n myMethod -c 'userName == "admin"'
|
|
|
|
# Modify existing breakpoint
|
|
(lldb) breakpoint modify -c 'index >= 5' 1</code></pre>
|
|
<h3>Managing Breakpoints</h3>
|
|
<pre><code class="lang-lldb"># List all breakpoints
|
|
(lldb) breakpoint list
|
|
(lldb) br l
|
|
|
|
# Disable/enable breakpoint
|
|
(lldb) breakpoint disable 1
|
|
(lldb) breakpoint enable 1
|
|
|
|
# Delete breakpoint
|
|
(lldb) breakpoint delete 1
|
|
(lldb) br del 1
|
|
|
|
# Delete all breakpoints
|
|
(lldb) breakpoint delete
|
|
|
|
# Ignore breakpoint N times
|
|
(lldb) breakpoint modify -i 10 1</code></pre>
|
|
<h3>Watchpoints</h3>
|
|
<p><strong>Monitor memory changes</strong>:</p>
|
|
<pre><code class="lang-lldb"># Watch variable
|
|
(lldb) watchpoint set variable myVariable
|
|
(lldb) watch set var myVariable
|
|
|
|
# Watch memory address
|
|
(lldb) watchpoint set expression -- 0x7ffeefbff5b0
|
|
(lldb) watch set expr -- 0x7ffeefbff5b0
|
|
|
|
# Watch with condition
|
|
(lldb) watchpoint set variable count
|
|
(lldb) watchpoint modify -c 'count > 100' 1
|
|
|
|
# List watchpoints
|
|
(lldb) watchpoint list
|
|
|
|
# Delete watchpoint
|
|
(lldb) watchpoint delete 1</code></pre>
|
|
<hr>
|
|
<h2>Program Control</h2>
|
|
<h3>Running Programs</h3>
|
|
<pre><code class="lang-lldb"># Launch program
|
|
(lldb) process launch
|
|
(lldb) run
|
|
(lldb) r
|
|
|
|
# Launch with arguments
|
|
(lldb) process launch -- arg1 arg2
|
|
(lldb) run arg1 arg2
|
|
|
|
# Set arguments before launch
|
|
(lldb) settings set target.run-args arg1 arg2
|
|
(lldb) run
|
|
|
|
# Launch with environment variables
|
|
(lldb) env VAR=value
|
|
(lldb) run
|
|
|
|
# Launch with input redirection
|
|
(lldb) process launch -i input.txt</code></pre>
|
|
<h3>Stepping Through Code</h3>
|
|
<pre><code class="lang-lldb"># Step into (enter functions)
|
|
(lldb) thread step-in
|
|
(lldb) step
|
|
(lldb) s
|
|
|
|
# Step over (don't enter functions)
|
|
(lldb) thread step-over
|
|
(lldb) next
|
|
(lldb) n
|
|
|
|
# Step out (finish current function)
|
|
(lldb) thread step-out
|
|
(lldb) finish
|
|
|
|
# Step one instruction
|
|
(lldb) thread step-inst
|
|
(lldb) stepi
|
|
(lldb) si
|
|
|
|
# Continue until line
|
|
(lldb) thread until 50
|
|
|
|
# Continue execution
|
|
(lldb) process continue
|
|
(lldb) continue
|
|
(lldb) c</code></pre>
|
|
<h3>Performance: 50x Faster Step-Over (2025)</h3>
|
|
<p><strong>Context</strong>: As of 2025, LLDB step-over is 50x faster for optimized Swift code compared to 2020 versions.</p>
|
|
<p><strong>Usage</strong>:</p>
|
|
<pre><code class="lang-lldb"># Fast step-over in Swift (2025 LLDB)
|
|
(lldb) thread step-over # 50x faster than older LLDB
|
|
|
|
# Enable performance optimizations
|
|
(lldb) settings set target.skip-prologue true
|
|
(lldb) settings set target.process.optimization-warnings false</code></pre>
|
|
<p><strong>Benchmark</strong> (2025 data):</p>
|
|
<pre><code>Stepping through 1000 lines of optimized Swift:
|
|
- LLDB 2020: ~25 seconds
|
|
- LLDB 2025: ~0.5 seconds (50x improvement)</code></pre>
|
|
<hr>
|
|
<h2>Stack Inspection</h2>
|
|
<h3>Backtraces</h3>
|
|
<pre><code class="lang-lldb"># Full backtrace
|
|
(lldb) thread backtrace
|
|
(lldb) bt
|
|
|
|
# Backtrace with arguments
|
|
(lldb) bt all
|
|
|
|
# Backtrace all threads
|
|
(lldb) thread backtrace all
|
|
|
|
# Limited backtrace
|
|
(lldb) thread backtrace -c 10</code></pre>
|
|
<h3>Frame Navigation</h3>
|
|
<pre><code class="lang-lldb"># Show current frame
|
|
(lldb) frame info
|
|
|
|
# Select frame
|
|
(lldb) frame select 2
|
|
(lldb) f 2
|
|
|
|
# Move up/down
|
|
(lldb) up
|
|
(lldb) down
|
|
|
|
# Show frame variables
|
|
(lldb) frame variable
|
|
(lldb) fr v
|
|
|
|
# Show specific variable
|
|
(lldb) frame variable count
|
|
(lldb) fr v count</code></pre>
|
|
<hr>
|
|
<h2>Variable Inspection</h2>
|
|
<h3>Expression Evaluation</h3>
|
|
<pre><code class="lang-lldb"># Evaluate expression
|
|
(lldb) expression count + 1
|
|
(lldb) expr count + 1
|
|
(lldb) p count + 1
|
|
|
|
# Assign variable
|
|
(lldb) expr count = 42
|
|
|
|
# Call function
|
|
(lldb) expr -l swift -- print("Debug message")
|
|
(lldb) po print("Debug message") # Swift
|
|
|
|
# Objective-C call
|
|
(lldb) expr -l objc -- (void)[self printDebugInfo]
|
|
(lldb) po [self description]</code></pre>
|
|
<h3>Swift Debugging</h3>
|
|
<p><strong>Print Swift objects</strong>:</p>
|
|
<pre><code class="lang-lldb"># Print description (CustomStringConvertible)
|
|
(lldb) po myObject
|
|
|
|
# Print detailed info
|
|
(lldb) frame variable -D myObject
|
|
(lldb) fr v -D myObject
|
|
|
|
# Print type
|
|
(lldb) type lookup MyClass</code></pre>
|
|
<p><strong>Swift-specific commands</strong>:</p>
|
|
<pre><code class="lang-lldb"># Import Swift module
|
|
(lldb) expr import MyFramework
|
|
|
|
# Swift REPL (exit with :quit)
|
|
(lldb) repl</code></pre>
|
|
<h3>Objective-C Debugging</h3>
|
|
<p><strong>Print Objective-C objects</strong>:</p>
|
|
<pre><code class="lang-lldb"># Print description
|
|
(lldb) po myObject
|
|
(lldb) expr -O -- myObject
|
|
|
|
# Call method
|
|
(lldb) po [myArray count]
|
|
(lldb) po [myString uppercaseString]
|
|
|
|
# Print ivar
|
|
(lldb) po myObject->_privateIvar</code></pre>
|
|
<h3>Memory Examination</h3>
|
|
<pre><code class="lang-lldb"># Read memory
|
|
(lldb) memory read 0x7ffeefbff5b0
|
|
(lldb) x 0x7ffeefbff5b0
|
|
|
|
# Read with format
|
|
(lldb) memory read -f x -c 10 0x7ffeefbff5b0 # 10 hex values
|
|
(lldb) x/10xw 0x7ffeefbff5b0 # GDB syntax also works
|
|
|
|
# Read string
|
|
(lldb) memory read -f s 0x100003f80
|
|
(lldb) x/s 0x100003f80
|
|
|
|
# Write memory (dangerous!)
|
|
(lldb) memory write 0x7ffeefbff5b0 0x42</code></pre>
|
|
<hr>
|
|
<h2>Xcode Integration</h2>
|
|
<h3>Xcode Debugger Console</h3>
|
|
<p><strong>Access LLDB console in Xcode</strong>:</p>
|
|
<ol><li>Run app (Cmd+R)</li><li>Pause execution (breakpoint or pause button)</li><li>View > Debug Area > Activate Console (Cmd+Shift+Y)</li><li>Type LLDB commands in console</li></ol>
|
|
<p><strong>Common Xcode workflows</strong>:</p>
|
|
<pre><code class="lang-lldb"># In Xcode console, all LLDB commands work
|
|
|
|
# Print variable
|
|
(lldb) po self.userName
|
|
|
|
# Modify variable
|
|
(lldb) expr self.count = 10
|
|
|
|
# Continue
|
|
(lldb) continue
|
|
|
|
# Force unwrap Swift optional
|
|
(lldb) po myOptional!
|
|
|
|
# Break on exception
|
|
(lldb) breakpoint set -E swift
|
|
(lldb) br s -E objc # Objective-C exceptions</code></pre>
|
|
<h3>Symbolic Breakpoints in Xcode</h3>
|
|
<ol><li>Debug Navigator (Cmd+7)</li><li>Click + → Symbolic Breakpoint</li><li>Symbol: <code>MyClass.myMethod</code> or <code>-[MyClass myMethod:]</code></li><li>Condition: <code>count > 10</code></li><li>Action: Log message, run script, etc.</li></ol>
|
|
<h3>View Debugging</h3>
|
|
<p><strong>Xcode View Debugger</strong> (3D UI hierarchy):</p>
|
|
<ol><li>Run app</li><li>Debug > View Debugging > Capture View Hierarchy</li><li>Inspect view properties in inspector</li></ol>
|
|
<p><strong>LLDB view commands</strong>:</p>
|
|
<pre><code class="lang-lldb"># Print view hierarchy (UIKit)
|
|
(lldb) po UIApplication.shared.keyWindow?.rootViewController?.view.recursiveDescription()
|
|
|
|
# Print responder chain
|
|
(lldb) po [UIResponder.firstResponder]
|
|
|
|
# Modify view
|
|
(lldb) expr ((UIView *)0x7f8a3d4050f0).backgroundColor = UIColor.red</code></pre>
|
|
<hr>
|
|
<h2>Advanced Features</h2>
|
|
<h3>Python Scripting</h3>
|
|
<p><strong>Load Python script</strong>:</p>
|
|
<pre><code class="lang-lldb">(lldb) command script import ~/lldb_scripts/my_script.py</code></pre>
|
|
<p><strong>my_script.py</strong>:</p>
|
|
<pre><code class="lang-python">import lldb
|
|
|
|
def hello_command(debugger, command, result, internal_dict):
|
|
"""Print hello message."""
|
|
print(f"Hello, {command}!")
|
|
|
|
def __lldb_init_module(debugger, internal_dict):
|
|
debugger.HandleCommand('command script add -f my_script.hello_command hello')
|
|
print("Custom commands loaded")</code></pre>
|
|
<p><strong>Swift pretty printer</strong>:</p>
|
|
<pre><code class="lang-python">import lldb
|
|
|
|
def swift_array_summary(valobj, internal_dict):
|
|
"""Custom summary for Swift Array."""
|
|
count = valobj.GetChildAtIndex(0).GetValueAsUnsigned()
|
|
return f"Array with {count} elements"
|
|
|
|
def __lldb_init_module(debugger, internal_dict):
|
|
debugger.HandleCommand('type summary add -F my_script.swift_array_summary "Swift.Array"')</code></pre>
|
|
<h3>.lldbinit Customization</h3>
|
|
<p><strong>~/.lldbinit</strong> (global) or <strong>./.lldbinit</strong> (project):</p>
|
|
<pre><code class="lang-lldb"># Settings
|
|
settings set target.skip-prologue false
|
|
settings set target.process.extra-startup-command QSetLogging:bitmask=LOG_ALL;
|
|
|
|
# Aliases
|
|
command alias bfl breakpoint set -f %1 -l %2
|
|
command alias bp breakpoint set -n %1
|
|
|
|
# Auto-import scripts
|
|
command script import ~/lldb_scripts/swift_helpers.py
|
|
|
|
# Break on Swift errors
|
|
breakpoint set -E swift
|
|
|
|
# Stop on Objective-C exceptions
|
|
breakpoint set -E objc</code></pre>
|
|
<h3>Custom Commands</h3>
|
|
<pre><code class="lang-lldb"># Create alias
|
|
(lldb) command alias bfl breakpoint set -f %1 -l %2
|
|
|
|
# Use alias
|
|
(lldb) bfl ViewController.swift 42
|
|
|
|
# Create regex command
|
|
(lldb) command regex jump 's/(.+)/thread jump --by %1/'
|
|
|
|
# Use regex
|
|
(lldb) jump 5 # Jump forward 5 lines</code></pre>
|
|
<hr>
|
|
<h2>Remote Debugging</h2>
|
|
<h3>iOS Device Debugging</h3>
|
|
<p><strong>Xcode handles this automatically</strong>, but for manual setup:</p>
|
|
<pre><code class="lang-lldb"># Connect device via USB
|
|
# Start debugserver on device (requires jailbreak or Xcode)
|
|
|
|
# On Mac:
|
|
(lldb) platform select remote-ios
|
|
(lldb) platform connect connect://localhost:6666
|
|
(lldb) file /path/to/MyApp.app/MyApp
|
|
(lldb) run</code></pre>
|
|
<h3>Remote macOS Debugging</h3>
|
|
<p><strong>Start debugserver on remote Mac</strong>:</p>
|
|
<pre><code class="lang-bash"># Remote Mac
|
|
/Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Resources/debugserver localhost:2345 ./my_program</code></pre>
|
|
<p><strong>Connect from local Mac</strong>:</p>
|
|
<pre><code class="lang-lldb"># Local Mac
|
|
(lldb) platform select remote-macosx
|
|
(lldb) platform connect connect://192.168.1.100:2345
|
|
(lldb) continue</code></pre>
|
|
<hr>
|
|
<h2>Swift-Specific Debugging</h2>
|
|
<h3>Swift Error Handling</h3>
|
|
<pre><code class="lang-lldb"># Break on Swift error throw
|
|
(lldb) breakpoint set -E swift
|
|
(lldb) br s -E swift
|
|
|
|
# Break on specific error type
|
|
(lldb) breakpoint set -E swift -O "MyError"</code></pre>
|
|
<h3>Swift Type Inspection</h3>
|
|
<pre><code class="lang-lldb"># Inspect type metadata
|
|
(lldb) type lookup MyStruct
|
|
|
|
# Dump type layout
|
|
(lldb) type lookup --show-layout MyClass
|
|
|
|
# Print protocol conformances
|
|
(lldb) expr -l swift -- import Foundation
|
|
(lldb) expr -l swift -- print(type(of: myObject))</code></pre>
|
|
<h3>Swift REPL</h3>
|
|
<pre><code class="lang-lldb"># Launch Swift REPL
|
|
(lldb) repl
|
|
|
|
# In REPL:
|
|
1> import Foundation
|
|
2> let url = URL(string: "https://example.com")
|
|
3> print(url)
|
|
4> :quit</code></pre>
|
|
<hr>
|
|
<h2>Objective-C-Specific Debugging</h2>
|
|
<h3>Method Breakpoints</h3>
|
|
<pre><code class="lang-lldb"># Instance method
|
|
(lldb) breakpoint set -n "-[MyClass myMethod:]"
|
|
(lldb) b -[MyClass myMethod:]
|
|
|
|
# Class method
|
|
(lldb) breakpoint set -n "+[MyClass classMethod]"
|
|
(lldb) b +[MyClass classMethod]
|
|
|
|
# All methods in class
|
|
(lldb) breakpoint set -r '\[MyClass .*\]'</code></pre>
|
|
<h3>Message Tracing</h3>
|
|
<pre><code class="lang-lldb"># Trace all messages to object
|
|
(lldb) expr (void)instrumentObjcMessageSends(YES)
|
|
|
|
# Check /tmp/msgSends-<pid> for log</code></pre>
|
|
<hr>
|
|
<h2>Performance Optimization</h2>
|
|
<h3>Faster Debugging (2025 Best Practices)</h3>
|
|
<pre><code class="lang-lldb"># Enable fast step-over (2025 feature)
|
|
(lldb) settings set target.skip-prologue true
|
|
|
|
# Reduce output verbosity
|
|
(lldb) settings set thread.format "thread #${thread.index}: tid = ${thread.id}\n"
|
|
|
|
# Disable auto-summary for large collections
|
|
(lldb) type summary delete "Swift.Array"
|
|
|
|
# Use hardware breakpoints (limited, but faster)
|
|
(lldb) breakpoint set -n main -H</code></pre>
|
|
<h3>Benchmarking LLDB Performance</h3>
|
|
<pre><code class="lang-bash"># Profile LLDB command execution
|
|
time lldb -b -o "run" -o "bt" -o "quit" ./my_program
|
|
|
|
# Enable LLDB logging
|
|
(lldb) log enable lldb all
|
|
(lldb) log enable gdb-remote packets</code></pre>
|
|
<hr>
|
|
<h2>Core Dump Analysis (macOS)</h2>
|
|
<h3>Enable Core Dumps</h3>
|
|
<pre><code class="lang-bash"># macOS: core dumps disabled by default
|
|
ulimit -c unlimited
|
|
|
|
# Set core file location
|
|
sudo sysctl -w kern.corefile=/tmp/core.%P
|
|
|
|
# Check settings
|
|
ulimit -c
|
|
sysctl kern.corefile</code></pre>
|
|
<h3>Load Core Dump</h3>
|
|
<pre><code class="lang-lldb"># Load core dump
|
|
lldb -c /tmp/core.12345 ./my_program
|
|
|
|
# Or within LLDB:
|
|
(lldb) target create ./my_program
|
|
(lldb) target core /tmp/core.12345
|
|
|
|
# Analyze
|
|
(lldb) bt
|
|
(lldb) frame info
|
|
(lldb) thread backtrace all</code></pre>
|
|
<hr>
|
|
<h2>Multi-threaded Debugging</h2>
|
|
<h3>Thread Commands</h3>
|
|
<pre><code class="lang-lldb"># List threads
|
|
(lldb) thread list
|
|
|
|
# Select thread
|
|
(lldb) thread select 2
|
|
|
|
# Backtrace all threads
|
|
(lldb) thread backtrace all
|
|
|
|
# Apply command to all threads
|
|
(lldb) thread apply all bt
|
|
|
|
# Step only current thread
|
|
(lldb) thread step-over</code></pre>
|
|
<hr>
|
|
<h2>Common Workflows</h2>
|
|
<h3>Debugging Swift Crashes</h3>
|
|
<pre><code class="lang-lldb"># Run until crash
|
|
(lldb) run
|
|
|
|
# Examine crash
|
|
(lldb) thread backtrace
|
|
(lldb) frame variable
|
|
(lldb) po self
|
|
|
|
# Check for force-unwrap crash
|
|
(lldb) fr v myOptional # Check if nil</code></pre>
|
|
<h3>Debugging UI Issues</h3>
|
|
<pre><code class="lang-lldb"># Print view hierarchy
|
|
(lldb) po UIApplication.shared.keyWindow?.rootViewController?.view.recursiveDescription()
|
|
|
|
# Modify view background
|
|
(lldb) expr myView.backgroundColor = .red
|
|
|
|
# Continue to see change
|
|
(lldb) continue</code></pre>
|
|
<h3>Debugging Memory Issues</h3>
|
|
<p><strong>Use Instruments instead of LLDB</strong>:</p>
|
|
<ul><li>Leaks instrument</li><li>Allocations instrument</li><li>Zombies template (dangling pointers)</li></ul>
|
|
<p><strong>LLDB memory debugging</strong>:</p>
|
|
<pre><code class="lang-lldb"># Print retain count (Objective-C)
|
|
(lldb) po [myObject retainCount]
|
|
|
|
# Print all instances of class
|
|
(lldb) expr -l objc -- (void)[NSClassFromString(@"MyClass") instancesRespondToSelector:@selector(description)]</code></pre>
|
|
<hr>
|
|
<h2>Anti-Patterns</h2>
|
|
<h3>Common Mistakes</h3>
|
|
<pre><code>❌ NEVER: Use GDB for Swift/Objective-C debugging
|
|
→ LLDB has native support, GDB doesn't
|
|
|
|
❌ NEVER: Ignore 50x faster step-over (2025 LLDB)
|
|
→ Update Xcode for performance gains
|
|
|
|
❌ NEVER: Debug optimized Swift without -Onone
|
|
→ Variables optimized out, inaccurate stepping
|
|
|
|
❌ NEVER: Use `po` for non-printable types
|
|
→ Use `frame variable` instead
|
|
|
|
❌ NEVER: Attach to system processes without SIP disabled
|
|
→ macOS System Integrity Protection blocks this
|
|
|
|
❌ NEVER: Modify memory in production apps
|
|
→ Undefined behavior, crashes</code></pre>
|
|
<h3>Best Practices</h3>
|
|
<pre><code>✅ ALWAYS: Use LLDB for macOS/iOS development
|
|
✅ ALWAYS: Update Xcode for latest LLDB features (50x perf)
|
|
✅ ALWAYS: Use `po` for Swift/ObjC objects, `fr v` for primitives
|
|
✅ ALWAYS: Set symbolic breakpoints in Xcode for convenience
|
|
✅ ALWAYS: Use Instruments for memory/performance debugging
|
|
✅ ALWAYS: Save .lldbinit for project-specific commands</code></pre>
|
|
<hr>
|
|
<h2>Related Skills</h2>
|
|
<ul><li><strong>gdb-fundamentals.md</strong>: GDB debugger for C/C++/Rust</li><li><strong>python-debugging.md</strong>: Python debugging tools</li><li><strong>browser-devtools.md</strong>: Browser debugging</li><li><strong>remote-debugging.md</strong>: Remote debugging techniques</li></ul>
|
|
<hr>
|
|
<h2>Summary</h2>
|
|
<p>LLDB is the standard debugger for macOS/iOS. Key capabilities:</p>
|
|
<ol><li><strong>Swift/Objective-C</strong>: Native debugging with <code>po</code>, expression evaluation</li><li><strong>Performance</strong>: 50x faster step-over for optimized Swift (2025)</li><li><strong>Xcode integration</strong>: Seamless debugging in Xcode with console access</li><li><strong>Python scripting</strong>: Custom commands, pretty printers</li><li><strong>Remote debugging</strong>: iOS devices, remote Macs</li><li><strong>Structured syntax</strong>: <code>breakpoint set</code>, <code>thread step-in</code>, <code>process launch</code></li></ol>
|
|
<p><strong>Quick start</strong>:</p>
|
|
<pre><code class="lang-bash">lldb ./my_program
|
|
(lldb) breakpoint set -n main
|
|
(lldb) run
|
|
(lldb) thread step-over
|
|
(lldb) po myVariable
|
|
(lldb) thread backtrace</code></pre>
|
|
<p>Master LLDB for efficient debugging on Apple platforms.</p>
|
|
<footer>
|
|
<div class="fmap">
|
|
<div><b>Build</b>
|
|
<a href="https://hanzo.app">hanzo.app</a> app builder
|
|
<a href="https://hanzo.codes">hanzo.codes</a> code with an agent
|
|
<a href="https://hanzoskills.com">hanzoskills.com</a> what an agent reads</div>
|
|
<div><b>Run</b>
|
|
<a href="https://console.hanzo.ai">console.hanzo.ai</a> cloud console
|
|
<a href="https://api.hanzo.ai">api.hanzo.ai</a> the API</div>
|
|
<div><b>Account</b>
|
|
<a href="https://hanzo.id">hanzo.id</a> sign in
|
|
<a href="https://pay.hanzo.ai">pay.hanzo.ai</a> top up
|
|
<a href="https://billing.hanzo.ai">billing.hanzo.ai</a> invoices and usage</div>
|
|
<div><b>Company</b>
|
|
<a href="https://hanzo.ai">hanzo.ai</a> canonical
|
|
<a href="https://hanzo.ventures">hanzo.ventures</a> ventures</div>
|
|
</div>
|
|
<div class="fend"><a href="/debugging-lldb-macos-debugging.md">This page as plain text</a> · <a href="/llms.txt">Index for agents</a></div>
|
|
</footer>
|
|
</div></body></html> |