Reputation: 23
I have this problem: I need to control the perl-debugger from an external script. By research I found out about various solutions, but I don't understand them. I failed to properly set up the RemotePort option (editing ".perldb"), which was the first I tried, and found no useful information on providing a filehandle from which the debugger would get its input (by somehow setting @cmdfhs) I found both options over here: http://search.cpan.org/~nwclark/perl-5.8.6/lib/perl5db.pl
It would be nice if you could tell me how to provide the filehandle from which the debugger gets its input, or if you know a link where this is explained?
Upvotes: 2
Views: 151
Reputation: 7098
Devel::Trepan is a gdb-like debugger. Although it has remote control, you can also run it at the outset with the option --command
which will "source" (in the gdb-sense) or run a series of debugger commands.
To go into remote control, either start the debugger using the --server
option or inside the debugger use the "server" command once inside the debugger.
See Options for a list of options you can give at the outset.
Upvotes: 0
Reputation: 34308
Here's a simple example setting it up using RemotePort
, which seemed easier to me:
The trick to using RemotePort
is that you have to have someone listening on the remote end BEFORE you launch the script to be debugged.
As soon as you launch your script with -d
Perl will attempt to connect to RemotePort
. So you have to make sure the initial connection succeeds by having someone listening there beforehand.
Here I assume some Linux/Unix variant, which has the netcat
utility installed. We use netcat
to wait for incoming connections in this example, but you can use anything else you wish too which is able to create a service port and shuffle data between that and the current TTY:
In terminal 1:
# Use netcat to listen for incoming connections on port 9999
> nc -l -p 9999
In terminal 2:
# Start perl with -d and request a RemotePort connection
> PERLDB_OPTS=RemotePort=127.0.0.1:9999 perl -d my_script.pl
As soon as you do that in terminal 1 you will see something like this:
Loading DB routines from perl5db.pl version 1.39_10
Editor support available.
Enter h or 'h h' for help, or 'man perldebug' for more help.
main::(my_script.pl:4):
DB<1>
There you go..debug away.
Upvotes: 1