Run Perl Debugger Twice
I have a case where I call the Perl debugger twice. For example progA.pl
:
use warnings;
use strict;
system("perl -d progB.pl");
and progB.pl
:
use warnings;
use strict;
$DB::single=1;
print "Hello\n";
Then I run progA.pl
like:
$ perl -d progA.pl
This is not good. On my system (Ubuntu 14.04 and Perl version 5.18) I am getting some errors from the debugger. For example:
### Forked, but not sure how to create a new TTY. ######### Since two debuggers are fighting over the same TTY, input is hardget confused.
I know how to switch output to another window in xterms, OS / 2 and Mac OS X Terminal.app. For a manual switch, enter the name of the created TTY in $ DB :: fork_TTY, or define the DB :: get_fork_TTY () function returns this.
On UNIX-like systems, you can get the TTY name for a given window by typing tty and disabling the shell from the TTY in sleep mode 1,000,000.
It also tries to open a new terminal window with a title Dauther Perl debugger
, but the new terminal only shows an error sh: 1: 3: Bad file descriptor
.
How can these problems be avoided? I just want the debugger to work fine.
Use 'do' instead of 'system'
perl -d progA.pl
# will stop after your $DB::single = 1
# line in progB.pl
perldoc -f do
do EXPR Uses the value of EXPR as a filename and executes the contents
of the file as a Perl script.
do 'stat.pl';
is just like
eval `cat stat.pl`;
I'm not sure if this is what you are looking for because I do not understand the big picture of what you are trying to do.
But if you are using another debugger from the start, like Devel :: Trepan , then everything might work:
$ trepan.pl progA.pl
-- main::(progA.pl:4 @0x21282c8)
system("perl -d progB.pl");
(trepanpl): s
-- main::(progB.pl:3 @0x7042a8)
$DB::single=1;
(trepanpl): s
-- main::(progB.pl:4 @0x878be8)
print "Hello\n";
(trepanpl): s
Hello
Debugged program terminated. Use 'q' to quit or 'R' to restart.
(trepanpl): quit
trepan.pl: That all, folks...
Debugged program terminated. Use 'q' to quit or 'R' to restart
(trepanpl) quit
trepan.pl: That all, folks...
Request (trepanpl)
after program termination message is slightly odd. But all this means that progB.pl is finished. After that, as I said above, if you had a different Perl statement after your system () command, then the debugger shows that it would rather give a second "ready" message.
Another feature of Devel :: Trepan is that you can do nested debugging within this debugger using the debug command . Here's an example of this:
trepan.pl progA.pl
-- main::(progA.pl:4 @0x10612c8)
system("perl -d progB.pl");
set auto eval is on.
(trepanpl): debug system("perl -d progB.pl")
-- main::((eval 1437)[/usr/local/share/perl/5.18.2/Devel/Trepan/DB/../../../Devel/Trepan/DB/Eval.pm:129] remapped /tmp/HSXy.pl:6 @0x51f13e0)
system("perl -d progB.pl")
((trepanpl)): s
-- main::(progB.pl:3 @0x9382a8)
$DB::single=1;
(trepanpl): s
-- main::(progB.pl:4 @0xaacbe8)
print "Hello\n";
(trepanpl): s
Hello
Debugged program terminated. Use 'q' to quit or 'R' to restart.
(trepanpl): quit
trepan.pl: That all, folks...
$DB::D[0] = 0
Leaving nested debug level 1
-- main::(progA.pl:4 @0x10612c8)
system("perl -d progB.pl");
(trepanpl):