Debian Codegraph @

src/tools/ci/cores_backtrace.sh

raw
1 #! /bin/sh
2
3 os=$1
4 directory=$2
5 executable_directory=$3
6
7 if [ "$os" != 'openbsd' ] && [ $# -ne 2 ]; then
8 echo "cores_backtrace.sh <os> <directory>"
9 exit 1
10 fi
11
12 if [ "$os" = 'openbsd' ] && [ $# -ne 3 ]; then
13 echo "cores_backtrace.sh <os> <core_directory> <executable_directory>"
14 exit 1
15 fi
16
17 case $os in
18 freebsd|linux|macos|netbsd|openbsd)
19 ;;
20 *)
21 echo "unsupported operating system ${os}"
22 exit 1
23 ;;
24 esac
25
26 if [ "$os" = 'openbsd' ]; then
27 export PATH="${executable_directory}:${PATH}"
28 fi
29
30 first=1
31 for corefile in $(find "$directory" -type f) ; do
32 if [ "$first" -eq 1 ]; then
33 first=0
34 else
35 # to make it easier to separate the different crash reports
36 echo -e '\n\n'
37 fi
38
39 if [ "$os" = 'macos' ]; then
40 lldb -c $corefile --batch -o 'thread backtrace all' -o 'quit'
41 elif [ "$os" = 'openbsd' ]; then
42 # OpenBSD's ELF format doesn't include executable information, so we
43 # search for the executable manually in <executable_directory>.
44 filename=$(basename "$corefile")
45 base=$(echo "$filename" | sed 's/\.core.*$//')
46 binary=$(which "${base}")
47
48 if [ -z "$binary" ]; then
49 echo "executable ${base} not found in ${PATH}, running 'lldb' without debug information"
50 lldb -c "$corefile" --batch -o 'thread backtrace all' -o 'quit'
51 else
52 lldb "$binary" -c "$corefile" --batch -o 'thread backtrace all' -o 'quit'
53 fi
54 else
55 auxv=$(gdb --quiet --core ${corefile} --batch -ex 'info auxv' 2>/dev/null)
56 if [ $? -ne 0 ]; then
57 echo "could not process ${corefile}"
58 continue
59 fi
60
61 if [ "$os" = 'freebsd' ]; then
62 binary=$(echo "$auxv" | grep AT_EXECPATH | perl -pe "s/^.*\"(.*)\"\$/\$1/g")
63 elif [ "$os" = 'netbsd' ]; then
64 binary=$(echo "$auxv" | grep AT_SUN_EXECNAME | perl -pe "s/^.*\"(.*)\"\$/\$1/g")
65 elif [ "$os" = 'linux' ]; then
66 binary=$(echo "$auxv" | grep AT_EXECFN | perl -pe "s/^.*\"(.*)\"\$/\$1/g")
67 else
68 echo 'should not get here'
69 exit 1
70 fi
71
72 echo "dumping ${corefile} for ${binary}"
73 gdb --batch --quiet -ex "thread apply all bt full" -ex "quit" "$binary" "$corefile" 2>/dev/null
74 fi
75 done