3 # A script to check that we have as many instance_finalize that instance_init
6 # $1 = input file (debug log)
14 echo "Usage: $0 <logfile> [display_ok=true|false] - default to 'false'" 1>&2
17 if [ "$1" = "" ]; then
22 if [ "${2}" = "" ]; then
24 elif [ "${2}" = "display_ok=false" ]; then
26 elif [ "${2}" = "display_ok=true" ]; then
35 tmp1
=/tmp
/${0##*/}.$$
.1
36 tmp2
=/tmp
/${0##*/}.$$
.2
37 tmp3
=/tmp
/${0##*/}.$$
.3
39 \rm
-f /tmp
/${0##*/}.
*
44 echo /tmp
/${0##*/}.$$.
${1}
49 typeset ftmp
=$
(getftmp
${1})
55 typeset ftmp
=$
(getftmp
${1})
61 typeset ftmp
=$
(getftmp
${1})
67 typeset ftmp
=$
(getftmp
${1})
73 typeset ftmp
=$
(getftmp
${1})
74 typeset value
=$
(cat ${ftmp})
79 function count_display
81 typeset ftmp
=$
(getftmp
${1})
87 typeset fused
=/tmp
/${0##*/}.$$.reused
88 typeset triplet
="${1}"
91 typeset used_line
="$(grep -w ${triplet} ${fused} 2>/dev/null)"
92 if [ "${used_line}" = "" ]; then
94 echo "${triplet} ${count}" >> ${fused}
96 count=$(echo ${used_line} | awk '{ print $2 }')
98 grep -v ${triplet} ${fused} > ${fused}.tmp
99 echo "${triplet} ${count}" >> ${fused}.tmp
100 mv ${fused}.tmp
${fused}
106 # get in tmp1 just the list of instance_init/instance_dispose with line numbers
107 # it is kept in run order (input line number order)
108 # note that instance_init on a base class has the base class name
109 # while instance_finalize on this same base class has the derived class name
110 echo -n "Extracting and formatting relevant lines from ${1}"
114 grep -En "instance_init|instance_${check_for}" ${1} |
grep -vE 'quitting main window|parent=|children=|tree=|deleted=' |
while read line
; do
117 if [ ${count100} -ge 100 ]; then
122 if [ ${count500} -ge 500 ]; then
126 numline
=$
(echo ${line} | cut
-d: -f1)
127 fn_name
=$
(echo ${line} |
awk '{ print $3 }' |
sed 's/:$//')
128 obj_address
=$
(echo ${line} |
awk '{ print $4 }' |
sed -e 's/.*=//' -e 's/,$//')
129 class
=$
(echo ${line} |
awk '{ print $5 }' |
sed 's/[(),]*//g')
130 [ "${class}" = "" ] && echo "warning: no class found in line '${line}'" 1>&2
131 prefix
=$
(echo ${fn_name} |
sed 's/_instance.*$//')
133 [ "$(echo ${fn_name} | grep instance_init)" = "" ] && nature
="2:final"
134 reused
=$
(is_reused
${obj_address}-${prefix}-${nature})
135 echo "${numline} ${fn_name} ${obj_address} ${class} ${prefix} ${nature} ${reused}" >> ${tmp1}
137 count=$(wc -l ${tmp1} | awk '{ print $1 }')
138 echo " ${count} lines
read"
142 # sort on: reused_count, object_address, class_name, line_number
144 sortparms="-k7,7n
-k3,3 -k5,5 -k1,1n
"
145 cat ${tmp1} | LC_ALL=C sort ${sortparms} > ${tmp2}
147 #cat ${tmp3} | sort ${sortparms}
153 count_init count_undisposed
154 count_init count_undisposed_bis
155 count_init count_warns
156 str_init list_undisposed
157 cat ${tmp2} | while read line; do
158 nature=$(echo ${line} | awk '{ print $6 }')
159 if [ "${nature}" = "1:init
" ]; then
160 if [ "${line_init}" = "" ]; then
162 obj_address_init=$(echo ${line} | awk '{ print $3 }')
163 fn_prefix_init=$(echo ${line} | awk '{ print $5 }')
166 # init line being read, but previous was also an init line
167 # say previous was an error
168 # and restart with init line being read
169 class=$(echo ${line_init} | awk '{ print $4 }')
170 if [ "$
(str_grep list_undisposed
${obj_address_init})" = "" ]; then
171 num=$(echo ${line_init} | awk '{ print $1 }')
172 echo "- unfinalized
${class} at ${obj_address_init} intialized at line ${num}"
173 str_add list_undisposed ${obj_address_init}
174 count_inc count_undisposed
176 echo "- do not record
${class} at ${obj_address_init} already counted
"
177 count_inc count_undisposed_bis
180 obj_address_init=$(echo ${line} | awk '{ print $3 }')
181 fn_prefix_init=$(echo ${line} | awk '{ print $5 }')
185 if [ "${line_init}" = "" ]; then
186 # dispose line being read but previous was also a dispose line
187 # just signals the dispose line is an error
188 echo "warning
: unwaited line
: ${line}"
189 count_inc count_warns
191 # we have an init line, and are reading a dispose line
192 # test if they are for the same object
193 class=$(echo ${line} | awk '{ print $4 }')
194 obj_address_dispose=$(echo ${line} | awk '{ print $3 }')
195 fn_prefix_dispose=$(echo ${line} | awk '{ print $5 }')
196 line_dispose="${line}"
197 if [ "${obj_address_dispose}" = "${obj_address_init}" ]; then
198 numline_init=$(echo ${line_init} | awk '{ print $1 }')
199 numline_dispose=$(echo ${line_dispose} | awk '{ print $1 }')
200 type_init=$(echo ${line_init} | awk '{ print $4 }')
201 if [ ${display_ok} -eq 1 ]; then
202 echo "${type_init} ${addr_init} (${numline_init},${numline_dispose}): OK
"
206 # if they are not for the same object, the two are errors
208 class=$(echo ${line_init} | awk '{ print $4 }')
209 if [ "$
(str_grep list_undisposed
${obj_address_init})" = "" ]; then
210 num=$(echo ${line_init} | awk '{ print $1 }')
211 echo "- unfinalized
${class} at ${obj_address_init} intialized at line ${num}"
212 str_add list_undisposed ${obj_address_init}
213 count_inc count_undisposed
215 echo "- do not record
${class} at ${obj_address_init} already counted
"
216 count_inc count_undisposed_bis
219 echo "warning
: unwaited line
: ${line}"
220 count_inc count_warns
226 echo "${line_init}" > /tmp/${0##*/}.$$.line_init
228 # does not work because shell variables do not go out of a while loop in bash
229 #if [ "${line_init}" != "" ]; then
230 # class=$(echo ${line_init} | awk '{ print $4 }')
231 # if [ "$
(str_grep list_undisposed
${obj_address_init})" = "" ]; then
232 # num=$(echo ${line_init} | awk '{ print $1 }')
233 # echo "- unfinalized
${class} at ${obj_address_init} intialized at line ${num}"
234 # str_add list_undisposed ${obj_address_init}
235 # count_inc count_undisposed
237 # echo "- do not record
${class} at ${obj_address_init} already counted
"
238 # count_inc count_undisposed_bis
241 line_init="$
(cat /tmp
/${0##*/}.$$.line_init
)"
242 if [ "${line_init}" != "" ]; then
243 obj_address_init=$(echo "${line_init}" | awk '{ print $3 }')
244 class=$(echo "${line_init}" | awk '{ print $4 }')
245 if [ "$
(str_grep list_undisposed
${obj_address_init})" = "" ]; then
246 num=$(echo "${line_init}" | awk '{ print $1 }')
247 echo "- unfinalized
${class} at ${obj_address_init} intialized at line ${num}"
248 str_add list_undisposed ${obj_address_init}
249 count_inc count_undisposed
251 echo "- do not record
${class} at ${obj_address_init} already counted
"
252 count_inc count_undisposed_bis
257 echo "Objects are OK
: $
(count_display count_ok
)"
258 echo "Unfinalized objects
: $
(count_display count_undisposed
) (not re-counted lines
: $
(count_display count_undisposed_bis
))"
259 echo "Other warnings
: $
(count_display count_warns
)"