-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathasan_exec.sh
executable file
·81 lines (66 loc) · 1.47 KB
/
asan_exec.sh
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
#!/bin/bash
# Helper sript to enable/disable ASAN memory leaks detection
# NOTE: see ASAN_OPTIONS: check_initialization_order=1:strict_init_order=1:detect_odr_violation=1
# ASAN suppression file
root_directory=$(dirname "$0")
suppression_file="$root_directory/asan_suppressions.txt"
# Global on/off variable
# 0 means disabled
# 1 means enabled
leaks_detection="1"
print_help()
{
echo "For interactive usage: asan_exec.sh executable"
echo "Or, directly tell to enable or disable leak detections: asan_exec.sh --detect_leaks=[1|0] executable"
}
# Ask the user if he wanst to enable or disable leaks detection
ask_on_off()
{
echo -n "Enable ASAN leaks detection ? [y|yes|n|no(default:no)]: "
read answer
if [ "$answer" == "y" ]
then
leaks_detection="1"
elif [ "$answer" == "yes" ]
then
leaks_detection="1"
else
leaks_detection="0"
fi
}
parse_detect_leaks_option()
{
if [ "$1" == "--detect_leaks=1" ]
then
leaks_detection="1"
elif [ "$1" == "--detect_leaks=0" ]
then
leaks_detection="0"
else
echo "Error: unknown option $1"
print_help
exit 1
fi
}
setup_variables()
{
export ASAN_OPTIONS="detect_leaks=$leaks_detection"
export LSAN_OPTIONS="suppressions=$suppression_file"
}
# Main
if (( $# == 0 ))
then
echo "Error: expected a command to execute - Abort"
print_help
exit 1
fi
if (( $# == 1 ))
then
ask_on_off
setup_variables
exec "${@:1}"
else
parse_detect_leaks_option "$1"
setup_variables
exec "${@:2}"
fi