Improved Syntax Highlighting in the Debugger

You may recall me writing about DB::Color a few years ago. That module let you do this with the debugger:

Perl Debugger with Syntax Highlighting

It has some issues, including the fact that syntax highlighting Perl code is, um, not always perfect, but it does the job. The main drawback, however, is that it runs about as fast as a sloth with a spinal injury. It was so bad that even I stopped using it, and I love the damned thing. Today, I may have fixed that.

Version 0.20 is on github and wending its merry way to the CPAN. The docs now list a suggested workflow which looks sort of like this:

$ cpanm DB::Color
$ echo "use DB::Color sentinel => '.colorize'" >> ~/.perldb
# cd to project you want to colorize and create the sentinel
$ touch .colorize
# colorize the project. This will likely take a long time
$ PERL5LIB=lib:t/tests perldbsyntax

At that point, you're almost good to go. However, as you're rapidly changing files, the debugger will still probably be very slow. Instead, create a watcher to watch your project directories and rehighlight any files which have been created or modified. An example of a watcher program is the examples/colorize program included with this distribution. It looks like this:

Basically, pass it a list of absolute paths, daemonize it, and it colorize files for you on the fly. So far it appears to be much fast than the original version.

Of course, you could provide your own highlighter, if desired.

1 Comment

Some comments and questions.

Why did you decide on Syntax::Highlight::Engine::Kate::Perl instead of Syntax::Highlight::Perl::Improved ?

Having done the same thing myself in Devel::Trepan, I am curious at the merits and disadvantages of each approach. Although Devel::Trepan can be slow, the slowness is not due to its syntax highlighting (via Syntax::Highlight::Perl::Improved).

One tough case to get colorized is inside eval strings. I don't see why DB::Color shouldn't be able to handle this, but following the instructions above in the blog, I've not been able to get perl5db to colorize dynamically.

So consider this case:

$var = '
# This line is not a comment of the above $var assignment
$x = 2;
$y = 3;
$z = 4';
eval $var;
$eval_sub='
sub five() {
   my @args = @_;
   print "ho\n";
   5;
}';
eval $eval_sub;
$y = five();
print "$y\n";

When you eval $eval_sub and when step into five() is the Perl code colorized?

Lastly, I like the caching code. I have long been an advocate of having a debugger report a SHA1 of the file contents so that if you have some other source around (which is more likely to happen when you are debugging remotely) you can know whether that matches the source the debugger is currently working on.

I looked at DB::Color::Highlight::_get_file_and_path() and see a MD5 sum is used instead. That's probably as good as a SHA1. However it also seems to add _get_unique_factors which would defeat the purpose of using the hash for verifying file contents in a file of a different name. So what's the purpose of _get_file_and_path() using _get_unique_factors?

About Ovid

user-pic Freelance Perl/Testing/Agile consultant and trainer. See http://www.allaroundtheworld.fr/ for our services. If you have a problem with Perl, we will solve it for you. And don't forget to buy my book! http://www.amazon.com/Beginning-Perl-Curtis-Poe/dp/1118013840/