moderated >> Disable debugging when called from DB::sub

by James » Thu, 04 Aug 2005 07:29:39 GMT

I'm playing around with an idea for an alternative to DProf. It may
never come to fruition, but I'm getting a bit stuck at a basic point.

I was writing a function DB::sub which looks like this:

package DB;

sub sub {
&$sub;
}

All good so far. But now I want to disable debugging behaviour for all
the functions that I call from this, even if they are in a different
pacakge.

I tried resetting $^P, $^D, no joy.

I thought that using perl_call_sv with G_NODEBUG might work, but this
doesn't seem to either...

I tried similar function

XS(XS_DB_sub) {
...
SV* fn = newSVpv("DB::sub2", 0);
perl_call_sv( fn, GIMME_V | G_NODEBUG );
}
sub sub2 {
# disable debugging somehow
...
# enable debugging
&$sub;
# disable
...
# enable again
}

What happens is that sub2 calls a method, which calls DB::sub, which
calls method ... etc to seg fault.

If anybody has any suggestions I would much appreciate.

Thanks!

James

moderated >> Disable debugging when called from DB::sub

by James » Fri, 05 Aug 2005 19:49:06 GMT



I changed the code to:

package DB;

our $in_debug = 0;
our $depth = 0;

sub sub {
if ( $in_debug ) {
&$sub;
}
else {
$in_debug = 1;
... stuff ..
$in_debug = 0;
$depth++;
&$sub;
$depth--;
$in_debug = 1;
... other stuff ..
$in_debug = 0;
}
}

However, there is some extremely strange behaviour when using scripts
that use Carp. It goes into a never-ending loop...
Trivial scripts that dont use Carp seem to work OK.

Any ideas appreciated.

Cheers
James

Similar Threads

1. trace sub's calls stack to STDERR (for cgi debugging)

Hi,

I am developing a web application framework (based on template toolkit).
Its design is Object Oriented, so a lot of
  $self->foobar();
kind of methods are called.

I'd like to trace these calls to a log file or STDERR (with Carp perhaps?)
so they get to Apache's error log.

All my classes are subclasses of a Object.pm package, so if I can change the
method invocation there to write a debug statement, I am all set.

Any hints ?

TIA

henq





2. Question about sub calling other sub - Perl

3. Legitimate use of calling a sub as &sub

Hi all,

Below is a program to calculate the cubic root of a number by
Newton-Raphson which I knocked up to post to the "cubic root subroutine"
thread below. I noticed that the nr function passed 2 of its 3 arguments
unchanged when it recursed. It occured to me that this might be a
legitimate use of using &nr to recurse, having altered the one argument in
@_ which did change. I was just wondering if this is bad style, because I
changed @_, or if it is acceptable ... any comments anyone?

Rich


#!/usr/bin/perl

use strict;
use warnings;

# Program to find the cubic root of a number using the Newton-Raphson
#   method for approximating the roots of polynomials
#
# Here, f(x) = x**3 - n where n is the number to be rooted
# thus f'(x) = 3x**2
#
# [ f'(x) is the first differential of f(x) wrt x ]

my $findcubicrootof = $ARGV[0] || 27;
my $first_guess = $findcubicrootof / 3;
my $accuracy = 0.00000001;

# Arbitrarily set to what works on my machine. YMMV
die "Accuracy exceeds machine limits\n" if ($accuracy < 1e-15);

print "The cubic root of $findcubicrootof is ",
    nr($first_guess,$findcubicrootof,$accuracy),
    " +/- $accuracy\n";

sub nr {
    my ($guess,$n,$accuracy) = @_;

    # Find delta
    my $delta = fofx($guess,$n) / fdashofx($guess,$n);

    if (abs($delta) < $accuracy) {
        return $guess;
    } else {
        $_[0] = $_[0] - $delta;
        return &nr;
    }
}

# Returns f(x)
sub fofx {
    my ($x,$n) = @_;
    return $x ** 3 - $n;
}

# Returns f'(x)
sub fdashofx {
    my ($x,$n) = @_;
    return 3 * $x ** 2;
}

4. disabling Perl "threads" and "debugging" to allow DBI install - Perl

5. Sub Sub Folder Emails Disappeared

Hi,

I have noticed that tonight, without anything unusual happening, emails have 
disappeared from my Outlook Express 6.

I have a large number of folders in my tree structure, and the affected 
folders are all sub sub folders, rather than top level folders. Yet, some sub 
sub folders on the same level as those where emails have disappeared still 
contain their emails. When emails have been deleted all mails in that folder 
have disappeared. Nothing unusual has happened today, no crashes, new 
software installs, error messages etc - a normal day.

Is there any fix for this, as I'd very much like to get back these mails as 
they're important.

Thanks,

Wrafter

6. Disabled Debug and Start without debugging menues in Visual C++ 2005 Express Edition - Visual Studio

7. [tao-users] GNU AutoConf build created debug symbols when using --disable-debug

8. Checking to see if a call to the DB worked