1f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu#!/usr/bin/env perl 2f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu 3f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Guuse warnings; 4f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Guuse strict; 5f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu 6f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu#--------------------------------------------------------------------- 7f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu# A list of files specific to the tool at hand. Line numbers in 8f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu# these files will be removed from backtrace entries matching these files. 9f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu#--------------------------------------------------------------------- 10f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gumy @tool_files = ( "vg_replace_strmem.c", "vg_replace_malloc.c" ); 11f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu 12f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu 13f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gusub massage_backtrace_line ($$$) { 14f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu my ($line, $tool_files, $cmdlin_files) = @_; 15f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu my ($string, $qstring); 16f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu 178cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout# If LINE matches any of the file names passed on the command line 18f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu# (i.e. in CMDLIN_FILES) return LINE unmodified. 198cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout 208cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout foreach $string (@$cmdlin_files) { 218cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout $qstring = quotemeta($string); 22f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu return $line if ($line =~ /$qstring/); 23f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu } 248cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout 25f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu# If LINE matches any of the file names in TOOL_FILES remove the line 268cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout# number and return the so modified line. 278cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout 28f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu foreach $string (@$tool_files) { 29f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu $qstring = quotemeta($string); 308cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout return $line if ($line =~ s/$qstring:[0-9]+/$string:.../m); 31f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu# Special case for functions whose line numbers have been removed in 32f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu# filter_stderr_basic. FIXME: filter_stderr_basic should not do that. 338cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout return $line if ($line =~ s/$qstring:\.\.\./$string:.../m); 348cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout } 358cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout 368cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout# Did not match anything 378cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout $line =~ s/[\w]+.*/.../m; 38f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu 39f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu return "$line"; 408cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout} 41fa2e2acf79d791a90410025daad438968550d18cAlan Viverette 428cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout 438cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout#--------------------------------------------------------------------- 448cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout# Process lines. Two categories 458cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout# (a) lines from back traces 468cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout# pass through those lines that contain file names we're interested in 478cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout# (b) everything else 488cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout# pass through as is 498cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stout#--------------------------------------------------------------------- 508cef5c8d58f50d5baca1da44a7c19f623cbf98ecCraig Stoutmy $prev_line = ""; 51fa2e2acf79d791a90410025daad438968550d18cAlan Viverettewhile (<STDIN>) { 52b7087e036a48f5a3db28d02ff7f9b97fbbc46c4fDake Gu my $line = $_; 53b7087e036a48f5a3db28d02ff7f9b97fbbc46c4fDake Gu chomp($line); 54b7087e036a48f5a3db28d02ff7f9b97fbbc46c4fDake Gu if ($line =~ /^\s+(at |by )/) { # lines in a back trace 55f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu $line = massage_backtrace_line($line, \@tool_files, \@ARGV); 56f4b2f81cf278d3f08d60feefee139b532db3ce01Dake Gu if ($line =~ /\s+\.\.\./) { 57 print "$line\n" if ($prev_line !~ /\s+\.\.\./); 58 } else { 59 print "$line\n"; 60 } 61 } else { 62 print "$line\n"; # everything else 63 } 64 $prev_line = $line 65} 66 67exit 0; 68