Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

${"_<a.pl"}[$i] no longer numerical for pragmas #21564

Closed
ikegami opened this issue Oct 15, 2023 · 6 comments · Fixed by #21566
Closed

${"_<a.pl"}[$i] no longer numerical for pragmas #21564

ikegami opened this issue Oct 15, 2023 · 6 comments · Fixed by #21566

Comments

@ikegami
Copy link
Contributor

ikegami commented Oct 15, 2023

See https://www.perlmonks.org/?node_id=11154956

perldebguts says:

Each array @{"_<$filename"} holds the lines of $filename for a file
compiled by Perl. [...] Values in this array are magical in numeric
context: they compare equal to zero only if the line is not breakable.

The last bit is not always true since 5.36.

Take the program

#!/usr/bin/perl

use strict;
use warnings;

use v5.10;

say 'Hello, world!';

In 5.36 and 5.38, we see:

  DB<1> use Devel::Peek;

  DB<2> Dump( ${"_<a.pl"}[8] );
SV = PVMG(0x55d8627958e0) at 0x55d86251ff80
  REFCNT = 1
  FLAGS = (IOK,POK,IsCOW,pIOK,pPOK)
  IV = 94387850872920
  NV = 0
  PV = 0x55d8628074b0 "say 'Hello, world!';\n"\0
  CUR = 21
  LEN = 32
  COW_REFCNT = 1

  DB<3> Dump( ${"_<a.pl"}[6] );
SV = PVMG(0x55d862786d50) at 0x55d86251fec0
  REFCNT = 1
  FLAGS = (POK,pIOK,pNOK,pPOK)
  IV = 0
  NV = 0
  PV = 0x55d8627d7d50 "use v5.10;\n"\0
  CUR = 11
  LEN = 16

Note that lack of IOK for line 6? It should look like line 5.

  DB<4> use Devel::Peek;Dump( ${"_<a.pl"}[5] );
SV = PVMG(0x55856a4198d0) at 0x55856a4e9630
  REFCNT = 1
  FLAGS = (IOK,POK,pIOK,pPOK)
  IV = 0
  NV = 0
  PV = 0x55856a486840 "\n"\0
  CUR = 1
  LEN = 16

This also means that only the lines with pragmas are broken.

This is a deviation from 5.34. In 5.34, we see

      DB<3> Dump( ${"_<a.pl"}[6] );
    SV = PVMG(0x55874ddaf680) at 0x55874db508a8
      REFCNT = 1
      FLAGS = (IOK,POK,pIOK,pPOK)
      IV = 94039612799016
      NV = 0
      PV = 0x55874db739a0 "use v5.10;\n"\0
      CUR = 11
      LEN = 16

(Same goes at least as far back as 5.10.)

So they were breakable in 5.34, but not in 5.36. Sounds like a valid bug fix. But it sounds like the person that fixed this forgot to set IOK when making that change.

@jkeenan
Copy link
Contributor

jkeenan commented Oct 17, 2023

I'm unclear as to how to reproduce this output. Even with a -DDEBUGGING perl, I get fewer lines of output in the debugger than @ikegami.

$ $THISPERL -d gh-21564-debug-pragma.pl

Loading DB routines from perl5db.pl version 1.77
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(gh-21564-debug-pragma.pl:8):
8:	say 'Hello, world!';
  DB<1> use Devel::Peek;

  DB<2> Dump( ${"_<a.pl"}[8] );
SV = NULL(0x0) at 0x55b2c651d3e0
  REFCNT = 908
  FLAGS = (READONLY,PROTECT)

  DB<3> 

What am I missing?

@mauke
Copy link
Contributor

mauke commented Oct 17, 2023

@jkeenan The name of the array needs to match the name of the source file. Your source file is named gh-21564-debug-pragma.pl, so you need to Dump( ${"_<gh-21564-debug-pragma.pl"}[8] );. Alternatively, rename the file to a.pl.

What you're seeing is the dump of an unset variable, basically.

@jkeenan
Copy link
Contributor

jkeenan commented Oct 17, 2023

@jkeenan The name of the array needs to match the name of the source file. Your source file is named gh-21564-debug-pragma.pl, so you need to Dump( ${"_<gh-21564-debug-pragma.pl"}[8] );. Alternatively, rename the file to a.pl.

What you're seeing is the dump of an unset variable, basically.

@mauke, thanks for that clarification. But now I'm seeing even fewer elements in the FLAGS() list on the line with the pragma call than, did @ikegami.

$ $THISPERL -d gh-21564-debug-pragma.pl

Loading DB routines from perl5db.pl version 1.77
Editor support available.

Enter h or 'h h' for help, or 'man perldebug' for more help.

main::(gh-21564-debug-pragma.pl:8):
8:	say 'Hello, world!';
  DB<1> use Devel::Peek;

  DB<2> Dump( ${"_<gh-21564-debug-pragma.pl"}[8] );
SV = PVMG(0x55e304ea1a98) at 0x55e304c54660
  REFCNT = 1
  FLAGS = (IOK,POK,IsCOW,pIOK,pPOK)
  IV = 94433525995512
  NV = 0
  PV = 0x55e30507f208 "say 'Hello, world!';\n"\0
  CUR = 21
  LEN = 32
  COW_REFCNT = 1

  DB<3> Dump( ${"_<gh-21564-debug-pragma.pl"}[6]); 
SV = PVMG(0x55e3052f7208) at 0x55e304c545a0
  REFCNT = 1
  FLAGS = (POK,pPOK)
  IV = 0
  NV = 0
  PV = 0x55e304f03d98 "use v5.10;\n"\0
  CUR = 11
  LEN = 16

  DB<4> Dump( ${"_<gh-21564-debug-pragma.pl"}[5]); 
SV = PVMG(0x55e3052f71a8) at 0x55e3052c9978
  REFCNT = 1
  FLAGS = (IOK,POK,pIOK,pPOK)
  IV = 0
  NV = 0
  PV = 0x55e304c57b88 "\n"\0
  CUR = 1
  LEN = 16

I only get 2 flags where he got 4.

In any case, we'll have to figure out a way to bisect this.

@ikegami
Copy link
Contributor Author

ikegami commented Oct 17, 2023

I only get 2 flags where he got 4.

The problem was originally written in terms of ${"_<a.pl"}[6] == 0 warning.
(Don't forget to use -w.)
So I must have run that earlier in the session.
That's what added pIOK and pNOK.

That's not relevant to the issue.

@ikegami
Copy link
Contributor Author

ikegami commented Oct 17, 2023

In any case, we'll have to figure out a way to bisect this.

There shouldn't be many changes to the debugger between 5.34 and 5.36, I say with the confidence of the ignorant.

@tonycoz
Copy link
Contributor

tonycoz commented Oct 17, 2023

It's not (directly) a change to the debugger that caused it.

As to bisecting:

tony@venus:.../git/perl6$ cat ../21564/Devel/D21564.pm 
package DB;

sub DB {
}

1;
tony@venus:.../git/perl6$ cat ../21564b.pl
#!/usr/bin/perl

#use strict;
use warnings;
use B qw(svref_2object SVf_IOK);

use v5.10;

my $b = svref_2object(\(${"_<../21564b.pl"}[4]));
unless ($b->FLAGS & SVf_IOK) {
  die "Fail!";
}
say "Ok";

tony@venus:.../git/perl6$ perl ../bisect.pl --start=v5.34.0 -- ./perl -Ilib -I../21564 -d:D21564 ../21564b.pl
...
bad - non-zero exit from ./perl -Ilib -I../21564 -d:D21564 ../21564b.pl
0cdbe2162863542f45a5faa22e46c1aa76c029cb is the first bad commit
commit 0cdbe2162863542f45a5faa22e46c1aa76c029cb
Author: Tony Cook <tony@develop-help.com>
Date:   Wed Oct 20 15:36:44 2021 +1100

    remove cop addressed from saved lines when the cop is freed
    
    This could cause a bad read and write when the debugger tried to
    set a breakpoint on the line.
    
    Fixed #19198

 lib/perl5db.t | 43 +++++++++++++++++++++++++++++++++++++++++++
 op.c          | 14 ++++++++++++++
 2 files changed, 57 insertions(+)
bisect found first bad commitThat took 1013 seconds.

I don't remember why I turned off IOK.

Edit: add (trivial) Devel::D21564 source

tonycoz added a commit to tonycoz/perl5 that referenced this issue Oct 17, 2023
These are meant to be IOK even when non-breakable, and I broke that
when fixing Perl#19198.

Fixes Perl#21564
tonycoz added a commit to tonycoz/perl5 that referenced this issue Oct 18, 2023
These are meant to be IOK even when non-breakable, and I broke that
when fixing Perl#19198.

Fixes Perl#21564
jkeenan added a commit to jkeenan/perl5 that referenced this issue Oct 19, 2023
tonycoz added a commit that referenced this issue Oct 19, 2023
These are meant to be IOK even when non-breakable, and I broke that
when fixing #19198.

Fixes #21564
jkeenan added a commit to jkeenan/perl5 that referenced this issue Oct 20, 2023
jkeenan added a commit to jkeenan/perl5 that referenced this issue Oct 20, 2023
jkeenan added a commit that referenced this issue Oct 21, 2023
Based on Tony Cook's example in
#21564.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants