forked from mariadb-corporation/MaxScale
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstacktrace
executable file
·87 lines (71 loc) · 1.49 KB
/
stacktrace
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
# How we recognize whether a line in the file is from the stack-trace.
STACK_LINE=".*\(.*\) \[.*\]"
# How we match the date + time part of a line.
DATE_TIME="[0-9]\+-[0-9]\+-[0-9]\+ [0-9]\+:[0-9]\+:[0-9]\+"
function print_usage {
echo "usage: stacktrace [-p prefix] [stacktrace.txt]"
echo
echo "-p frefix: The path prefix (e.g. /usr/local/mariadb-maxscale/) "
echo " to remove when searching for files."
echo
echo "stacktrace.txt: A file containing a stack-trace."
exit 1
}
function print_usage_and_exit {
print_usage
exit 1
}
function parse_stack_trace {
local prefix=$1
local file=$2
egrep "$STACK_LINE" < "$file" | sed "s/$DATE_TIME//" | \
while read line
do
local path=${line%%(*}
local entry="("${line##*(}
path=${path#$prefix}
if [ -e "${path}" ]
then
file "${path}" | fgrep -q executable
let rc=$?
local address;
if [ $rc -eq 0 ]
then
address=${entry#*\[}
address=${address%\]*}
else
address=${entry#*\+}
address=${address%\)*}
fi
addr2line -e "${path}" "${address}"
else
echo "${line}"
fi
done
}
function main {
local prefix
local key
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-h)
print_usage
exit
;;
-p|--prefix)
prefix="$2";
shift
;;
*)
echo "error: Unknown parameter $key"
print_usage_and_exit
esac
shift
done
local file=$1
parse_stack_trace "$prefix" "$file"
}
main "$@"