Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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

by rockyb (Scribe)
on Jul 15, 2018 at 20:55 UTC ( [id://1218517]=perlquestion: print w/replies, xml ) Need Help??

rockyb has asked for the wisdom of the Perl Monks concerning the following question:

O Omnificent Omnipotent Ones -

In a running Perl program if I have an Op address (either by B::Concise, Devel::Callsite or via mysterious other ways) is there a simple way to cast that into the right kind of B::OP, short of walking an Opcode tree?

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

Replies are listed 'Best First'.
Re: How can I turn an op address into the right kind of B::OP?
by haukex (Archbishop) on Jul 17, 2018 at 06:24 UTC

    Crossposted to StackOverflow, with more details there. Crossposting is acceptable, but it is considered polite to inform about it so that efforts are not duplicated. (I understand the crosspost, because you didn't get any responses here - although feel free to add the additional information here as well.)

      Yes, I understand. Thanks for pointing that out both here and on StackOverflow.

      I will update this as soon as there is some sort of closure on this.

      Note that I waited a day for some response here; currently there is nothing much to report either here or in StackOverflow. In StackOverflow though, there was a little more verbiage if only to get more clarification. So right now see StackOverflow if this question is as confusing to you as appearently it was (is?) to Mike Schwern.

      Again, I will update with condensed summary information here when there is something to report, as I have done in the past where I have received help on StackOverflow but also asked on PerlMongers first. To do it while things are in the air doesn't seem like a worthwhile use of time and and may be confusing for folks as well.

      Similarly, if there is activity here, I'll update the StackOverflow side when there is some sort of closure.

      Of course, monks and others can just follow one place if that's what they prefer. Ultimately, you'll find the same information (albeit in condensed form) in either place.

        So right now see StackOverflow for this if this question is as confusing to you as appearently it was (is?) to Mike Schwern.

        I'm not an expert on the internals, so I just don't have an answer to your question in this case (at least not yet, maybe someday ;-) ). Also, I'm not sure what your use case is, that is, I can't judge if this might be an XY Problem or not.

Re: How can I turn an op address into the right kind of B::OP?
by ikegami (Patriarch) on Jul 17, 2018 at 17:06 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]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1218517]
Approved by Corion
Front-paged by haukex
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (5)
As of 2024-04-23 20:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found