]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix handling of `#` chars in `cg_diff`.
authorNicholas Nethercote <n.nethercote@gmail.com>
Tue, 30 Nov 2021 03:11:10 +0000 (14:11 +1100)
committerNicholas Nethercote <n.nethercote@gmail.com>
Tue, 30 Nov 2021 03:16:39 +0000 (14:16 +1100)
Rust v0 symbols can have `#` chars in them, things like this:
```
core::panic::unwind_safe::AssertUnwindSafe<<proc_macro::bridge::server::Dispat
cher<proc_macro::bridge::server::MarkedTypes<rustc_expand::proc_macro_server::Rustc>> 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

index 9d9258ef6071d030320d93b81bfa7f05fc317a3f..462308b49e45faacbbb31680d3756ef22c3fc235 100755 (executable)
@@ -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 (<INPUTFILE>) {
-        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");