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

Re: B::Xref buggy?

by dave_the_m (Monsignor)
on Nov 15, 2018 at 11:58 UTC ( [id://1225854]=note: print w/replies, xml ) Need Help??


in reply to B::Xref buggy?

Line number reporting in perl is a bit dodgy. The only place in the optree where the src line number is recorded is in 'nextstate' ops which are prepended to each statement. Whether B::Xref is doing even worse than is merited even by the poor quality data available to it, I don't know - I haven't looked closely enough at your example.

Dave.

Replies are listed 'Best First'.
Re^2: B::Xref buggy?
by LanX (Saint) on Nov 15, 2018 at 12:50 UTC
    It's probably dodgy if you have two statements in the same line.

    But Xref is ignoring the whole part inside while (...) and the linenumber is present, I used B::Concise to check.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

      Looking at the src code for B::Xref, it appears to scan the op tree in execution (op_next) order, noting the current line and file number any time it sees an OP_NEXTSTATE. When it comes to an op that has more than one possible next op (such as loops etc) it recursively follows each branch, without restoring the old file/line number on each return. Thus giving silly results.

      Dave.

        Thanks Dave.

        I'm no expert on OP-Codes but that doesn't seem to be always the case.

        On a simpler example the insides of while are parsed but the following line-number is wrong

        (manually added #:markers)

        D:\tmp>more tst_b_xref2.pl use strict; use warnings; my $sth; while ( my @row =$sth->fetchrow) { #:5 intro print "@row"; #:6 used }

        activating debug options

        D:\tmp>perl -MO=Xref,-r,-d,-DO tst_b_xref2.pl OP (0x163e650) enter COP (0x10fcdd8) nextstate OP (0x10fce38) padsv tst_b_xref2.pl (main) 3 (lexical) $ sth + intro COP (0x163e698) nextstate LOOP (0x163e740) enterloop OP (0x16579c8) pushmark OP (0x1657a50) pushmark PADOP (0x1657b48) gvsv tst_b_xref2.pl (main) 5 main $ " + used OP (0x1657ad0) padav tst_b_xref2.pl (main) 5 (lexical) @ row + used #:used? LISTOP (0x1657a88) join LISTOP (0x1657a08) print OP (0x163e870) unstack OP (0x1657bd0) pushmark OP (0x1657d60) pushmark OP (0x10fcd18) padsv tst_b_xref2.pl (main) 5 (lexical) $ sth + used METHOP (0x1657d18) method_named UNOP (0x1657cd0) entersub tst_b_xref2.pl (main) 5 (lexical) $ sth + subused OP (0x1657c50) pushmark OP (0x10fcd58) padav tst_b_xref2.pl (main) 5 (lexical) @ row + intro #:5?intro? BINOP (0x1657b88) aassign LOGOP (0x163e7e0) and BINOP (0x163e6f8) leaveloop LISTOP (0x10fcd90) leave tst_b_xref2.pl syntax OK

        It's worth noting that B::Concise and B::Deparse are getting the line-numbers right:

        D:\tmp>perl -MO=Concise,-src tst_b_xref2.pl n <@> leave[1 ref] vKP/REFC ->(end) 1 <0> enter ->2 # 3: my $sth; 2 <;> nextstate(main 3 tst_b_xref2.pl:3) v:*,&,{,x*,x&,x$,$ ->3 3 <0> padsv[$sth:3,9] vM/LVINTRO ->4 # 5: while ( my @row =$sth->fetchrow) { #: +line 5 4 <;> nextstate(main 4 tst_b_xref2.pl:5) v:*,&,{,x*,x&,x$,$ ->5 m <2> leaveloop vK/2 ->n 5 <{> enterloop(next->c last->m redo->6) v ->d - <1> null vK/1 ->m l <|> and(other->6) vK/1 ->m k <2> aassign[t4] sKS/COM_AGG ->l - <1> ex-list lK ->i d <0> pushmark s ->e h <1> entersub[t3] lKS/TARG,STRICT ->i e <0> pushmark s ->f f <0> padsv[$sth:3,9] sM ->g g <.> method_named[PV "fetchrow"] l ->h - <1> ex-list lK ->k i <0> pushmark s ->j j <0> padav[@row:5,8] lRM*/LVINTRO ->k #: +@row intro - <@> lineseq vK ->- - <@> scope vK ->c # 6: print "@row"; #: +line 6 - <;> ex-nextstate(main 7 tst_b_xref2.pl:6) v:*,&,x +*,x&,x$,$ ->6 b <@> print vK ->c 6 <0> pushmark s ->7 a <@> join[t6] sK/2 ->b 7 <0> pushmark s ->8 - <1> ex-rv2sv sK/STRICT,1 ->9 8 <#> gvsv[*"] s ->9 9 <0> padav[@row:5,8] l ->a #: +@row used c <0> unstack v ->d tst_b_xref2.pl syntax OK

        So probably B::Xref is better implemented by extending B::Concise ?

        Cheers Rolf
        (addicted to the Perl Programming Language :)
        Wikisyntax for the Monastery FootballPerl is like chess, only without the dice

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1225854]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-04-25 21:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found