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

Title:
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, details, 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, summary, 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.