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

Wrong context determined for <>/IO::Handle::getline in debug mode #15698

Open
p5pRT opened this issue Nov 4, 2016 · 5 comments
Open

Wrong context determined for <>/IO::Handle::getline in debug mode #15698

p5pRT opened this issue Nov 4, 2016 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented Nov 4, 2016

Migrated from rt.perl.org#130021 (status was 'open')

Searchable as RT130021$

@p5pRT
Copy link
Author

p5pRT commented Nov 4, 2016

From @KES777

Created by @KES777

Sorry, can not replay to https://rt.perl.org/Public/Bug/Display.html?id=92728
When I logged in I am redirected to​: https://rt.perl.org/SelfService/

When I debug my script and it is use IO​::Handle I got errors issued from​:
https://metacpan.org/source/TODDR/IO-1.36_01/lib/IO/Handle.pm#L437

$ mojo generate lite_ap
$ perl -Ilib -d​:DebugHooks​::Terminal myapp.pl get /
...
DB​::sub DB​::state​: l​:1 d​:0 s​:0 t​:0 lib/IO/Handle.pm​:437 --> IO​::Handle​::_create_getline_subs
DB​::sub DB​::state​: l​:1 d​:1 s​:0 t​:0 lib/Devel/DebugHooks.pm​:100 --> Devel​::DebugHooks​::test
DB​::sub DB​::state​: l​:1 d​:1 s​:0 t​:0 lib/Devel/DebugHooks.pm​:135 --> DB​::emit
DB​::sub DB​::state​: l​:1 d​:1 s​:0 t​:0 lib/Devel/DebugHooks.pm​:147 --> DB​::emit
Unquoted string "croak" may clash with future reserved word at (eval 4)[lib/Devel/DebugHooks.pm​:1434] line 2.
String found where operator expected at (eval 4)[lib/Devel/DebugHooks.pm​:1434] line 2, near "croak 'usage​: $io->getline()'"
  (Do you need to predeclare croak?)
Unquoted string "croak" may clash with future reserved word at (eval 4)[lib/Devel/DebugHooks.pm​:1434] line 8.
String found where operator expected at (eval 4)[lib/Devel/DebugHooks.pm​:1434] line 8, near "croak 'usage​: $io->getlines()'"
  (Do you need to predeclare croak?)
Unquoted string "croak" may clash with future reserved word at (eval 4)[lib/Devel/DebugHooks.pm​:1434] line 10.
String found where operator expected at (eval 4)[lib/Devel/DebugHooks.pm​:1434] line 10, near "croak 'Can\'t call $io->getlines in a scalar context, use $io->getline'"
  (Do you need to predeclare croak?)
syntax error at (eval 4)[lib/Devel/DebugHooks.pm​:1434] line 2, near "croak 'usage​: $io->getline()'"
syntax error at (eval 4)[lib/Devel/DebugHooks.pm​:1434] line 8, near "croak 'usage​: $io->getlines()'"
syntax error at (eval 4)[lib/Devel/DebugHooks.pm​:1434] line 10, near "croak 'Can\'t call $io->getlines in a scalar context, use $io->getline'"
Compilation failed in require at lib/Mojo/Base.pm line 13.
BEGIN failed--compilation aborted at lib/Mojo/Base.pm line 13.
Compilation failed in require at lib/Mojolicious/Lite.pm line 2.
BEGIN failed--compilation aborted at lib/Mojolicious/Lite.pm line 2.
Compilation failed in require at myapp.pl line 2.
BEGIN failed--compilation aborted at myapp.pl line 2.

I modify IO​::Handle to look like​:
# Special XS wrapper to make them inherit lexical hints from the caller.
_create_getline_subs( <<'END' ) or die $@​;
sub getline {
  DB​::orig_frames;
  die "DDD>>>". __PACKAGE__;
  @​_ == 1 or croak( 'usage​: $io->getline()'. "@​_" );
  my $this = shift;
  return scalar <$this>;
}

sub getlines {
  @​_ == 1 or croak( 'usage​: $io->getlines()' );
  wantarray or
  croak( 'Can\'t call $io->getlines in a scalar context, use $io->getline' );
  my $this = shift;
  return <$this>;
}
1; # return true for error checking
END

DB​::getline(); # line 460

And I get this error​:
DB lib/Devel/DebugHooks.pm 1439 DB​::orig_frames
IO​::Handle lib/IO/Handle.pm 460 DB​::getline
Mojo​::Base lib/Mojo/Base.pm 13 (eval)
main lib/IO/Handle.pm 0 Mojo​::Base​::BEGIN
main lib/IO/Handle.pm 0 (eval)
Mojolicious​::Lite lib/Mojolicious/Lite.pm 2 (eval)
main lib/IO/Handle.pm 0 Mojolicious​::Lite​::BEGIN
main lib/IO/Handle.pm 0 (eval)
main myapp.pl 2 (eval)
main lib/IO/Handle.pm 0 main​::BEGIN
main lib/IO/Handle.pm 0 (eval)

DDD>>>DB at lib/Devel/DebugHooks.pm line 1439.

I suppose context in debugger mode is not determined right by _create_getline_subs
so getline/getlines are created in DB package instead of IO​::Handle
But I may wrong.

Perl Info

Flags:
    category=library
    severity=low
    module=IO::Handle

Site configuration information for perl 5.24.0:

Configured by kes at Tue Jun  7 00:21:02 EEST 2016.

Summary of my perl5 (revision 5 version 24 subversion 0) configuration:
   
  Platform:
    osname=linux, osvers=3.13.0-37-generic, archname=x86_64-linux
    uname='linux kes-desktop 3.13.0-37-generic #64-ubuntu smp mon sep 22 21:28:38 utc 2014 x86_64 x86_64 x86_64 gnulinux '
    config_args='-de -Dprefix=/home/kes/perl5/perlbrew/perls/perl-5.24.0 -Aeval:scriptdir=/home/kes/perl5/perlbrew/perls/perl-5.24.0/bin'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.8.4', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678, doublekind=3
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16, longdblkind=3
    ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=8, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed /usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib /usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.19.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.19'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector'

Locally applied patches:
    Devel::PatchPerl 1.38


@INC for perl 5.24.0:
    /home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0/x86_64-linux
    /home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/site_perl/5.24.0
    /home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/5.24.0/x86_64-linux
    /home/kes/perl5/perlbrew/perls/perl-5.24.0/lib/5.24.0
    .


Environment for perl 5.24.0:
    HOME=/home/kes
    LANG=ru_UA.UTF-8
    LANGUAGE=en
    LC_MESSAGES=en_US.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/kes/perl5/perlbrew/bin:/home/kes/perl5/perlbrew/perls/perl-5.24.0/bin:/home/kes/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
    PERLBREW=command perlbrew
    PERLBREW_BASHRC_VERSION=0.76
    PERLBREW_HOME=/home/kes/.perlbrew
    PERLBREW_MANPATH=/home/kes/perl5/perlbrew/perls/perl-5.24.0/man
    PERLBREW_PATH=/home/kes/perl5/perlbrew/bin:/home/kes/perl5/perlbrew/perls/perl-5.24.0/bin
    PERLBREW_PERL=perl-5.24.0
    PERLBREW_ROOT=/home/kes/perl5/perlbrew
    PERLBREW_VERSION=0.76
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Nov 4, 2016

From @jkeenan

On Fri, 04 Nov 2016 22​:58​:10 GMT, kes-kes@​yandex.ru wrote​:

Reply-To​: kes-kes@​yandex.ru
Subject​: Wrong context determined for <> in debug mode
From​: kes-kes@​yandex.ru
Cc​: kes-kes@​yandex.ru
Message-Id​: <5.24.0_8991_1478299133@​kes-desktop>
To​: perlbug@​perl.org

This is a bug report for perl from kes-kes@​yandex.ru,
generated with the help of perlbug 1.40 running under perl 5.24.0.

-----------------------------------------------------------------
[Please describe your issue here]

This report does not appear to be appropriate for rt.perl.org.

Sorry, can not replay to
https://rt.perl.org/Public/Bug/Display.html?id=92728
When I logged in I am redirected to​: https://rt.perl.org/SelfService/

That RT was closed more than five years ago. It's not clear why you were trying to reply to it.

When I debug my script and it is use IO​::Handle I got errors issued
from​:
https://metacpan.org/source/TODDR/IO-1.36_01/lib/IO/Handle.pm#L437

$ mojo generate lite_ap
$ perl -Ilib -d​:DebugHooks​::Terminal myapp.pl get /
...
DB​::sub DB​::state​: l​:1 d​:0 s​:0 t​:0 lib/IO/Handle.pm​:437 -->
IO​::Handle​::_create_getline_subs
DB​::sub DB​::state​: l​:1 d​:1 s​:0 t​:0 lib/Devel/DebugHooks.pm​:100 -->
Devel​::DebugHooks​::test
DB​::sub DB​::state​: l​:1 d​:1 s​:0 t​:0 lib/Devel/DebugHooks.pm​:135 -->
DB​::emit
DB​::sub DB​::state​: l​:1 d​:1 s​:0 t​:0 lib/Devel/DebugHooks.pm​:147 -->
DB​::emit
Unquoted string "croak" may clash with future reserved word at (eval
4)[lib/Devel/DebugHooks.pm​:1434] line 2.
String found where operator expected at (eval
4)[lib/Devel/DebugHooks.pm​:1434] line 2, near "croak 'usage​: $io-

getline()'"
(Do you need to predeclare croak?)

In my experience, this error message appears when I fail to say​:

#####
use Carp;
#####

Could you try that first?

Thank you very much.

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented Nov 4, 2016

The RT System itself - Status changed from 'new' to 'open'

@p5pRT
Copy link
Author

p5pRT commented Nov 5, 2016

From @cpansprout

On Fri, 04 Nov 2016 16​:18​:11 -0700, jkeenan wrote​:

In my experience, this error message appears when I fail to say​:

#####
use Carp;
#####

Could you try that first?

The line in question is actually in IO​::Handle, which already does ‘use Carp’. There appears to be some ugly interaction between a sub that has no nextstate ops and the debugger. I wonder whether it affects subs in the CORE​:: namespace too, as they use a similar trick to run code with the caller’s hints.

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented May 15, 2018

From @KES777

I minify testcase. This is occur only when I do call to Time​::HiRes​::gettimeofday

$ cat Devel/DB.pm
package DB;

sub DB {
}

use Time​::HiRes qw/ gettimeofday /;
sub sub {
  print "$DB​::sub is called\n";
  # my $t = [ gettimeofday ]; # <<< Uncomment this to get error

  return &$DB​::sub;
}

1;

$ cat t.pl
use IO​::Handle();
1;

$ perl -d​:DB t.pl
...
strict​::unimport is called
strict​::bits is called
IO​::Handle​::_create_getline_subs is called
String found where operator expected at (eval 4)[Devel/DB.pm​:11] line 2, near "croak 'usage​: $io->getline()'"
  (Do you need to predeclare croak?)
syntax error at (eval 4)[Devel/DB.pm​:11] line 2, near "croak 'usage​: $io->getline()'"
Compilation failed in require at t.pl line 1.
BEGIN failed--compilation aborted at t.pl line 1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants