Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

perl -d myprog autostarts - but only in one specific directory

by ibm1620 (Pilgrim)
on Jan 18, 2022 at 13:49 UTC ( #11140562=perlquestion: print w/replies, xml ) Need Help??

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

When I run the debugger on any program from one particular directory, it does not stop at the first executable line, but runs to completion as if I'd given the 'c' debugger command to continue.

The-Air:~/private/lewis_folder/client$ cat wjma.pl #!/usr/bin/env perl use warnings; use strict; print "HEY\n";
Here's my perl executable:
The-Air:~/private/lewis_folder/client$ which perl /Users/chap/perl5/perlbrew/perls/perl-5.34.0/bin/perl
Demonstrating that the program works:
The-Air:~/private/lewis_folder/client$ ./wjma.pl HEY
Demonstrating running debugger on program, from within the problem directory. Note that it automatically runs to completion.
The-Air:~/private/lewis_folder/client$ perl -d wjma.pl Loading DB routines from perl5db.pl version 1.60 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. main::(wjma.pl:4): print "HEY\n"; DB<1> HEY The-Air:~/private/lewis_folder/client$
Now I run the debugger on the same program while in a different directory. Note that it behaves correctly, stopping on the first statement.
The-Air:~$ /bin/pwd /Users/chap The-Air:~$ perl -d /Users/chap/private/lewis_folder/client/wjma.pl Loading DB routines from perl5db.pl version 1.60 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. main::(/Users/chap/private/lewis_folder/client/wjma.pl:4): 4: print "HEY\n"; DB<1>
Now I run the debugger from the problem directory on the same program, located in a different directory. Note that again it runs to completion rather than stopping:
The-Air:~/private/lewis_folder/client$ perl -d /Users/chap/private/per +l/wjma.pl Loading DB routines from perl5db.pl version 1.60 Editor support available. Enter h or 'h h' for help, or 'man perldebug' for more help. main::(/Users/chap/private/perl/wjma.pl:4): 4: print "HEY\n"; DB<1> HEY The-Air:~/private/lewis_folder/client$
So the problem occurs when I run perl -d from this one directory, which contains:
The-Air:~/private/lewis_folder/client$ ls -al total 56 drwxrwxr-x 8 chap staff 256 Jan 18 08:43 . drwxrwxr-x 7 chap staff 224 Apr 2 2020 .. drwxrwxr-x 3 chap staff 96 Jul 13 2013 con lrwxrwxr-x 1 chap staff 25 Nov 27 2015 dict -> /Users/chap/priv +ate/text/ drwxrwxr-x 4 chap staff 128 Sep 29 2010 dictorg -rwxrwxr-x 1 chap staff 15749 Jan 18 07:29 lewis-client -rw-rw-r-- 1 chap staff 4880 Jan 17 19:56 lewis-client.config -rwxr-xr-x 1 chap staff 61 Jan 18 08:22 wjma.pl The-Air:~/private/lewis_folder/client$
I'm scratching my head here. Any suggestions?

Replies are listed 'Best First'.
Re: perl -d myprog autostarts - but only in one specific directory
by ikegami (Patriarch) on Jan 18, 2022 at 14:09 UTC

    Could the debugger be reading from con? That's the equivalent of /dev/tty on Windows.

    Upd: I can't replicate your result exactly, but the existence of con is definitely a problem. In my test in Linux, it also wrote to con, which it then read, which caused more output, which ...

      I can replicate on Linux. With an empty con dir in current dir, debugger does not break until program exits. If ./con is a file, it writes to it and enters some kind of never-ending loop, as you say.

      strace perl -d a.pl shows this:

      newfstatat(AT_FDCWD, "con", ..., ...)

      Then, if con is found, it is opened with openat(AT_FDCWD, "con", O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) and it is writing to it.

      perl a.pl does not look for con

      The flag AT_FDCWD has the meaning of "relative to current dir", i.e. where you execute from and not where script is located.

      documentation mentions it:

      If there is a TTY, we have to determine who it belongs to before we ca +n proceed. If this is a slave editor or graphical debugger (denoted b +y the first command-line switch being '-emacs'), we shift this off an +d set $rl to 0 (XXX ostensibly to do straight reads). We then determine what the console should be on various systems: Cygwin - We use stdin instead of a separate device. Windows or MSDOS - use con. AmigaOS - use CONSOLE:. VMS - use sys$command. Unix - use /dev/tty.

      Question is: why on Unix con has a role?

      And I find this in source of perl5db.pl:

      elsif ( $^O eq 'dos' or -e "con" or $^O eq 'MSWin32' ) { $console = "con"; }

      -e "con" short-circuits the Unix check further down (if file or dir "con" exists in current dir): if( -e '/dev/tty'). Surely a bug AFAICS.

      bw, bliako

        > Surely a bug AFAICS.

        AFAICF = as far as I can fix :-)

        map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]
      Holy smokes.

      That was it. I deleted con/ and all is well. Incidentally, I don't see any evidence that anything was written into the directory, which just contained a small perl program whose purpose I no longer recall.

      Thank you all.

      I did not know of that CON thingy and your mention let me to investigate it. ++

Re: perl -d myprog autostarts - but only in one specific directory
by Fletch (Bishop) on Jan 18, 2022 at 14:29 UTC

    Was going to mention the possibility of a .perldb file but that's not showing up in your ls output. The other thing is maybe something is setting PERLDB_OPTS to contain "NonStop=1" in the misbehaving case (perhaps you're sourcing an extra startup file in the one shell you're not in the default case).

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      .perldb can be in home, and ENV could have special settings too.

        Right but because things weren't misbehaving in other directories that was suggesting something wonky in a local startup config rather than the global user's. There's also packages (e.g. direnv) which setup environment variables specifically for different directories which could be in play. The con problem found earlier is most likely the culprit but things like this are worth keeping in mind.

        The cake is a lie.
        The cake is a lie.
        The cake is a lie.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11140562]
Approved by 1nickt
Front-paged by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2022-05-24 22:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (84 votes). Check out past polls.

    Notices?