From: Florian Krohm Date: Sat, 1 Oct 2011 21:07:32 +0000 (+0000) Subject: Change the filtering of helgrind's XML output. X-Git-Tag: svn/VALGRIND_3_7_0~160 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6925f05d3590f33367a477c2c72254f0082b786c;p=thirdparty%2Fvalgrind.git Change the filtering of helgrind's XML output. New file helgrind/tests/filter_xml. Update expected result for tc06_two_races_xml. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12077 --- diff --git a/helgrind/tests/filter_xml b/helgrind/tests/filter_xml new file mode 100755 index 0000000000..282de5c85b --- /dev/null +++ b/helgrind/tests/filter_xml @@ -0,0 +1,156 @@ +#!/usr/bin/env perl + +#--------------------------------------------------------------------- +# Quick and dirty program to filter helgrind's XML output. +# +# The script works line-by-line and is generally unaware of XML structure +# and does not bother with issues of well-formedness. +# +# Consists of two parts +# (1) Global match and replace (see PATTERNS below) +# (2) Removal of stack frames +# Stack frames whose associated file name does not match any name in +# TOOL_FILES or in the list of files given on the command line +# will be discarded. For a sequence of one or more discarded frames +# a line ... will be inserted. +# +#--------------------------------------------------------------------- + +use warnings; +use strict; + +#--------------------------------------------------------------------- +# A list of files specific to the tool at hand. Line numbers in +# these files will be removed from stack frames matching these files. +#--------------------------------------------------------------------- +my @tool_files = ( "hg_intercepts.c", "vg_replace_malloc.c" ); + +# List of patterns and replacement strings. +# Each pattern must identify a substring which will be replaced. +my %patterns = ( + "(.*)" => "...", + "(.*)" => "...", + "" => "...", + "(.*)" => "...", + "(.*)" => "...", + "(.*)" => "...", + "(.*)" => "...", + "(.*)" => "...", + "thread #([0-9]+)" => "x", + "0x([0-9a-zA-Z]+)" => "........", + "Using Valgrind-([^\\s]*)" => "X.Y.X", + "Copyright \\(C\\) ([0-9]{4}-[0-9]{4}).*" => "XXXX-YYYY" +); + +# List of XML sections to be ignored. +my %ignore_sections = ( + "" => "", + "" => "" +); + + +# If FILE matches any of the FILES return 1 +sub file_matches ($$) { + my ($file, $files) = @_; + my ($string, $qstring); + + foreach $string (@$files) { + $qstring = quotemeta($string); + return 1 if ($file =~ /$qstring/); + } + + return 0; +} + + +my $frame_buf = ""; +my ($file, $lineno, $in_frame, $keep_frame, $num_discarded, $ignore_line); + +$in_frame = $keep_frame = $num_discarded = $ignore_line = 0; + +line: +while () { + my $line = $_; + chomp($line); + +# Check whether we're ignoring this piece of XML.. + if ($ignore_line) { + foreach my $tag (keys %ignore_sections) { + if ($line =~ $ignore_sections{$tag}) { + print "$tag...$ignore_sections{$tag}\n"; + $ignore_line = 0; + next line; + } + } + } else { + foreach my $tag (keys %ignore_sections) { + if ($line =~ $tag) { + $ignore_line = 1; + } + } + } + + next if ($ignore_line); + +# OK. This line is not to be ignored. + +# Massage line by applying PATTERNS. + foreach my $key (keys %patterns) { + if ($line =~ $key) { + $line =~ s/$1/$patterns{$key}/g; + } + } + +# Handle frames + if ($in_frame) { + if ($line =~ /<\/frame>/) { + $frame_buf .= "$line\n"; +# The end of a frame + if ($keep_frame) { +# First: If there were any preceding frames that were discarded +# print ... + if ($num_discarded) { + print " ...\n"; + $num_discarded = 0; + } +# Secondly: Write out the frame itself + print "$frame_buf"; + } else { +# We don't want to write this frame + ++$num_discarded; + } + $in_frame = $keep_frame = 0; + $file = ""; + } elsif ($line =~ /(.*)<\/file>/) { + $frame_buf .= "$line\n"; + $file = $1; + if (file_matches($file, \@tool_files) || + file_matches($file, \@ARGV)) { + $keep_frame = 1; + } + } elsif ($line =~ /(.*)<\/line>/) { +# This code assumes that always precedes + $lineno = $1; + if (file_matches($file, \@tool_files)) { + $line =~ s/$1/.../; + } + $frame_buf .= "$line\n"; + } else { + $frame_buf .= "$line\n"; + } + } else { +# not within frame + if ($line =~ /<\/stack>/) { + print " ...\n" if ($num_discarded); + $num_discarded = 0; + } + if ($line =~ //) { + $in_frame = 1; + $frame_buf = "$line\n"; + } else { + print "$line\n"; + } + } +} + +exit 0; diff --git a/helgrind/tests/tc06_two_races_xml.stderr.exp b/helgrind/tests/tc06_two_races_xml.stderr.exp index 25ee580e10..0fd5cd498d 100644 --- a/helgrind/tests/tc06_two_races_xml.stderr.exp +++ b/helgrind/tests/tc06_two_races_xml.stderr.exp @@ -6,10 +6,10 @@ helgrind - ... - ... - ... - ... + Helgrind, a thread error detector + Copyright (C) XXXX-YYYY, and GNU GPL'd, by OpenWorks LLP et al. + Using Valgrind-X.Y.X and LibVEX; rerun with -h for copyright info + Command: ./tc06_two_races ... @@ -17,9 +17,18 @@ helgrind - ... + + ... + --command-line-only=yes + --memcheck:leak-check=no + --tool=helgrind + --read-var-info=yes + --xml=yes + --xml-fd=2 + --log-file=/dev/null + - ./tc06_two_races + ... @@ -36,22 +45,7 @@ 2 - - 0x........ - ... - clone - ... - clone.S - ... - - - 0x........ - ... - pthread_create@@GLIBC_2.2.5 - ... - createthread.c - ... - + ... 0x........ ... @@ -74,13 +68,13 @@ main ... tc06_two_races.c - ... + 26 - 0x........ + ... ... Race @@ -94,7 +88,7 @@ main ... tc06_two_races.c - ... + 31 @@ -108,7 +102,7 @@ child_fn ... tc06_two_races.c - ... + 14 0x........ @@ -118,24 +112,14 @@ hg_intercepts.c ... - - 0x........ - ... - start_thread - ... - pthread_create.c - ... - - - 0x........ - + ... Location 0x........ is 0 bytes inside global var "unprot1" - declared at tc06_two_races.c:9 tc06_two_races.c ... + declared at tc06_two_races.c:9 tc06_two_races.c 9 - 0x........ + ... ... Race @@ -149,7 +133,7 @@ main ... tc06_two_races.c - ... + 31 @@ -163,7 +147,7 @@ child_fn ... tc06_two_races.c - ... + 14 0x........ @@ -173,24 +157,14 @@ hg_intercepts.c ... - - 0x........ - ... - start_thread - ... - pthread_create.c - ... - - - 0x........ - + ... Location 0x........ is 0 bytes inside global var "unprot1" - declared at tc06_two_races.c:9 tc06_two_races.c ... + declared at tc06_two_races.c:9 tc06_two_races.c 9 - 0x........ + ... ... Race @@ -204,7 +178,7 @@ main ... tc06_two_races.c - ... + 35 @@ -218,7 +192,7 @@ child_fn ... tc06_two_races.c - ... + 18 0x........ @@ -228,24 +202,14 @@ hg_intercepts.c ... - - 0x........ - ... - start_thread - ... - pthread_create.c - ... - - - 0x........ - + ... Location 0x........ is 0 bytes inside global var "unprot2" - declared at tc06_two_races.c:9 tc06_two_races.c ... + declared at tc06_two_races.c:9 tc06_two_races.c 9 - 0x........ + ... ... Race @@ -259,7 +223,7 @@ main ... tc06_two_races.c - ... + 35 @@ -273,7 +237,7 @@ child_fn ... tc06_two_races.c - ... + 18 0x........ @@ -283,20 +247,10 @@ hg_intercepts.c ... - - 0x........ - ... - start_thread - ... - pthread_create.c - ... - - - 0x........ - + ... Location 0x........ is 0 bytes inside global var "unprot2" - declared at tc06_two_races.c:9 tc06_two_races.c ... + declared at tc06_two_races.c:9 tc06_two_races.c 9 @@ -305,24 +259,7 @@ - - - ... - 0x........ - - - ... - 0x........ - - - ... - 0x........ - - - ... - 0x........ - - +... ... diff --git a/helgrind/tests/tc06_two_races_xml.vgtest b/helgrind/tests/tc06_two_races_xml.vgtest index 26f3e8145b..48c0528520 100644 --- a/helgrind/tests/tc06_two_races_xml.vgtest +++ b/helgrind/tests/tc06_two_races_xml.vgtest @@ -1,3 +1,4 @@ prog: tc06_two_races vgopts: --read-var-info=yes --xml=yes --xml-fd=2 --log-file=/dev/null -stderr_filter: ../../memcheck/tests/filter_xml +stderr_filter: ./filter_xml +stderr_filter_args: tc06_two_races.c