Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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.


  • Use the readahead buffer if you can pregenerate a fixed set of commands.
  • Use the filehandle stack if you can't predetermine the commands you'll use but don't need to read any responses or output from the debugger to generate further commands.
  • Use the socket option if you really want to drive the debugger from a separate program. It may be easier to write a secondary "glue" script between your shell script and the debugger that lets the shell script think it's just reading STDIN and printing to STDOUT, but it's actually being proxied into the debugger's remote port.

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.

In reply to Re: Use Perl Debugger, where input is the output from shell script by pemungkah
in thread Use Perl Debugger, where input is the output from shell script by ban

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others taking refuge in the Monastery: (3)
    As of 2017-02-26 02:48 GMT
    Find Nodes?
      Voting Booth?
      Before electricity was invented, what was the Electric Eel called?

      Results (371 votes). Check out past polls.