jkeenan1 has asked for the wisdom of the Perl Monks concerning the following question:

I am surprised by certain behavior of the perl debugger. Let's say I have this very simple program in directory ~/learn/perl/p5p:

$ cat abc.pl print "hello world\n"; print "goodbye world\n";
I run it from my home directory:
$ cd $ perl ~/learn/perl/p5p/abc.pl hello world goodbye world
I get the expected results. I now run it thru the perl debugger from my home directory:
$ perl -d ~/learn/perl/p5p/abc.pl Loading DB routines from perl5db.pl version 1.49_04 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. main::(/home/jkeenan/learn/perl/p5p/abc.pl:1): 1: print "hello world\n"; DB<1> c hello world goodbye world 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. DB<1> q
I get the expected results. Now I switch to the directory in which the progam is located and try to run the debugger on the program in that directory:
$ cd learn/perl/p5p $ perl -d abc.pl hello world goodbye world Var=
The debugger fails to stop at the first line of code, runs the entire program, then prints "Var=\n". If I switch to a directory underneath that directory and run the program through the debugger, I get normal results:
$ cd xyz $ perl -d ../abc.pl Loading DB routines from perl5db.pl version 1.49_04 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. main::(../abc.pl:1): print "hello world\n"; DB<1> c hello world goodbye world 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. DB<1> q
I have no setting in PERLDB_OPTS that could explain this:
$ echo $PERLDB_OPTS
Why is the debugger behaving this way when run on a program in the current directory?

Thank you very much.

Jim Keenan

Replies are listed 'Best First'.
Re: perl -d: puzzling behavior when run in program in current directory (.perldb file)
by LanX (Saint) on Jan 01, 2017 at 16:37 UTC
Re: perl -d: puzzling behavior when run in program in current directory
by Linicks (Scribe) on Jan 01, 2017 at 15:51 UTC

    Strange - I just replicated your set-up (and code), and all works fine here? (Slackware 14.1, Summary of my perl5 revision 5 version 18 subversion 1)

    Nick

      When I create a new directory at the same level (~/learn/perl/oldp5p), then copy over all the contents from the original directory to the new one, then run the program from the new directory, the problem appears:

      $ cd ../oldp5p $ cat abc.pl print "hello world\n"; print "goodbye world\n"; $ perl abc.pl hello world goodbye world $ perl -d abc.pl hello world goodbye world Var=
      But when I wipeout the original directory, create a new directory with the same name, then copy over the test program to the new directory and run the debugger, the problem goes away.
      $ cd .. $ rmtree1.pl p5p $ mkdir p5p $ cp -v oldp5p/abc.pl p5p 'oldp5p/abc.pl' -> 'p5p/abc.pl' $ cd p5p $ perl abc.pl hello world goodbye world $ perl -d abc.pl Loading DB routines from perl5db.pl version 1.49_04 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. main::(abc.pl:1): print "hello world\n"; DB<1> q
      So if seems as if something in the original directory is "polluting" the operation of the debugger.

      Jim Keenan
        Aha! Here is the explanation.

        Two days ago I was working on this bug report: RT 130445. In the course of that work, I created this hidden file in the original directory:

        $ ack 'db\.out' . .perldb 1:&parse_options("NonStop=0 TTY=db.out");
        So when I ran the perl debugger over any program from that directory, it was silently processing '.perldb' and setting the 'NonStop' option and redirecting legitimate output to a file in that directory called 'db.out'.

        Once I deleted '.perldb', the output of perl -d abc.pl returned to normal.

        Thank you very much.

        Jim Keenan
        So if seems as if something in the original directory is "polluting" the operation of the debugger.

        Just some ideas: .dot files, hard links, symbolic links, directory permissions, ACLs? Does ls -lAR on the respective directories show anything like that?

      Strange indeed. I can only produce the problem when running the debugger in that specific directory on that platform. When I copy the program to the next higher directory and run the program in that directory, I get normal results:

      $ cd - /home/jkeenan/learn/perl $ cat abc.pl print "hello world\n"; print "goodbye world\n"; $ perl -d abc.pl Loading DB routines from perl5db.pl version 1.49_04 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. main::(abc.pl:1): print "hello world\n"; DB<1> c hello world goodbye world 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. DB<1> q
      And when I run the program through the debugger in a directory with the same name on a different platform (a FreeBSD-11.0 VM on the same box), I get expected results.

      Jim Keenan

        Ummm. I just messed about with directory permissions, and that doesn't seem to do anything (other than what you would expect). Peculiar indeed. Worth persisting to get to the bottom of this

        Nick