This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
revamp the op_dump() output format
authorDavid Mitchell <davem@iabyn.com>
Tue, 17 Jan 2017 17:40:32 +0000 (17:40 +0000)
committerDavid Mitchell <davem@iabyn.com>
Sat, 21 Jan 2017 10:04:44 +0000 (10:04 +0000)
commitcd6e48741f9105d4b8da0e141bfdf362f1dd0961
tree5cd9b61e6eb5230eb13d9221b088417c534106a4
parent1e85b6586ab5aca2ff20296114f8e70b45956a92
revamp the op_dump() output format

This is mainly used for low-level debugging these days (higher level stuff
like Concise having since been created), e.g. calling op_dump() from
within a debugger or running with -Dx. Make it display more info, and use
an ACSII-art tree to show the structure.

The main changes are:

* added 'ASCII-art' tree structure;
* it now displays each op's class and address;
* for op_next etc links, it now displays the type and address of the
  linked-to op in addition to its sequence number;
* the following ops now have their op_other field displayed, like op_and
  etc already do:
    andassign argdefelem dor dorassign entergiven entertry enterwhen
    once orassign regcomp substcont
* enteriter now has its op_redo etc fields displayed, like enterloop
  already does;

Here is a sample before and after of perl -Dx -e'($x+$y) * $z'

Before:

    {
    1   TYPE = leave  ===> NULL
        TARG = 1
        FLAGS = (VOID,KIDS,PARENS,SLABBED)
        PRIVATE = (REFC)
        REFCNT = 1
        {
    2       TYPE = enter  ===> 3
            FLAGS = (UNKNOWN,SLABBED,MORESIB)
        }
        {
    3       TYPE = nextstate  ===> 4
            FLAGS = (VOID,SLABBED,MORESIB)
            LINE = 1
            PACKAGE = "main"
            SEQ = 4294967246
        }
        {
    5       TYPE = multiply  ===> 1
            TARG = 5
            FLAGS = (VOID,KIDS,SLABBED)
            PRIVATE = (0x2)
            {
    6           TYPE = add  ===> 7
                TARG = 3
                FLAGS = (SCALAR,KIDS,PARENS,SLABBED,MORESIB)
                PRIVATE = (0x2)
                {
    8               TYPE = null  ===> (9)
                      (was rv2sv)
                    FLAGS = (SCALAR,KIDS,SLABBED,MORESIB)
                    PRIVATE = (0x1)
                    {
    4                   TYPE = gvsv  ===> 9
                        FLAGS = (SCALAR,SLABBED)
                        PADIX = 1
                    }
                }
                {
    10              TYPE = null  ===> (6)
                      (was rv2sv)
                    FLAGS = (SCALAR,KIDS,SLABBED)
                    PRIVATE = (0x1)
                    {
    9                   TYPE = gvsv  ===> 6
                        FLAGS = (SCALAR,SLABBED)
                        PADIX = 2
                    }
                }
            }
            {
    11          TYPE = null  ===> (5)
                  (was rv2sv)
                FLAGS = (SCALAR,KIDS,SLABBED)
                PRIVATE = (0x1)
                {
    7               TYPE = gvsv  ===> 5
                    FLAGS = (SCALAR,SLABBED)
                    PADIX = 4
                }
            }
        }
    }

After:

    1    leave LISTOP(0xdecb38) ===> [0x0]
         TARG = 1
         FLAGS = (VOID,KIDS,PARENS,SLABBED)
         PRIVATE = (REFC)
         REFCNT = 1
         |
    2    +--enter OP(0xdecb00) ===> 3 [nextstate 0xdecb80]
         |   FLAGS = (UNKNOWN,SLABBED,MORESIB)
         |
    3    +--nextstate COP(0xdecb80) ===> 4 [gvsv 0xdeb3b8]
         |   FLAGS = (VOID,SLABBED,MORESIB)
         |   LINE = 1
         |   PACKAGE = "main"
         |   SEQ = 4294967246
         |
    5    +--multiply BINOP(0xdecbe0) ===> 1 [leave 0xdecb38]
             TARG = 5
             FLAGS = (VOID,KIDS,SLABBED)
             PRIVATE = (0x2)
             |
    6        +--add BINOP(0xdeb2b0) ===> 7 [gvsv 0xdeb270]
             |   TARG = 3
             |   FLAGS = (SCALAR,KIDS,PARENS,SLABBED,MORESIB)
             |   PRIVATE = (0x2)
             |   |
    8        |   +--null (ex-rv2sv) UNOP(0xdeb378) ===> 9 [gvsv 0xdeb338]
             |   |   FLAGS = (SCALAR,KIDS,SLABBED,MORESIB)
             |   |   PRIVATE = (0x1)
             |   |   |
    4        |   |   +--gvsv PADOP(0xdeb3b8) ===> 9 [gvsv 0xdeb338]
             |   |       FLAGS = (SCALAR,SLABBED)
             |   |       PADIX = 1
             |   |
    10       |   +--null (ex-rv2sv) UNOP(0xdeb2f8) ===> 6 [add 0xdeb2b0]
             |       FLAGS = (SCALAR,KIDS,SLABBED)
             |       PRIVATE = (0x1)
             |       |
    9        |       +--gvsv PADOP(0xdeb338) ===> 6 [add 0xdeb2b0]
             |           FLAGS = (SCALAR,SLABBED)
             |           PADIX = 2
             |
    11       +--null (ex-rv2sv) UNOP(0xdeb220) ===> 5 [multiply 0xdecbe0]
                 FLAGS = (SCALAR,KIDS,SLABBED)
                 PRIVATE = (0x1)
                 |
    7            +--gvsv PADOP(0xdeb270) ===> 5 [multiply 0xdecbe0]
                     FLAGS = (SCALAR,SLABBED)
                     PADIX = 4
dump.c
ext/Devel-Peek/t/Peek.t