Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are some good Perl debugging methods?

People also ask

Does Perl have a debugger?

In Perl, the debugger is not a separate program as it usually is in the typical compiled environment. Instead, the -d flag tells the compiler to insert source information into the parse trees it's about to hand off to the interpreter. That means your code must first compile correctly for the debugger to work on it.

What is Perl debugger and what are several ways to call the debugger explain in detail?

If you invoke Perl with the -d switch, your script runs under the Perl source debugger. This works like an interactive Perl environment, prompting for debugger commands that let you examine source code, set breakpoints, get stack backtraces, change the values of variables, etc.

How do you breakpoint in Perl?

b-command is used to set a breakpoint in a program. Whenever a specified line is about to be executed, this command tells the debugger to halt the program. Note : There can be any number of breakpoints in a program.


Available tools for debugging

There are several tools available in Perl for debugging and similar tasks.


Built-in command line debugger.

perl -d yourcode.pl

Devel::ptkdb

Perl/Tk based graphical debugger by Andrew E. Page.


Regex Coach

This a free tool running both on Linux and Windows written in Lisp. Source code is not available.


Rx: A Regex Debugger for Perl

The Perl Regex debugger and an article about it written by Mark Jason Dominus.


A GUI for the Perl Debugger


There are lots of things out there to help you:

  • Devel::Trace - print every line that executes
  • Carp::REPL - drop into a REPL* when the code throws a warning
  • Devel::ebug - a debugger you can control from Perl code
  • Enbugger - use a debugger at runtime regardless of whether your process was started with debugging

I like Devel::Trace. Basically it gives you an execution dump, showing you the code paths.

On another side, test-driven development is all the rage now, so you could also be interested in profiling tools like Devel::NYTProf for highly advanced testing. See this Tim Bunce's blog post for an interesting overview.


I use ActiveState Komodo for step-by-step debugging.

Eclipse has a step by step debugger for its EPIC plugin.

Personally I prefer the ActiveState version. It just seems more solid and stable, but it does cost (and work is paying for me). If it was my money then I would use Eclipse and EPIC as these are free.