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

perl debugger doesn't save starting dir to restart from #13691

Closed
p5pRT opened this issue Mar 26, 2014 · 10 comments
Closed

perl debugger doesn't save starting dir to restart from #13691

p5pRT opened this issue Mar 26, 2014 · 10 comments

Comments

@p5pRT
Copy link

p5pRT commented Mar 26, 2014

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

Searchable as RT121509$

@p5pRT
Copy link
Author

p5pRT commented Mar 26, 2014

From perl-diddler@tlinx.org

Created by perl-diddler@tlinx.org

Working with a program that uses a sub dir for a cache dir.

So that the path to the root of the cache will be the same as
the path on what I am caching, as soon as the cache module
is opened, it cd's to the cache directory.

Later, I stepped past the point where I wanted to look at
something so hit 'R' to restart. Instead of restoring the
original directory and reading the script, the debugger
simply tried to open the file from the wrong directory.

Seems like it would be best if it saved the starting directory
and 'cd'ed back to it before attempting to reread the original
program (which was in the current directory when the debugger
previously started the program).

Perl Info

Flags:
    category=utilities
    severity=medium

Site configuration information for perl 5.16.3:

Configured by law at Wed Jan 22 12:58:58 PST 2014.

Summary of my perl5 (revision 5 version 16 subversion 3) configuration:
   
  Platform:
    osname=linux, osvers=3.12.0-isht-van, archname=x86_64-linux-thread-multi-ld
    uname='linux ishtar 3.12.0-isht-van #1 smp preempt wed nov 13 16:50:51 pst 2013 x86_64 x86_64 x86_64 gnulinux '
    config_args=''
    hint=previous, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=define, uselongdouble=define
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-g -O2',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_REENTRANT -D_GNU_SOURCE -fno-strict-aliasing -pipe -fstack-protector -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    ccversion='', gccversion='4.8.1 20130909 [gcc-4_8-branch revision 202388]', 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='long double', nvsize=16, Off_t='off_t', lseeksize=8
    alignbytes=16, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags ='-g -fstack-protector -fPIC'
    libpth=/usr/lib64 /lib64
    libs=-lnsl -lndbm -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc -lgdbm_compat
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/libc-2.18.so, so=so, useshrplib=true, libperl=libperl-5.16.3.so
    gnulibc_version='2.18'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/home/perl/perl-5.16.3/lib/x86_64-linux-thread-multi-ld/CORE'
    cccdlflags='-fPIC', lddlflags='-shared -g -O2 -fstack-protector -fPIC'

Locally applied patches:
    


@INC for perl 5.16.3:
    /home/law/bin/lib
    /home/perl/perl-5.16.3/lib/site/x86_64-linux-thread-multi-ld
    /home/perl/perl-5.16.3/lib/site
    /home/perl/perl-5.16.3/lib/x86_64-linux-thread-multi-ld
    /home/perl/perl-5.16.3/lib
    .


Environment for perl 5.16.3:
    HOME=/home/law
    LANG=en_US.utf8
    LANGUAGE (unset)
    LC_COLLATE=C
    LC_CTYPE=en_US.utf8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/law/bin/lib:/sbin:/home/law/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/games:/opt/kde3/bin:/usr/lib/mit/bin:/usr/lib/mit/sbin:.:/usr/lib/qt3/bin:/opt/dell/srvadmin/bin:/usr/sbin:/etc/local/func_lib:/home/law/lib
    PERL5OPT=-Mutf8 -CSA -I/home/law/bin/lib
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Mar 27, 2014

From @rjbs

* Linda Walsh (via RT) <perlbug-followup@​perl.org> [2014-03-26T04​:57​:57]

Seems like it would be best if it saved the starting directory
and 'cd'ed back to it before attempting to reread the original
program (which was in the current directory when the debugger
previously started the program).

Seems reasonable to me, at least at first blush.

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Mar 27, 2014

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

@p5pRT
Copy link
Author

p5pRT commented Mar 27, 2014

From @shlomif

Hi all,

On Thu Mar 27 06​:15​:04 2014, perl.p5p@​rjbs.manxome.org wrote​:

* Linda Walsh (via RT) <perlbug-followup@​perl.org> [2014-03-26T04​:57​:57]

Seems like it would be best if it saved the starting directory
and 'cd'ed back to it before attempting to reread the original
program (which was in the current directory when the debugger
previously started the program).

Seems reasonable to me, at least at first blush.

since it seemed reasonable to me as well, I wrote a patch to fix it, and it's attached to this message and can also be found in this GitHub branch​:

https://github.com/shlomif/perl/tree/rt_121509_bug_fix

The patch adds a regression test (which succeeds after applying it) and all existing test pass (at least without threads) on my Mageia Linux 5 (Cauldron) x86-64 system.

Thanks to Linda for reporting the problem, and to Ricardo (RJBS) for approving of a fix. Please review and apply the patch when you can.

Regards,

-- Shlomi Fish

@p5pRT
Copy link
Author

p5pRT commented Mar 27, 2014

From @shlomif

0001-Fix-RT-121509-perl-d-handling-chdir.patch
From f79d705adacc51a29e573092924d11b98c883ef0 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Thu, 27 Mar 2014 19:07:50 +0200
Subject: [PATCH] Fix RT #121509 : perl -d handling chdir().

See: https://rt.perl.org/Ticket/Display.html?id=121509

    [perl #121509] perl debugger doesn't save starting dir to restart from

Thanks to Linda Walsh for reporting the problem and RJBS for commenting
for initial approval. Fix and a regression test by Shlomi Fish.
---
 MANIFEST                                    |  1 +
 lib/perl5db.pl                              | 14 +++++++-
 lib/perl5db.t                               | 51 ++++++++++++++++++++++++++++-
 lib/perl5db/t/rt-121509-restart-after-chdir | 33 +++++++++++++++++++
 4 files changed, 97 insertions(+), 2 deletions(-)
 create mode 100644 lib/perl5db/t/rt-121509-restart-after-chdir

diff --git a/MANIFEST b/MANIFEST
index 70565d5..ef0bb95 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -4244,6 +4244,7 @@ lib/perl5db/t/lvalue-bug	Tests for the Perl debugger
 lib/perl5db/t/MyModule.pm	Tests for the Perl debugger
 lib/perl5db/t/proxy-constants	Tests for the Perl debugger
 lib/perl5db/t/rt-104168		Tests for the Perl debugger
+lib/perl5db/t/rt-121509-restart-after-chdir		Tests for the Perl debugger
 lib/perl5db/t/rt-61222		Tests for the Perl debugger
 lib/perl5db/t/rt-66110		Tests for the Perl debugger
 lib/perl5db/t/source-cmd-test-no-q.perldb		Tests for the Perl debugger
diff --git a/lib/perl5db.pl b/lib/perl5db.pl
index c1d6752..b0d517d 100644
--- a/lib/perl5db.pl
+++ b/lib/perl5db.pl
@@ -512,18 +512,23 @@ package DB;
 
 use strict;
 
+use Cwd ();
+
+my $_initial_cwd;
+
 BEGIN {eval 'use IO::Handle'}; # Needed for flush only? breaks under miniperl
 
 BEGIN {
     require feature;
     $^V =~ /^v(\d+\.\d+)/;
     feature->import(":$1");
+    $_initial_cwd = Cwd::getcwd();
 }
 
 # Debugger for Perl 5.00x; perl5db.pl patch level:
 use vars qw($VERSION $header);
 
-$VERSION = '1.43';
+$VERSION = '1.44';
 
 $header = "perl5db.pl version $VERSION";
 
@@ -2257,6 +2262,13 @@ sub _DB__handle_restart_and_rerun_commands {
     # R - restart execution.
     # rerun - controlled restart execution.
     if ($cmd_cmd eq 'rerun' or $cmd_params eq '') {
+
+        # Change directory to the initial current working directory on
+        # the script startup, so if the debugged program changed the
+        # directory, then we will still be able to find the path to the
+        # the program. (perl 5 RT #121509 ).
+        chdir ($_initial_cwd);
+
         my @args = ($cmd_cmd eq 'R' ? restart() : rerun($cmd_params));
 
         # Close all non-system fds for a clean restart.  A more
diff --git a/lib/perl5db.t b/lib/perl5db.t
index 3af7f64..bd5615a 100644
--- a/lib/perl5db.t
+++ b/lib/perl5db.t
@@ -29,7 +29,7 @@ BEGIN {
     $ENV{PERL_RL} = 'Perl'; # Suppress system Term::ReadLine::Gnu
 }
 
-plan(119);
+plan(120);
 
 my $rc_filename = '.perldb';
 
@@ -2697,6 +2697,55 @@ DebugWrap->new({
     );
 }
 
+# perl 5 RT #121509 regression bug.
+# “perl debugger doesn't save starting dir to restart from”
+# Thanks to Linda Walsh for reporting it.
+{
+    use File::Temp qw/tempdir/;
+
+    my $temp_dir = tempdir( CLEANUP => 1 );
+
+    local $ENV{__PERLDB_TEMP_DIR} = $temp_dir;
+    my $wrapper = DebugWrap->new(
+        {
+            cmds =>
+            [
+                # This is to avoid getting the "Debugger program terminated"
+                # junk that interferes with the normal output.
+                'b _after_chdir',
+                'c',
+                'R',
+                'b _finale',
+                'c',
+                'n',
+                'n',
+                'n',
+                'n',
+                'n',
+                'n',
+                'n',
+                'n',
+                'n',
+                'n',
+                'n',
+                'n',
+                'q',
+            ],
+            prog => '../lib/perl5db/t/rt-121509-restart-after-chdir',
+        }
+    );
+
+    $wrapper->output_like(
+        qr/
+In\ _finale\ No\ 1
+    .*?
+In\ _finale\ No\ 2
+    .*?
+In\ _finale\ No\ 3
+        /msx,
+        "Test that the debugger chdirs to the initial directory after a restart.",
+    );
+}
 # Test the perldoc command
 # We don't actually run the program, but we need to provide one to the wrapper.
 SKIP:
diff --git a/lib/perl5db/t/rt-121509-restart-after-chdir b/lib/perl5db/t/rt-121509-restart-after-chdir
new file mode 100644
index 0000000..f8250d7
--- /dev/null
+++ b/lib/perl5db/t/rt-121509-restart-after-chdir
@@ -0,0 +1,33 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use IO::Handle;
+
+STDOUT->autoflush(1);
+
+my $tmpdir = $ENV{__PERLDB_TEMP_DIR};
+
+sub _do_chdir
+{
+    chdir($tmpdir);
+}
+
+sub _after_chdir
+{
+    print "_after_chdir\n";
+}
+
+sub _finale
+{
+    my $i = 1;
+    while (1)
+    {
+        print "In _finale No " . ($i++) . "\n";
+    }
+}
+
+_do_chdir();
+_after_chdir();
+_finale();
-- 
1.8.5.4

@p5pRT
Copy link
Author

p5pRT commented Mar 27, 2014

From @shlomif

On Thu Mar 27 10​:21​:04 2014, shlomif wrote​:

Hi all,

On Thu Mar 27 06​:15​:04 2014, perl.p5p@​rjbs.manxome.org wrote​:

* Linda Walsh (via RT) <perlbug-followup@​perl.org> [2014-03-
26T04​:57​:57]

Seems like it would be best if it saved the starting directory
and 'cd'ed back to it before attempting to reread the original
program (which was in the current directory when the debugger
previously started the program).

Seems reasonable to me, at least at first blush.

since it seemed reasonable to me as well, I wrote a patch to fix it,
and it's attached to this message and can also be found in this GitHub
branch​:

https://github.com/shlomif/perl/tree/rt_121509_bug_fix

The patch adds a regression test (which succeeds after applying it)
and all existing test pass (at least without threads) on my Mageia
Linux 5 (Cauldron) x86-64 system.

And now I verified that the tests pass on threaded perls​:

All tests successful.
Files=2396, Tests=710235, 245 wallclock secs (76.02 usr 5.70 sys + 513.34 cusr 19.62 csys = 614.68 CPU)
Result​: PASS

Regards,

-- Shlomi Fish

@p5pRT
Copy link
Author

p5pRT commented Mar 28, 2014

From @rjbs

* "Shlomi Fish via RT" <perlbug-followup@​perl.org> [2014-03-27T13​:21​:05]

Thanks to Linda for reporting the problem, and to Ricardo (RJBS) for
approving of a fix. Please review and apply the patch when you can.

I've marked this for review for 5.21.1.

--
rjbs

@p5pRT
Copy link
Author

p5pRT commented Mar 28, 2014

From @shlomif

On Thu, 27 Mar 2014 21​:55​:49 -0400
Ricardo Signes <perl.p5p@​rjbs.manxome.org> wrote​:

* "Shlomi Fish via RT" <perlbug-followup@​perl.org> [2014-03-27T13​:21​:05]

Thanks to Linda for reporting the problem, and to Ricardo (RJBS) for
approving of a fix. Please review and apply the patch when you can.

I've marked this for review for 5.21.1.

‎Thanks!

Regards,

-- Shlomi Fish

--


Shlomi Fish http​://www.shlomifish.org/
Selina Mandrake - The Slayer (Buffy parody) - http​://shlom.in/selina

What is is. Perceive It. Integrate it. Act on it. Idealize it.
  — Leonard Peikoff

Please reply to list if it's a mailing list post - http​://shlom.in/reply .

@p5pRT
Copy link
Author

p5pRT commented May 28, 2014

From @tonycoz

On Fri Mar 28 00​:27​:43 2014, shlomif@​shlomifish.org wrote​:

On Thu, 27 Mar 2014 21​:55​:49 -0400
Ricardo Signes <perl.p5p@​rjbs.manxome.org> wrote​:

* "Shlomi Fish via RT" <perlbug-followup@​perl.org> [2014-03-27T13​:21​:05]

Thanks to Linda for reporting the problem, and to Ricardo (RJBS) for
approving of a fix. Please review and apply the patch when you can.

I've marked this for review for 5.21.1.

‎Thanks!

Thanks, applied as c59f1e0.

Tony

@p5pRT
Copy link
Author

p5pRT commented May 28, 2014

@tonycoz - Status changed from 'open' 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