1 | #!/bin/bash |
---|
2 | |
---|
3 | if [ -z $1 ] ; then |
---|
4 | echo '' |
---|
5 | echo 'Usage: arb_valgrind [-m] [-c <callers>] [-f <filter>] [-l [-r]] [-A] <arb_program> <arguments>' |
---|
6 | echo '' |
---|
7 | echo ' runs valgrind (versions 3.x) on <arb_program> piping results through a filter' |
---|
8 | echo ' so that the output can be used as emacs error messages' |
---|
9 | echo '' |
---|
10 | echo ' -m use massif (default uses memcheck)' |
---|
11 | echo ' -c <callers> show <callers> stackframes (default: none)' |
---|
12 | echo ' [in fact they are always shown, but not marked as errors]' |
---|
13 | echo ' -f <filter> regexpr to filter the reason (default: all)' |
---|
14 | echo ' -l [-r] turn on leak-checking (-r for reachable blocks)' |
---|
15 | echo ' -A show known boring errors (most Xt/Motif-related)' |
---|
16 | echo ' -D run gdb on error' |
---|
17 | echo '' |
---|
18 | echo '' |
---|
19 | echo 'Usage: arb_valgrind update' |
---|
20 | echo '' |
---|
21 | echo ' Updates the source file list which is needed to create correct file refs.' |
---|
22 | echo ' Called automatically by normal use if list is missing.' |
---|
23 | echo ' Call if files are not highlighted as errors (i.e if you have new files).' |
---|
24 | echo '' |
---|
25 | echo 'Environment:' |
---|
26 | echo '' |
---|
27 | echo ' $ARBHOME a directory which has to contain a subdirectory SOURCE_TOOLS.' |
---|
28 | echo ' SOURCE_TOOLS has to contain valgrind2grep and has to be writeable for the user' |
---|
29 | echo '' |
---|
30 | echo ' $ARB_VALGRIND_SOURCE_ROOT down from here the script scans for sources' |
---|
31 | echo ' (defaults to $ARBHOME if empty)' |
---|
32 | echo '' |
---|
33 | echo 'Note: I use this from inside emacs as follows:' |
---|
34 | echo ' M-x compile' |
---|
35 | echo ' with:' |
---|
36 | echo ' (cd $ARBHOME;make nt) && arb_valgrind -l arb_ntree ~/ARB/demo.arb' |
---|
37 | echo '' |
---|
38 | echo 'There are scripts for older valgrind versions: ' |
---|
39 | ls -al $ARBHOME/SOURCE_TOOLS/arb_valgrind_* |
---|
40 | echo '' |
---|
41 | |
---|
42 | else |
---|
43 | if [ -z $ARB_VALGRIND_SOURCE_ROOT ] ; then |
---|
44 | ARB_VALGRIND_SOURCE_ROOT=$ARBHOME |
---|
45 | fi |
---|
46 | |
---|
47 | DIR=$ARBHOME/SOURCE_TOOLS |
---|
48 | LIST=$DIR/valgrind2grep.lst |
---|
49 | |
---|
50 | UPDATE=0 |
---|
51 | RUN=0 |
---|
52 | CALLERS=0 |
---|
53 | SUPPX='--suppress-common' |
---|
54 | FILTER='.*' |
---|
55 | LEAK_CHECK='' |
---|
56 | TOOL='--tool=memcheck' |
---|
57 | ATTACH='' |
---|
58 | |
---|
59 | if [ ! -f $LIST ] ; then |
---|
60 | UPDATE=1 |
---|
61 | fi |
---|
62 | if [ $1 = "update" ] ; then |
---|
63 | UPDATE=1 |
---|
64 | else |
---|
65 | RUN=1 |
---|
66 | SCAN_ARGS=1 |
---|
67 | |
---|
68 | while [ $SCAN_ARGS = 1 ] ; do |
---|
69 | SCAN_ARGS=0 |
---|
70 | if [ $1 = '-m' ] ; then |
---|
71 | TOOL='--tool=massif' |
---|
72 | shift 1 |
---|
73 | SCAN_ARGS=1 |
---|
74 | fi |
---|
75 | if [ $1 = '-c' ] ; then |
---|
76 | CALLERS=$2 |
---|
77 | shift 2 |
---|
78 | SCAN_ARGS=1 |
---|
79 | fi |
---|
80 | if [ $1 = '-f' ] ; then |
---|
81 | FILTER=$2 |
---|
82 | shift 2 |
---|
83 | SCAN_ARGS=1 |
---|
84 | fi |
---|
85 | if [ $1 = '-l' ] ; then |
---|
86 | LEAK_CHECK="$LEAK_CHECK --leak-check=yes --leak-resolution=high" |
---|
87 | shift 1 |
---|
88 | SCAN_ARGS=1 |
---|
89 | fi |
---|
90 | if [ $1 = '-r' ] ; then |
---|
91 | LEAK_CHECK="$LEAK_CHECK --show-reachable=yes" |
---|
92 | shift 1 |
---|
93 | SCAN_ARGS=1 |
---|
94 | fi |
---|
95 | if [ $1 = '-A' ] ; then |
---|
96 | SUPPX='' |
---|
97 | shift 1 |
---|
98 | SCAN_ARGS=1 |
---|
99 | fi |
---|
100 | if [ $1 = '-D' ] ; then |
---|
101 | ATTACH='--db-attach=yes' |
---|
102 | shift 1 |
---|
103 | SCAN_ARGS=1 |
---|
104 | fi |
---|
105 | done |
---|
106 | fi |
---|
107 | |
---|
108 | if [ "X$LEAK_CHECK" = "X" ] ; then |
---|
109 | LEAK_CHECK="--leak-check=no" |
---|
110 | fi |
---|
111 | |
---|
112 | if [ $UPDATE = 1 ] ; then |
---|
113 | echo "Creating list of source files starting in $ARB_VALGRIND_SOURCE_ROOT ..." |
---|
114 | find $ARB_VALGRIND_SOURCE_ROOT \! -path "*\{arch\}*" -a \ |
---|
115 | \( -name "*.[ch]" -o \ |
---|
116 | -name "*.[ch]xx" -o \ |
---|
117 | -name "*.[ch]pp" -o \ |
---|
118 | -name "*.cc" -o \ |
---|
119 | -name "*.hh" \) \ |
---|
120 | > $LIST |
---|
121 | echo 'done.' |
---|
122 | fi |
---|
123 | if [ $RUN = 1 ] ; then |
---|
124 | echo "Running valgrind on '$*' ..." |
---|
125 | echo "CALLERS='$CALLERS'" |
---|
126 | echo "FILTER ='$FILTER'" |
---|
127 | VG_CALLERS=$[$CALLERS+5] |
---|
128 | COMMAND="valgrind $TOOL -v --error-limit=no --num-callers=$VG_CALLERS $SHOW_REACHABLE $LEAK_CHECK $ATTACH $*" |
---|
129 | echo "COMMAND='$COMMAND'" |
---|
130 | if [ "$ATTACH" = "" ]; then |
---|
131 | $COMMAND 2>&1 >/tmp/arb_valgrind_$USER.stdout | $DIR/valgrind2grep $CALLERS "$FILTER" $SUPPX |
---|
132 | else |
---|
133 | $COMMAND |
---|
134 | fi |
---|
135 | echo 'valgrind done.' |
---|
136 | fi |
---|
137 | fi |
---|