From: Ash Berlin Date: Tue, 14 Jul 2009 20:20:29 +0000 (+0100) Subject: Conditionally expand linestrings under perl debugger. X-Git-Tag: 0.005008~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7dd7d0088daadec6edede7f44b02afd64019957d;p=p5sagit%2FDevel-Declare.git Conditionally expand linestrings under perl debugger. --- diff --git a/Changes b/Changes index cea2981..f1797e5 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,7 @@ Changes for Devel-Declare + - Conditionally expand linestrings under perl debugger. + 0.005007 - 13 Jul 2009 - Fix line numbers not being updated from skipspace calls diff --git a/Declare.xs b/Declare.xs index 6b188c3..c3a8dee 100644 --- a/Declare.xs +++ b/Declare.xs @@ -11,6 +11,11 @@ # define Newx(v,n,t) New(0,v,n,t) #endif /* !Newx */ +#define DD_DEBUGf_UPDATED_LINESTR 1 +#define DD_DEBUGf_TRACE 2 + +#define DD_DEBUG_UPDATED_LINESTR (dd_debug & DD_DEBUGf_UPDATED_LINESTR) +#define DD_DEBUG_TRACE (dd_debug & DD_DEBUGf_TRACE) static int dd_debug = 0; #define LEX_NORMAL 10 @@ -128,6 +133,17 @@ void dd_set_linestr(pTHX_ char* new_value) { SvCUR_set(PL_linestr, new_len); PL_bufend = SvPVX(PL_linestr) + new_len; + + if ( DD_DEBUG_UPDATED_LINESTR && PERLDB_LINE && PL_curstash != PL_debstash) { + // Cribbed from toke.c + SV * const sv = NEWSV(85,0); + + sv_upgrade(sv, SVt_PVMG); + sv_setpvn(sv,PL_bufptr,PL_bufend-PL_bufptr); + (void)SvIOK_on(sv); + SvIV_set(sv, 0); + av_store(CopFILEAV(&PL_compiling),(I32)CopLINE(&PL_compiling),sv); + } } char* dd_get_lex_stuff(pTHX) { @@ -218,7 +234,7 @@ STATIC OP *dd_ck_rv2cv(pTHX_ OP *o, void *user_data) { PERL_UNUSED_VAR(user_data); if (in_declare) { - if (dd_debug) { + if (DD_DEBUG_TRACE) { printf("Deconstructing declare\n"); printf("PL_bufptr: %s\n", PL_bufptr); printf("bufend at: %i\n", PL_bufend - PL_bufptr); @@ -236,7 +252,7 @@ STATIC OP *dd_ck_rv2cv(pTHX_ OP *o, void *user_data) { FREETMPS; LEAVE; - if (dd_debug) { + if (DD_DEBUG_TRACE) { printf("PL_bufptr: %s\n", PL_bufptr); printf("bufend at: %i\n", PL_bufend - PL_bufptr); printf("linestr: %s\n", SvPVX(PL_linestr)); @@ -254,7 +270,7 @@ STATIC OP *dd_ck_rv2cv(pTHX_ OP *o, void *user_data) { if (!DD_AM_LEXING) return o; /* not lexing? */ - if (dd_debug) { + if (DD_DEBUG_TRACE) { printf("Checking GV %s -> %s\n", HvNAME(GvSTASH(kGVOP_gv)), GvNAME(kGVOP_gv)); } @@ -263,7 +279,7 @@ STATIC OP *dd_ck_rv2cv(pTHX_ OP *o, void *user_data) { if (dd_flags == -1) return o; - if (dd_debug) { + if (DD_DEBUG_TRACE) { printf("dd_flags are: %i\n", dd_flags); printf("PL_tokenbuf: %s\n", PL_tokenbuf); } @@ -286,7 +302,7 @@ OP* dd_pp_entereval(pTHX) { #endif sv = POPs; if (SvPOK(sv)) { - if (dd_debug) { + if (DD_DEBUG_TRACE) { printf("mangling eval sv\n"); } if (SvREADONLY(sv)) @@ -473,5 +489,5 @@ set_in_declare(int value) BOOT: if (getenv ("DD_DEBUG")) { - dd_debug = 1; + dd_debug = atoi(getenv("DD_DEBUG")); } diff --git a/t/debug.pl b/t/debug.pl new file mode 100644 index 0000000..5f382a2 --- /dev/null +++ b/t/debug.pl @@ -0,0 +1,43 @@ +use strict; +use warnings; + +use Devel::Declare; + +BEGIN { + + Devel::Declare->install_declarator( + 'DeclareTest', 'method', DECLARE_PACKAGE | DECLARE_PROTO, + sub { + my ($name, $proto) = @_; + return 'my $self = shift;' unless defined $proto && $proto ne '@_'; + return 'my ($self'.(length $proto ? ", ${proto}" : "").') = @_;'; + }, + sub { + my ($name, $proto, $sub, @rest) = @_; + if (defined $name && length $name) { + unless ($name =~ /::/) { + $name = "DeclareTest::${name}"; + } + no strict 'refs'; + *{$name} = $sub; + } + return wantarray ? ($sub, @rest) : $sub; + } + ); + +} + +my ($test_method1, $test_method2, @test_list); + +{ + package DeclareTest; + + method new { + }; + +} + +{ no strict; + no warnings 'uninitialized'; + print @{"_ 1; + +use Cwd qw/cwd/; +use FindBin qw/$Bin/; + +$ENV{PERLDB_OPTS} = "NonStop"; +$ENV{DD_DEBUG} = 1; +cwd("$Bin/.."); + +# Write a .perldb file so we make sure we dont use the users one +open PERLDB, ">", "$Bin/../.perldb" or die "Cannot open $Bin/../.perldb: $!"; +close PERLDB; + +$SIG{CHLD} = 'IGNORE'; +$SIG{ALRM} = sub { + fail("SIGALRM timeout triggered"); + kill(9, $$); +}; + +alarm 10; +my $output = `$^X -d t/debug.pl`; + +like($output, qr/method new {}, sub {my \$self = shift;/, + "replaced line string visible in debug lines"); +1;