Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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, wont 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, wont 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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2024-06-24 22:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.