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 .app_version)
15 channel=$(cat $input_file | jq -r .release_channel)
16 target_triple=$(cat $input_file | jq -r .target)
17
18 which llvm-symbolizer rustfilt >dev/null || echo Need to install llvm-symbolizer and rustfilt
19
20 echo $channel;
21
22 mkdir -p target/dsyms/$channel
23
24 dsym="$channel/zed-$version-$target_triple.dbg"
25 if [[ ! -f target/dsyms/$dsym ]]; then
26 echo "Downloading $dsym..."
27 curl -o target/dsyms/$dsym.gz "https://zed-debug-symbols.nyc3.digitaloceanspaces.com/$dsym.gz"
28 gunzip target/dsyms/$dsym.gz
29 fi
30
31 cat $input_file | jq -r .backtrace[] | sed s'/.*+//' | llvm-symbolizer --no-demangle --obj=target/dsyms/$dsym | rustfilt
32
33else # ips file
34
35 version=$(cat $input_file | head -n 1 | jq -r .app_version)
36 bundle_id=$(cat $input_file | head -n 1 | jq -r .bundleID)
37 cpu_type=$(cat $input_file | tail -n+2 | jq -r .cpuType)
38
39 which symbolicate >/dev/null || cargo install symbolicate
40
41 arch="x86_64-apple-darwin"
42 if [[ "$cpu_type" == *ARM-64* ]]; then
43 arch="aarch64-apple-darwin"
44 fi
45 echo $bundle_id;
46
47 channel="stable"
48 if [[ "$bundle_id" == *Nightly* ]]; then
49 channel="nightly"
50 elif [[ "$bundle_id" == *Preview* ]]; then
51 channel="preview"
52 fi
53
54 mkdir -p target/dsyms/$channel
55
56 # NOTE: if you see "no such file --uuid", you need to update your symbolicate
57 uuid=$(symbolicate $input_file --uuid || true)
58 if [[ $? -ne 0 ]]; then
59 echo "You need to update your symbolicate: cargo install symbolicate"
60 exit 1
61 fi
62 dsym="$uuid.dwarf"
63 if [[ ! -f target/dsyms/$dsym ]]; then
64 echo "Downloading $dsym..."
65 curl -f -o target/dsyms/$dsym.gz "https://zed-debug-symbols.nyc3.digitaloceanspaces.com/by-uuid/${uuid}.dwarf.gz" ||
66 curl -f -o target/dsyms/$dsym.gz "https://zed-debug-symbols.nyc3.digitaloceanspaces.com/$channel/Zed-$version-$arch.dwarf.gz"
67 gunzip target/dsyms/$dsym.gz
68 fi
69
70 symbolicate $input_file target/dsyms/$dsym
71
72fi