Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Perl 5.10 features inside the debugger?

Tags:

perl

I am unable to evaluate 'modern Perl' code inside the Perl debugger. It works OK when debugging the code in a file, but not from the prompt.

Minimal example:

# Activating 5-10 features with -E (it works)
$  perl -E 'say "x"'
x
# Calling the debugger with -E
# It works for infile code, but for prompt line code...
$  perl -dEbug    Loading DB routines from perl5db.pl version 1.33
    DB say "x"
    String found where operator expected at (eval 16)[/local-perl/lib/5.12.1/perl5db.pl:638] line 2, near "say "x""
    at (eval 16)[/local-perl/lib/5.12.1/perl5db.pl:638] line 2
        eval '($@, $!, $^E, $,, $/, $\\, $^W) = @saved;package main; $^D = $^D | $DB::db_stop;say "x";

(Note: the same happens with "use feature ':5.10'".)

Am I missing something?

like image 973
Pablo Marin-Garcia Avatar asked Aug 22 '10 01:08

Pablo Marin-Garcia


People also ask

How do you set a breakpoint in Perl debugger?

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.

How do I debug a Perl code in Visual Studio?

From the VS Marketplace plugin page download the extension with the "Download Extension" link on the right hand side. Open a Perl source file, click "Run -> Start Debugging" or hit F5 and observe there is no error as before. Now explore all VSCocde IDE functions working nicely with Perl!


1 Answers

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. Essentially, if you take a look at toke.c in the Perl source, you see the following:

if (PL_perldb) {
    /* Generate a string of Perl code to load the debugger.
     * If PERL5DB is set, it will return the contents of that,
     * otherwise a compile-time require of perl5db.pl.  */

    const char * const pdb = PerlEnv_getenv("PERL5DB");
            ...
}
...
if (PL_minus_E)
    sv_catpvs(PL_linestr,
          "use feature ':5." STRINGIFY(PERL_VERSION) "';");

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"
  x

The closest I've seen to a solution is:

  1. copy perl5db.pl from your PERL5LIB to either somewhere in PERL5LIB or the current directory, with a different name, say myperl5db.pl 2. Edit myperl5db.pl to have use feature ':5.10'; (or just 'state', or just 'say') on the first line. 3. Set the environment variable PERL5DB to "BEGIN { require 'myperl5db.pl' }"

Which I found at PerlMonks.

like image 82
eldarerathis Avatar answered Sep 18 '22 05:09

eldarerathis