This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
MARK -Ds debugging
authorReini Urban <rurban@cpanel.net>
Mon, 16 Mar 2015 09:27:37 +0000 (10:27 +0100)
committerTony Cook <tony@develop-help.com>
Tue, 10 Nov 2015 03:17:23 +0000 (14:17 +1100)
display the MARK arity and pointers with MARK macros.
assert on markptr underflow.

perl.c
pp.h
pp_ctl.c
pp_hot.c
scope.c

diff --git a/perl.c b/perl.c
index b64975b..8182562 100644 (file)
--- a/perl.c
+++ b/perl.c
@@ -2776,9 +2776,9 @@ Perl_call_sv(pTHX_ SV *sv, VOL I32 flags)
     }
     else {
        myop.op_other = (OP*)&myop;
-       PL_markstack_ptr--;
+       POPMARK;
        create_eval_scope(flags|G_FAKINGEVAL);
-       PL_markstack_ptr++;
+       INCMARK;
 
        JMPENV_PUSH(ret);
 
diff --git a/pp.h b/pp.h
index b497085..5712b8e 100644 (file)
--- a/pp.h
+++ b/pp.h
@@ -55,16 +55,47 @@ Refetch the stack pointer.  Used after a callback.  See L<perlcall>.
 #define MARK mark
 #define TARG targ
 
-#define PUSHMARK(p)    \
-       STMT_START {                                    \
-           I32 * mark_stack_entry;                     \
-           if (UNLIKELY((mark_stack_entry = ++PL_markstack_ptr) == PL_markstack_max))  \
-           mark_stack_entry = markstack_grow();                                        \
-           *mark_stack_entry  = (I32)((p) - PL_stack_base);                            \
-       } STMT_END
-
-#define TOPMARK                (*PL_markstack_ptr)
-#define POPMARK                (*PL_markstack_ptr--)
+#if defined(DEBUGGING) && defined(PERL_USE_GCC_BRACE_GROUPS)
+#define PUSHMARK(p)                                                   \
+    STMT_START {                                                      \
+        I32 * mark_stack_entry;                                       \
+        if (UNLIKELY((mark_stack_entry = ++PL_markstack_ptr) == PL_markstack_max)) \
+           mark_stack_entry = markstack_grow();                      \
+        *mark_stack_entry  = (I32)((p) - PL_stack_base);              \
+        DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK push %p %d\n",    \
+                PL_markstack_ptr, *mark_stack_entry));                \
+    } STMT_END
+#define TOPMARK                                                       \
+    ({                                                                \
+        DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK top  %p %d\n",    \
+                PL_markstack_ptr, *PL_markstack_ptr));                \
+        *PL_markstack_ptr;                                            \
+    })
+#define POPMARK                                                       \
+    ({                                                                \
+        DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK pop  %p %d\n",    \
+                (PL_markstack_ptr-1), *(PL_markstack_ptr-1)));        \
+        assert((PL_markstack_ptr > PL_markstack) || !"MARK underflow");\
+        *PL_markstack_ptr--;                                          \
+    })
+#define INCMARK                                                       \
+    ({                                                                \
+        DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK inc  %p %d\n",    \
+                (PL_markstack_ptr+1), *(PL_markstack_ptr+1)));        \
+        *PL_markstack_ptr++;                                          \
+    })
+#else
+#define PUSHMARK(p)                                                   \
+    STMT_START {                                                     \
+        I32 * mark_stack_entry;                                       \
+        if (UNLIKELY((mark_stack_entry = ++PL_markstack_ptr) == PL_markstack_max)) \
+           mark_stack_entry = markstack_grow();                      \
+        *mark_stack_entry  = (I32)((p) - PL_stack_base);              \
+    } STMT_END
+#define TOPMARK                (*PL_markstack_ptr)
+#define POPMARK                (*PL_markstack_ptr--)
+#define INCMARK                (*PL_markstack_ptr++)
+#endif
 
 #define dSP            SV **sp = PL_stack_sp
 #define djSP           dSP
@@ -506,7 +537,7 @@ Does not use C<TARG>.  See also C<L</XPUSHu>>, C<L</mPUSHu>> and C<L</PUSHu>>.
                while (jump_o->op_type == OP_NULL)              \
                    jump_o = jump_o->op_next;                   \
                assert(jump_o->op_type == OP_ENTERSUB);         \
-               PL_markstack_ptr--;                             \
+               POPMARK;                                        \
                return jump_o->op_next;                         \
            }                                                   \
            return NORMAL;                                      \
index cdbdbd0..f9306e1 100644 (file)
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -928,13 +928,13 @@ PP(pp_grepstart)
     dSP;
     SV *src;
 
-    if (PL_stack_base + *PL_markstack_ptr == SP) {
+    if (PL_stack_base + TOPMARK == SP) {
        (void)POPMARK;
        if (GIMME_V == G_SCALAR)
            mXPUSHi(0);
        RETURNOP(PL_op->op_next->op_next);
     }
-    PL_stack_sp = PL_stack_base + *PL_markstack_ptr + 1;
+    PL_stack_sp = PL_stack_base + TOPMARK + 1;
     Perl_pp_pushmark(aTHX);                            /* push dst */
     Perl_pp_pushmark(aTHX);                            /* push src */
     ENTER_with_name("grep");                                   /* enter outer scope */
@@ -944,9 +944,9 @@ PP(pp_grepstart)
     ENTER_with_name("grep_item");                                      /* enter inner scope */
     SAVEVPTR(PL_curpm);
 
-    src = PL_stack_base[*PL_markstack_ptr];
+    src = PL_stack_base[TOPMARK];
     if (SvPADTMP(src)) {
-       src = PL_stack_base[*PL_markstack_ptr] = sv_mortalcopy(src);
+       src = PL_stack_base[TOPMARK] = sv_mortalcopy(src);
        PL_tmps_floor++;
     }
     SvTEMP_off(src);
@@ -962,7 +962,7 @@ PP(pp_mapwhile)
 {
     dSP;
     const I32 gimme = GIMME_V;
-    I32 items = (SP - PL_stack_base) - *PL_markstack_ptr; /* how many new items */
+    I32 items = (SP - PL_stack_base) - TOPMARK; /* how many new items */
     I32 count;
     I32 shift;
     SV** src;
@@ -1063,7 +1063,7 @@ PP(pp_mapwhile)
     LEAVE_with_name("grep_item");                                      /* exit inner scope */
 
     /* All done yet? */
-    if (PL_markstack_ptr[-1] > *PL_markstack_ptr) {
+    if (PL_markstack_ptr[-1] > TOPMARK) {
 
        (void)POPMARK;                          /* pop top */
        LEAVE_with_name("grep");                                        /* exit outer scope */
index 87e306c..d1e5562 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -3157,9 +3157,9 @@ PP(pp_grepwhile)
        ENTER_with_name("grep_item");                                   /* enter inner scope */
        SAVEVPTR(PL_curpm);
 
-       src = PL_stack_base[*PL_markstack_ptr];
+       src = PL_stack_base[TOPMARK];
        if (SvPADTMP(src)) {
-           src = PL_stack_base[*PL_markstack_ptr] = sv_mortalcopy(src);
+           src = PL_stack_base[TOPMARK] = sv_mortalcopy(src);
            PL_tmps_floor++;
        }
        SvTEMP_off(src);
diff --git a/scope.c b/scope.c
index bdf299a..037bbc0 100644 (file)
--- a/scope.c
+++ b/scope.c
@@ -131,6 +131,8 @@ Perl_markstack_grow(pTHX)
     Renew(PL_markstack, newmax, I32);
     PL_markstack_max = PL_markstack + newmax;
     PL_markstack_ptr = PL_markstack + oldmax;
+    DEBUG_s(PerlIO_printf(Perl_debug_log, "MARK grow %p %d by %d\n",
+            PL_markstack_ptr, *PL_markstack_ptr, oldmax));
     return PL_markstack_ptr;
 }