perl5db.xs

filter: Statementstmt 0.0% 0 / 71 Branchbran 0.0% 0 / 54 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 125 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/dbgp-helper/DB/OSType.pm ↑ Summary DB/DbgrXS.pm »
1 #define PERL_NO_GET_CONTEXT
2 #include "EXTERN.h"
3 #include "perl.h"
4 #include "XSUB.h"
5 #include "ppport.h"
6  
7 #define MY_CXT_KEY "perl5db::_guts" XS_VERSION
8  
9 typedef struct {
10 SV *ldebug;
11 AV *stack;
12 GV *stack_depth;
13 SV *deep;
14 HV *fq_function_names;
15 } my_cxt_t;
16  
17 START_MY_CXT
18  
19 #define dblog(string) \
20 STMT_START { \
21 if (SvIV(MY_CXT.ldebug)) { \
22 const char *arg = (string); \
23 PUTBACK; \
24 do_dblog(aTHX_ arg); \
25 SPAGAIN; \
26 } \
27 } STMT_END
28  
29 0 static void do_dblog(pTHX_ const char *string) {
30 0 dSP;
31  
32 0 ▶ EXTEND(SP, 1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 1); 0 0 0
33  
34 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
35 0 PUSHs(sv_2mortal(newSVpv(string, 0)));
36 0 PUTBACK;
37  
38 0 call_pv("DB::dblog", G_VOID | G_DISCARD | G_NODEBUG);
39 0 }
40  
41 #if PERL_VERSION >= 22
42 0 static void PL_DBsingle_iv_set(pTHX_ IV x) {
43 0 PL_DBsingle_iv = x;
44 0 }
45 #else
46 #define PL_DBsingle_iv SvIV(PL_DBsingle)
47  
48 static void PL_DBsingle_iv_set(pTHX_ IV x) {
49 SvIV_set(PL_DBsingle, x);
50 SvIOK_only(PL_DBsingle);
51 }
52 #endif
53  
54 0 static void reinit_my_cxt(pTHX_ pMY_CXT) {
55 0 MY_CXT.ldebug = get_sv("DB::ldebug", 0);
56 0 MY_CXT.stack_depth = gv_fetchpv("DB::stack_depth", 0, 0);
57  
58 0 call_pv("DB::setup_lexicals", G_VOID | G_DISCARD | G_NODEBUG);
59 0 }
60  
61 0 static void try_breaking(pTHX_ pMY_CXT_ SV *sub, const char *type) {
62 0 dSP;
63  
64 0 HE *entry = hv_fetch_ent(MY_CXT.fq_function_names, sub, 0, 0);
65 0 ▶ if (!entry)
Branch: 1 branch
BranchTrueFalseTotal
if (!entry) 0 0 0
66 0 return;
67  
68 0 ▶ EXTEND(SP, 3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 3); 0 0 0
69  
70 0 ▶ PUSHMARK(SP);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(SP); 0 0 0
71 0 PUSHs(HeVAL(entry));
72 0 PUSHs(sub);
73 0 PUSHs(sv_2mortal(newSVpv(type, 0)));
74 0 PUTBACK;
75  
76 0 call_pv("DB::tryBreaking", G_VOID | G_DISCARD | G_NODEBUG);
77 }
78  
79 0 static bool before_call(pTHX_ pMY_CXT_ int current_depth) {
80 0 bool in_debugger = FALSE;
81  
82 /* local $stach_depth = $stack_depth + 1 */
83 0 ▶ SAVEGENERICSV(GvSVn(MY_CXT.stack_depth));
Branch: 1 branch
BranchTrueFalseTotal
SAVEGENERICSV(GvSVn(MY_CXT.stack_depth)); 0 0 0
84 0 ▶ GvSVn((MY_CXT.stack_depth)) = newSViv(current_depth);
Branch: 1 branch
BranchTrueFalseTotal
GvSVn((MY_CXT.stack_depth)) = newSViv(current_depth); 0 0 0
85  
86 /* $#stack = $stack_depth */
87 0 av_fill(MY_CXT.stack, current_depth);
88  
89 /* $stack[-1] = $single */
90 0 IV single = PL_DBsingle_iv;
91 {
92 0 SV **top = av_fetch(MY_CXT.stack, current_depth, 1);
93  
94 0 sv_setiv(*top, single);
95 }
96 /* $single &= 1 */
97 0 single = single & 1;
98  
99 /* $single |= 4 if $#stack == $deep */
100 0 ▶ if (current_depth == SvIV(MY_CXT.deep))
Branch: 1 branch
BranchTrueFalseTotal
if (current_depth == SvIV(MY_CXT.deep)) 0 0 0
101 0 single = single | 4;
102 0 PL_DBsingle_iv_set(aTHX_ single);
103  
104 {
105 0 HV *stash = CopSTASH(PL_curcop);
106 0 ▶ STRLEN len = HvNAMELEN_get(stash);
Branch: 6 branches
BranchTrueFalseTotal
STRLEN len = HvNAMELEN_get(stash); 0 0 0
STRLEN len = HvNAMELEN_get(stash); 0 0 0
STRLEN len = HvNAMELEN_get(stash); 0 0 0
STRLEN len = HvNAMELEN_get(stash); 0 0 0
STRLEN len = HvNAMELEN_get(stash); 0 0 0
STRLEN len = HvNAMELEN_get(stash); 0 0 0
107 0 ▶ const char *name = HvNAME(stash);
Branch: 6 branches
BranchTrueFalseTotal
const char *name = HvNAME(stash); 0 0 0
const char *name = HvNAME(stash); 0 0 0
const char *name = HvNAME(stash); 0 0 0
const char *name = HvNAME(stash); 0 0 0
const char *name = HvNAME(stash); 0 0 0
const char *name = HvNAME(stash); 0 0 0
108  
109 0 ▶ if (len > 4 && strncmp(name, "DB::", 4) == 0)
Branch: 2 branches
BranchTrueFalseTotal
if (len > 4 && strncmp(name, "DB::", 4) == 0) 0 0 0
if (len > 4 && strncmp(name, "DB::", 4) == 0) 0 0 0
110 0 in_debugger = TRUE;
111 }
112  
113 /* check function call breakpoint */
114 0 ▶ if (!in_debugger)
Branch: 1 branch
BranchTrueFalseTotal
if (!in_debugger) 0 0 0
115 0 try_breaking(aTHX_ aMY_CXT_ GvSV(PL_DBsub), "call");
116  
117 0 return in_debugger;
118 }
119  
120 0 static void after_call(pTHX_ pMY_CXT_ bool in_debugger, int current_depth) {
121 /* $single |= $stack[$stack_depth] */
122 {
123 0 SV **top = av_fetch(MY_CXT.stack, current_depth, 0);
124  
125 0 PL_DBsingle_iv_set(aTHX_ PL_DBsingle_iv | SvIV(*top));
126 }
127  
128 /* check function return breakpoint */
129 0 ▶ if (!in_debugger)
Branch: 1 branch
BranchTrueFalseTotal
if (!in_debugger) 0 0 0
130 0 try_breaking(aTHX_ aMY_CXT_ GvSV(PL_DBsub), "return");
131 0 }
132  
133 MODULE=dbgp_helper::perl5db PACKAGE=DB::XS
134  
135 void
136 sub_xs(...)
137 PREINIT:
138 dMY_CXT;
139 /* needs a separate CV so we can set the LVALUE flag */
140 ALIAS:
141 lsub_xs = 1
142 INIT:
143 0 SV *sub = GvSV(PL_DBsub);
144 0 ▶ IV current_depth = SvIV(GvSVn(MY_CXT.stack_depth)) + 1;
Branch: 1 branch
BranchTrueFalseTotal
IV current_depth = SvIV(GvSVn(MY_CXT.stack_depth)) + 1; 0 0 0
145 0 I32 context = GIMME_V;
146 /*
147 If the original sub was called with the &foo syntax,
148 add G_NOARGS to the call_sv() call, so @_ is not copied,
149 and the callee can modify it.
150  
151 DB::sub (Perl) does this for all calls, because it's written in
152 Perl, so @_ is always there, but when DB::XS::sub is called,
153 @_ is not set up, because the sub is an XS.
154 */
155 0 ▶ I32 noargs = (PL_op->op_flags & OPf_STACKED) ? 0 : G_NOARGS;
Branch: 1 branch
BranchTrueFalseTotal
I32 noargs = (PL_op->op_flags & OPf_STACKED) ? 0 : G_NOARGS; 0 0 0
156 bool in_debugger;
157 int retcount;
158 PPCODE:
159 /*
160 We're passing through our arguments unmodified, so we can
161 re-push them in place, or just restore the MARK declared by
162 the implicit dXSARGS, and get the non-adjusted stack pointer
163 from the interpreter global.
164 */
165 0 ▶ PUSHMARK(MARK);
Branch: 1 branch
BranchTrueFalseTotal
PUSHMARK(MARK); 0 0 0
166 /* not needed right now, added just in case */
167 0 SPAGAIN;
168  
169 0 in_debugger = before_call(aTHX_ aMY_CXT_ current_depth);
170 0 retcount = call_sv(sub, context | noargs | G_NODEBUG);
171 0 after_call(aTHX_ aMY_CXT_ in_debugger, current_depth);
172  
173 /*
174 The global stack pointer is already at the right place, so we
175 refresh our local copy so the implict PUTBACK at the end is a
176 no-op. We could also do XSRETURN(retcount)
177 */
178 0 SPAGAIN;
179  
180 void
181 setup_lexicals(SV *ldebug, SV *stack, SV *deep, SV *fq_function_names)
182 PREINIT:
183 dMY_CXT;
184 CODE:
185 0 MY_CXT.ldebug = SvRV(ldebug);
186 0 MY_CXT.stack = (AV *) SvRV(stack);
187 0 MY_CXT.deep = SvRV(deep);
188 0 MY_CXT.fq_function_names = (HV *) SvRV(fq_function_names);
189  
190 void
191 CLONE(...)
192 CODE:
193 MY_CXT_CLONE;
194 0 reinit_my_cxt(aTHX_ aMY_CXT);
195  
196 BOOT:
197 MY_CXT_INIT;
198 0 reinit_my_cxt(aTHX_ aMY_CXT);
199  
200 0 CvLVALUE_on(get_cv("DB::XS::lsub_xs", 0));
« blib/lib/dbgp-helper/DB/OSType.pm ↑ Summary DB/DbgrXS.pm »