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

Is it possible to invoke the perl debugger at runtime? I'm currently working on Devel::Trace, writing a test suite for all the nifty changes.

But 'make test' runs - of course - perl without the -d switch. Stating use Devel::Trace @args doesn't initialize the debugger. My workaround is...

use strict; use Test::More tests => 1; my $result = join '', `perl -It -Iblib/lib -d:Trace t/foo.pl 2>&1`; my $expected = join '',<DATA>; is($result,$expected); __DATA__ * expected output here *

but that is inelegant as feck.

Does anybody of you monks know how to instantiate the debugger at or after compile time? Is it even possible?

Or, as another possibility, shoehorn the -d flag into the test suite?

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re: Invoke the perl debugger at runtime
by hippo (Archbishop) on Oct 01, 2024 at 14:55 UTC
    But 'make test' runs - of course - perl without the -d switch.

    So, don't run make test but rather make testdb.


    🦛

      Thank you very much hippo. I dinn' know about that target. Feeling like a kid wrt perl right now - but then I am a kid on other targets as well...

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re: Invoke the perl debugger at runtime
by LanX (Saint) on Oct 01, 2024 at 14:46 UTC
    Enbugger ?

    (Already mentioned in the CB)

    edit

    I've also recently seen a module messing around with $^P flags to access debugger features in the DB:: namespace. But I didn't have time to investigate further.

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

      Yeah, right. But I want Devel::Trace as stand-alone, without dependency on Enbugger.

      Thanks very much for the hint. Will look how Enbugger does things.

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
        IIRC from way back when diotalevi made Enbugger, perl compiles differently when run under the debugger, and Enbugger has to rewrite the optree to replace some normal ops with debug flavors. If you can't get the -d flag set initially, I think Enbugger is the only way.
        --
        A math joke: r = | |csc(θ)|+|sec(θ)| |-| |csc(θ)|-|sec(θ)| |
Re: Invoke the perl debugger at runtime
by etj (Priest) on Oct 02, 2024 at 11:25 UTC
    Please use $^X to get the correct perl, and also use open $fh, '-|', ... rather than executing a string to avoid problems with paths with spaces in.