5

I have a perl script, that runs fine EXCEPT when I try to run it in the debug mode with the -d switch. When I use the -d switch, I get a compilation error like:

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

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

main::(..\..\bin\testnbestrover1.pl:23):
23:     binmode STDOUT, ":utf8";
Access is denied.
Unknown error
Compilation failed in require at //fbl/NAS/PUB/RapTools/Perl64/lib/Term/ReadLine
/Perl.pm line 65.
 at //fbl/NAS/PUB/RapTools/Perl64/lib/Term/ReadLine/Perl.pm line 65
        Term::ReadLine::Perl::new('Term::ReadLine', 'perldb', 'GLOB(0x382418)',
'GLOB(0x322c30)') called at //fbl/NAS/PUB/RapTools/Perl64/lib/perl5db.pl line 60
68
        DB::setterm called at //fbl/NAS/PUB/RapTools/Perl64/lib/perl5db.pl line
2241
        DB::DB called at ..\..\bin\testnbestrover1.pl line 23
Attempt to reload Term/ReadLine/readline.pm aborted.
Compilation failed in require at //fbl/NAS/PUB/RapTools/Perl64/lib/Term/ReadLine
/Perl.pm line 65.
END failed--call queue aborted at ..\..\bin\testnbestrover1.pl line 65.
 at ..\..\bin\testnbestrover1.pl line 65

This does not happen when I run the script without the -d switch. Any ideas about what may be going wrong here?

Thanks!

EDIT: The same error in Term/ReadLine/Perl.pm line 65 occurs if I comment out the binmode STDOUT, ":utf8"; statement. Upon searching for this specific error on the web, I found someone else had faced the same error when they were redirecting their STDOUT to a file using the ">" operator. Turns out, my perl command was doing the same thing, and when I removed it, the debugger works fine. Seems to be a problem with the specific perl debugger (i.e., per5db.pl version 1.33)?

assassin
  • 19,899
  • 10
  • 30
  • 43
  • @toolic I checked out this post - http://stackoverflow.com/questions/4272939/inverse-heisenbug-unit-test-fails-only-when-debugger-is-attached but it doesn't prove useful.. there is no solution to his question on the thread yet. – assassin Mar 17 '14 at 20:47
  • I'm inclined to think that the problem is to do with binmode STDOUT, ":utf8"; which works fine without the -d switch, but somehow produces and Access Denied error in the debug mode – assassin Mar 17 '14 at 20:49

1 Answers1

4

The stacktrace indicates that the problem comes from Term::ReadLine::Perl which is loaded from the debugger. So no debugging -> no loading of debugger -> no loading of Term::ReadLine::Perl -> no error.

From looking at Term::ReadLine::Perl I guess that the problem is in the line where it tries to load Term::ReadLine::readline which tries to do some stuff with STDIN, STDOUT etc to use it as a terminal. Because this effectively means, that some byte sequences have a special meaning (escape and control codes, like to reset terminal, switch line mode, echo etc) this might infere with your binmode STDOUT settings.

Steffen Ullrich
  • 114,247
  • 10
  • 131
  • 172
  • I commented the binmode line, and the same error occurs. I figured the error goes away if I remove the redirection operator (">") in the command I'm executing... complete details in the EDIT part of my question. – assassin Mar 17 '14 at 21:52
  • 2
    Given the path notation I guess you are on windows. I don't think that windows has something like a tty, e.g. access to the terminal independend of STDOUT/STDIN, so I guess it is not possible to use readline on windows with a redirected STDOUT - thus it fails to load. – Steffen Ullrich Mar 18 '14 at 05:37