原文:
17.3. Is there a debugger specifically for perl/Tk?
Not for the latest version - but the -w switch and use strict; are always helpful with debugging as they provide informative error messages.
You can, of course, run under the standard perl debugger using the -d switch like so: perl -d myscript
But it is recommended that you set you breakpoints carefully since just the calls to ManWindow->new require many steps.
(Older information): Gurusamy Sarathy mailto:gsar@engin.umich.edu had built a PERL5DB file called Tkperldb (which despite the name is for pTk not Tk/perl). One must install an early de-bugger then apply a patch to bring the debugger up to date. The early debugger kit was available from: ftp://ftp.perl.com/pub/perl/ext/TK/
And Gurusamy Sarathy notes that the patch to bring the debugger up to date is available at: You need a post 5.001m perl that has support for debugging closures. Or you can simply apply: http://www-personal.umich.edu/~gsar/ to 5.001m. (5.002beta includes all the fixes in the above patch).
Note that a perl debugger may be invoked within your script with a line like: $ENV{'PERL5DB'} = 'BEGIN { require Tkperldb }';
See man perldebug(1) for more help.
Keep in mind that you are programming in perl after all. The perl debug line mode is available to you through executing the following from your shell: perl -de 0
Whereupon you must enter all the lines of a script including use Tk;. (Fancier file reads & evals are possible - but if you are getting that sophisticated why not create your own custom PERL5DB file?) When using perl -dwe 0 beware of the emacs like line editing under this debugger, and be forewarned that as soon as you type in the MainLoop; statement perl will no longer read from <STDIN>.
Ilya Zakharevich <ilya@math.ohio-state.edu> points out that very recent perldb versions will allow for simultaneous X and STDIN reads. He also points out: Note that you may use sub myLoop { if (defined &DB::DB) { while (1) { # MainWindow->Count Tk::DoOneEvent(0); } } else { MainLoop; } }(and I hope the analogous provision will be in MainLoop in tk-b9 - hi, Nick ;-)
译文:
17.3. 有专门Perl/Tk的调试工具吗?
最近的版本中还没有——但是-w开关和use strict;语句的运用是会对程序的调试很有帮助的,因为他们可以给出详细的出错信息。
当然,你也可以使用标准的perl调试开关-d,方法如下:
perl –d myscript
但是,建议大家小心的设置调试的断点,因为只是语句MainWindow->new就需要很多步骤。
(旧信息):Gurusamy Sarathy作了一个PERL5DB文件叫Tkperldb(尽管这个名字是对pTk而不是Tk/perl的)。要使用这个调试器,用户必须安装一个早期版本的调试器,然后打一个补丁来调用它。老版本的调试器安装包可以从下面的地址得到:
ftp://ftp.perl.com/pub/perl/ext/TK/
并且Gurusamy Sarathy发现要调用这个调试器的补丁的获得方法如下:
你需要一个张贴出来的5.001m版本的perl,因为他支持调试关闭(?)。
或者你可以简单的在5.001m上用http://www-personal.umich.edu/~gsar/。(5.002beta已经包含上面的补丁的修复)。
请注意,你可以在你的脚本中使用如下面的一行代码来调用perl调试器:
$ENV{'PERL5DB'} = 'BEGIN { require Tkperldb }';
需要更多的帮助请参阅perldebug的手册页:perldoc perldebug。
记住,你毕竟是在调试一个perl程序。因此你完全可以使用perl的命令行调试方式,也就是在shell中执行如下命令:
perl –de 0
但是,你必须输入脚本的所有行,包括use Tk;。当你使用perl –dwe 0时,请注意这个调试器是支持如emacs的行编辑的。另外,预先说明一下,一旦你输入了MainLoop;语句,perl就不会再从标准输入STDIN读取内容了。
Ilya Zakharevich指出,最近版本的perldb将允许同时从X和STDIN读取输入。他还指出:
注意,你还可以使用:
sub myLoop {
if (defined &DB::DB) {
while (1) { # MainWindow->Count
Tk::DoOneEvent(0);
}
} else {
MainLoop;
}
}
(并且,我希望Nick会在MainLoop中也提供相应的功能。)