summaryrefslogtreecommitdiff
path: root/tools/stackdump
blob: df460e824131a40f74f500112dc0bfb5e283fa29 (plain) (blame)
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
#!/bin/bash

case "$1" in
	map|char|login)
		# Check for SQL postfix
		if [ "$2" = "sql" ]; then
			SERVER="$1-server_sql"
		else
			SERVER="$1-server"
		fi
		;;

	*|""|help)
		echo "Usage 1: ${0##*/} [server-type] [txt/sql]"
		echo Server type can be map, login, or char. Examples:
		echo "$ ./${0##*/} map"
		echo "$ ./${0##*/} login sql"
		echo
		echo "Usage 2: ${0##*/} [server-type] [txt/sql] [number]"
		echo Server type can be map, login, or char. Examples:
		echo "$ ./${0##*/} map txt 0001"
		echo "$ ./${0##*/} login sql 0002"
		echo
		echo Note: Dump files inside /log will also be scanned.
		exit
		;;
esac

# Check if server file needs .exe (Windows/Cygwin)
if [ -e $SERVER.exe ]; then
	SERVER="$SERVER.exe"
elif [ ! -e $SERVER ]; then
	echo Error: $SERVER not found!
	exit
fi

# Assemble stackdump filename
if [ $# -gt 2 ]; then
	STACK="$SERVER$3.stackdump"
else
	STACK="$SERVER.stackdump"
fi

# Check if file exists.
# Try looking under '/log' if it isn't

if [ ! -e $STACK ]; then
	if [ -e log/$STACK ]; then
		STACK=log/$STACK
	else
		echo Error: $STACK not found!
		exit
	fi
fi

# Finally dump the backtrace
# If number is given, Sig-plugin format. otherwise, standard stackdump format
if [ $# -gt 2 ]; then
	awk '$2 ~ /[0-9a-eA-E]\]$/{print $2}' $STACK | tr -d \[\] | addr2line -f -e $SERVER 
else
	awk '/^[0-9]/{print $2}' $STACK | addr2line -f -e $SERVER
fi