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

Debugger stops on use statement #15642

Open
p5pRT opened this issue Oct 3, 2016 · 3 comments
Open

Debugger stops on use statement #15642

p5pRT opened this issue Oct 3, 2016 · 3 comments

Comments

@p5pRT
Copy link

@p5pRT p5pRT commented Oct 3, 2016

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

Searchable as RT129794$

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Oct 3, 2016

From @KES777

Created by @KES777

When we enclose this code into braces​:

$ cat t3.pl
#!/usr/bin/env perl

{
  use warnings 'void';
  1;
}

The debugger stops on use warnings 'void' statement​:

main​::(/home/kes/tmp/t3.pl​:4)​: use warnings 'void';
  DB<1> l 1-20
1 #!/usr/bin/env perl
2
3 {
4==> use warnings 'void';
5​: 1;
6 }
7

Perl Info

Flags:
    category=core
    severity=low

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 p5pRT commented Dec 3, 2016

From @jkeenan

On Mon, 03 Oct 2016 07​:41​:49 GMT, kes-kes@​yandex.ru wrote​:

Reply-To​: kes-kes@​yandex.ru
From​: kes-kes@​yandex.ru
To​: perlbug@​perl.org
Subject​: Debugger stops on `use` statement
Message-Id​: <5.24.0_2691_1475479756@​kes-desktop>
Cc​: kes-kes@​yandex.ru

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]

When we enclose this code into braces​:

$ cat t3.pl
#!/usr/bin/env perl

{
use warnings 'void';
1;
}

The debugger stops on use warnings 'void' statement​:

main​::(/home/kes/tmp/t3.pl​:4)​: use warnings 'void';
DB<1> l 1-20
1 #!/usr/bin/env perl
2
3 {
4==> use warnings 'void';
5​: 1;
6 }
7

Here is my understanding of the situation.

In 'perldoc -f use', we find this discussion of how 'use' is used for pragmata such as 'warnings'​:

#####
Because this is a wide-open interface, pragmas (compiler directives) are also implemented this way. Some of the currently implemented pragmas are​:

  use constant;
  use diagnostics;
  use integer;
  use sigtrap qw(SEGV BUS);
  use strict qw(subs vars refs);
  use subs qw(afunc blurfl);
  use warnings qw(all);
  use sort qw(stable _quicksort _mergesort);

Some of these pseudo-modules import semantics into the current block scope (like "strict" or "integer", unlike ordinary modules, which import symbols into the current package (which are effective through the end of the file).
#####

I understand this to mean​: "If I put a 'use MODULE;' statement within a block, it will be effective past the end of the block up to the end of the file. The result will be the same as if I had not put the 'use MODULE;' statement within a block."

I can confirm this understanding with these two programs​:

#####
$ cat 129794-lc-no-block.pl
#!/usr/bin/env perl

use List​::Compare;

my $lc = List​::Compare->new(
  [ qw(abel abel baker camera) ],
  [ qw(baker camera delta delta) ],
);
my @​int = $lc->get_intersection;
print "@​int\n";

__END__
baker camera
#####
$ cat 129794-lc-block.pl
#!/usr/bin/env perl

{
  use List​::Compare;
  1;
}
my $lc = List​::Compare->new(
  [ qw(abel abel baker camera) ],
  [ qw(baker camera delta delta) ],
);
my @​int = $lc->get_intersection;
print "@​int\n";

__END__
baker camera
#####

But I further understand the 'use' documentation to mean​: "Unlike 'use MODULE;', 'use PRAGMA LIST;' only imports semantics into the block in which that 'use' statement appears. Once that block is closed, the pragma's semantics no longer apply.

I can confirm this understanding with the following two programs, which behave different from one another with respect to warnings​:

#####
$ cat 129794-debugger-no-block.pl
#!/usr/bin/env perl

use warnings 'void';
$one, $two = 1, 2;

print "Finished\n";

$ perl 129794-debugger-no-block.pl
Useless use of a constant (2) in void context at 129794-debugger-no-block.pl line 4.
Useless use of a variable in void context at 129794-debugger-no-block.pl line 4.
Finished
#####
$ cat 129794-debugger-block.pl
#!/usr/bin/env perl

{
  use warnings 'void';
  $one, $two = 1, 2;
  1;
}
print "Divider\n";

$one, $two = 1, 2;

print "Finished\n";

$ perl 129794-debugger-block.pl
Useless use of a constant (2) in void context at 129794-debugger-block.pl line 5.
Useless use of a variable in void context at 129794-debugger-block.pl line 5.
Divider
Finished
#####

So in 129794-debugger-block.pl, "use warnings 'void';" is found within a block. If we therefore infer that this statement now qualifies as a run-time executable statement, we satisfy this language from 'perldoc perldebug'​:

#####
The program will halt right before the first run-time executable statement (but see below regarding compile-time statements) and ask you to enter a debugger command.
#####

However, the following language, also from 'perldoc perldebug', muddies the waters​:

#####
Debugging Compile-Time Statements

If you have compile-time executable statements (such as code within BEGIN, UNITCHECK and CHECK blocks or "use" statements), these will not be stopped by debugger, although "require"s and INIT blocks will, and compile-time statements can be traced with the "AutoTrace" option set in "PERLDB_OPTS").
#####

Most of the time, we don't put 'use' statements into blocks, so we tend to think of them as being "compile-time". And we also tend to think of 'perl -d' as doing its "compile-time" work, as it were, "up front". However, given the differences between 'use MODULE' and 'use PRAGMA' with respect to blocks, it makes more sense to think of '{ use PRAGMA; }' as being a runtime executable statement on which the debugger would stop for the user to enter a command.

Comments? Suggestions for documentation improvements?

Thank you very much.

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

@p5pRT
Copy link
Author

@p5pRT p5pRT commented Dec 3, 2016

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

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

Successfully merging a pull request may close this issue.

None yet
1 participant