in reply to How can I turn an op address into the right kind of B::OP?

Answered

  • Comment on Re: How can I turn an op address into the right kind of B::OP?

Replies are listed 'Best First'.
Re^2: How can I turn an op address into the right kind of B::OP?
by rockyb (Scribe) on Jul 18, 2018 at 09:00 UTC

    Actually, I thought so at first, but perhaps not. op_class[] is not available on Perl 5.24.4 and earlier. But leaving that aside, although the "name" method seems to return the right thing, other fields don't

    When I try with:

    sub testing { my $site = sub { callsite() }; my $addr = $site->(); printf "Op address is 0x%x\n", $addr; my $op = make_op_object($addr); printf("op %s, name: %s, parent: %s\n", $op, $op->name, $op->paren +t); # I can get OPs by walking and looking for $op_addr, # but I don't want to do that. my $walker = B::Concise::compile('-terse', '-src', \&testing); B::Concise::walk_output(\my $buf); $walker->(); # walks and renders into $buf; print $buf; } testing();
    I get:
    Op address is 0x55eddbdfba80 op B::OP=SCALAR(0x55eddba2c578), name: padsv, parent: B::BINOP=SCALAR( +0x55eddba422d0) B::Concise::compile(CODE(0x55eddbe20a80)) UNOP (0x55eddbe1ab10) leavesub [1] LISTOP (0x55eddbdfb9a0) lineseq # 37: my $site = sub { callsite() }; COP (0x55eddbab2048) nextstate BINOP (0x55eddbdfb9f8) sassign UNOP (0x55eddbdfba40) srefgen UNOP (0x55eddbdfbab8) null [157] SVOP (0x55eddbdfbb00) anoncode [2] CV (0x55eddba4d +0f8) OP (0x55eddbdfbb40) padsv [1] # 38: my $addr = $site->(); COP (0x55eddbab1e68) nextstate BINOP (0x55eddbab1ec8) sassign UNOP (0x55eddbab1f10) entersub [4] UNOP (0x55eddbab1f88) null [157] OP (0x55eddbab1f50) pushmark UNOP (0x55eddbab1fd0) null [16] OP (0x55eddbab2010) padsv [1] OP (0x55eddbdfba80) padsv [3]
    Note that the address is different as is the parent.

      You're printing the address of the B objects, not the address of the ops themselves.

      printf("op: %s (0x%x), parent: %s (0x%x)\n", $op->name, $$op, $parent->name, $$parent);
      op: padsv (0x104cc20), parent: sassign (0xfc7788)
      # 42: my $addr = $site->(); COP (0xfc7728) nextstate BINOP (0xfc7788) sassign UNOP (0xfc77d0) entersub [4] UNOP (0xfc7848) null [157] OP (0xfc7810) pushmark UNOP (0xfc7890) null [16] OP (0xfc78d0) padsv [1] OP (0x104cc20) padsv [3]

        Thanks for the information and clarification.

        I need to put all of this on hold and focus on other things, but if/when I come back to this I'll use your suggestions with respect to copying ext/B/B.xs in Perl versions other than 5.26.