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

Bug [5.11.3] debugger bug in evaluation of user actions ('a' command) #10034

Closed
p5pRT opened this issue Dec 28, 2009 · 26 comments
Closed

Bug [5.11.3] debugger bug in evaluation of user actions ('a' command) #10034

p5pRT opened this issue Dec 28, 2009 · 26 comments

Comments

@p5pRT
Copy link

p5pRT commented Dec 28, 2009

Migrated from rt.perl.org#71678 (status was 'resolved')

Searchable as RT71678$

@p5pRT
Copy link
Author

p5pRT commented Dec 28, 2009

From heiko.eissfeldt@hexco.de

This is a bug report for perl from heiko@​hexco.de,
generated with the help of perlbug 1.39 running under perl 5.11.3.

Hello all,

I am having a little trouble with the action command 'a'
under recent perls.

For example when i use the following little program with the
'a' (action) command in recent perls (up to 5.11.3) under linux,
I am getting an unexpected warning message, after control leaves
the scope of the subroutine. It looks to me as if the
evaluation of the action is done at the wrong place
(as $arg is not in scope anymore after 'return').

Can this be written into a test?
Thanks, Heiko

simple.pl​:

use strict; use warnings;

greet('Hello');

sub greet
{
  my $arg = shift;
  print "$arg\n";
  return;
}

A debugging session with an action that prints $arg, before the subroutine returns, follows. Please note the warning message at
the end.

========================================================================
heiko@​heiko-desktop​:~/perl/my_tests$ perl5.11.3 -wd simple.pl

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

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

sigwarn handler installed!
main​::(simple.pl​:3)​: greet('Hello');
  DB<1> a 9 print " \$arg = $arg\n"
  DB<2> c 9
Hello
main​::greet(simple.pl​:9)​: return;
$arg = Hello
  DB<3> s
Debugged program terminated. Use q to quit or R to restart,
  use o inhibit_exit to avoid stopping after program termination,
  h q, h R or h o to get additional info.
Use of uninitialized value $arg in concatenation (.) or string at (eval 8)[/home/heiko/localperl/lib/5.11.3/perl5db.pl​:638] line 1.
$arg =
  DB<3>


Flags​:
  category=core
  severity=low


Site configuration information for perl 5.11.3​:

Configured by heiko at Tue Dec 22 11​:32​:24 CET 2009.

Summary of my perl5 (revision 5 version 11 subversion 3) configuration​:
 
  Platform​:
  osname=linux, osvers=2.6.31-16-generic, archname=x86_64-linux
  uname='linux heiko-desktop 2.6.31-16-generic #53-ubuntu smp tue dec 8 04​:02​:15 utc 2009 x86_64 gnulinux '
  config_args='-des -Dprefix=/home/heiko/localperl -Dusedevel'
  hint=recommended, useposix=true, d_sigaction=define
  useithreads=undef, usemultiplicity=undef
  useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
  use64bitint=define, use64bitall=define, uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
  optimize='-O2',
  cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
  ccversion='', gccversion='4.4.1', gccosandvers=''
  intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
  d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
  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 /lib /usr/lib /lib64 /usr/lib64
  libs=-lnsl -ldl -lm -lcrypt -lutil -lc
  perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
  libc=/lib/libc-2.10.1.so, so=so, useshrplib=false, libperl=libperl.a
  gnulibc_version='2.10.1'
  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​:
 


@​INC for perl 5.11.3​:
  /home/heiko/localperl/lib/site_perl/5.11.3/x86_64-linux
  /home/heiko/localperl/lib/site_perl/5.11.3
  /home/heiko/localperl/lib/5.11.3/x86_64-linux
  /home/heiko/localperl/lib/5.11.3
  .


Environment for perl 5.11.3​:
  HOME=/home/heiko
  LANG=de_DE.UTF-8
  LANGUAGE=de_DE.UTF-8
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=/usr/local/sbin​:/usr/local/bin​:/usr/sbin​:/usr/bin​:/sbin​:/bin​:/usr/games
  PERL_BADLANG (unset)
  SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Dec 31, 2009

From @obra

Thanks for the report. I've confirmed that this issue also manifests
on 5.10.0.

-Jesse

On Mon 28.Dec'09 at 10​:05​:58 -0800, heiko.eissfeldt@​hexco.de (via RT) wrote​:

# New Ticket Created by heiko.eissfeldt@​hexco.de
# Please include the string​: [perl #71678]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org/rt3/Ticket/Display.html?id=71678 >

This is a bug report for perl from heiko@​hexco.de,
generated with the help of perlbug 1.39 running under perl 5.11.3.

Hello all,

I am having a little trouble with the action command 'a'
under recent perls.

For example when i use the following little program with the
'a' (action) command in recent perls (up to 5.11.3) under linux,
I am getting an unexpected warning message, after control leaves
the scope of the subroutine. It looks to me as if the
evaluation of the action is done at the wrong place
(as $arg is not in scope anymore after 'return').

Can this be written into a test?
Thanks, Heiko

simple.pl​:

use strict; use warnings;

greet('Hello');

sub greet
{
my $arg = shift;
print "$arg\n";
return;
}

A debugging session with an action that prints $arg, before the subroutine returns, follows. Please note the warning message at
the end.

========================================================================
heiko@​heiko-desktop​:~/perl/my_tests$ perl5.11.3 -wd simple.pl

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

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

sigwarn handler installed!
main​::(simple.pl​:3)​: greet('Hello');
DB<1> a 9 print " \$arg = $arg\n"
DB<2> c 9
Hello
main​::greet(simple.pl​:9)​: return;
$arg = Hello
DB<3> s
Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
Use of uninitialized value $arg in concatenation (.) or string at (eval 8)[/home/heiko/localperl/lib/5.11.3/perl5db.pl​:638] line 1.
$arg =
DB<3>

---
Flags​:
category=core
severity=low
---
Site configuration information for perl 5.11.3​:

Configured by heiko at Tue Dec 22 11​:32​:24 CET 2009.

Summary of my perl5 (revision 5 version 11 subversion 3) configuration​:

Platform​:
osname=linux, osvers=2.6.31-16-generic, archname=x86_64-linux
uname='linux heiko-desktop 2.6.31-16-generic #53-ubuntu smp tue dec 8 04​:02​:15 utc 2009 x86_64 gnulinux '
config_args='-des -Dprefix=/home/heiko/localperl -Dusedevel'
hint=recommended, useposix=true, d_sigaction=define
useithreads=undef, usemultiplicity=undef
useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
use64bitint=define, use64bitall=define, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
optimize='-O2',
cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
ccversion='', gccversion='4.4.1', gccosandvers=''
intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
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 /lib /usr/lib /lib64 /usr/lib64
libs=-lnsl -ldl -lm -lcrypt -lutil -lc
perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
libc=/lib/libc-2.10.1.so, so=so, useshrplib=false, libperl=libperl.a
gnulibc_version='2.10.1'
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​:

---
@​INC for perl 5.11.3​:
/home/heiko/localperl/lib/site_perl/5.11.3/x86_64-linux
/home/heiko/localperl/lib/site_perl/5.11.3
/home/heiko/localperl/lib/5.11.3/x86_64-linux
/home/heiko/localperl/lib/5.11.3
.

---
Environment for perl 5.11.3​:
HOME=/home/heiko
LANG=de_DE.UTF-8
LANGUAGE=de_DE.UTF-8
LD_LIBRARY_PATH (unset)
LOGDIR (unset)
PATH=/usr/local/sbin​:/usr/local/bin​:/usr/sbin​:/usr/bin​:/sbin​:/bin​:/usr/games
PERL_BADLANG (unset)
SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Dec 31, 2009

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

@p5pRT
Copy link
Author

p5pRT commented Jan 2, 2010

From heiko@hexco.de

The following one-line patch fixes the issue for me.

After the program has terminated, the action should be set to undef to
avoid an extra eval call later in line 2165.

Greetings, heiko

@p5pRT
Copy link
Author

p5pRT commented Jan 2, 2010

From heiko@hexco.de

71678_perldb.pl.patch
--- perl5db.pl.org	2009-10-20 15:40:18.000000000 +0200
+++ perl5db.pl	2010-01-02 22:29:37.000000000 +0100
@@ -2077,6 +2077,7 @@
 EOP
 
             # Set the DB::eval context appropriately.
+            $action = undef;
             $package     = 'main';
             $usercontext =
                 '($@, $!, $^E, $,, $/, $\, $^W) = @saved;'

@p5pRT
Copy link
Author

p5pRT commented Feb 2, 2010

From heiko@hexco.de

Jesse Vincent schrieb​:

Thanks for the report. I've confirmed that this issue also manifests
on 5.10.0.

-Jesse

The following one-line patch fixes the issue for me.

After the program has terminated, the action should be set to undef to
avoid an extra eval call later in line 2165.

Greetings, heiko

@p5pRT
Copy link
Author

p5pRT commented Feb 2, 2010

From heiko@hexco.de

71678_perldb.pl.patch
--- perl5db.pl.org	2009-10-20 15:40:18.000000000 +0200
+++ perl5db.pl	2010-01-02 22:29:37.000000000 +0100
@@ -2077,6 +2077,7 @@
 EOP
 
             # Set the DB::eval context appropriately.
+            $action = undef;
             $package     = 'main';
             $usercontext =
                 '($@, $!, $^E, $,, $/, $\, $^W) = @saved;'

@p5pRT
Copy link
Author

p5pRT commented Feb 22, 2010

From heiko@hexco.de

Dear porters,

maybe my patch for perl #71678 'debugger bug in evaluation of
useractions ('a' command)' got lost, so I resend it here (this time even
with a change doc and an incremented version number :-).

After the program to be debugged has terminated, any user defined
actions (command 'a') can be cancelled in order to avoid evaluation of
the action in the command loop later (with undefined data).

Or should those actions be preserved for a possible next run?
Then the program state (terminated) would have to be used to suppress
the evaluation of the action. And the fix would be more difficult than
my current patch, of course.

Please check and consider for integration.

I would also like to point you to the patch for perl #71806
'perldb does not setup %dbline with the shebang option -d'
from Father Chrysostomos (sprout@​cpan.org), which fixes the bug for me.
BTW​: Thanks to Father Chrysostomos!

Keep up the good work,
Cheers, Heiko

@p5pRT
Copy link
Author

p5pRT commented Feb 22, 2010

From heiko@hexco.de

71678.patch
--- perl5db.pl.org	2010-02-13 18:15:08.000000000 +0100
+++ perl5db.pl	2010-02-21 21:32:47.000000000 +0100
@@ -511,7 +511,7 @@
 BEGIN {eval 'use IO::Handle'};	# Needed for flush only? breaks under miniperl
 
 # Debugger for Perl 5.00x; perl5db.pl patch level:
-$VERSION = '1.33';
+$VERSION = '1.34';
 
 $header = "perl5db.pl version $VERSION";
 
@@ -952,6 +952,9 @@
 # Changes: 1.32: Jun 03, 2009 Jonathan Leto <jonathan@leto.net>
 #   + Fix bug where a key _< with undefined value was put into the symbol table
 #   +   when the $filename variable is not set
+# Changes: 1.34: Feb 21, 2010 Heiko Eissfeldt <heiko@hexco.de>
+#   + Fix a bug where a user defined action was called after the program
+#   +   terminated.
 ########################################################################
 
 =head1 DEBUGGER INITIALIZATION
@@ -2077,6 +2080,8 @@
 EOP
 
             # Set the DB::eval context appropriately.
+            # At program termination disable any user actions.
+            $action      = undef;
             $package     = 'main';
             $usercontext =
                 '($@, $!, $^E, $,, $/, $\, $^W) = @saved;'

@p5pRT
Copy link
Author

p5pRT commented Feb 28, 2010

From @iabyn

On Sun, Feb 21, 2010 at 09​:51​:18PM +0100, Heiko Eißfeldt wrote​:

maybe my patch for perl #71678 'debugger bug in evaluation of
useractions ('a' command)' got lost, so I resend it here (this time even
with a change doc and an incremented version number :-).

Thanks for this effort. However, we are currently in the last stages of
code freeze for 5.12 release, and only fixes for a handful of show stoppers
are being applied at the moment. Hopefully your patch will be reviewed and
applied after 5.12 is released.

--
The Enterprise is captured by a vastly superior alien intelligence which
does not put them on trial.
  -- Things That Never Happen in "Star Trek" #10

@p5pRT
Copy link
Author

p5pRT commented Sep 26, 2010

From @cpansprout

On Mon Feb 22 13​:32​:09 2010, hexcoder wrote​:

maybe my patch for perl #71678 'debugger bug in evaluation of
useractions ('a' command)' got lost, so I resend it here (this time even
with a change doc and an incremented version number :-).

After the program to be debugged has terminated, any user defined
actions (command 'a') can be cancelled in order to avoid evaluation of
the action in the command loop later (with undefined data).

Or should those actions be preserved for a possible next run?
Then the program state (terminated) would have to be used to suppress
the evaluation of the action. And the fix would be more difficult than
my current patch, of course.

Please check and consider for integration.

I don’ think it has to do with the end of the program. This script
displays the message three times. I’ve never used the debugger before,
so I don’t know whether this is correct. But it seems to me that $action
needs to be cleared elsewhere in the debugger.

BEGIN {
  push @​DB​::typeahead, 'a 11 print "thrext\n"', 'c 8', ('s')x3, 'q';
  $DB​::single = 0;
}
use strict; use warnings;

greet('Hello');

sub greet
{
  my $arg = shift;
  print "$arg\n";
  return;
}
__END__

@p5pRT
Copy link
Author

p5pRT commented Sep 28, 2010

From heiko@hexco.de

Greetings,

I agree now it had nothing todo with the end of the program.
But it should be evaluated _once_ instead of thrice in your test script
because control reaches line 11 only once.
The definition of the 'a' command is according to the debugger book
'Pro Perl Debugging' from Richard Foley and Andy Lester
like this (on page 241)​:
"Create an action to run the supplied perl expression each time the code
on the given line number is about to be executed."

So the evaluation needs to take the line number into account, which it
currently does not.
Once the action is activated, it is performed on each line upto the end
of the scope (at least).

Note​: this is not related to perlbug #71806 'perldb does not setup
%dbline with shebang option -d',
because the behaviour is present also without shebang option -d.

I don’ think it has to do with the end of the program. This script
displays the message three times. I’ve never used the debugger before,
so I don’t know whether this is correct. But it seems to me that $action
needs to be cleared elsewhere in the debugger.

BEGIN {
push @​DB​::typeahead, 'a 11 print "thrext\n"', 'c 8', ('s')x3, 'q';
$DB​::single = 0;
}
use strict; use warnings;

greet('Hello');

sub greet
{
my $arg = shift;
print "$arg\n";
return;
}
__END__

I propose this example (see attachment), which uses a lexical variable
from the inner scope​:
==== quote ========
BEGIN {
  push @​DB​::typeahead, 'a 12 print "${arg}__${arg}\n"', ('s')x4, 'q';
  $DB​::single = 0;
}
use strict; use warnings;

greet('Hello'); # first stop in debugger

sub greet
{
  my $arg = shift;
  $arg = ''; # line 12
  return;
}
===== end quote =======

Thanks, hexcoder

@p5pRT
Copy link
Author

p5pRT commented Sep 28, 2010

From heiko@hexco.de

debugger_a.pl

@p5pRT
Copy link
Author

p5pRT commented Mar 28, 2012

From @jkeenan

On Tue Sep 28 01​:07​:49 2010, hexcoder wrote​:

Greetings,

But it should be evaluated _once_ instead of thrice in your test script
because control reaches line 11 only once.
The definition of the 'a' command is according to the debugger book
'Pro Perl Debugging' from Richard Foley and Andy Lester
like this (on page 241)​:
"Create an action to run the supplied perl expression each time the code
on the given line number is about to be executed."

So the evaluation needs to take the line number into account, which it
currently does not.
Once the action is activated, it is performed on each line upto the end
of the scope (at least).

Note​: this is not related to perlbug #71806 'perldb does not setup
%dbline with shebang option -d',
because the behaviour is present also without shebang option -d.

I don’ think it has to do with the end of the program. This script
displays the message three times. I’ve never used the debugger before,
so I don’t know whether this is correct. But it seems to me that $action
needs to be cleared elsewhere in the debugger.

BEGIN {
push @​DB​::typeahead, 'a 11 print "thrext\n"', 'c 8', ('s')x3, 'q';
$DB​::single = 0;
}
use strict; use warnings;

greet('Hello');

sub greet
{
my $arg = shift;
print "$arg\n";
return;
}
__END__

I propose this example (see attachment), which uses a lexical variable
from the inner scope​:
==== quote ========
BEGIN {
push @​DB​::typeahead, 'a 12 print "${arg}__${arg}\n"', ('s')x4, 'q';
$DB​::single = 0;
}
use strict; use warnings;

greet('Hello'); # first stop in debugger

sub greet
{
my $arg = shift;
$arg = ''; # line 12
return;
}
===== end quote =======

Thanks, hexcoder

Discussion of this issue petered out about a year-and-a-half ago. Is
there anyone familiar with debugger issues who could review this RT?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Jan 28, 2013

From @jkeenan

On Tue Mar 27 18​:24​:27 2012, jkeenan wrote​:

On Tue Sep 28 01​:07​:49 2010, hexcoder wrote​:

Greetings,

But it should be evaluated _once_ instead of thrice in your test script
because control reaches line 11 only once.
The definition of the 'a' command is according to the debugger book
'Pro Perl Debugging' from Richard Foley and Andy Lester
like this (on page 241)​:
"Create an action to run the supplied perl expression each time the code
on the given line number is about to be executed."

So the evaluation needs to take the line number into account, which it
currently does not.
Once the action is activated, it is performed on each line upto the end
of the scope (at least).

Note​: this is not related to perlbug #71806 'perldb does not setup
%dbline with shebang option -d',
because the behaviour is present also without shebang option -d.

I don’ think it has to do with the end of the program. This script
displays the message three times. I’ve never used the debugger before,
so I don’t know whether this is correct. But it seems to me that
$action
needs to be cleared elsewhere in the debugger.

BEGIN {
push @​DB​::typeahead, 'a 11 print "thrext\n"', 'c 8', ('s')x3, 'q';
$DB​::single = 0;
}
use strict; use warnings;

greet('Hello');

sub greet
{
my $arg = shift;
print "$arg\n";
return;
}
__END__

I propose this example (see attachment), which uses a lexical variable
from the inner scope​:
==== quote ========
BEGIN {
push @​DB​::typeahead, 'a 12 print "${arg}__${arg}\n"', ('s')x4, 'q';
$DB​::single = 0;
}
use strict; use warnings;

greet('Hello'); # first stop in debugger

sub greet
{
my $arg = shift;
$arg = ''; # line 12
return;
}
===== end quote =======

Thanks, hexcoder

Discussion of this issue petered out about a year-and-a-half ago. Is
there anyone familiar with debugger issues who could review this RT?

Thank you very much.
Jim Keenan

There have been many discussions about the Perl debugger on P5P during
the past year. Can anyone who participated in those discussions take a
look at this ticket?

Thank you very much.
Jim Keenan

@p5pRT
Copy link
Author

p5pRT commented Jan 29, 2013

From @rocky

Here is my short assessment​: ick.

Here is the longer story, as best as I can tell, of what might be going on.
But I don't consider myself and expert on perl5db.pl

The debugger action command stores the action code string to be eval'd in
@​DB​::dbline. The DB​::DB() subroutine will at some point notice this and set
global $DB​::action if there is a value. (And it will clear it if there is
no value).

But the code in DB​:DB() is long, tortuous and there are a number of
if/elsif branches.

The branch taken when the program has terminated seems to get run before
$DB​::action is reset in another branch. And in some situations where step
is involved, those branches may also avoid resetting $action under various
circumstances that I don't really understand (or care to).

hexcoder's one-line patch is in my opinion a valid in that it deals with
the one situation originally reported. I don't think I agree with the
comment about in the face of a R(estart) the action is somehow disabled,
because the original place this is stored is in $DB​::dbline. In *all* cases
then $DB​::action should be reset.
But I could be wrong here.

But as subsequently noted, there are other possibilities and the one-line
patch doesn't fix of those other possibilities. It is therefore possible
that there is a better fix to handle all of the cases some other way.

In Devel​::Trepan <https://metacpan.org/module/Devel::Trepan>,  I use a
lexical variable to save the values of action. So that might be another
approach. So as best as I can tell, Devel​::Trepan doesn't exhibit any of
the problems noted here.

On Sun, Jan 27, 2013 at 8​:11 PM, James E Keenan via RT <
perlbug-followup@​perl.org> wrote​:

On Tue Mar 27 18​:24​:27 2012, jkeenan wrote​:

On Tue Sep 28 01​:07​:49 2010, hexcoder wrote​:

Greetings,

But it should be evaluated _once_ instead of thrice in your test
script
because control reaches line 11 only once.
The definition of the 'a' command is according to the debugger book
'Pro Perl Debugging' from Richard Foley and Andy Lester
like this (on page 241)​:
"Create an action to run the supplied perl expression each time the
code
on the given line number is about to be executed."

So the evaluation needs to take the line number into account, which it
currently does not.
Once the action is activated, it is performed on each line upto the end
of the scope (at least).

Note​: this is not related to perlbug #71806 'perldb does not setup
%dbline with shebang option -d',
because the behaviour is present also without shebang option -d.

I don’ think it has to do with the end of the program. This script
displays the message three times. I’ve never used the debugger
before,
so I don’t know whether this is correct. But it seems to me that
$action
needs to be cleared elsewhere in the debugger.

BEGIN {
push @​DB​::typeahead, 'a 11 print "thrext\n"', 'c 8', ('s')x3, 'q';
$DB​::single = 0;
}
use strict; use warnings;

greet('Hello');

sub greet
{
my $arg = shift;
print "$arg\n";
return;
}
__END__

I propose this example (see attachment), which uses a lexical variable
from the inner scope​:
==== quote ========
BEGIN {
push @​DB​::typeahead, 'a 12 print "${arg}__${arg}\n"', ('s')x4, 'q';
$DB​::single = 0;
}
use strict; use warnings;

greet('Hello'); # first stop in debugger

sub greet
{
my $arg = shift;
$arg = ''; # line 12
return;
}
===== end quote =======

Thanks, hexcoder

Discussion of this issue petered out about a year-and-a-half ago. Is
there anyone familiar with debugger issues who could review this RT?

Thank you very much.
Jim Keenan

There have been many discussions about the Perl debugger on P5P during
the past year. Can anyone who participated in those discussions take a
look at this ticket?

Thank you very much.
Jim Keenan

---
via perlbug​: queue​: perl5 status​: open
https://rt-archive.perl.org/perl5/Ticket/Display.html?id=71678

@p5pRT
Copy link
Author

p5pRT commented Aug 24, 2013

From @kevindawson

I suspect this is another item fixed by shlom-fish wake :)

$ perl -d ~/workspace/p5p/script/simple.pl

Loading DB routines from perl5db.pl version 1.39_10
Editor support available.

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

main​::(/home/kevin/workspace/p5p/script/simple.pl​:8)​:
8​: greet('Hello');
  DB<1> v 7
4
5​: use strict;
6​: use warnings;
7
8==> greet('Hello');
9
10 sub greet {
11​: my $arg = shift;
12​: print "$arg\n";
13​: return;
  DB<2> a 12 print " \$arg = $arg\n"
  DB<3> v 7
4
5​: use strict;
6​: use warnings;
7
8==> greet('Hello');
9
10 sub greet {
11​: my $arg = shift;
12​:a print "$arg\n";
13​: return;
  DB<4> c 12
main​::greet(/home/kevin/workspace/p5p/script/simple.pl​:12)​:
12​: print "$arg\n";
$arg = Hello
  DB<5> .
main​::greet(/home/kevin/workspace/p5p/script/simple.pl​:12)​:
12​: print "$arg\n";
  DB<5> v 8
5​: use strict;
6​: use warnings;
7
8​: greet('Hello');
9
10 sub greet {
11​: my $arg = shift;
12==>a print "$arg\n";
13​: return;
14 }
  DB<6> c
Hello
Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
$arg =
  DB<6> q
kevin@​billy​:~/src/p5p/perl$

imho this is now fixed

@p5pRT
Copy link
Author

p5pRT commented Aug 24, 2013

From [Unknown Contact. See original ticket]

I suspect this is another item fixed by shlom-fish wake :)

$ perl -d ~/workspace/p5p/script/simple.pl

Loading DB routines from perl5db.pl version 1.39_10
Editor support available.

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

main​::(/home/kevin/workspace/p5p/script/simple.pl​:8)​:
8​: greet('Hello');
  DB<1> v 7
4
5​: use strict;
6​: use warnings;
7
8==> greet('Hello');
9
10 sub greet {
11​: my $arg = shift;
12​: print "$arg\n";
13​: return;
  DB<2> a 12 print " \$arg = $arg\n"
  DB<3> v 7
4
5​: use strict;
6​: use warnings;
7
8==> greet('Hello');
9
10 sub greet {
11​: my $arg = shift;
12​:a print "$arg\n";
13​: return;
  DB<4> c 12
main​::greet(/home/kevin/workspace/p5p/script/simple.pl​:12)​:
12​: print "$arg\n";
$arg = Hello
  DB<5> .
main​::greet(/home/kevin/workspace/p5p/script/simple.pl​:12)​:
12​: print "$arg\n";
  DB<5> v 8
5​: use strict;
6​: use warnings;
7
8​: greet('Hello');
9
10 sub greet {
11​: my $arg = shift;
12==>a print "$arg\n";
13​: return;
14 }
  DB<6> c
Hello
Debugged program terminated. Use q to quit or R to restart,
use o inhibit_exit to avoid stopping after program termination,
h q, h R or h o to get additional info.
$arg =
  DB<6> q
kevin@​billy​:~/src/p5p/perl$

imho this is now fixed

@p5pRT
Copy link
Author

p5pRT commented May 25, 2015

From @shlomif

On Sat Aug 24 15​:20​:38 2013, bowtie wrote​:

I suspect this is another item fixed by shlom-fish wake :)

$ perl -d ~/workspace/p5p/script/simple.pl

This item was not fixed, and the reason you did not exhibit it is because you forgot to add the "-w" flag. With the "-w" flag I'm still getting the erroneous behaviour.

Attached is a git patch against bleadperl to fix the problem (or at least these particular symptoms) with a test added based on this bug. It can also be found here​:

https://github.com/shlomif/perl/tree/rt71678--perl5db--a-statement-after-exit 

Please apply it some time after the release of perl-5.22.0.

Best regards,

-- Shlomi Fish

@p5pRT
Copy link
Author

p5pRT commented May 25, 2015

From @shlomif

0001-Fix-RT-71678-d-a-command-after-exit-with-a-test.patch
From c0d8bec5e0c3ef31bd522c22f380f18480f11afc Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Mon, 25 May 2015 20:56:23 +0300
Subject: [PATCH] Fix RT#71678 (-d a command after exit) with a test.

Credits to Heiko Eissfeldt for the reported bug, the test program and a
proposed fix.
---
 MANIFEST                         |  1 +
 lib/perl5db.pl                   |  5 ++++-
 lib/perl5db.t                    | 27 ++++++++++++++++++++++++++-
 lib/perl5db/t/test-a-statement-2 | 10 ++++++++++
 4 files changed, 41 insertions(+), 2 deletions(-)
 create mode 100644 lib/perl5db/t/test-a-statement-2

diff --git a/MANIFEST b/MANIFEST
index 4278740..df05d3b 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -4228,6 +4228,7 @@ lib/perl5db/t/source-cmd-test.perldb		Tests for the Perl debugger
 lib/perl5db/t/symbol-table-bug	Tests for the Perl debugger
 lib/perl5db/t/taint		Tests for the Perl debugger
 lib/perl5db/t/test-a-statement-1	Tests for the Perl debugger
+lib/perl5db/t/test-a-statement-2	Tests for the Perl debugger
 lib/perl5db/t/test-dieLevel-option-1	Tests for the Perl debugger
 lib/perl5db/t/test-frame-option-1	Tests for the Perl debugger
 lib/perl5db/t/test-l-statement-1	Tests for the Perl debugger
diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index 7e7194e..0d240ae 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -528,7 +528,7 @@ BEGIN {
 # Debugger for Perl 5.00x; perl5db.pl patch level:
 use vars qw($VERSION $header);
 
-$VERSION = '1.49';
+$VERSION = '1.49_01';
 
 $header = "perl5db.pl version $VERSION";
 
@@ -3319,6 +3319,9 @@ B<h q>, B<h R> or B<h o> to get additional info.
 EOP
 
         # Set the DB::eval context appropriately.
+        # At program termination disable any user actions.
+        $DB::action = undef;
+
         $DB::package     = 'main';
         $DB::usercontext = DB::_calc_usercontext($DB::package);
     } ## end elsif ($package eq 'DB::fake')
diff --git a/lib/perl5db.t b/lib/perl5db.t
index e93aee0..98a3686 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -29,7 +29,7 @@ BEGIN {
     $ENV{PERL_RL} = 'Perl'; # Suppress system Term::ReadLine::Gnu
 }
 
-plan(120);
+plan(121);
 
 my $rc_filename = '.perldb';
 
@@ -2774,6 +2774,31 @@ SKIP:
     );
 }
 
+# [perl #71678] debugger bug in evaluation of user actions ('a' command)
+# Still evaluated after the script finishes.
+{
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                q#a 9 print " \$arg = $arg\n"#,
+                'c 9',
+                's',
+                'q',
+            ],
+            prog => '../lib/perl5db/t/test-a-statement-2',
+            switches => [ '-dw', ],
+            stderr => 1,
+        }
+    );
+
+    $wrapper->contents_unlike(qr/
+        Use\ of\ uninitialized\ value\ \$arg\ in\ concatenation\ [\S ]+\ or\ string\ at
+        /msx,
+        'Test that the a command does not emit warnings on program exit.',
+    );
+}
+
 END {
     1 while unlink ($rc_filename, $out_fn);
 }
diff --git a/lib/perl5db/t/test-a-statement-2 b/lib/perl5db/t/test-a-statement-2
new file mode 100644
index 0000000..0a3d304
--- /dev/null
+++ b/lib/perl5db/t/test-a-statement-2
@@ -0,0 +1,10 @@
+use strict; use warnings;
+
+greet('Hello');
+
+sub greet
+{
+    my $arg = shift;
+    print "$arg\n";
+    return;
+}
-- 
1.8.5.6

@p5pRT
Copy link
Author

p5pRT commented May 26, 2015

From @tonycoz

On Mon May 25 11​:12​:13 2015, shlomif wrote​:

On Sat Aug 24 15​:20​:38 2013, bowtie wrote​:

I suspect this is another item fixed by shlom-fish wake :)

$ perl -d ~/workspace/p5p/script/simple.pl

This item was not fixed, and the reason you did not exhibit it is
because you forgot to add the "-w" flag. With the "-w" flag I'm still
getting the erroneous behaviour.

Attached is a git patch against bleadperl to fix the problem (or at
least these particular symptoms) with a test added based on this bug.
It can also be found here​:

https://github.com/shlomif/perl/tree/rt71678--perl5db--a-statement-
after-exit

Please apply it some time after the release of perl-5.22.0.

Added to my post-5.22 branch.

Tony

@p5pRT
Copy link
Author

p5pRT commented Jun 3, 2015

From @tonycoz

On Mon May 25 11​:12​:13 2015, shlomif wrote​:

On Sat Aug 24 15​:20​:38 2013, bowtie wrote​:

I suspect this is another item fixed by shlom-fish wake :)

$ perl -d ~/workspace/p5p/script/simple.pl

This item was not fixed, and the reason you did not exhibit it is
because you forgot to add the "-w" flag. With the "-w" flag I'm still
getting the erroneous behaviour.

Attached is a git patch against bleadperl to fix the problem (or at
least these particular symptoms) with a test added based on this bug.
It can also be found here​:

https://github.com/shlomif/perl/tree/rt71678--perl5db--a-statement-
after-exit

Please apply it some time after the release of perl-5.22.0.

Thanks, applied as 0b1fcdc.

Tony

@p5pRT
Copy link
Author

p5pRT commented Jun 3, 2015

@tonycoz - Status changed from 'open' to 'resolved'

@p5pRT
Copy link
Author

p5pRT commented Jun 4, 2015

@tonycoz - Status changed from 'resolved' to 'pending release'

@p5pRT
Copy link
Author

p5pRT commented May 13, 2016

From @khwilliamson

Thank you for submitting this report. You have helped make Perl better.
 
With the release of Perl 5.24.0 on May 9, 2016, this and 149 other issues have been resolved.

Perl 5.24.0 may be downloaded via https://metacpan.org/release/RJBS/perl-5.24.0

@p5pRT
Copy link
Author

p5pRT commented May 13, 2016

@khwilliamson - Status changed from 'pending release' to 'resolved'

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

1 participant