]>
Commit | Line | Data |
---|---|---|
11fdf7f2 | 1 | #!/usr/bin/env bash |
7c673cae FG |
2 | |
3 | function die() { | |
4 | echo $@ >&2 | |
5 | exit 1 | |
6 | } | |
7 | ||
8 | function usage() { | |
9 | echo "bt: $0 -c core_path [-d distro] [-C directory] [-v]" | |
10 | exit 1 | |
11 | } | |
12 | ||
13 | function log() { | |
14 | if [ -n "$verbose" ]; then | |
15 | echo $* | |
16 | fi | |
17 | } | |
18 | ||
19 | function get_machine() { | |
20 | local core_path=$1 | |
21 | local machine=${core_path%/coredump/*} | |
22 | echo $(basename $machine) | |
23 | } | |
24 | ||
25 | function get_t_dir() { | |
26 | local core_path=$1 | |
27 | echo ${core_path%/remote/*} | |
28 | } | |
29 | ||
30 | while getopts "c:C:d:v" opt | |
31 | do | |
32 | case $opt in | |
33 | c) core_path=$OPTARG;; | |
34 | C) wd=$OPTARG;; | |
35 | d) codename=$OPTARG;; | |
36 | v) verbose=1;; | |
37 | *) usage;; | |
38 | esac | |
39 | done | |
40 | ||
41 | if [ -z $core_path ]; then | |
42 | usage | |
43 | fi | |
44 | ||
45 | sha1=$(strings $core_path | gawk 'BEGIN{ FS = "=" } /^CEPH_REF/{print $2}') | |
46 | if [ -z $sha1 ]; then | |
47 | teuthology_log=$(get_t_dir $core_path)/teuthology.log | |
48 | sha1=$(grep -m1 -A1 "Running command: sudo ceph --version" ${teuthology_log} | tail -n1 | grep -oP "ceph version [^ ]+ \(\K[^\) ]+") | |
49 | fi | |
50 | ||
51 | if [ -z $distro ]; then | |
52 | machine=$(get_machine $core_path) | |
53 | teuthology_log=$(get_t_dir $core_path)/teuthology.log | |
54 | if [ ! -r ${teuthology_log} ]; then | |
55 | die "missing distro, and unable to read it from ${teuthology_log}" | |
56 | fi | |
57 | ld=$(grep -m1 -A1 "${machine}:Running.*linux_distribution" ${teuthology_log} | tail -n1 | grep -oP "\(\K[^\)]+") | |
58 | distro=$(echo $ld | gawk -F ", " '{print $1}' | sed s/\'//g) | |
59 | distro=$(echo $distro | tr '[:upper:]' '[:lower:]') | |
60 | distro_ver=$(echo $ld | gawk -F ", " '{print $2}' | sed s/\'//g) | |
61 | codename=$(echo $ld | gawk -F ", " '{print $3}' | sed s/\'//g) | |
62 | if [ "$distro" == "centos linux" ]; then | |
63 | # there is chance that it's actually something different, | |
64 | # but we take it as centos7 anyway. | |
65 | distro=centos | |
66 | distro_ver=7 | |
67 | fi | |
68 | else | |
69 | case $codename in | |
70 | xenial) | |
71 | distro=ubuntu | |
72 | distro_ver=16.04 | |
73 | ;; | |
74 | trusty) | |
75 | distro=ubuntu | |
76 | distro_ver=14.04 | |
77 | ;; | |
78 | centos7) | |
79 | distro=centos | |
80 | distro_ver=7 | |
81 | ;; | |
82 | *) | |
83 | die "unknown distro: $distro" | |
84 | ;; | |
85 | esac | |
86 | fi | |
87 | ||
88 | # try to figure out a name for working directory | |
89 | if [ -z $wd ]; then | |
90 | run=${core_path%/remote/*} | |
91 | job_id=${run#/a/} | |
92 | if [ $job_id != $core_path ]; then | |
93 | # use the run/job for the working dir | |
94 | wd=$job_id | |
95 | fi | |
96 | fi | |
97 | ||
98 | if [ -z $wd ]; then | |
99 | wd=$(basename $core_path) | |
100 | wd=${wd%.*} | |
101 | echo "unable to figure out the working directory, using ${wd}" | |
102 | fi | |
103 | ||
104 | log "creating ${wd}" | |
105 | mkdir -p $wd | |
106 | cd $wd | |
107 | ||
108 | prog=$(file $core_path | grep -oP "from '\K[^']+" | cut -d' ' -f1) | |
109 | case $prog in | |
110 | ceph_test_*) | |
111 | pkgs="ceph-test librados2" | |
112 | ;; | |
113 | ceph-osd|ceph-mon) | |
114 | pkgs=$prog | |
115 | ;; | |
116 | */python*) | |
117 | prog=$(basename $prog) | |
118 | pkgs=librados2 | |
119 | ;; | |
120 | rados) | |
121 | pkgs="ceph-common librados2 libradosstriper1" | |
122 | ;; | |
123 | *) | |
124 | die "unknown prog: $prog" | |
125 | ;; | |
126 | esac | |
127 | ||
128 | flavor=default | |
129 | arch=x86_64 | |
130 | ||
131 | release=$(strings $core_path | grep -m1 -oP '/build/ceph-\K[^/]+') | |
132 | if [ -z $release ]; then | |
133 | teuthology_log=$(get_t_dir $core_path)/teuthology.log | |
134 | release=$(grep -m1 -A1 "Running command: sudo ceph --version" ${teuthology_log} | tail -n1 | grep -oP "ceph version \K[^ ]+") | |
135 | fi | |
136 | ||
137 | case $distro in | |
138 | ubuntu) | |
139 | pkg_path=pool/main/c/ceph/%s_%s-1${codename}_amd64.deb | |
140 | for p in $pkgs; do | |
141 | t="$t $p $p-dbg" | |
142 | done | |
143 | pkgs="$t" | |
144 | ;; | |
145 | centos) | |
146 | pkg_path=${arch}/%s-%s.el7.x86_64.rpm | |
147 | # 11.0.2-1022-g5b25cd3 => 11.0.2-1022.g5b25cd3 | |
148 | release=$(echo $release | sed s/-/./2) | |
149 | pkgs="$pkgs ceph-debuginfo" | |
150 | ;; | |
151 | *) | |
152 | die "unknown distro: $distro" | |
153 | ;; | |
154 | esac | |
155 | ||
156 | query_url="https://shaman.ceph.com/api/search?status=ready&project=ceph&flavor=${flavor}&distros=${distro}%2F${distro_ver}%2F${arch}&sha1=${sha1}" | |
157 | repo_url=`curl -L -s "${query_url}" | jq -r '.[0] | .url'` | |
158 | pkg_url=${repo_url}/${pkg_path} | |
159 | log "repo url is ${repo_url}" | |
160 | ||
161 | for pkg in ${pkgs}; do | |
162 | url=`printf $pkg_url $pkg $release` | |
163 | log "downloading ${url}" | |
164 | curl -O -L -C - --silent --fail --insecure $url | |
165 | fname=`basename $url` | |
166 | case $fname in | |
167 | *.deb) | |
168 | ar p `basename $fname` data.tar.xz | tar xJv;; | |
169 | *.rpm) | |
170 | rpm2cpio < $fname | cpio -id;; | |
171 | *) | |
172 | esac | |
173 | done | |
174 | ||
175 | cat > preclude.gdb <<EOF | |
176 | set sysroot . | |
177 | set debug-file-directory ./usr/lib/debug | |
178 | set solib-search-path ./usr/lib64 | |
179 | file ./usr/bin/$prog | |
180 | core $core_path | |
181 | EOF | |
182 | gdb -x preclude.gdb |