Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^2: debugging eval'd code with source

by sharkey (Scribe)
on Jul 09, 2008 at 18:01 UTC ( [id://696512]=note: print w/replies, xml ) Need Help??


in reply to Re: debugging eval'd code with source
in thread debugging eval'd code with source (SOLVED)

Thanks for your answer. Here's a more concrete example to show the problem.
$ cat -n tt 1 #!/usr/bin/perl 2 3 my $perl = <<'EOF'; 4 sub { 5 my $x = 123; 6 $x += shift; 7 print "x is $x\n" 8 } 9 EOF 10 11 my $cf = eval $perl; 12 13 $cf->(4); $ perl -d tt Loading DB routines from perl5db.pl version 1.28 Editor support available. Enter h or `h h' for help, or `man perldebug' for more help. main::(tt:3): my $perl = <<'EOF'; main::(tt:4): sub { main::(tt:5): my $x = 123; main::(tt:6): $x += shift; main::(tt:7): print "x is $x\n" DB<8> s main::(tt:11): my $cf = eval $perl; DB<8> s main::((eval 20)[tt:11]:7): ;
Now we are inside the eval, and we can see the code...
DB<8> p $#{"_<(eval 20)[tt:11]"} 7 DB<9> l (eval 20) 1 sub { 2: my $x = 123; 3: $x += shift; 4: print "x is $x\n" 5 } 6 7==> ;
But as soon as we step out of the eval, the code is gone...
DB<10> s main::(tt:13): $cf->(4); DB<10> p $#{"_<(eval 20)[tt:11]"} -1
And yet, there are other evals out there, for the code stays around...
DB<11> p join "\n", map { "$_ $#{$_}" } grep /_<\(/, keys %:: _<(eval 20)[tt:11] -1 _<(eval 22)[/usr/lib/perl5/5.8.8/SelfLoader.pm:38] 6 _<(eval 11)[/usr/lib/perl5/5.8.8/SelfLoader.pm:111] 1 _<(eval 12)[/usr/lib/perl5/5.8.8/SelfLoader.pm:38] 40 _<(eval 5)[/usr/lib/perl5/5.8.8/Term/ReadLine.pm:306] -1 _<(eval 21)[/usr/lib/perl5/5.8.8/SelfLoader.pm:38] 10 _<(eval 23)[/usr/lib/perl5/5.8.8/SelfLoader.pm:38] 20 _<(eval 26)[/usr/lib/perl5/5.8.8/perl5db.pl:628] 4 DB<13> f eval 22 Choosing (eval 22)[/usr/lib/perl5/5.8.8/SelfLoader.pm:38] matching `ev +al 22': 1 package readline; sub F_PreviousHistory { 2: &get_line_from_history($rl_HistoryIndex - shift); 3 } 4 5 6 ;
I no longer can get to my eval'd code...
DB<14> f eval 20 Choosing (eval 20)[tt:11] matching `eval 20': DB<15> l
And neither can the debugger...
DB<15> s main::CODE(0x97b7d28)((eval 20)[tt:11]:2): 2: DB<15> main::CODE(0x97b7d28)((eval 20)[tt:11]:3): 3: DB<15> main::CODE(0x97b7d28)((eval 20)[tt:11]:4): 4: DB<15> x is 127 Debugged program terminated. Use q to quit or R to restart, use o inhibit_exit to avoid stopping after program termination, h q, h R or h o to get additional info.
So the question remains, why does my eval'd source code get discarded, while other eval'd source code stays in memory? And what can I do to convince perl to keep my eval'd source code?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://696512]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (9)
As of 2024-04-16 11:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found