<?xml version="1.0" encoding="windows-1252"?>
<node id="750510" title="Re: Debugging Perl scripts which use fork()" created="2009-03-13 15:55:11" updated="2009-03-13 15:55:11">
<type id="11">
note</type>
<author id="20250">
pemungkah</author>
<data>
<field name="doctext">
You should be able to define the subs you mention in .perldb (either in the current directory, or in ~/.perldb on Unix-like systems). Quoting the debugger's internal docs (&lt;code&gt;perldoc perl5db.pl&lt;/code&gt;):
&lt;blockquote&gt;
When &lt;code&gt;perl5db.pl&lt;/code&gt; starts, it reads an rcfile (&lt;code&gt;perl5db.ini&lt;/code&gt; for non-interactive sessions, &lt;code&gt;.perldb&lt;/code&gt; for interactive ones) that can set a number of options. In addition, this file may define a subroutine &lt;code&gt;afterinit&lt;/code&gt; that will be executed (in the debugger's context) after the debugger has initialized itself. This can be set in the options, or by setting it in &lt;code&gt;.perldb&lt;/code&gt;.
&lt;/blockquote&gt;
&lt;code&gt;afterinit()&lt;/code&gt; runs a little too late - &lt;i&gt;after&lt;/i&gt; TTY allocation -  so you can't do the TTY mojo there. However, &lt;code&gt;.perldb&lt;/code&gt; gets control right after option processing, and just &lt;i&gt;before&lt;/i&gt; the &lt;code&gt;get_fork_TTY&lt;/code&gt; subroutine is checked for and called, so it's an optimum point to set this up if you don't want to use another module to do it. 
&lt;p&gt;
You can of course &lt;code&gt;use&lt;/code&gt; a module that defines &lt;code&gt;DB::get_fork_TTY&lt;/code&gt; in &lt;code&gt;.perldb&lt;/code&gt; as well, if you prefer to have all your magic in one place, so to speak.
&lt;p&gt;
Another item of note is the &lt;code&gt;$DB::CreateTTY&lt;/code&gt; variable, which controls when the debugger decides to try grabbing a new TTY (this is a bit-field scalar, so if you want more than one option, you sum them):
&lt;ul&gt;&lt;li&gt;1 - on &lt;code&gt;fork()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;2 - when debugger is started inside the debugger&lt;/li&gt;
&lt;li&gt;4 - on startup&lt;/li&gt;&lt;/ul&gt;
This lets you decide when you want (and when you don't want) the debugger to try grabbing another TTY. The default is 3 (on fork, and on nest).
</field>
<field name="root_node">
128283</field>
<field name="parent_node">
128283</field>
</data>
</node>
