symbolicate

 1#!/usr/bin/env bash
 2
 3set -eu
 4if [[ $# -eq 0 ]] || [[ "$1" == "--help" ]]; then
 5  echo "Usage: $(basename $0) <path_to_ips_file_or_json>"
 6  echo "This script symbolicates the provided .ips file or .json panic report using the appropriate debug symbols from DigitalOcean"
 7  echo ""
 8  exit 1
 9fi
10
11input_file=$1;
12
13if [[ "$input_file" == *.json ]]; then
14    version=$(cat $input_file | jq -r .panic.app_version)
15    channel=$(cat $input_file | jq -r .panic.release_channel)
16    target_triple=$(cat $input_file | jq -r .panic.target)
17
18    which llvm-symbolizer rustfilt >/dev/null || (echo Need to install llvm-symbolizer and rustfilt && exit 1)
19
20    echo $channel;
21
22    mkdir -p target/dsyms/$channel
23
24    if [[ "$version" == "remote-server-"* ]]; then
25        version="${version#remote-server-}"
26        dsym="$channel/remote_server-$version-$target_triple.dbg"
27    else
28        dsym="$channel/zed-$version-$target_triple.dbg"
29    fi
30    if [[ ! -f target/dsyms/$dsym ]]; then
31        echo "Downloading $dsym..."
32        curl -o target/dsyms/$dsym.gz "https://zed-debug-symbols.nyc3.digitaloceanspaces.com/$dsym.gz"
33        gunzip  target/dsyms/$dsym.gz
34    fi
35
36    cat $input_file | jq -r .panic.backtrace[] | sed s'/.*+//' | llvm-symbolizer --no-demangle --obj=target/dsyms/$dsym | rustfilt
37
38else # ips file
39
40    version=$(cat $input_file | head -n 1 | jq -r .app_version)
41    bundle_id=$(cat $input_file | head -n 1 | jq -r .bundleID)
42    cpu_type=$(cat $input_file | tail -n+2 | jq -r .cpuType)
43
44    which symbolicate >/dev/null || cargo install symbolicate
45
46    arch="x86_64-apple-darwin"
47    if [[ "$cpu_type" == *ARM-64* ]]; then
48        arch="aarch64-apple-darwin"
49    fi
50    echo $bundle_id;
51
52    channel="stable"
53    if [[ "$bundle_id" == *Nightly* ]]; then
54        channel="nightly"
55    elif [[ "$bundle_id" == *Preview* ]]; then
56        channel="preview"
57    fi
58
59    mkdir -p target/dsyms/$channel
60
61    # NOTE: if you see "no such file --uuid", you need to update your symbolicate
62    uuid=$(symbolicate $input_file --uuid || true)
63    if [[ $? -ne 0 ]]; then
64        echo "You need to update your symbolicate: cargo install symbolicate"
65        exit 1
66    fi
67    dsym="$uuid.dwarf"
68    if [[ ! -f target/dsyms/$dsym ]]; then
69        echo "Downloading $dsym..."
70        curl -f -o target/dsyms/$dsym.gz "https://zed-debug-symbols.nyc3.digitaloceanspaces.com/by-uuid/${uuid}.dwarf.gz" ||
71            curl -f -o target/dsyms/$dsym.gz "https://zed-debug-symbols.nyc3.digitaloceanspaces.com/$channel/Zed-$version-$arch.dwarf.gz"
72        gunzip  target/dsyms/$dsym.gz
73    fi
74
75    symbolicate $input_file target/dsyms/$dsym
76
77fi