Sunday, 22 August 2010

perl debugger and perl >5.10 features

I have been using perl >5.10 for a long time and I use give/when and ~~ a lot. But when I try to debug my programs I get annoyed by the fact that I can not use this features in the debugger command line: Why I can not use these features directly in the debugger?? The debugger handle them very well when they are in the code but not in the command line.

This is annoying because I am also get used to use the debugger as a REPL (yes, I know Devel::REPL but I have not installed it everywhere and I usually have a perl debugger already open in my emacs).

After a lot of time avoiding the issue I asked it in stack overflow:

How to use perl 5.10 features inside the debugger?

and eldarerathis explained to me why

perl -dEbug

is not working:

[ eldarerathis]
I found a reference to the issue here, but it's about a year old. However, the relevant portion of the perl source hasn't changed since, and can be seen here.
Basically, the debugger is loaded before the -E flag is processed, so the features aren't yet enabled when the debugger gets loaded. The gist of this is that you can't currently use -E with the -d command. If you want to use say, switch, or any other feature from the debug prompt, you have to do it like this:
  DB<1> use feature 'say'; say "x"

Also seems that feature is lexically scoped so this does not work:

DB<19> use feature 'say'
DB<20> say 1
Number found where operator expected at (eval 41)[/homes/pmg/pmg-soft/local-perl/lib/5.12.1/] line 2, near "say 1"

but this does:

DB<21> use feature 'say';say 1

This is annoying because when debuggin perl >5.10 scripts, sometimes I need to fix a given/when, or a line with ~~ or copy-paste a line with say and it does not work :-(.

If someone has any idea how to use new Perl code features in the debugger command line please let me know or answer in stack overflow.


Chas. Owens said...

It is cheesy, but you can add whatever you want to line 23 of ebug/Backend/Plugin/ By adding "use 5.012;" I got it to work for me.

my $v = eval "package $context->{package}; use 5.012; $eval";

Pablo Marin-Garcia said...

thanks Chas.