| 1 |
# Copyright (C) 2014-2025 Free Software Foundation, Inc. |
| 2 |
|
| 3 |
# This program is free software; you can redistribute it and/or modify |
| 4 |
# it under the terms of the GNU General Public License as published by |
| 5 |
# the Free Software Foundation; either version 3 of the License, or |
| 6 |
# (at your option) any later version. |
| 7 |
# |
| 8 |
# This program is distributed in the hope that it will be useful, |
| 9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
# GNU General Public License for more details. |
| 12 |
# |
| 13 |
# You should have received a copy of the GNU General Public License |
| 14 |
# along with GCC; see the file COPYING3. If not see |
| 15 |
# <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
# Look for lines of the form: |
| 18 |
# definitely lost: 11,316 bytes in 235 blocks |
| 19 |
# indirectly lost: 352 bytes in 4 blocks |
| 20 |
# Report zero bytes lost as a a PASS. |
| 21 |
# Use LEAK_REPORT_FUNCTION to report non-zero bytes lost (either fail or xfail) |
| 22 |
|
| 23 |
proc report_leak {kind name logfile line leak_report_function} { |
| 24 |
set match [regexp "$kind lost: .*" $line result] |
| 25 |
if $match { |
| 26 |
verbose "Saw \"$result\" within \"$line\"" 4 |
| 27 |
# Extract bytes and blocks. |
| 28 |
# These can contain commas as well as numerals, |
| 29 |
# but we only care about whether we have zero. |
| 30 |
regexp "$kind lost: (.+) bytes in (.+) blocks" \ |
| 31 |
$result -> bytes blocks |
| 32 |
verbose "bytes: '$bytes'" 4 |
| 33 |
verbose "blocks: '$blocks'" 4 |
| 34 |
if { $bytes == 0 } { |
| 35 |
pass "$name: $logfile: $result" |
| 36 |
} else { |
| 37 |
$leak_report_function "$name: $logfile: $result" |
| 38 |
} |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
proc parse_valgrind_logfile {name logfile leak_report_function} { |
| 43 |
verbose "parse_valgrind_logfile: $logfile" 2 |
| 44 |
if [catch {set f [open $logfile]}] { |
| 45 |
fail "$name: unable to read $logfile" |
| 46 |
return |
| 47 |
} |
| 48 |
|
| 49 |
while { [gets $f line] >= 0 } { |
| 50 |
# Strip off the PID prefix e.g. ==7675== |
| 51 |
set line [regsub "==\[0-9\]*== " $line ""] |
| 52 |
verbose $line 2 |
| 53 |
|
| 54 |
report_leak "definitely" $name $logfile $line $leak_report_function |
| 55 |
report_leak "indirectly" $name $logfile $line $leak_report_function |
| 56 |
} |
| 57 |
close $f |
| 58 |
} |