develooper Front page | perl.perl5.porters | Postings from October 2003

Re: How to tell if Perl has -DDEBUGGING?

Thread Previous | Thread Next
From:
Jim Cromie
Date:
October 25, 2003 10:41
Subject:
Re: How to tell if Perl has -DDEBUGGING?
Message ID:
3F9AB5B3.1080200@divsol.com
Nicholas Clark wrote:

>On Fri, Oct 24, 2003 at 04:15:05PM -0600, Jim Cromie wrote:
>  
>
>>and without $^D set, its difficult to get at hidden/obfuscated code.
>>If they do monkey with $^D on a non-debugging perl, it still wouldnt
>>give them what they want.
>>    
>>
>
>I'm not so sure about that. The perl debugger works on a non-"debugging"
>perl. If you run under the -d switch this code in toke.c is activated:
>
>        /* debugger active and we're not compiling the debugger code,
>         * so store the line into the debugger's array of lines
>         */
>        if (PERLDB_LINE && PL_curstash != PL_debstash) {
>            SV *sv = NEWSV(85,0);
>
>            sv_upgrade(sv, SVt_PVMG);
>            sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr);
>            (void)SvIOK_on(sv);
>            SvIVX(sv) = 0;
>            av_store(CopFILEAV(PL_curcop),(I32)CopLINE(PL_curcop),sv);
>        }
>
>You don't even have to use the perl debugger - you can write your own
>which would dump source back out from the array of source lines.
>
>It can't be this easy. If it is I'm surprised that no-one has commented
>on this before.
>
>Nicholas Clark
>
>.
>
>  
>
I dont understand that snippet - but I do see that
its part of S_skipspace, so its only called from within toke.c,
(~39 times, not counting where 2 macros are expanded)
Im not sure what that means about when/how it can effect the parse.


Im quite sure I dont know enough about all the latent subtleties,
but here are a few interesting observations

# $^D isnt set for -d debugging. (but see below for CAVEAT)

  DB<2> x $^D
0  0
  DB<3> use Config

  DB<4> p $Config{ccflags}
-D_REENTRANT -D_GNU_SOURCE -DTHREADS_HAVE_PIDS -DDEBUGGING 
-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE 
-D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm
  DB<5>
  DB<7> p $]
5.008001

# when set inside debugger, it seems to have no effect
#- I expected it to spew lots of regex debuggery

main::(-e:1):    1
  DB<1> p $]
5.008
  DB<2> x $^D
0  0
  DB<3> use Config

  DB<5> p $Config{ccflags}
-fno-strict-aliasing -I/usr/local/include -D_LARGEFILE_SOURCE 
-D_FILE_OFFSET_BITS=64 -I/usr/include/gdbm
  DB<6> $^D = 'r'

  DB<7> x $^D            
0  0
  DB<8> $a = qr/aliteral/

  DB<8>


# it also doesnt appear to be inspectable from the debugger,
# nor within a module (by inference)

$ perl -Dr -de 1
....
Freeing REx: `"[\\\\']"'
Freeing REx: `"MPW"'
Freeing REx: `","'
Freeing REx: `".Header: ([^,]+),v(\\s+\\S+\\s+\\S+).*$"'
Freeing REx: `"'"'
Freeing REx: `"^-?[\\d.]+$"'
Freeing REx: `"(.*)"'
Guessing start of match, REx `^_<' against `-e'...
String not equal...
Match rejected by optimizer
Omitting $` $& $' support.

EXECUTING...

main::(-e:1):    1
  DB<1> x $^D
0  0
  DB<2>

Theres something here I dont grok..


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About