You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by fr...@ugcs.caltech.edu on 2004/02/19 02:57:17 UTC

[mp1] Apache::Log and goto &NAME

Using Apache/1.3.27 (Unix) mod_gzip/1.3.26.1a mod_perl/1.27, perl
5.8.0.

Hi,

I'm working with some servers which print debugging messages through a
wrapper function that calls Apache::Log::debug, here is a simplified
version:

sub mydebug {
    my $msg = shift;
    Apache->server()->log()->debug($msg);
}

Since Apache::Log::debug inserts the file and line number of its
calling location into each log entry, this means that our log entries
all contain the same file and line number, corresponding to the
location of the Apache::Log::debug call inside 'mydebug'.

I'm trying to figure out how to get Apache::Log to use the correct
file and line numbers, i.e. those of the caller of our wrapper
function, instead. The perlfunc man page suggests that the 'goto
&NAME' form of 'goto' can be used to trick 'caller', but rewriting the
wrapper function in the following manner:

sub mydebug {
    my $msg = shift;
    @_=(Apache->server()->log(), $msg);
    goto &Apache::Log::debug;
}

doesn't change the behavior - it still manages to print the file and
line number of the 'goto' statement, not of the caller of 'mydebug'.
Can anyone help us with this?

Thanks in advance,

Frederik Eaton


Summary of my perl5 (revision 5.0 version 8 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.4.20, archname=i686-linux-64int
    uname='linux yourmom 2.4.20 #4 smp thu feb 27 15:11:19 pst 2003 i686 unknown '
    config_args='-Duse64bitint -de'
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef usemultiplicity=undef
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=define use64bitall=undef uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2',
    cppflags='-fno-strict-aliasing'
    ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.1 2.96-98)', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =''
    libpth=/lib /usr/lib
    libs=-lnsl -ldl -lm -lc -lcrypt -lutil
    perllibs=-lnsl -ldl -lm -lc -lcrypt -lutil
    libc=/lib/libc-2.2.4.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.2.4'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared'


Characteristics of this binary (from libperl): 
  Compile-time options: USE_64_BIT_INT USE_LARGE_FILES
  Built under linux
  Compiled at Feb  5 2003 07:25:46

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp1] Apache::Log and goto &NAME

Posted by Stas Bekman <st...@stason.org>.
frederik@ugcs.caltech.edu wrote:
[...]
> I guess there is still the question of why 'goto &NAME' doesn't work.
> Is this a bug? Is it a known bug?

Log.xs:16 does:

static void ApacheLog(int level, SV *sv, SV *msg)
     ...
     if((lmask == APLOG_DEBUG) && (s->loglevel >= APLOG_DEBUG)) {
	SV *caller;
	bool old_T = tainting; tainting = FALSE;
	caller = perl_eval_pv("[ (caller)[1,2] ]", TRUE);
	tainting = old_T;
	file = SvPV(*av_fetch((AV *)SvRV(caller), 0, FALSE),na);
	line = (int)SvIV(*av_fetch((AV *)SvRV(caller), 1, FALSE));
     }

I've tested and caller called from a plain perl function works just fine. It's 
possible that this is just the behavior of any XS function. It'd try to write 
a simple XS function to test that.

I wonder why Doug had to go throught the pain of using eval_pv on caller to 
get the line numbers in XS. The following patch does it much simpler and seems 
to work even with 5.005_03. A Perl caller of an XS function is the same thing 
as the function itself, unless I miss something. May be it's needed when an XS 
function calls another XS function via eval_sv or something...

Index: src/modules/perl/Log.xs
===================================================================
RCS file: /home/cvs/modperl/src/modules/perl/Log.xs,v
retrieving revision 1.12
diff -u -r1.12 Log.xs
--- src/modules/perl/Log.xs     25 Jan 2001 07:43:05 -0000      1.12
+++ src/modules/perl/Log.xs     20 Feb 2004 02:59:39 -0000
@@ -13,6 +13,12 @@
      GvCV(gp) = perl_get_cv(from, TRUE);
  }

+#ifdef USE_ITHREADS
+#define cop_file PL_curcop->cop_file
+#else
+#define cop_file SvPVX(GvSV(PL_curcop->cop_filegv))
+#endif
+
  static void ApacheLog(int level, SV *sv, SV *msg)
  {
   dTHR;
@@ -36,12 +42,8 @@
      }

      if((lmask == APLOG_DEBUG) && (s->loglevel >= APLOG_DEBUG)) {
-       SV *caller;
-       bool old_T = tainting; tainting = FALSE;
-       caller = perl_eval_pv("[ (caller)[1,2] ]", TRUE);
-       tainting = old_T;
-       file = SvPV(*av_fetch((AV *)SvRV(caller), 0, FALSE),na);
-       line = (int)SvIV(*av_fetch((AV *)SvRV(caller), 1, FALSE));
+        file = cop_file;
+        line = PL_curcop->cop_line;
      }

      if((s->loglevel >= lmask) &&


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp1] Apache::Log and goto &NAME

Posted by fr...@ugcs.caltech.edu.
Stas Bekman <st...@stason.org> writes:

> frederik@ugcs.caltech.edu wrote:
>> Using Apache/1.3.27 (Unix) mod_gzip/1.3.26.1a mod_perl/1.27, perl
>> 5.8.0.
>> Hi,
>> I'm working with some servers which print debugging messages through
>> a
>> wrapper function that calls Apache::Log::debug, here is a simplified
>> version:
>> sub mydebug {
>>     my $msg = shift;
>>     Apache->server()->log()->debug($msg);
>> }
>> Since Apache::Log::debug inserts the file and line number of its
>> calling location into each log entry, this means that our log entries
>> all contain the same file and line number, corresponding to the
>> location of the Apache::Log::debug call inside 'mydebug'.
>> I'm trying to figure out how to get Apache::Log to use the correct
>> file and line numbers, i.e. those of the caller of our wrapper
>> function, instead. The perlfunc man page suggests that the 'goto
>> &NAME' form of 'goto' can be used to trick 'caller', but rewriting the
>> wrapper function in the following manner:
>
> If you don't care about a little slowdown (and you probably don't,
> since it's a debug), you can do:
>
> sub mydebug {
>      my $msg = shift;
>      my($filename, $line) = (caller)[1..2];
> return eval <<EOE;
> #line $line $filename
>      Apache->server()->log()->debug($msg);
> EOE
>
> }
>
> mod_perl 2.0 API allows you to explicitly path __LINE__ and __FILE__
> arguments, to the logging functions.

Thanks for the tip! We'll probably end up using something like this.

I guess there is still the question of why 'goto &NAME' doesn't work.
Is this a bug? Is it a known bug?

Frederik

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html


Re: [mp1] Apache::Log and goto &NAME

Posted by Stas Bekman <st...@stason.org>.
frederik@ugcs.caltech.edu wrote:
> Using Apache/1.3.27 (Unix) mod_gzip/1.3.26.1a mod_perl/1.27, perl
> 5.8.0.
> 
> Hi,
> 
> I'm working with some servers which print debugging messages through a
> wrapper function that calls Apache::Log::debug, here is a simplified
> version:
> 
> sub mydebug {
>     my $msg = shift;
>     Apache->server()->log()->debug($msg);
> }
> 
> Since Apache::Log::debug inserts the file and line number of its
> calling location into each log entry, this means that our log entries
> all contain the same file and line number, corresponding to the
> location of the Apache::Log::debug call inside 'mydebug'.
> 
> I'm trying to figure out how to get Apache::Log to use the correct
> file and line numbers, i.e. those of the caller of our wrapper
> function, instead. The perlfunc man page suggests that the 'goto
> &NAME' form of 'goto' can be used to trick 'caller', but rewriting the
> wrapper function in the following manner:

If you don't care about a little slowdown (and you probably don't, since it's 
a debug), you can do:

sub mydebug {
     my $msg = shift;
     my($filename, $line) = (caller)[1..2];
return eval <<EOE;
#line $line $filename
     Apache->server()->log()->debug($msg);
EOE

}

mod_perl 2.0 API allows you to explicitly path __LINE__ and __FILE__ 
arguments, to the logging functions.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html