Add scripts for symbolicating crash logs.

This commit is contained in:
Brent Simmons committed 2025-11-28 10:55:37 -08:00
1 parent 25f98a5795
commit 5392f901e2
4 files changed
+946

No files matched your search

+190
View File
@@ -0,0 +1,190 @@
# Crash Log Symbolication Scripts
## Overview
Three scripts for symbolicating macOS crash logs:
1. **symbolicate_all_crashes.sh** - Batch process multiple crash logs
2. **symbolicate_crash_simple.sh** - Symbolicate single crash log (recommended)
3. **symbolicate_crash.sh** - Advanced single file with detailed logging
## Quick Start
```bash
# Symbolicate all crash logs in current directory
./symbolicate_all_crashes.sh
# Symbolicate a single crash log
./symbolicate_crash_simple.sh MacCrash.log
# Symbolicate crashes in specific directory
./symbolicate_all_crashes.sh /path/to/crash/logs
```
## What Gets Symbolicated
### ✅ Your App's Code (Always)
- Your main app binary
- Your frameworks and libraries
- App extensions
- Embedded frameworks
**Example:**
```
Before: 0x00000001059feea0 0x1058d0000 + 1240736
After: closure #1 in ReaderAPICaller.retrieveEntries(articleIDs:completion:) (ReaderAPICaller.swift:527)
```
### ⚠️ System Frameworks (Limited)
- AppKit, CoreFoundation, UIKit, etc.
- **May NOT symbolicate** on newer macOS versions
- Symbols often stripped from release builds
- Requires OS-specific symbols from Apple
**Why System Symbols Are Limited:**
1. **Stripped Binaries** - Release builds of macOS don't include debug symbols
2. **Dyld Shared Cache** - System frameworks are in a shared cache, not individual files
3. **OS Version Matching** - Requires exact OS build symbols
4. **Availability** - Apple doesn't always provide public symbol downloads for all macOS versions
## System Symbol Options
### Option 1: Use Current Scripts (Best Effort)
The scripts attempt to find system symbols by searching:
- `/System/Library/Frameworks`
- `/System/Library/PrivateFrameworks`
- `/usr/lib`
This works for some frameworks but not all.
### Option 2: Download Symbols from Apple (If Available)
For older macOS versions, you may be able to download symbols:
1. **Xcode Downloads** (For older OS versions):
- Xcode → Settings → Platforms
- Download symbols for specific OS versions
2. **Manual Symbol Download**:
- Some macOS versions have public symbol packages
- Not available for all versions/builds
### Option 3: Run on Matching OS Version
Symbolicate on a Mac running the **same OS version** as the crash:
- Symbols may be available locally
- Best chance for system framework symbolication
### Option 4: Focus on Your Code
Often, system framework symbols aren't needed:
- **Your code symbols** are what you can fix
- System framework stack frames show the call path
- Offsets can still indicate which system API was called
## Understanding the Output
### Fully Symbolicated Frame:
```
0 Account 0x1059feea0 closure #1 in ReaderAPICaller.retrieveEntries(articleIDs:completion:) + 1240736 (ReaderAPICaller.swift:527)
```
- **Function**: `closure #1 in ReaderAPICaller.retrieveEntries`
- **File**: `ReaderAPICaller.swift`
- **Line**: `527`
### Partially Symbolicated Frame (System):
```
12 CoreFoundation 0x18464e980 0x1845c5000 + 563584
```
- Shows framework name and offset
- No function/file info (symbols not available)
- Still useful for understanding call stack
## Technical Details
### How It Works
1. **Extract App Info** - Reads process name, architecture, platform from crash log
2. **Extract UUIDs** - Gets unique identifiers for each binary
3. **Find Archive** - Searches Xcode archives for matching UUID
4. **Symbolicate** - Uses Apple's `symbolicatecrash` tool
5. **Add Symbols** - Replaces addresses with function names
### Requirements
- macOS with Xcode installed
- Xcode archives with dSYM files
- Crash log must be from your own build
### Files Created
- `*_symbolicated.log` - Output file with symbols
- Original crash log is never modified
## Troubleshooting
### "No matching archive found"
- Ensure you have an Xcode archive for this build
- Check that archive contains dSYM files
- Verify archive matches crash log's architecture (arm64/x86_64)
### "Could not find dSYMs"
- Archive may not have been created with debug symbols
- Check Build Settings → Debug Information Format = "DWARF with dSYM File"
### System frameworks not symbolicated
- **This is normal** for many macOS versions
- See "System Symbol Options" above
- Focus on your own code's symbols
### Wrong archive selected
- Script matches by UUID (most accurate)
- Falls back to name matching if UUID fails
- Specify archive manually: `./symbolicate_crash_simple.sh crash.log /path/to/archive/dSYMs`
## Advanced Usage
### Specify Custom dSYM Directory
```bash
./symbolicate_crash_simple.sh MacCrash.log ~/path/to/dSYMs
```
### Enable Debug Output
```bash
DEBUG=1 ./symbolicate_crash.sh MacCrash.log
```
### Process Specific Pattern
```bash
# Only files matching pattern
find . -name "*production_crash*.log" -exec ./symbolicate_crash_simple.sh {} \;
```
## Best Practices
1. **Always archive with dSYMs** - Enable "Debug Information Format" in build settings
2. **Keep all archives** - You need the exact build's archive to symbolicate
3. **Save archives by version** - Organize by version number and build number
4. **Test symbolication** - Verify after each release that you can symbolicate
## Limitations
- Cannot symbolicate crashes from App Store builds without matching archive
- System framework symbolication depends on OS version
- Requires Xcode installation
- macOS only (for macOS crash logs)
## Output Format
Symbolicated logs maintain Apple's standard crash log format and can be:
- Opened in Console.app
- Shared with Apple via Feedback Assistant
- Analyzed with other crash analysis tools
- Searched for specific functions/files
## Additional Resources
- [Apple Technical Note TN2151 - Understanding Crash Reports](https://developer.apple.com/documentation/xcode/diagnosing-issues-using-crash-reports-and-device-logs)
- [WWDC Videos on Crash Analysis](https://developer.apple.com/videos/)
- Xcode Help → "Analyzing Crash Reports"
+239
View File
@@ -0,0 +1,239 @@
#!/bin/bash
# symbolicate_all_crashes.sh - Batch symbolicate all crash logs in a directory
# Usage: ./symbolicate_all_crashes.sh [directory]
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
print_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_section() {
echo -e "\n${CYAN}========================================${NC}"
echo -e "${CYAN}$1${NC}"
echo -e "${CYAN}========================================${NC}\n"
}
# Get directory to process
CRASH_DIR="${1:-.}"
if [ ! -d "$CRASH_DIR" ]; then
print_error "Directory not found: $CRASH_DIR"
exit 1
fi
# Find symbolicatecrash tool
SYMBOLICATE_CRASH=$(find /Applications/Xcode.app -name "symbolicatecrash" 2>/dev/null | head -n 1)
if [ -z "$SYMBOLICATE_CRASH" ]; then
print_error "symbolicatecrash not found. Please install Xcode."
exit 1
fi
export DEVELOPER_DIR="/Applications/Xcode.app/Contents/Developer"
print_section "Crash Log Batch Symbolication"
print_info "Directory: $CRASH_DIR"
print_info "Pattern: *crash*.log (case-insensitive)"
# Find all crash log files (case-insensitive)
CRASH_LOGS=()
while IFS= read -r -d '' file; do
CRASH_LOGS+=("$file")
done < <(find "$CRASH_DIR" -maxdepth 1 -type f -iname "*crash*.log" -print0 2>/dev/null)
if [ ${#CRASH_LOGS[@]} -eq 0 ]; then
print_warning "No crash logs found matching pattern '*crash*.log'"
exit 0
fi
print_info "Found ${#CRASH_LOGS[@]} crash log(s) to process"
echo ""
# Statistics
TOTAL=${#CRASH_LOGS[@]}
SUCCESSFUL=0
FAILED=0
SKIPPED=0
# Function to symbolicate a single crash log
symbolicate_single() {
local crash_log="$1"
local index="$2"
local total="$3"
local basename=$(basename "$crash_log")
local output_file="${crash_log%.log}_symbolicated.log"
print_section "[$index/$total] Processing: $basename"
# Check if already symbolicated
if [ -f "$output_file" ]; then
read -p "$(echo -e ${YELLOW}Output file exists. Overwrite? [y/N]:${NC} )" -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
print_warning "Skipped: $basename"
return 2
fi
fi
# Extract app info
APP_NAME=$(grep "^Process:" "$crash_log" | awk '{print $2}' | head -n 1)
APP_PATH=$(grep "^Path:" "$crash_log" | awk '{print $2}' | head -n 1)
if [ -z "$APP_NAME" ]; then
print_error "Could not extract app name from crash log"
return 1
fi
print_info "App: $APP_NAME"
# Detect platform
if [[ "$APP_PATH" == *"/Contents/MacOS/"* ]]; then
PLATFORM="macOS"
else
PLATFORM="iOS"
fi
print_info "Platform: $PLATFORM"
# Extract UUID
APP_UUID=$(sed -n '/^Binary Images:/,$p' "$crash_log" | grep "0x" | grep "+$APP_NAME " | head -n 1 | grep -o '<[a-f0-9]*>' | tr -d '<>' || echo "")
# Find matching archive
DSYM_DIR=""
ARCHIVE_BASE="$HOME/Library/Developer/Xcode/Archives"
if [ -n "$APP_UUID" ]; then
print_info "App UUID: $APP_UUID"
print_info "Searching for matching archive..."
# Search for archive by UUID
while IFS= read -r archive; do
archive_name=$(basename "$archive")
# Filter by platform
if [[ "$PLATFORM" == "macOS" ]] && [[ "$archive_name" == *"iOS"* ]]; then
continue
fi
if [[ "$PLATFORM" == "iOS" ]] && [[ "$archive_name" != *"iOS"* ]]; then
continue
fi
# Find app dSYM
app_dsym=$(find "$archive/dSYMs" -name "$APP_NAME.app.dSYM" -type d 2>/dev/null | head -n 1)
if [ -n "$app_dsym" ]; then
dwarf_file=$(find "$app_dsym" -type f -path "*/DWARF/$APP_NAME" 2>/dev/null | head -n 1)
if [ -f "$dwarf_file" ]; then
archive_uuid=$(dwarfdump --uuid "$dwarf_file" 2>/dev/null | grep -i "arm64\|x86_64" | head -n 1 | awk '{print $2}' | tr -d '-' | tr '[:upper:]' '[:lower:]')
if [ "$archive_uuid" == "$APP_UUID" ]; then
DSYM_DIR="$archive/dSYMs"
print_info "Found by UUID: $(basename "$archive")"
break
fi
fi
fi
done < <(find "$ARCHIVE_BASE" -name "*.xcarchive" -type d 2>/dev/null | sort -r)
fi
# Fallback: find by name
if [ -z "$DSYM_DIR" ]; then
print_warning "UUID match failed, searching by name..."
while IFS= read -r archive; do
archive_name=$(basename "$archive")
# Filter by platform
if [[ "$PLATFORM" == "macOS" ]] && [[ "$archive_name" == *"iOS"* ]]; then
continue
fi
if [[ "$PLATFORM" == "iOS" ]] && [[ "$archive_name" != *"iOS"* ]]; then
continue
fi
if [[ "$archive_name" == *"$APP_NAME"* ]]; then
DSYM_DIR="$archive/dSYMs"
print_warning "Using by name: $(basename "$archive")"
break
fi
done < <(find "$ARCHIVE_BASE" -name "*.xcarchive" -type d 2>/dev/null | sort -r)
fi
if [ -z "$DSYM_DIR" ] || [ ! -d "$DSYM_DIR" ]; then
print_error "Could not find dSYMs for $APP_NAME"
return 1
fi
# Symbolicate with system framework paths
print_info "Symbolicating..."
if DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer "$SYMBOLICATE_CRASH" -d "$DSYM_DIR" "$crash_log" /System/Library/Frameworks /System/Library/PrivateFrameworks /usr/lib > "$output_file" 2>/dev/null; then
print_info "✓ Success: $output_file"
# Show preview
if grep -q "Thread 0 Crashed:" "$output_file" 2>/dev/null; then
echo ""
echo -e "${BLUE}Preview (first 5 frames):${NC}"
sed -n '/^Thread 0 Crashed:/,/^Thread [0-9]/p' "$output_file" | head -n 7 | tail -n +2
fi
return 0
else
print_warning "symbolicatecrash completed with warnings"
if [ -f "$output_file" ]; then
print_info "Partial output saved: $output_file"
return 0
else
return 1
fi
fi
}
# Process each crash log
for i in "${!CRASH_LOGS[@]}"; do
crash_log="${CRASH_LOGS[$i]}"
index=$((i + 1))
if symbolicate_single "$crash_log" "$index" "$TOTAL"; then
SUCCESSFUL=$((SUCCESSFUL + 1))
else
exit_code=$?
if [ $exit_code -eq 2 ]; then
SKIPPED=$((SKIPPED + 1))
else
FAILED=$((FAILED + 1))
fi
fi
echo ""
done
# Print summary
print_section "Summary"
echo -e "${GREEN}Successful:${NC} $SUCCESSFUL"
echo -e "${YELLOW}Skipped:${NC} $SKIPPED"
echo -e "${RED}Failed:${NC} $FAILED"
echo -e "Total: $TOTAL"
echo ""
if [ $SUCCESSFUL -gt 0 ]; then
print_info "Symbolicated files are saved with '_symbolicated.log' suffix"
fi
exit 0
+334
View File
@@ -0,0 +1,334 @@
#!/bin/bash
# symbolicate_crash.sh - Symbolicate macOS crash logs
# Usage: ./symbolicate_crash.sh <crash_log_file> [archive_path]
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_debug() {
if [ -n "$DEBUG" ]; then
echo -e "${BLUE}[DEBUG]${NC} $1"
fi
}
# Check if crash log file is provided
if [ $# -lt 1 ]; then
echo "Usage: $0 <crash_log_file> [archive_path]"
echo ""
echo "Arguments:"
echo " crash_log_file - Path to the crash log file to symbolicate"
echo " archive_path - (Optional) Path to specific .xcarchive directory"
echo " If not provided, will search for matching archive by UUID"
echo ""
echo "Example:"
echo " $0 MacCrash.log"
echo " $0 MacCrash.log ~/Library/Developer/Xcode/Archives/2024-11-28/MyApp.xcarchive"
echo ""
echo "Environment variables:"
echo " DEBUG=1 - Enable debug output"
exit 1
fi
CRASH_LOG="$1"
SPECIFIC_ARCHIVE="$2"
# Verify crash log exists
if [ ! -f "$CRASH_LOG" ]; then
print_error "Crash log file not found: $CRASH_LOG"
exit 1
fi
print_info "Crash log: $CRASH_LOG"
# Extract app info from crash log
APP_NAME=$(grep "^Process:" "$CRASH_LOG" | awk '{print $2}' | head -n 1)
APP_IDENTIFIER=$(grep "^Identifier:" "$CRASH_LOG" | awk '{print $2}' | head -n 1)
APP_VERSION=$(grep "^Version:" "$CRASH_LOG" | awk '{print $2, $3}' | head -n 1)
CODE_TYPE=$(grep "^Code Type:" "$CRASH_LOG" | awk '{print $3}' | head -n 1)
print_info "App: $APP_NAME ($APP_IDENTIFIER)"
print_info "Version: $APP_VERSION"
print_info "Architecture: $CODE_TYPE"
# Determine architecture for atos
if [ "$CODE_TYPE" == "ARM-64" ]; then
ARCH="arm64"
elif [ "$CODE_TYPE" == "X86-64" ]; then
ARCH="x86_64"
else
print_warning "Unknown architecture: $CODE_TYPE, defaulting to arm64"
ARCH="arm64"
fi
# Extract binary images and UUIDs from crash log
print_info "Extracting UUIDs from crash log..."
# Detect platform (Mac vs iOS)
APP_PATH=$(grep "^Path:" "$CRASH_LOG" | awk '{print $2}' | head -n 1)
if [[ "$APP_PATH" == *"/Contents/MacOS/"* ]]; then
PLATFORM="macOS"
print_info "Detected platform: macOS"
else
PLATFORM="iOS"
print_info "Detected platform: iOS"
fi
temp_uuids=$(mktemp)
# Extract lines from "Binary Images:" section
sed -n '/^Binary Images:/,$p' "$CRASH_LOG" | grep "0x" | while read line; do
# Extract binary name and UUID
# Format: 0xaddress - 0xaddress [+]BinaryName arch <uuid> /path
# Fields: 1=start_addr 2=- 3=end_addr 4=[+]binary 5=arch 6=<uuid> 7+=path
if [[ "$line" =~ \<([a-f0-9]+)\> ]]; then
uuid="${BASH_REMATCH[1]}"
# Extract field 4 which is the binary name
binary=$(echo "$line" | awk '{
# Field 4 contains the binary name (possibly with + prefix)
bin = $4
# Remove leading + if present
gsub(/^\+/, "", bin)
print bin
}')
echo "$binary:$uuid" >> "$temp_uuids"
fi
done
# Read UUIDs into a temp file
mv "$temp_uuids" /tmp/crash_uuids.txt
print_info "Found $(wc -l < /tmp/crash_uuids.txt | tr -d ' ') binary images with UUIDs"
# Find the correct archive
ARCHIVE_PATH=""
if [ -n "$SPECIFIC_ARCHIVE" ]; then
# User specified an archive
if [ ! -d "$SPECIFIC_ARCHIVE" ]; then
print_error "Specified archive not found: $SPECIFIC_ARCHIVE"
exit 1
fi
ARCHIVE_PATH="$SPECIFIC_ARCHIVE"
print_info "Using specified archive: $(basename "$ARCHIVE_PATH")"
else
# Search for matching archive by UUID
print_info "Searching for matching archive in ~/Library/Developer/Xcode/Archives"
ARCHIVE_BASE="$HOME/Library/Developer/Xcode/Archives"
if [ ! -d "$ARCHIVE_BASE" ]; then
print_error "Archive directory not found: $ARCHIVE_BASE"
exit 1
fi
# Get the main app UUID to search for
APP_UUID=$(grep "^$APP_NAME:" /tmp/crash_uuids.txt | cut -d: -f2 | head -n 1)
if [ -z "$APP_UUID" ]; then
print_warning "Could not find UUID for $APP_NAME in crash log"
print_info "Falling back to name-based archive search..."
# Fall back to name-based search
while IFS= read -r archive; do
info_plist="$archive/Info.plist"
if [ -f "$info_plist" ]; then
archive_name=$(/usr/libexec/PlistBuddy -c "Print :Name" "$info_plist" 2>/dev/null || echo "")
archive_bundle_id=$(/usr/libexec/PlistBuddy -c "Print :ApplicationProperties:CFBundleIdentifier" "$info_plist" 2>/dev/null || echo "")
# Check if name/bundle ID matches
name_matches=false
if [[ "$archive_name" == *"$APP_NAME"* ]] || [[ "$archive_bundle_id" == "$APP_IDENTIFIER" ]]; then
name_matches=true
fi
# Check platform match
platform_matches=false
if [[ "$PLATFORM" == "macOS" ]] && [[ "$archive_name" != *"-iOS"* ]] && [[ "$archive_name" != *"iOS"* ]]; then
platform_matches=true
elif [[ "$PLATFORM" == "iOS" ]] && [[ "$archive_name" == *"iOS"* ]]; then
platform_matches=true
fi
if [[ "$name_matches" == "true" ]] && [[ "$platform_matches" == "true" ]]; then
ARCHIVE_PATH="$archive"
print_warning "Using most recent archive (UUID matching failed): $(basename "$archive")"
break
fi
fi
done < <(find "$ARCHIVE_BASE" -name "*.xcarchive" -type d 2>/dev/null | sort -r)
else
print_info "Searching for archive with matching UUID: $APP_UUID"
# Search for archive with matching UUID
while IFS= read -r archive; do
# Find the app bundle in the archive
app_dsym=$(find "$archive/dSYMs" -name "$APP_NAME.app.dSYM" -type d 2>/dev/null | head -n 1)
if [ -n "$app_dsym" ]; then
dwarf_file=$(find "$app_dsym" -type f -path "*/DWARF/$APP_NAME" 2>/dev/null | head -n 1)
if [ -f "$dwarf_file" ]; then
archive_uuid=$(dwarfdump --uuid "$dwarf_file" 2>/dev/null | grep "$ARCH" | awk '{print $2}' | tr -d '-' | tr '[:upper:]' '[:lower:]')
print_debug "Checking archive: $(basename "$archive") - UUID: $archive_uuid"
if [ "$archive_uuid" == "$APP_UUID" ]; then
ARCHIVE_PATH="$archive"
print_info "Found matching archive by UUID: $(basename "$archive")"
break
fi
fi
fi
done < <(find "$ARCHIVE_BASE" -name "*.xcarchive" -type d 2>/dev/null | sort -r)
fi
if [ -z "$ARCHIVE_PATH" ]; then
print_error "No matching archive found for $APP_NAME"
print_info "Please specify an archive path manually"
exit 1
fi
fi
# Find dSYMs directory
DSYMS_DIR="$ARCHIVE_PATH/dSYMs"
if [ ! -d "$DSYMS_DIR" ]; then
print_error "dSYMs directory not found in archive: $DSYMS_DIR"
exit 1
fi
print_info "dSYMs directory: $(basename "$ARCHIVE_PATH")/dSYMs"
# List all available dSYMs
print_info "Available dSYMs:"
find "$DSYMS_DIR" -name "*.dSYM" -type d 2>/dev/null | while IFS= read -r dsym; do
basename "$dsym" .dSYM
done
# Create output file
OUTPUT_FILE="${CRASH_LOG%.log}_symbolicated.log"
cp "$CRASH_LOG" "$OUTPUT_FILE"
print_info "Symbolicating crash log..."
# Cache for dSYM lookups to avoid repeated searches
DSYM_CACHE=$(mktemp)
# Function to find dSYM path for a binary
find_dsym_for_binary() {
local binary_name="$1"
local dsyms_dir="$2"
# Check cache first
cached=$(grep "^$binary_name:" "$DSYM_CACHE" 2>/dev/null | cut -d: -f2-)
if [ -n "$cached" ]; then
echo "$cached"
return 0
fi
# Look for matching dSYM - try different patterns
local dsym_path=""
# Try exact match first (e.g., MyApp)
dsym_path=$(find "$dsyms_dir" -name "${binary_name}.dSYM" -type d 2>/dev/null | head -n 1)
# Try framework pattern (e.g., MyFramework.framework)
if [ -z "$dsym_path" ]; then
dsym_path=$(find "$dsyms_dir" -name "${binary_name}.framework.dSYM" -type d 2>/dev/null | head -n 1)
fi
# Try app pattern (e.g., MyApp.app)
if [ -z "$dsym_path" ]; then
dsym_path=$(find "$dsyms_dir" -name "${binary_name}.app.dSYM" -type d 2>/dev/null | head -n 1)
fi
if [ -n "$dsym_path" ]; then
# Find the actual binary inside the dSYM
local binary_base=$(basename "$binary_name" .framework)
binary_base=$(basename "$binary_base" .app)
local binary_path=$(find "$dsym_path" -type f -path "*/DWARF/$binary_base" 2>/dev/null | head -n 1)
if [ -n "$binary_path" ]; then
# Cache the result
echo "$binary_name:$binary_path" >> "$DSYM_CACHE"
echo "$binary_path"
return 0
fi
fi
return 1
}
# Process each line of the crash log
print_info "Processing stack traces..."
# Symbolicate using atos for each frame
temp_file=$(mktemp)
symbolicated_count=0
while IFS= read -r line; do
# Check if this is a stack frame line
# Format: <frame_num> <binary_name> <address> <load_address> + <offset>
if [[ "$line" =~ ^[[:space:]]*([0-9]+)[[:space:]]+([^[:space:]]+)[[:space:]]+(0x[0-9a-f]+)[[:space:]]+(0x[0-9a-f]+)[[:space:]]+\+[[:space:]]+([0-9]+) ]]; then
frame_num="${BASH_REMATCH[1]}"
binary_name="${BASH_REMATCH[2]}"
address="${BASH_REMATCH[3]}"
load_address="${BASH_REMATCH[4]}"
offset="${BASH_REMATCH[5]}"
# Find dSYM for this binary
dsym_binary=$(find_dsym_for_binary "$binary_name" "$DSYMS_DIR")
if [ -n "$dsym_binary" ]; then
# Symbolicate the address
symbol=$(atos -arch "$ARCH" -o "$dsym_binary" -l "$load_address" "$address" 2>/dev/null)
# If we got a valid symbol (not just the address back), use it
if [ -n "$symbol" ] && [[ ! "$symbol" =~ ^0x[0-9a-f]+ ]] && [[ "$symbol" != "$address "* ]]; then
# Format the symbolicated line to match Apple's format
echo "$line ($symbol)" >> "$temp_file"
symbolicated_count=$((symbolicated_count + 1))
continue
fi
fi
fi
# If not symbolicated or not a stack frame, keep original line
echo "$line" >> "$temp_file"
done < "$CRASH_LOG"
mv "$temp_file" "$OUTPUT_FILE"
rm -f "$DSYM_CACHE" /tmp/crash_uuids.txt
print_info "Symbolication complete!"
print_info "Symbolicated $symbolicated_count addresses"
print_info "Output file: $OUTPUT_FILE"
# Show a preview of the symbolicated crash
print_info ""
print_info "Preview of symbolicated crash (Thread 0):"
echo ""
sed -n '/^Thread 0 Crashed:/,/^Thread [0-9]/p' "$OUTPUT_FILE" | head -n 15
echo ""
print_info "Full symbolicated crash log saved to: $OUTPUT_FILE"
+183
View File
@@ -0,0 +1,183 @@
#!/bin/bash
# symbolicate_crash_simple.sh - Symbolicate macOS crash logs using Apple's symbolicatecrash
# Usage: ./symbolicate_crash_simple.sh <crash_log_file> [dsym_path]
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
print_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
if [ $# -lt 1 ]; then
echo "Usage: $0 <crash_log_file> [dsym_directory]"
echo ""
echo "Arguments:"
echo " crash_log_file - Path to the crash log file"
echo " dsym_directory - (Optional) Path to directory containing dSYMs"
echo " Defaults to searching Xcode archives"
echo ""
echo "Example:"
echo " $0 MacCrash.log"
echo " $0 MacCrash.log ~/Library/Developer/Xcode/Archives/.../dSYMs"
exit 1
fi
CRASH_LOG="$1"
DSYM_DIR="$2"
if [ ! -f "$CRASH_LOG" ]; then
print_error "Crash log not found: $CRASH_LOG"
exit 1
fi
# Find symbolicatecrash
SYMBOLICATE_CRASH=$(find /Applications/Xcode.app -name "symbolicatecrash" 2>/dev/null | head -n 1)
if [ -z "$SYMBOLICATE_CRASH" ]; then
print_error "symbolicatecrash not found. Please install Xcode."
exit 1
fi
print_info "Using symbolicatecrash: $SYMBOLICATE_CRASH"
# Set up environment for symbolicatecrash
export DEVELOPER_DIR="/Applications/Xcode.app/Contents/Developer"
# If no dSYM directory specified, try to find it
if [ -z "$DSYM_DIR" ]; then
print_info "Searching for matching dSYMs..."
# Extract app info
APP_NAME=$(grep "^Process:" "$CRASH_LOG" | awk '{print $2}' | head -n 1)
APP_PATH=$(grep "^Path:" "$CRASH_LOG" | awk '{print $2}' | head -n 1)
print_info "App: $APP_NAME"
# Detect platform
if [[ "$APP_PATH" == *"/Contents/MacOS/"* ]]; then
PLATFORM="macOS"
print_info "Platform: macOS"
else
PLATFORM="iOS"
print_info "Platform: iOS"
fi
# Extract UUID
APP_UUID=$(sed -n '/^Binary Images:/,$p' "$CRASH_LOG" | grep "0x" | grep "+$APP_NAME " | head -n 1 | grep -o '<[a-f0-9]*>' | tr -d '<>' || echo "")
if [ -n "$APP_UUID" ]; then
print_info "App UUID: $APP_UUID"
# Search for matching archive
ARCHIVE_BASE="$HOME/Library/Developer/Xcode/Archives"
FOUND_ARCHIVE=""
while IFS= read -r archive; do
# Check platform
archive_name=$(basename "$archive")
if [[ "$PLATFORM" == "macOS" ]] && [[ "$archive_name" == *"iOS"* ]]; then
continue
fi
if [[ "$PLATFORM" == "iOS" ]] && [[ "$archive_name" != *"iOS"* ]]; then
continue
fi
# Find app dSYM
app_dsym=$(find "$archive/dSYMs" -name "$APP_NAME.app.dSYM" -type d 2>/dev/null | head -n 1)
if [ -n "$app_dsym" ]; then
dwarf_file=$(find "$app_dsym" -type f -path "*/DWARF/$APP_NAME" 2>/dev/null | head -n 1)
if [ -f "$dwarf_file" ]; then
archive_uuid=$(dwarfdump --uuid "$dwarf_file" 2>/dev/null | grep -i "arm64\|x86_64" | head -n 1 | awk '{print $2}' | tr -d '-' | tr '[:upper:]' '[:lower:]')
if [ "$archive_uuid" == "$APP_UUID" ]; then
FOUND_ARCHIVE="$archive"
print_info "Found matching archive: $(basename "$archive")"
break
fi
fi
fi
done < <(find "$ARCHIVE_BASE" -name "*.xcarchive" -type d 2>/dev/null | sort -r)
if [ -n "$FOUND_ARCHIVE" ]; then
DSYM_DIR="$FOUND_ARCHIVE/dSYMs"
fi
fi
# Fallback: use most recent matching archive
if [ -z "$DSYM_DIR" ]; then
print_warning "Could not find archive by UUID, trying by name..."
while IFS= read -r archive; do
archive_name=$(basename "$archive")
if [[ "$PLATFORM" == "macOS" ]] && [[ "$archive_name" == *"iOS"* ]]; then
continue
fi
if [[ "$PLATFORM" == "iOS" ]] && [[ "$archive_name" != *"iOS"* ]]; then
continue
fi
if [[ "$archive_name" == *"$APP_NAME"* ]]; then
DSYM_DIR="$archive/dSYMs"
print_warning "Using most recent archive: $(basename "$archive")"
break
fi
done < <(find "$ARCHIVE_BASE" -name "*.xcarchive" -type d 2>/dev/null | sort -r)
fi
if [ -z "$DSYM_DIR" ]; then
print_error "Could not find dSYMs. Please specify dSYM directory manually."
exit 1
fi
fi
if [ ! -d "$DSYM_DIR" ]; then
print_error "dSYM directory not found: $DSYM_DIR"
exit 1
fi
print_info "dSYM directory: $DSYM_DIR"
print_info "Available dSYMs:"
find "$DSYM_DIR" -name "*.dSYM" -type d 2>/dev/null | while IFS= read -r dsym; do
basename "$dsym" .dSYM
done
# Create output file
OUTPUT_FILE="${CRASH_LOG%.log}_symbolicated.log"
print_info "Symbolicating crash log..."
print_info "This may take a minute..."
# Run symbolicatecrash with system framework paths for better system symbol resolution
# Note: System symbols may not be available for all macOS versions
if DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer "$SYMBOLICATE_CRASH" -d "$DSYM_DIR" "$CRASH_LOG" /System/Library/Frameworks /System/Library/PrivateFrameworks /usr/lib > "$OUTPUT_FILE" 2>/dev/null; then
print_info "Symbolication complete!"
print_info "Output: $OUTPUT_FILE"
print_info ""
print_info "Preview (Thread 0):"
echo ""
sed -n '/^Thread 0 Crashed:/,/^Thread [0-9]/p' "$OUTPUT_FILE" | head -n 15
else
print_warning "symbolicatecrash completed with warnings"
print_info "Output may be partial: $OUTPUT_FILE"
fi
echo ""
print_info "Full symbolicated log: $OUTPUT_FILE"