Håkon Hægland
Håkon Hægland

Reputation: 40718

Running Perl debugger twice

I have a case where I invoke 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 does not work very well. On my system (Ubuntu 14.04, and Perl version 5.18), I get some errors from the debugger. For example:

### Forked, but do not know how to create a new TTY. ######### Since two debuggers fight for the same TTY, input is severely

entangled.

I know how to switch the output to a different window in xterms, OS/2 consoles, and Mac OS X Terminal.app only. For a manual switch, put the name of the created TTY in $DB::fork_TTY, or define a function DB::get_fork_TTY() returning this.

On UNIX-like systems one can get the name of a TTY for the given window by typing tty, and disconnect the shell from TTY by sleep 1000000.

It also tries to open a new terminal window, with title Dauther Perl debugger but the new terminal only show the error sh: 1: 3: Bad file descriptor.

How can these problems be avoided? I just want the debugger to work as normal.

Upvotes: 3

Views: 191

Answers (2)

rocky
rocky

Reputation: 7098

I'm not sure if this is what you are looking for, because I don't understand the bigger picture of what you are trying to do.

But if you use a different debugger like Devel::Trepan at the outset, then things may 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's all, folks...
Debugged program terminated.  Use 'q' to quit or 'R' to restart 
(trepanpl) quit
trepan.pl: That's all, folks...

The (trepanpl) prompt after the "program terminated" message is a bit odd. But all it means here is that progB.pl is finished. After quitting that, as I did above, if you had another Perl statement after your system() command, then debugger show that rather give the second "finished" message.

Another feature of Devel::Trepan is that you can do nested debugging from inside that debugger with its debug command. Here is an example of that:

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's all, folks...
$DB::D[0] = 0
Leaving nested debug level 1
-- main::(progA.pl:4 @0x10612c8)
system("perl -d progB.pl");
(trepanpl): 

Upvotes: 1

xxfelixxx
xxfelixxx

Reputation: 6592

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`;

Upvotes: 1

Related Questions