From 1cf2cf91e77db18f8d95767f73af3b3068d1a3ab Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 30 Nov 2021 14:11:10 +1100 Subject: [PATCH] Fix handling of `#` chars in `cg_diff`. Rust v0 symbols can have `#` chars in them, things like this: ``` core::panic::unwind_safe::AssertUnwindSafe<> as proc_macro::bridge::server::DispatcherTrait>::dispatch::{closure#14}>, ()> ``` `cg_diff` currently messes these up in two ways. - It treats anything after a `#` in the input file as a comment. In comparison, `cg_annotate` only treats a `#` as starting a comment at the start of a line. - It uses `#` to temporarily join file names and function names while processing. This commit adjusts the parsing to fix the first problem, and changes the joiner sequence to `###` to fix the second problem. --- cachegrind/cg_diff.in | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/cachegrind/cg_diff.in b/cachegrind/cg_diff.in index 9d9258ef60..462308b49e 100755 --- a/cachegrind/cg_diff.in +++ b/cachegrind/cg_diff.in @@ -191,15 +191,17 @@ sub read_input_file($) my $currFileName; my $currFileFuncName; - my %CCs; # hash("$filename#$funcname" => CC array) + my %CCs; # hash("$filename###$funcname" => CC array) my $currCC = undef; # CC array my $summaryCC; # Read body of input file. while () { - s/#.*$//; # remove comments - if (s/^(\d+)\s+//) { + # Skip comments and empty lines. + next if /^\s*$/ || /^\#/; + + if (s/^(-?\d+)\s+//) { my $CC = line_to_CC($_, $numEvents); defined($currCC) || die; add_array_a_to_b($CC, $currCC); @@ -210,7 +212,7 @@ sub read_input_file($) if (defined $mod_funcname) { eval "\$tmpFuncName =~ $mod_funcname"; } - $currFileFuncName = "$currFileName#$tmpFuncName"; + $currFileFuncName = "$currFileName###$tmpFuncName"; $currCC = $CCs{$currFileFuncName}; if (not defined $currCC) { $currCC = []; @@ -225,9 +227,6 @@ sub read_input_file($) # Assume that a "fn=" line is followed by a "fl=" line. $currFileFuncName = undef; - } elsif (s/^\s*$//) { - # blank, do nothing - } elsif (s/^summary:\s+//) { $summaryCC = line_to_CC($_, $numEvents); (scalar(@$summaryCC) == @events) @@ -260,7 +259,7 @@ my $events1; my $events2; # Individual CCs, organised by filename/funcname/line_num. -# hashref("$filename#$funcname", CC array) +# hashref("$filename###$funcname", CC array) my $CCs1; my $CCs2; @@ -313,7 +312,7 @@ print("\n"); while (my ($filefuncname, $CC) = each(%$CCs2)) { - my @x = split(/#/, $filefuncname); + my @x = split(/###/, $filefuncname); (scalar @x == 2) || die; print("fl=$x[0]\n"); -- 2.47.2