… | |
… | |
675 | |
675 | |
676 | while ((PL_op = CALL_FPTR (PL_op->op_ppaddr) (aTHX))) |
676 | while ((PL_op = CALL_FPTR (PL_op->op_ppaddr) (aTHX))) |
677 | { |
677 | { |
678 | PERL_ASYNC_CHECK (); |
678 | PERL_ASYNC_CHECK (); |
679 | |
679 | |
680 | if (PL_op->op_type == OP_LEAVESUB && cctx->flags & CC_TRACE_SUB) |
680 | if (cctx->flags & CC_TRACE_ALL) |
681 | { |
681 | { |
682 | PERL_CONTEXT *cx = &cxstack[cxstack_ix]; |
682 | if (PL_op->op_type == OP_LEAVESUB && cctx->flags & CC_TRACE_SUB) |
683 | SV **bot, **top; |
|
|
684 | AV *av = newAV (); /* return values */ |
|
|
685 | SV **cb; |
|
|
686 | runops_proc_t old_runops = PL_runops; |
|
|
687 | dSP; |
|
|
688 | ENTER; |
|
|
689 | SAVETMPS; |
|
|
690 | EXTEND (SP, 3); |
|
|
691 | PL_runops = RUNOPS_DEFAULT; |
|
|
692 | |
|
|
693 | GV *gv = CvGV (cx->blk_sub.cv); |
|
|
694 | SV *fullname = sv_2mortal (newSV (0)); |
|
|
695 | if (isGV (gv)) |
|
|
696 | gv_efullname3 (fullname, gv, 0); |
|
|
697 | |
|
|
698 | bot = PL_stack_base + cx->blk_oldsp + 1; |
|
|
699 | top = cx->blk_gimme == G_ARRAY ? SP + 1 |
|
|
700 | : cx->blk_gimme == G_SCALAR ? bot + 1 |
|
|
701 | : bot; |
|
|
702 | |
|
|
703 | while (bot < top) |
|
|
704 | av_push (av, SvREFCNT_inc (*bot++)); |
|
|
705 | |
|
|
706 | PUSHMARK (SP); |
|
|
707 | PUSHs (&PL_sv_no); |
|
|
708 | PUSHs (fullname); |
|
|
709 | PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
|
|
710 | PUTBACK; |
|
|
711 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
|
|
712 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
|
|
713 | SPAGAIN; |
|
|
714 | |
|
|
715 | FREETMPS; |
|
|
716 | LEAVE; |
|
|
717 | PL_runops = old_runops; |
|
|
718 | } |
|
|
719 | |
|
|
720 | if (oldcop != PL_curcop) |
|
|
721 | { |
|
|
722 | oldcop = PL_curcop; |
|
|
723 | |
|
|
724 | if (PL_curcop != &PL_compiling) |
|
|
725 | { |
683 | { |
|
|
684 | PERL_CONTEXT *cx = &cxstack[cxstack_ix]; |
|
|
685 | SV **bot, **top; |
|
|
686 | AV *av = newAV (); /* return values */ |
726 | SV **cb; |
687 | SV **cb; |
727 | runops_proc_t old_runops = PL_runops; |
|
|
728 | dSP; |
688 | dSP; |
|
|
689 | |
|
|
690 | GV *gv = CvGV (cx->blk_sub.cv); |
|
|
691 | SV *fullname = sv_2mortal (newSV (0)); |
|
|
692 | if (isGV (gv)) |
|
|
693 | gv_efullname3 (fullname, gv, 0); |
|
|
694 | |
|
|
695 | bot = PL_stack_base + cx->blk_oldsp + 1; |
|
|
696 | top = cx->blk_gimme == G_ARRAY ? SP + 1 |
|
|
697 | : cx->blk_gimme == G_SCALAR ? bot + 1 |
|
|
698 | : bot; |
|
|
699 | |
|
|
700 | while (bot < top) |
|
|
701 | av_push (av, SvREFCNT_inc (*bot++)); |
|
|
702 | |
|
|
703 | PL_runops = RUNOPS_DEFAULT; |
729 | ENTER; |
704 | ENTER; |
730 | SAVETMPS; |
705 | SAVETMPS; |
731 | EXTEND (SP, 3); |
706 | EXTEND (SP, 3); |
732 | PL_runops = RUNOPS_DEFAULT; |
707 | PUSHMARK (SP); |
|
|
708 | PUSHs (&PL_sv_no); |
|
|
709 | PUSHs (fullname); |
|
|
710 | PUSHs (sv_2mortal (newRV_noinc ((SV *)av))); |
|
|
711 | PUTBACK; |
|
|
712 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
|
|
713 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
|
|
714 | SPAGAIN; |
|
|
715 | FREETMPS; |
|
|
716 | LEAVE; |
|
|
717 | PL_runops = runops_trace; |
|
|
718 | } |
733 | |
719 | |
734 | if (oldcxix != cxstack_ix && cctx->flags & CC_TRACE_SUB) |
720 | if (oldcop != PL_curcop) |
|
|
721 | { |
|
|
722 | oldcop = PL_curcop; |
|
|
723 | |
|
|
724 | if (PL_curcop != &PL_compiling) |
735 | { |
725 | { |
736 | PERL_CONTEXT *cx = &cxstack[cxstack_ix]; |
726 | SV **cb; |
737 | |
727 | |
738 | if (CxTYPE (cx) == CXt_SUB && oldcxix < cxstack_ix) |
728 | if (oldcxix != cxstack_ix && cctx->flags & CC_TRACE_SUB) |
739 | { |
729 | { |
|
|
730 | PERL_CONTEXT *cx = &cxstack[cxstack_ix]; |
|
|
731 | |
|
|
732 | if (CxTYPE (cx) == CXt_SUB && oldcxix < cxstack_ix) |
|
|
733 | { |
|
|
734 | runops_proc_t old_runops = PL_runops; |
|
|
735 | dSP; |
740 | GV *gv = CvGV (cx->blk_sub.cv); |
736 | GV *gv = CvGV (cx->blk_sub.cv); |
741 | SV *fullname = sv_2mortal (newSV (0)); |
737 | SV *fullname = sv_2mortal (newSV (0)); |
|
|
738 | |
742 | if (isGV (gv)) |
739 | if (isGV (gv)) |
743 | gv_efullname3 (fullname, gv, 0); |
740 | gv_efullname3 (fullname, gv, 0); |
744 | |
741 | |
|
|
742 | PL_runops = RUNOPS_DEFAULT; |
|
|
743 | ENTER; |
|
|
744 | SAVETMPS; |
|
|
745 | EXTEND (SP, 3); |
|
|
746 | PUSHMARK (SP); |
|
|
747 | PUSHs (&PL_sv_yes); |
|
|
748 | PUSHs (fullname); |
|
|
749 | PUSHs (cx->blk_sub.hasargs ? sv_2mortal (newRV_inc ((SV *)cx->blk_sub.argarray)) : &PL_sv_undef); |
|
|
750 | PUTBACK; |
|
|
751 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
|
|
752 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
|
|
753 | SPAGAIN; |
|
|
754 | FREETMPS; |
|
|
755 | LEAVE; |
|
|
756 | PL_runops = runops_trace; |
|
|
757 | } |
|
|
758 | |
|
|
759 | oldcxix = cxstack_ix; |
|
|
760 | } |
|
|
761 | |
|
|
762 | if (cctx->flags & CC_TRACE_LINE) |
|
|
763 | { |
|
|
764 | dSP; |
|
|
765 | |
|
|
766 | PL_runops = RUNOPS_DEFAULT; |
|
|
767 | ENTER; |
|
|
768 | SAVETMPS; |
|
|
769 | EXTEND (SP, 3); |
|
|
770 | PL_runops = RUNOPS_DEFAULT; |
745 | PUSHMARK (SP); |
771 | PUSHMARK (SP); |
746 | PUSHs (&PL_sv_yes); |
772 | PUSHs (sv_2mortal (newSVpv (OutCopFILE (oldcop), 0))); |
747 | PUSHs (fullname); |
773 | PUSHs (sv_2mortal (newSViv (CopLINE (oldcop)))); |
748 | PUSHs (cx->blk_sub.hasargs ? sv_2mortal (newRV_inc ((SV *)cx->blk_sub.argarray)) : &PL_sv_undef); |
|
|
749 | PUTBACK; |
774 | PUTBACK; |
750 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_sub_cb", sizeof ("_trace_sub_cb") - 1, 0); |
775 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_line_cb", sizeof ("_trace_line_cb") - 1, 0); |
751 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
776 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
752 | SPAGAIN; |
777 | SPAGAIN; |
|
|
778 | FREETMPS; |
|
|
779 | LEAVE; |
|
|
780 | PL_runops = runops_trace; |
753 | } |
781 | } |
754 | |
|
|
755 | oldcxix = cxstack_ix; |
|
|
756 | } |
782 | } |
757 | |
|
|
758 | if (cctx->flags & CC_TRACE_LINE) |
|
|
759 | { |
|
|
760 | PUSHMARK (SP); |
|
|
761 | PUSHs (sv_2mortal (newSVpv (OutCopFILE (oldcop), 0))); |
|
|
762 | PUSHs (sv_2mortal (newSViv (CopLINE (oldcop)))); |
|
|
763 | PUTBACK; |
|
|
764 | cb = hv_fetch ((HV *)SvRV (coro_current), "_trace_line_cb", sizeof ("_trace_line_cb") - 1, 0); |
|
|
765 | if (cb) call_sv (*cb, G_KEEPERR | G_EVAL | G_VOID | G_DISCARD); |
|
|
766 | SPAGAIN; |
|
|
767 | } |
|
|
768 | |
|
|
769 | FREETMPS; |
|
|
770 | LEAVE; |
|
|
771 | PL_runops = old_runops; |
|
|
772 | } |
783 | } |
773 | } |
784 | } |
774 | } |
785 | } |
775 | |
786 | |
776 | TAINT_NOT; |
787 | TAINT_NOT; |
… | |
… | |
1343 | } |
1354 | } |
1344 | else |
1355 | else |
1345 | return 0; |
1356 | return 0; |
1346 | } |
1357 | } |
1347 | |
1358 | |
|
|
1359 | static void |
|
|
1360 | api_trace (struct coro *coro, int flags) |
|
|
1361 | { |
|
|
1362 | dTHX; |
|
|
1363 | |
|
|
1364 | if (flags & CC_TRACE) |
|
|
1365 | { |
|
|
1366 | if (!coro->cctx) |
|
|
1367 | coro->cctx = cctx_new (); |
|
|
1368 | else if (!(coro->cctx->flags & CC_TRACE)) |
|
|
1369 | croak ("cannot enable tracing on coroutine with custom stack"); |
|
|
1370 | |
|
|
1371 | coro->cctx->flags |= CC_NOREUSE | (flags & (CC_TRACE | CC_TRACE_ALL)); |
|
|
1372 | } |
|
|
1373 | else if (coro->cctx && coro->cctx->flags & CC_TRACE) |
|
|
1374 | { |
|
|
1375 | coro->cctx->flags &= ~(CC_TRACE | CC_TRACE_ALL); |
|
|
1376 | |
|
|
1377 | if (coro->flags & CF_RUNNING) |
|
|
1378 | PL_runops = RUNOPS_DEFAULT; |
|
|
1379 | else |
|
|
1380 | coro->runops = RUNOPS_DEFAULT; |
|
|
1381 | } |
|
|
1382 | } |
|
|
1383 | |
1348 | MODULE = Coro::State PACKAGE = Coro::State |
1384 | MODULE = Coro::State PACKAGE = Coro::State PREFIX = api_ |
1349 | |
1385 | |
1350 | PROTOTYPES: DISABLE |
1386 | PROTOTYPES: DISABLE |
1351 | |
1387 | |
1352 | BOOT: |
1388 | BOOT: |
1353 | { |
1389 | { |
… | |
… | |
1576 | RETVAL = boolSV (coro->flags & ix); |
1612 | RETVAL = boolSV (coro->flags & ix); |
1577 | OUTPUT: |
1613 | OUTPUT: |
1578 | RETVAL |
1614 | RETVAL |
1579 | |
1615 | |
1580 | void |
1616 | void |
1581 | trace (Coro::State coro, int flags = CC_TRACE | CC_TRACE_SUB) |
1617 | api_trace (Coro::State coro, int flags = CC_TRACE | CC_TRACE_SUB) |
1582 | CODE: |
|
|
1583 | if (flags & CC_TRACE) |
|
|
1584 | { |
|
|
1585 | if (!coro->cctx) |
|
|
1586 | coro->cctx = cctx_new (); |
|
|
1587 | else if (!(coro->cctx->flags & CC_TRACE)) |
|
|
1588 | croak ("cannot enable tracing on coroutine with custom stack"); |
|
|
1589 | |
|
|
1590 | coro->cctx->flags |= flags & (CC_TRACE | CC_TRACE_ALL); |
|
|
1591 | } |
|
|
1592 | else |
|
|
1593 | if (coro->cctx && coro->cctx->flags & CC_TRACE) |
|
|
1594 | { |
|
|
1595 | coro->cctx->flags &= ~(CC_TRACE | CC_TRACE_ALL); |
|
|
1596 | coro->cctx->flags |= CC_NOREUSE; |
|
|
1597 | |
|
|
1598 | if (coro->flags & CF_RUNNING) |
|
|
1599 | PL_runops = RUNOPS_DEFAULT; |
|
|
1600 | else |
|
|
1601 | coro->runops = RUNOPS_DEFAULT; |
|
|
1602 | } |
|
|
1603 | |
1618 | |
1604 | SV * |
1619 | SV * |
1605 | has_stack (Coro::State coro) |
1620 | has_stack (Coro::State coro) |
1606 | PROTOTYPE: $ |
1621 | PROTOTYPE: $ |
1607 | CODE: |
1622 | CODE: |
… | |
… | |
1767 | av_clear (GvAV (PL_defgv)); |
1782 | av_clear (GvAV (PL_defgv)); |
1768 | hv_store ((HV *)SvRV (coro_current), "desc", sizeof ("desc") - 1, |
1783 | hv_store ((HV *)SvRV (coro_current), "desc", sizeof ("desc") - 1, |
1769 | newSVpvn ("[async_pool idle]", sizeof ("[async_pool idle]") - 1), 0); |
1784 | newSVpvn ("[async_pool idle]", sizeof ("[async_pool idle]") - 1), 0); |
1770 | coro->save = CORO_SAVE_DEF; |
1785 | coro->save = CORO_SAVE_DEF; |
1771 | coro->prio = 0; |
1786 | coro->prio = 0; |
|
|
1787 | |
|
|
1788 | if (coro->cctx && (coro->cctx->flags & CC_TRACE)) |
|
|
1789 | api_trace (coro, 0); |
|
|
1790 | |
1772 | av_push (av_async_pool, newSVsv (coro_current)); |
1791 | av_push (av_async_pool, newSVsv (coro_current)); |
1773 | } |
1792 | } |
1774 | |
1793 | |
1775 | |
1794 | |
1776 | MODULE = Coro::State PACKAGE = Coro::AIO |
1795 | MODULE = Coro::State PACKAGE = Coro::AIO |