๐ macOS Debugging Tools
macOS provides a rich set of debugging and diagnostic tools inherited from its BSD roots while also offering unique Darwin-specific utilities. These tools help developers and administrators monitor system performance, trace application behavior, and resolve issues efficiently.
๐ Core Debugging Utilities
dtruss โ System Call Tracing
macOS equivalent of strace/truss, built on DTrace for tracing system calls.
1 2 3 4 5 6 7 8 | |
๐ก Tip: Requires sudo privileges due to DTrace restrictions.
sample โ Process Sampling
Samples running processes to determine where they spend time, similar to a lightweight profiler.
1 2 3 4 5 | |
lldb โ LLVM Debugger
Modern replacement for GDB, Apple's preferred debugger for native applications.
1 2 3 4 5 6 7 8 9 10 11 | |
๐ Performance Analysis Tools
top โ Process Activity Monitor
Built-in tool showing real-time system resource usage.
1 2 3 4 5 6 7 8 | |
vm_stat โ Virtual Memory Statistics
Reports virtual memory statistics including pageins/pageouts and free pages.
1 2 3 4 5 | |
pmset โ Power Management Settings
Monitor and configure power management behaviors affecting performance.
1 2 3 4 5 6 7 8 | |
๐๏ธ Filesystem & Storage Diagnostics
lsof โ List Open Files
Identifies which processes have files open or are listening on ports.
1 2 3 4 5 6 7 8 | |
fs_usage โ Filesystem Activity Monitor
Monitors filesystem activity in real-time with detailed timestamps.
1 2 3 4 5 6 7 8 | |
diskutil โ Disk Utility CLI
Manage disks, partitions, and volumes from the command line.
1 2 3 4 5 6 7 8 | |
๐ Network Troubleshooting
netstat โ Network Statistics
Displays network connections, routing tables, and interface statistics.
1 2 3 4 5 6 7 8 | |
tcpdump โ Packet Sniffer
Captures and analyzes network traffic packets.
1 2 3 4 5 6 7 8 | |
networksetup โ Network Configuration
Configure network interfaces, proxies, and services.
1 2 3 4 5 6 7 8 | |
๐ง Memory Debugging
leaks โ Memory Leak Detection
Apple's tool for detecting memory leaks in applications.
1 2 3 4 5 6 7 8 | |
vmmap โ Virtual Memory Map
Shows detailed virtual memory layout of a process.
1 2 3 4 5 6 7 8 | |
๐ต๏ธโโ๏ธ Logs and System Messages
log โ Unified Logging System
Modern macOS logging system replacing traditional syslog.
1 2 3 4 5 6 7 8 | |
syslog โ Traditional System Logger
Legacy interface to system logging facilities.
1 2 3 4 5 | |
๐งฐ Advanced Diagnostic Tools
Instruments โ GUI Performance Analyzer
Xcode's powerful profiling tool with various templates: - Time Profiler - Allocations - Leaks - Energy Log - Network
Accessible via:
1 2 | |
spindump โ System Spin Dump
Generates detailed diagnostic reports when system appears unresponsive.
1 2 3 4 5 6 7 8 | |
sc_usage โ System Call Usage
Monitors system call usage across the entire system.
1 2 3 4 5 | |
๐งพ Summary Table
| Tool | Purpose |
|---|---|
dtruss |
System call tracing |
sample |
Process sampling/profiling |
lldb |
Modern source-level debugger |
vm_stat |
Virtual memory statistics |
lsof |
Open file descriptor tracking |
fs_usage |
Real-time filesystem monitoring |
tcpdump |
Network packet capture |
leaks |
Memory leak detection |
log |
Unified logging system |
Instruments |
GUI performance analysis toolkit |
๐ง Best Practices
โ
Use dtruss for syscall-level debugging (with sudo)
โ
Leverage log command for modern unified logging
โ
Combine sample and Instruments for performance profiling
โ
Monitor thermal throttling with pmset
โ
Use leaks regularly during development cycle
โ
Store logs systematically for post-mortem analysis
๐งพ See Also
- macOS BSD Userland Differences
- macOS DevTools and PATH
- macOS Filesystem and Permissions
- macOS Launchd and Services
- macOS Shell Basics
- Reference: BSD vs GNU Tools
- Patterns: Logging and Telemetry