in reply to Use Perl Debugger, where input is the output from shell script

Feeding input to the debugger is tricky. There are three supported mechanisms: the typeahead stack, the input file handle stack, and the remote port.

If your commands are predetermined before the debugger starts, you can use the debugger's @typeahead array to queue the lines up; the debugger's readline subroutine will read these lines preferentially over the filehandles in the filehandle stack, so you can simply add the lines you want the debugger to execute here and it will run all of them before prompting the user for further input. If you finish off with a 'q' command, it'll even exit.

If you want to generate commands dynamically, you can use either of the other options. The input filehandle stack @DB::cmdfhs, managed by DB::readline, can be set up prior to the actual execution of the debugger so that a filehandle pointing to your program (a pipe is probably simplest here) is on the top of the stack. The debugger normally reads from the top filehandle until it reaches EOF, then pops it and moves on to the next file handle. Once we run out, it defaults to reading from the terminal. You can, instead, feed the debugger commands and then a 'q'. This is essentially what the debugger's source command does.

You can also use the debugger's remote debugging option (which I admit I do not understand well, and which should be documented better than it is). This allows you to select a port that the debugger will listen on (essentially as the top of the filehandle stack) and interact with the debugger over that port.

I have personally used the typeahead buffer to do setup in a debugger session (load modules, etc.) and can confirm that works fine. The readahead stack may be your simplest option if your shell script can just happily spit out commands without checking back with the debugger. If you need to actually interact with the debugger, you're going to have to use the socket option.


user:LanX's comments point you to the options that can be used to set up the port; I personally recommend using .perldb and either stacking the commands in @DB::typeahead or opening a pipe to your shell script and pushing that onto @DB::cmdfhs.The socket option is significantly more complicated than those two.

If this seems a bit confusing, the only real place this is documented is in the debugger source code. Reading the debugger POD and comments may help you, especially in the case of the socket option. The code concerned with the socket option could use better comments, and if you puzzle it out better, submitting a patch to more precisely describe how it works probably wouldn't be a bad idea.