Now if they just had one that would help monitor Tk apps...
Debugging Tk is a different ball game. Using ptkdb doesn't play well as it introduces widgets and Tk events of its own, which potentially interact with and interfere with the application you are trying to debug.
It is possible to use perl5db on a Tk application, but using a debugger on any event driven system, like Tk or POE will always be tricky, because if your debugger is prompting you, the code cannot be servicing events. You will see your GUI freeze until you resume the application, though you can manually get GUI changes by calling $mainwindow->update from the debugger prompt.
The approach I tend to use is to rely primarily on logging, capturing stdout and stderr in my command window's scrollback. A technique I have used is to add a debug menu under "File" on the main window's menu bar. Here's an excerpt from one of my Tk apps:
# Add menu bar $mainw->configure(-menu => my $menubar = $mainw->Menu); my $mbfile = $menubar->cascade(-label => "~File", -menuitems =>[ [ command => '~Open main log', -command => [\&log_window, "$log_dir/SwapClearLogFile.$da +te", 'Main log file' ]], [ command => '~Exit', -command => [$mainw, 'destroy']], [ command => '~Configure', -command => \&configure_window], [ command => '~Accept all failing components', -command => [\&run_command, 'tidyPidTable.ksh +']], ]); my $mbdebug = $mbfile->cascade( -label => "~Debug", #-title => 'Debug', -menuitems =>[ [ command => "Set all", -command => [\&debug_set_all, 1]], [ command => "Unset all", -command => [\&debug_set_all, 0]], ]); ... my %dbug; my $debug = 0; sub debug { my $tag = shift; unless (exists $dbug{$tag}) { $dbug{$tag} = $debug; $mbdebug->checkbutton( -label => $tag, -variable => \$dbug{$tag}); } $dbug{$tag}; } sub debug_set_all { $debug = shift; $dbug{$_} = $debug for keys %dbug; }
Note that the list of checkbuttons on the debug menu is created dynamically, adding a new checkbutton each time debug() is called with a different parameter. Here's an example of my using the debug function from the same application:
sub system_messages { print "system_messages called\n" if debug('system_messages'); my $fh; open $fh,"showSystemMessages|" or do {print "failed\n" if debu +g('Open pipe fail'); return;}; print "open succeeded\n" if debug('Open pipe succeed'); $mainw->fileevent($fh, 'readable', [\&get_message_counts, $fh] +); print "Return from fileevent\n" if debug('post fileevent'); }
--
Oh Lord, won’t you burn me a Knoppix CD ?
My friends all rate Windows, I must disagree.
Your powers of persuasion will set them all free,
So oh Lord, won’t you burn me a Knoppix CD ?
(Missquoting Janis Joplin)
In reply to Re^2: Using the Perl Debugger (-d)
by rinceWind
in thread Using the Perl Debugger (-d)
by Melly
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |