Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

In the art of Perl Debugger Mastery, I seek enlightenment

by Tommy (Chaplain)
on Feb 09, 2011 at 20:57 UTC ( [id://887286]=perlquestion: print w/replies, xml ) Need Help??

Tommy has asked for the wisdom of the Perl Monks concerning the following question:

Greetings and Salutations!

I'm revving up to become a Perl Debugger ninja -- as in, a master of all things pertaining to the Perl Debugger.

This is a journey, I know. I have strong suspicions that there is much to be gained by mastering the use of this powerful tool. I've programmed _extensively_ in Perl for over a decade now, and my coding practices just have never included the debugger. I was never trained from the beginning in its arts or usefulness. I code and execute under strict, with warnings, and sometimes taint; I've relied "best practices", "documentation", and on warning/fatal exemption messages to guide me when I've had problems...

But now I think it's time to take it to the next level and identify the unseen problems, such as inefficiency and poor logic that aren't exposed by warnings or strict or taint! This also goes hand in hand with my simultaneous interest in code profiling (starting with NYTprof).

And so I seek your wisdom and advice. On my own I've amassed sundry documentation and examples from various sources on the internet-- the fruit of several searches. Now as I embark on this journey to enlightenment I humbly request of you: your own tips, tricks, links, references, and favorite places to go learn about the debugger. Flame away if you must, but I feel after my own due diligence that requesting the collective knowledge of those more versed in the pdb here at PM will produce yet more and possibly greater knowledge than what I've already found.

Am I "going overboard" with this pursuit? Is there really "not that much to know" about advanced debugging (and the next topic of interest- profiling)? I am pretty sure that such is not the case.

Thank you, my Perl bretheren and sisters for your guidance. <heartfelt digression>Thank you also, Perl, for the awesomeness that you've brought to both my career and my life. I love you, man!</digression>

--
Tommy
  • Comment on In the art of Perl Debugger Mastery, I seek enlightenment

Replies are listed 'Best First'.
Re: In the art of Perl Debugger Mastery, I seek enlightenment
by chrestomanci (Priest) on Feb 09, 2011 at 22:17 UTC

    That is an open ended question if ever I saw one. In short, yes it is worth learning the perl debugger.

    One of the very cool features of the perl debugger, that you tend not to find in flashy GUI debuggers found in expensive IDEs for compiled languages is the ability to try out stuff, and evaluate bits of code to see what happens.

    For example, earlier today, a foolish monk posted their homework question (or may been it was a test). Because I was mildly interested, I started the perl debugger by typing perl -demo into a handy shell prompt. (A trick I learnt here, I think from chromatic). This got me a perl shell into which I typed:

    x \{ split /[:;]/, "1:one;2:two;3:three" }

    This confirmed that I had the correct syntax for the solution. Quick and easy. No need to write a script, save it into a file and print the output.

    The ability to evaluate expressions is even more powerful when you are working on a big program. Frequently when I am using DBIx::Class or HTML::TreeBuilder, I will set a breakpoint in the script. (Add the line DB::single=1), and then start evaluating expressions to see where they lead. Once I have something useful, I paste it into my editor and go from there. You can do the same with complex regular expressions.

    There are plenty more tips on how to use the debugger. Many can be found here if you search.

    The other useful tip, is that many of the more senior monks in this monastery often keep lots of useful links on their home nodes, so if you have some free time, head over to Saints in our Book, and start clicking through to home nodes and see what you find. You may strike gold.

      The -demo mnemonic is great! I often run perl -e, but combining the power of -e and -d is *awesooome*.

      This one goes into my treasure trove of perl hackery. HAHA! Wo0T!

      --
      Tommy
Re: In the art of Perl Debugger Mastery, I seek enlightenment
by tilly (Archbishop) on Feb 09, 2011 at 21:56 UTC

      Now on order from Amazon. Thanks!

      --
      Tommy
Re: In the art of Perl Debugger Mastery, I seek enlightenment
by pemungkah (Priest) on Feb 09, 2011 at 23:28 UTC
    There's quite a lot to the debugger beyond just perl5db.pl itself.

    Since the debugger is actually two parts, the hooks into the Perl interpreter and the code that manipulates these hooks, there's an awful lot one can do with the debugger interface beyond just debugging. As you've noted, Devel::NYTProf and Devel::Cover both use these same hooks, but to watch what the program does instead of interfere with the process.

    If you're interested in learning some more about how a program executes (whether tracing it, gathering data about it, or otherwise fiddling about with it as it runs), the debugger hooks provide a useful if not simple interface to do that. Read perldebguts for more details on the hooks themselves; if you want to understand better how the debugger actually does stuff, read the debugger source, which contains extensive comments explaining how things work and how they get done. I recommend actually reading the raw source code rather than running it through perldoc, because the explanations make a lot more sense when you see the explanations and see the code that implements it at the same time.

Re: In the art of Perl Debugger Mastery, I seek enlightenment
by vkon (Curate) on Feb 10, 2011 at 07:19 UTC
    ptkdb cpan module is a well-known perl debugger using perl/Tk GUI.

    Despite being single-file, it is is very powerful and has quite many features. I used it a lot earlier, and found it very useful.

    Recently I've reworked it and

    • made it use Tcl::Tk instead of perl/Tk, so it got modernized look-n-feel and faster
    • removed a lot of really unused code and few unused features
    • made lot of places faster
    I haven't made online my changes, but am really planning to.

    all in all, this module definitely deserves a good look into it - while perl documentation describes its debugging capabilities quite well, ptkdb is a good example of usage of these features.

    regards,
    vkon

      Ooooooooo! There's even an ubuntu package! =D

      $ apt-cache search ptkdb
      libdevel-ptkdb-perl - Perl debugger using a Tk GUI
      
      --
      Tommy
        ptkdb is cool

        sometimes I was unhappy with it, but mostly - in 99.9% cases - it is pretty good :)

Re: In the art of Perl Debugger Mastery, I seek enlightenment
by educated_foo (Vicar) on Feb 10, 2011 at 05:13 UTC
    I'm revving up to become a Perl Debugger ninja -- as in, a master of all things pertaining to the Perl Debugger.
    If you want to get better at debugging Perl, then IMHO print STDERR will help you more than learning perl5db.pl tricks. In over a decade of C and Perl programming, I have found gdb invaluable and perldb rarely worth the trouble. If you want to better understand Perl's debugging hooks, then reading perldebguts is the way to go.
Re: In the art of Perl Debugger Mastery, I seek enlightenment
by TomDLux (Vicar) on Feb 10, 2011 at 17:18 UTC

    I find running the Perl debugger under Emacs is much nicer than running it on its own. Unfortunately, Emacs has a steep learning curve ... the first time I fired up Emacs, and got into the Tutorial, I couldn`t figure out how to get out!

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://887286]
Approved by petdance
Front-paged by Courage
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-04-25 10:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found