Re: Need advanced help with tracking down warnings in eval'd functions

From: Paul Johnson (paul_at_pjcj.net)
Date: 12/09/04


Date: Thu, 9 Dec 2004 15:36:59 +0100
To: Kirk Bauer <kirk@kaybee.org>

On Thu, Dec 09, 2004 at 07:16:02AM -0700, Kirk Bauer wrote:

> Not a beginner's question, but I don't know what other mailing list to
> use. Please direct me accordingly.

Not exactly mailing lists, but comp.lang.perl.moderated and
perlmonks.org might be helpful. (Actually, you can access
comp.lang.perl.moderated by mail.)

> I have a Perl program that defines numerous functions by eval'ing a
> string (read from an external file). I have a comprehensive
> $SIG{__WARN__} handler but for errors in these functions all I get is
> '(eval \d+)' for the file name containing the error.
>
> So, here is my first question -- in my $SIG{__WARN__} handler, if I get
> a warning from a (eval \d+) file, can I figure the name of the function
> that was being executed when the warning was triggered?
>
> But I have a better solution I'm hoping for. The number inside of the
> (eval \d+) description seemed to increment once per eval, and by looking
> at the Perl source code sure enough it seems to be tracked by the
> PL_evalseq variable.
>
> If I can find out what number was assigned to my eval statement, I could
> remember this and relate later warnings as appropriate. Something like
> this:
>
> my $str = "sub Blah {...}";
> my @eval_ids;
> eval $str;
> my $id = ????????
> $eval_ids[$id] = $str;
>
> $SIG{__WARN__} = sub {
> if ($_[0] =~ /\(eval (\d+)\)/) {
> print "Error was in code: $eval_ids[$1]\n";
> }
> };
>
> Any help with this, pointers to other mailing lists, or alternative
> approaches would be greatly appreciated.
>
> FYI the strings being eval'd come from external files that are split
> into section and are eval'd in several pieces.

This all sounds like a lot of work. If the code you want to eval is in
a file somewhere you likely know or can find out the name of the file
and the line number from where it came. I suggest adding

  #line linenumber file

at the beginning of the code you want to eval.

  $ perl -we 'eval "#line 4 qaz\n\$x = \$y + 1"'
  Use of uninitialized value in addition (+) at qaz line 4.

-- 
Paul Johnson - paul@pjcj.net
http://www.pjcj.net


Relevant Pages

  • Need advanced help with tracking down warnings in evald functions
    ... I have a Perl program that defines numerous functions by eval'ing a ... string (read from an external file). ... that was being executed when the warning was triggered? ... Any help with this, pointers to other mailing lists, or alternative ...
    (perl.beginners)
  • Re: Function Warning - Null Reference
    ... Warning 1 Function 'Dec2hms' doesn't return a value on all code paths. ... These include String, Integer, DateTime and Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Function Warning - Null Reference
    ... Warning 1 Function 'Dec2hms' doesn't return a value on all code paths. ... null reference exception could occur at run time when the result is used. ... default value for a String is String.Empty, the default value for an Integer ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Visual Studio 2005 - Warning in the Error List Window
    ... I'm receiving the same warning, and although this has been brought up ... Public sBillingAddress1 As String ... Private Sub LoadAddress() ... Dim Address As New addressEntry ...
    (microsoft.public.dotnet.languages.vb)
  • Re: PROBLEM
    ... tmp.c:1: warning: initialization discards qualifiers from pointer ... The problem with C compilers is that these options are not enabled ... Compiling new C code in a mode that flags possible writes to string ... become illegal if the language were modified to make string literals ...
    (comp.std.c)