RE: Enable Perl Debugging at Run-Time

From: David Le Blanc (david.leblanc_at_identity-solutions.com.au)
Date: 03/10/04


Date: Wed, 10 Mar 2004 14:01:19 +1100
To: "zentara" <zentara@highstream.net>, <beginners@perl.org>


> -----Original Message-----
> From: zentara [mailto:zentara@highstream.net]
> Sent: Wednesday, 10 March 2004 1:41 AM
> To: beginners@perl.org
> Subject: Re: Enable Perl Debugging at Run-Time
>
> On Tue, 9 Mar 2004 12:07:18 +1100,
> david.leblanc@identity-solutions.com.au (David Le Blanc) wrote:
>
> >
> >Hey all.
>
> >
> >This works, however it would be neater if there was a command in perl
> >where
> >I could enable 'debug' and hence start tracing from a point.
> While not
> >wasting
> >CPU cycles when debugging isn't enabled.
>
> I'm not sure what you are doing, but this post from perlmonks rang a
> bell in my head. Maybe it will give you an idea?
>
> http://perlmonks.org?node_id=323875

That looks good. It's a filter which removes 'debugging' code based on
POD style markup, where debugging is defined as 'code not required for
normal operation'

What I would like to do, is to effect the perl '-d' flag from WITHIN a
script.

Under normal execution, perl does not keep debugging hooks active.
Hooks
such as DB::sub and DB::DB are only active while '-d' is in effect.

This particular script is one of many CGI's, so I don't have much scope
for interactive debugging, however tools like 'Devel::Trace' allow the
code to 'self trace' and dump trace data to STDERR.

I want to customise the trace module so that I can have it available
always
(have my cake) and be able to turn it on and off at run-time depending
on
the existence of [external] trace flags (and eat it too.).

The custom version would log the trace to a file which I could then
browse
with an editor after the fact to identify what is going wrong..

As I said, I achieved this by tweaking the apache config to export an
empty 'PERL5DB' into the environment, and *always* run my script with
'-d'
enabled. (#!/path/to/perl -d -w) I then install a 'DB::DB' handler
when I
want tracing to start, and uninstall it when I want tracing to stop.

sub trace_on() { *DB::DB = \&tracer }
sub trace_off() { delete ${DB::}{DB} }

>
>
> --
> I'm not really a human, but I play one on earth.
> http://zentara.net/japh.html
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>



Relevant Pages

  • Re: Trace
    ... Trace is usually a method to send strings to a debugger ... Debugging Window". ... like a case of just making a big deal about writing a script. ...
    (microsoft.public.scripting.vbscript)
  • Re: Not able to open a file.
    ... Perl Express and I see that it is not running your script at all when you are ... debugging tools, and even renamed it beyond recognition. ... I'm sorry for keeping changing my mind, but I am slowly learning Perl Express. ... Perl menu and click on the Execution Directory item you will see an option ...
    (perl.beginners)
  • Re: How can I debug perl-xs code?
    ... > I am debugging a perl script on Linux OS which has a call to ... > function from perl code then I failed to debug the code. ...
    (perl.beginners)
  • Re: Debug Beginner Question: see the print
    ... I am a beginner in Perl, and of course of debugging even more. ... but I don't see any suggestion, how to see, what my script is printing ...
    (perl.beginners)
  • Re: Debug Beginner Question: see the print
    ... I am a beginner in Perl, and of course of debugging even more. ... but I don't see any suggestion, how to see, what my script is printing ...
    (perl.beginners)