derickr / vld

BSD 2-Clause "Simplified" License
464 stars 87 forks source link

"vld.save_paths=1" generates invalid "/tmp/paths.dot" with invalid syntax #74

Closed sebastianbergmann closed 2 years ago

sebastianbergmann commented 2 years ago

test.php

<?php declare(strict_types=1);
namespace foo\bar;

final class baz
{
    public function m(): void
    {
    }
}

php -d vld.active=1 -d vld.execute=0 -d vld.save_paths=1 test.php

Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /home/sb/test.php
function name:  (null)
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E > > RETURN                                                   1

branch: #  0; line:    11-   11; sop:     0; eop:     0; out0:  -2
path #1: 0, 
Class foo\bar\baz:
Function m:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /home/sb/test.php
function name:  m
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E > > RETURN                                                   null

branch: #  0; line:     8-    8; sop:     0; eop:     0; out0:  -2
path #1: 0, 
End of function m

End of class foo\bar\baz.

/tmp/paths.dot

digraph {
subgraph cluster_file_0x7f109de90000 { label="file /home/sb/test.php";
subgraph cluster_0x7f109de90000 {
    label="__main";
    graph [rankdir="LR"];
    node [shape = record];
    "__main_0" [ label = "{ op #0-0 | line 11-11 }" ];
    __main_ENTRY -> __main_0
    __main_0 -> __main_EXIT;
}
subgraph cluster_class_foo\bar\baz { label="class foo\bar\baz";
subgraph cluster_0x7f109de04208 {
    label="m";
    graph [rankdir="LR"];
    node [shape = record];
    "m_0" [ label = "{ op #0-0 | line 8-8 }" ];
    m_ENTRY -> m_0
    m_0 -> m_EXIT;
}
}
}
}

dot -Tpdf -o paths.pdf /tmp/paths.dot

Error: /tmp/paths.dot: syntax error in line 11 near '\'

Change that fixes the syntax

--- paths.dot.orig  2022-02-25 07:18:51.790727337 +0100
+++ paths.dot   2022-02-25 07:19:56.593225967 +0100
@@ -8,7 +8,7 @@
    __main_ENTRY -> __main_0
    __main_0 -> __main_EXIT;
 }
-subgraph cluster_class_foo\bar\baz { label="class foo\bar\baz";
+subgraph cluster_class_foo_bar_baz { label="class foo\bar\baz";
 subgraph cluster_0x7f109de04208 {
    label="m";
    graph [rankdir="LR"];

TL;DR: The \ character must not be used in cluster, node, etc. identifiers.

sebastianbergmann commented 2 years ago

Thank you!