| 1 |
|
| /* |
| 2 |
|
| * Copyright 2001-2026, Paul Johnson (paul@pjcj.net) |
| 3 |
|
| * |
| 4 |
|
| * This software is free. It is licensed under the same terms as Perl itself. |
| 5 |
|
| * |
| 6 |
|
| * The latest version of this software should be available from my homepage: |
| 7 |
|
| * https://pjcj.net |
| 8 |
|
| * |
| 9 |
|
| */ |
| 10 |
|
| |
| 11 |
|
| #ifdef __cplusplus |
| 12 |
|
| extern "C" { |
| 13 |
|
| #endif |
| 14 |
|
| |
| 15 |
|
| #define PERL_NO_GET_CONTEXT |
| 16 |
|
| #include "EXTERN.h" |
| 17 |
|
| #include "perl.h" |
| 18 |
|
| #include "XSUB.h" |
| 19 |
|
| |
| 20 |
|
| #ifdef __cplusplus |
| 21 |
|
| } |
| 22 |
|
| #endif |
| 23 |
|
| |
| 24 |
|
| #ifdef PERL_OBJECT |
| 25 |
|
| #define CALLOP this->*PL_op |
| 26 |
|
| #else |
| 27 |
|
| #define CALLOP *PL_op |
| 28 |
|
| #endif |
| 29 |
|
| |
| 30 |
|
| #ifndef START_MY_CXT |
| 31 |
|
| /* No threads in 5.6 */ |
| 32 |
|
| #define START_MY_CXT static my_cxt_t my_cxt; |
| 33 |
|
| #define dMY_CXT_SV dNOOP |
| 34 |
|
| #define dMY_CXT dNOOP |
| 35 |
|
| #define MY_CXT_INIT NOOP |
| 36 |
|
| #define MY_CXT my_cxt |
| 37 |
|
| |
| 38 |
|
| #define pMY_CXT void |
| 39 |
|
| #define pMY_CXT_ |
| 40 |
|
| #define _pMY_CXT |
| 41 |
|
| #define aMY_CXT |
| 42 |
|
| #define aMY_CXT_ |
| 43 |
|
| #define _aMY_CXT |
| 44 |
|
| #endif |
| 45 |
|
| |
| 46 |
|
| #define MY_CXT_KEY "Devel::Cover::_guts" XS_VERSION |
| 47 |
|
| |
| 48 |
|
| #define PDEB(a) a |
| 49 |
|
| #define NDEB(a) ; /* if change to a, comment defining PERL_NO_GET_CONTEXT */ |
| 50 |
|
| #define D PerlIO_printf |
| 51 |
|
| #define L Perl_debug_log |
| 52 |
|
| #define svdump(sv) do_sv_dump(0, L, (SV *)sv, 0, 10, 1, 0); |
| 53 |
|
| |
| 54 |
|
| #define None 0x00000000 |
| 55 |
|
| #define Statement 0x00000001 |
| 56 |
|
| #define Branch 0x00000002 |
| 57 |
|
| #define Condition 0x00000004 |
| 58 |
|
| #define Subroutine 0x00000008 |
| 59 |
|
| #define Path 0x00000010 |
| 60 |
|
| #define Pod 0x00000020 |
| 61 |
|
| #define Time 0x00000040 |
| 62 |
|
| #define All 0xffffffff |
| 63 |
|
| |
| 64 |
|
| #if defined HAS_GETTIMEOFDAY || defined HAS_TIMES |
| 65 |
|
| # define CAN_PROFILE 1 |
| 66 |
|
| #else |
| 67 |
|
| # define CAN_PROFILE 0 |
| 68 |
|
| #endif |
| 69 |
|
| |
| 70 |
|
| struct unique { /* Well, we'll be fairly unlucky if it's not */ |
| 71 |
|
| OP *addr, |
| 72 |
|
| op; |
| 73 |
|
| /* include hashed file location information, where available (cops) */ |
| 74 |
|
| size_t fileinfohash; |
| 75 |
|
| }; |
| 76 |
|
| |
| 77 |
|
| #define KEY_SZ sizeof(struct unique) |
| 78 |
|
| |
| 79 |
|
| typedef struct { |
| 80 |
|
| unsigned covering; |
| 81 |
|
| int collecting_here; |
| 82 |
|
| HV *cover, |
| 83 |
|
| *statements, |
| 84 |
|
| *branches, |
| 85 |
|
| *conditions, |
| 86 |
|
| #if CAN_PROFILE |
| 87 |
|
| *times, |
| 88 |
|
| #endif |
| 89 |
|
| *modules, |
| 90 |
|
| *files; |
| 91 |
|
| AV *ends; |
| 92 |
|
| char profiling_key[KEY_SZ]; |
| 93 |
|
| bool profiling_key_valid; |
| 94 |
|
| SV *module, |
| 95 |
|
| *lastfile; |
| 96 |
|
| int tid; |
| 97 |
|
| int replace_ops; |
| 98 |
|
| /* - fix up whatever is broken with module_relative on Windows here */ |
| 99 |
|
| |
| 100 |
|
| Perl_ppaddr_t ppaddr[MAXO]; |
| 101 |
|
| } my_cxt_t; |
| 102 |
|
| |
| 103 |
|
| #ifdef USE_ITHREADS |
| 104 |
|
| static perl_mutex DC_mutex; |
| 105 |
|
| #endif |
| 106 |
|
| |
| 107 |
|
| static HV *Pending_conditionals, |
| 108 |
|
| *Return_ops; |
| 109 |
|
| static int tid; |
| 110 |
|
| |
| 111 |
|
| START_MY_CXT |
| 112 |
|
| |
| 113 |
|
| #define collecting(criterion) (MY_CXT.covering & (criterion)) |
| 114 |
|
| |
| 115 |
|
| #ifdef HAS_GETTIMEOFDAY |
| 116 |
|
| |
| 117 |
|
| #ifdef __cplusplus |
| 118 |
|
| extern "C" { |
| 119 |
|
| #endif |
| 120 |
|
| |
| 121 |
|
| #ifdef WIN32 |
| 122 |
|
| #include <time.h> |
| 123 |
|
| #else |
| 124 |
|
| #include <sys/time.h> |
| 125 |
|
| #endif |
| 126 |
|
| |
| 127 |
|
| #ifdef __cplusplus |
| 128 |
|
| } |
| 129 |
|
| #endif |
| 130 |
|
| |
| 131 |
|
| /* op->op_sibling is deprecated on new perls, but the OpSIBLING macro doesn't |
| 132 |
|
| exist on older perls. We don't need to check for PERL_OP_PARENT here |
| 133 |
|
| because if PERL_OP_PARENT was set, and we needed to check op_moresib, |
| 134 |
|
| we would already have this macro. */ |
| 135 |
|
| #ifndef OpSIBLING |
| 136 |
|
| #define OpSIBLING(o) (0 + (o)->op_sibling) |
| 137 |
|
| #endif |
| 138 |
|
| |
| 139 |
1011 |
| static double get_elapsed() { |
| 140 |
|
| #ifdef WIN32 |
| 141 |
|
| dTHX; |
| 142 |
|
| #endif |
| 143 |
|
| struct timeval time; |
| 144 |
|
| double e; |
| 145 |
|
| |
| 146 |
1011 |
| gettimeofday(&time, NULL); |
| 147 |
1011 |
| e = time.tv_sec * 1e6 + time.tv_usec; |
| 148 |
|
| |
| 149 |
1011 |
| return e; |
| 150 |
|
| } |
| 151 |
|
| |
| 152 |
671 |
| static double elapsed() { |
| 153 |
|
| static double p; |
| 154 |
|
| double e, t; |
| 155 |
|
| |
| 156 |
671 |
| t = get_elapsed(); |
| 157 |
671 |
| e = t - p; |
| 158 |
671 |
| p = t; |
| 159 |
|
| |
| 160 |
671 |
| return e; |
| 161 |
|
| } |
| 162 |
|
| |
| 163 |
|
| #elif defined HAS_TIMES |
| 164 |
|
| |
| 165 |
|
| #ifndef HZ |
| 166 |
|
| # ifdef CLK_TCK |
| 167 |
|
| # define HZ CLK_TCK |
| 168 |
|
| # else |
| 169 |
|
| # define HZ 60 |
| 170 |
|
| # endif |
| 171 |
|
| #endif |
| 172 |
|
| |
| 173 |
|
| static int cpu() { |
| 174 |
|
| #ifdef WIN32 |
| 175 |
|
| dTHX; |
| 176 |
|
| #endif |
| 177 |
|
| static struct tms time; |
| 178 |
|
| static int utime = 0, |
| 179 |
|
| stime = 0; |
| 180 |
|
| int e; |
| 181 |
|
| |
| 182 |
|
| #ifndef VMS |
| 183 |
|
| (void)PerlProc_times(&time); |
| 184 |
|
| #else |
| 185 |
|
| (void)PerlProc_times((tbuffer_t *)&time); |
| 186 |
|
| #endif |
| 187 |
|
| |
| 188 |
|
| e = time.tms_utime - utime + time.tms_stime - stime; |
| 189 |
|
| utime = time.tms_utime; |
| 190 |
|
| stime = time.tms_stime; |
| 191 |
|
| |
| 192 |
|
| return e / HZ; |
| 193 |
|
| } |
| 194 |
|
| |
| 195 |
|
| #endif /* HAS_GETTIMEOFDAY */ |
| 196 |
|
| |
| 197 |
|
| /* |
| 198 |
|
| * https://codereview.stackexchange.com/questions/85556/simple-string-hashing-algorithm-implementation |
| 199 |
|
| * https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function |
| 200 |
|
| * http://www.isthe.com/chongo/tech/comp/fnv/index.html#public_domain |
| 201 |
|
| * |
| 202 |
|
| * FNV hash algorithms and source code have been released into the |
| 203 |
|
| * public domain. The authors of the FNV algorithm took deliberate |
| 204 |
|
| * steps to disclose the algorithm in a public forum soon after it was |
| 205 |
|
| * invented. More than a year passed after this public disclosure and the |
| 206 |
|
| * authors deliberately took no steps to patent the FNV algorithm. Therefore |
| 207 |
|
| * it is safe to say that the FNV authors have no patent claims on the FNV |
| 208 |
|
| * algorithm as published. |
| 209 |
|
| * |
| 210 |
|
| */ |
| 211 |
|
| |
| 212 |
|
| /* Fowler/Noll/Vo (FNV) hash function, variant 1a */ |
| 213 |
4184866379 |
| static size_t fnv1a_hash(const char* cp) |
| 214 |
|
| { |
| 215 |
4184866379 |
| size_t hash = 0x811c9dc5; |
| 216 |
250609228098 |
▶ | while (*cp) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (*cp) { |
246424361719 |
4184866379 |
250609228098 |
|
| 217 |
246424361719 |
| hash ^= (unsigned char) *cp++; |
| 218 |
246424361719 |
| hash *= 0x01000193; |
| 219 |
|
| } |
| 220 |
4184866379 |
| return hash; |
| 221 |
|
| } |
| 222 |
|
| |
| 223 |
|
| #define FILEINFOSZ 1024 |
| 224 |
|
| |
| 225 |
7084461038 |
| static char *get_key(OP *o) { |
| 226 |
|
| static struct unique uniq; |
| 227 |
|
| static char mybuf[FILEINFOSZ]; |
| 228 |
|
| |
| 229 |
7084461038 |
| uniq.addr = o; |
| 230 |
7084461038 |
| uniq.op = *o; |
| 231 |
7084461038 |
| uniq.op.op_ppaddr = 0; /* we mess with this field */ |
| 232 |
7084461038 |
| uniq.op.op_targ = 0; /* might change */ |
| 233 |
7084461038 |
▶ | if (o->op_type == OP_NEXTSTATE || o->op_type == OP_DBSTATE) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (o->op_type == OP_NEXTSTATE || o->op_type == OP_DBSTATE) { |
2899594659 |
4184866379 |
7084461038 |
| if (o->op_type == OP_NEXTSTATE || o->op_type == OP_DBSTATE) { |
0 |
2899594659 |
2899594659 |
|
| 234 |
|
| /* cop, has file location information */ |
| 235 |
4184866379 |
▶ | char *file = CopFILE((COP *)o); |
Branch: 1 branch
| Branch | True | False | Total |
| char *file = CopFILE((COP *)o); |
4184866379 |
0 |
4184866379 |
|
| 236 |
4184866379 |
| long line = CopLINE((COP *)o); |
| 237 |
4184866379 |
| snprintf(mybuf, FILEINFOSZ - 1, "%s:%ld", file, line); |
| 238 |
4184866379 |
| uniq.fileinfohash = fnv1a_hash(mybuf); |
| 239 |
|
| } else { |
| 240 |
|
| /* no file location information available */ |
| 241 |
2899594659 |
| uniq.fileinfohash = 0; |
| 242 |
|
| } |
| 243 |
|
| |
| 244 |
7084461038 |
| return (char *)&uniq; |
| 245 |
|
| } |
| 246 |
|
| |
| 247 |
0 |
| static char *hex_key(char *key) { |
| 248 |
|
| static char hk[KEY_SZ * 2 + 1]; |
| 249 |
|
| size_t c; |
| 250 |
0 |
▶ | for (c = 0; c < KEY_SZ; c++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (c = 0; c < KEY_SZ; c++) { |
0 |
0 |
0 |
|
| 251 |
|
| NDEB(D(L, "%zu of %zu, <%02X> at %p\n", |
| 252 |
|
| c, KEY_SZ, (unsigned char)key[c], hk + c * 2)); |
| 253 |
0 |
| sprintf(hk + c * 2, "%02X", (unsigned char)key[c]); |
| 254 |
|
| } |
| 255 |
0 |
| hk[c * 2] = 0; |
| 256 |
0 |
| return hk; |
| 257 |
|
| } |
| 258 |
|
| |
| 259 |
340 |
| static void set_firsts_if_needed(pTHX) { |
| 260 |
340 |
| SV *init = (SV *)get_cv("Devel::Cover::first_init", 0); |
| 261 |
340 |
| SV *end = (SV *)get_cv("Devel::Cover::first_end", 0); |
| 262 |
|
| NDEB(svdump(end)); |
| 263 |
340 |
▶ | if (PL_initav && av_len(PL_initav) >= 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (PL_initav && av_len(PL_initav) >= 0) |
340 |
0 |
340 |
| if (PL_initav && av_len(PL_initav) >= 0) |
320 |
20 |
340 |
|
| 264 |
|
| { |
| 265 |
320 |
| SV **cv = av_fetch(PL_initav, 0, 0); |
| 266 |
320 |
▶ | if (*cv != init) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*cv != init) { |
170 |
150 |
320 |
|
| 267 |
170 |
| av_unshift(PL_initav, 1); |
| 268 |
170 |
| av_store(PL_initav, 0, init); |
| 269 |
|
| } |
| 270 |
|
| } |
| 271 |
340 |
▶ | if (PL_endav && av_len(PL_endav) >= 0) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (PL_endav && av_len(PL_endav) >= 0) { |
340 |
0 |
340 |
| if (PL_endav && av_len(PL_endav) >= 0) { |
340 |
0 |
340 |
|
| 272 |
340 |
| SV **cv = av_fetch(PL_endav, 0, 0); |
| 273 |
340 |
▶ | if (*cv != end) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (*cv != end) { |
171 |
169 |
340 |
|
| 274 |
171 |
| av_unshift(PL_endav, 1); |
| 275 |
171 |
| av_store(PL_endav, 0, end); |
| 276 |
|
| } |
| 277 |
|
| } |
| 278 |
340 |
| } |
| 279 |
|
| |
| 280 |
3664257223 |
| static int check_if_collecting(pTHX_ COP *cop) { |
| 281 |
|
| dMY_CXT; |
| 282 |
|
| |
| 283 |
|
| #if !NO_TAINT_SUPPORT |
| 284 |
3664257223 |
| int tainted = PL_tainted; |
| 285 |
|
| #endif |
| 286 |
3664257223 |
▶ | char *file = CopFILE(cop); |
Branch: 1 branch
| Branch | True | False | Total |
| char *file = CopFILE(cop); |
3664257223 |
0 |
3664257223 |
|
| 287 |
3664257223 |
| int in_re_eval = strnEQ(file, "(reeval ", 8); |
| 288 |
|
| NDEB(D(L, "check_if_collecting at: %s:%ld\n", file, (long)CopLINE(cop))); |
| 289 |
7328514446 |
▶ | if (file && strNE(SvPV_nolen(MY_CXT.lastfile), file)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (file && strNE(SvPV_nolen(MY_CXT.lastfile), file)) { |
3664257223 |
0 |
3664257223 |
| if (file && strNE(SvPV_nolen(MY_CXT.lastfile), file)) { |
11110463 |
3653146760 |
3664257223 |
|
| 290 |
11110463 |
| int found = 0; |
| 291 |
11110463 |
▶ | if (MY_CXT.files) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (MY_CXT.files) { |
11110463 |
0 |
11110463 |
|
| 292 |
11110463 |
| SV **f = hv_fetch(MY_CXT.files, file, strlen(file), 0); |
| 293 |
11110463 |
▶ | if (f) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (f) { |
7406684 |
3703779 |
11110463 |
|
| 294 |
7406684 |
| MY_CXT.collecting_here = SvIV(*f); |
| 295 |
7406684 |
| found = 1; |
| 296 |
|
| NDEB(D(L, "File: %s:%ld [%d]\n", |
| 297 |
|
| file, (long)CopLINE(cop), MY_CXT.collecting_here)); |
| 298 |
|
| } |
| 299 |
|
| } |
| 300 |
|
| |
| 301 |
11110463 |
▶ | if (!found && MY_CXT.replace_ops && !in_re_eval) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (!found && MY_CXT.replace_ops && !in_re_eval) { |
3703779 |
7406684 |
11110463 |
| if (!found && MY_CXT.replace_ops && !in_re_eval) { |
3703779 |
0 |
3703779 |
| if (!found && MY_CXT.replace_ops && !in_re_eval) { |
3703779 |
0 |
3703779 |
|
| 302 |
3703779 |
| dSP; |
| 303 |
|
| int count; |
| 304 |
|
| SV *rv; |
| 305 |
|
| |
| 306 |
3703779 |
| ENTER; |
| 307 |
3703779 |
| SAVETMPS; |
| 308 |
|
| |
| 309 |
3703779 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
3703779 |
3703779 |
|
| 310 |
3703779 |
▶ | XPUSHs(sv_2mortal(newSVpv(file, 0))); |
Branch: 1 branch
| Branch | True | False | Total |
| XPUSHs(sv_2mortal(newSVpv(file, 0))); |
0 |
3703779 |
3703779 |
|
| 311 |
3703779 |
| PUTBACK; |
| 312 |
|
| |
| 313 |
3703779 |
| count = call_pv("Devel::Cover::use_file", G_SCALAR); |
| 314 |
|
| |
| 315 |
3703779 |
| SPAGAIN; |
| 316 |
|
| |
| 317 |
3703779 |
▶ | if (count != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (count != 1) |
0 |
3703779 |
3703779 |
|
| 318 |
0 |
| croak("use_file returned %d values\n", count); |
| 319 |
|
| |
| 320 |
3703779 |
| rv = POPs; |
| 321 |
3703779 |
| MY_CXT.collecting_here = SvTRUE(rv) ? 1 : 0; |
| 322 |
|
| |
| 323 |
|
| NDEB(D(L, "-- %s - %d\n", file, MY_CXT.collecting_here)); |
| 324 |
|
| |
| 325 |
3703779 |
| PUTBACK; |
| 326 |
3703779 |
▶ | FREETMPS; |
Branch: 1 branch
| Branch | True | False | Total |
| FREETMPS; |
3703779 |
0 |
3703779 |
|
| 327 |
3703779 |
| LEAVE; |
| 328 |
|
| } |
| 329 |
|
| |
| 330 |
11110463 |
| sv_setpv(MY_CXT.lastfile, file); |
| 331 |
|
| } |
| 332 |
|
| NDEB(D(L, "%s - %d\n", |
| 333 |
|
| SvPV_nolen(MY_CXT.lastfile), MY_CXT.collecting_here)); |
| 334 |
|
| |
| 335 |
3664257223 |
▶ | if (SvTRUE(MY_CXT.module)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvTRUE(MY_CXT.module)) { |
170 |
3664257053 |
3664257223 |
|
| 336 |
|
| STRLEN mlen, |
| 337 |
170 |
| flen = strlen(file); |
| 338 |
170 |
| char *m = SvPV(MY_CXT.module, mlen); |
| 339 |
170 |
▶ | if (flen >= mlen && strnEQ(m, file + flen - mlen, mlen)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (flen >= mlen && strnEQ(m, file + flen - mlen, mlen)) { |
166 |
4 |
170 |
| if (flen >= mlen && strnEQ(m, file + flen - mlen, mlen)) { |
70 |
96 |
166 |
|
| 340 |
70 |
| SV **dir = hv_fetch(MY_CXT.modules, file, strlen(file), 1); |
| 341 |
70 |
▶ | if (!SvROK(*dir)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvROK(*dir)) { |
70 |
0 |
70 |
|
| 342 |
70 |
| SV *cwd = newSV(0); |
| 343 |
70 |
| AV *d = newAV(); |
| 344 |
70 |
| *dir = newRV_inc((SV*) d); |
| 345 |
70 |
| av_push(d, newSVsv(MY_CXT.module)); |
| 346 |
70 |
▶ | if (getcwd_sv(cwd)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (getcwd_sv(cwd)) { |
70 |
0 |
70 |
|
| 347 |
70 |
| av_push(d, newSVsv(cwd)); |
| 348 |
|
| NDEB(D(L, "require %s as %s from %s\n", |
| 349 |
|
| m, file, SvPV_nolen(cwd))); |
| 350 |
|
| } |
| 351 |
|
| } |
| 352 |
|
| } |
| 353 |
170 |
| sv_setpv(MY_CXT.module, ""); |
| 354 |
170 |
| set_firsts_if_needed(aTHX); |
| 355 |
|
| } |
| 356 |
|
| |
| 357 |
|
| #if !NO_TAINT_SUPPORT |
| 358 |
3664257223 |
| PL_tainted = tainted; |
| 359 |
|
| #endif |
| 360 |
3664257223 |
| return MY_CXT.collecting_here; |
| 361 |
|
| } |
| 362 |
|
| |
| 363 |
|
| #if CAN_PROFILE |
| 364 |
|
| |
| 365 |
3553900896 |
| static void cover_time(pTHX) |
| 366 |
|
| { |
| 367 |
|
| dMY_CXT; |
| 368 |
|
| SV **count; |
| 369 |
|
| NV c; |
| 370 |
|
| |
| 371 |
3553900896 |
▶ | if (collecting(Time)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (collecting(Time)) { |
3530546726 |
23354170 |
3553900896 |
|
| 372 |
|
| /* |
| 373 |
|
| * Profiling information is stored against MY_CXT.profiling_key, |
| 374 |
|
| * the key for the op we have just run |
| 375 |
|
| */ |
| 376 |
|
| |
| 377 |
|
| NDEB(D(L, "Cop at %p, op at %p\n", PL_curcop, PL_op)); |
| 378 |
|
| |
| 379 |
3530546726 |
▶ | if (MY_CXT.profiling_key_valid) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (MY_CXT.profiling_key_valid) { |
501 |
3530546225 |
3530546726 |
|
| 380 |
501 |
| count = hv_fetch(MY_CXT.times, MY_CXT.profiling_key, KEY_SZ, 1); |
| 381 |
501 |
▶ | c = (SvTRUE(*count) ? SvNV(*count) : 0) + |
Branch: 1 branch
| Branch | True | False | Total |
| c = (SvTRUE(*count) ? SvNV(*count) : 0) + |
0 |
501 |
501 |
|
| 382 |
|
| #if defined HAS_GETTIMEOFDAY |
| 383 |
501 |
| elapsed(); |
| 384 |
|
| #else |
| 385 |
|
| cpu(); |
| 386 |
|
| #endif |
| 387 |
501 |
| sv_setnv(*count, c); |
| 388 |
|
| } |
| 389 |
3530546726 |
▶ | if (PL_op) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (PL_op) { |
3530546726 |
0 |
3530546726 |
|
| 390 |
3530546726 |
| memcpy(MY_CXT.profiling_key, get_key(PL_op), KEY_SZ); |
| 391 |
3530546726 |
| MY_CXT.profiling_key_valid = 1; |
| 392 |
|
| } else { |
| 393 |
0 |
| MY_CXT.profiling_key_valid = 0; |
| 394 |
|
| } |
| 395 |
|
| } |
| 396 |
3553900896 |
| } |
| 397 |
|
| |
| 398 |
|
| #endif |
| 399 |
|
| |
| 400 |
3553902839 |
| static int collecting_here(pTHX) { |
| 401 |
|
| dMY_CXT; |
| 402 |
|
| |
| 403 |
3553902839 |
▶ | if (MY_CXT.collecting_here) return 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (MY_CXT.collecting_here) return 1; |
6742 |
3553896097 |
3553902839 |
|
| 404 |
|
| |
| 405 |
|
| #if CAN_PROFILE |
| 406 |
3553896097 |
| cover_time(aTHX); |
| 407 |
3553896097 |
| MY_CXT.profiling_key_valid = 0; |
| 408 |
|
| #endif |
| 409 |
|
| |
| 410 |
|
| NDEB(D(L, "op %p is %s\n", PL_op, OP_NAME(PL_op))); |
| 411 |
3553896097 |
▶ | if (hv_exists(Return_ops, get_key(PL_op), KEY_SZ)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists(Return_ops, get_key(PL_op), KEY_SZ)) |
0 |
3553896097 |
3553896097 |
|
| 412 |
0 |
| return MY_CXT.collecting_here = 1; |
| 413 |
|
| else |
| 414 |
3553896097 |
| return 0; |
| 415 |
|
| } |
| 416 |
|
| |
| 417 |
80601466 |
| static void store_return(pTHX) { |
| 418 |
|
| dMY_CXT; |
| 419 |
|
| |
| 420 |
|
| /* |
| 421 |
|
| * If we are jumping somewhere we might not be collecting |
| 422 |
|
| * coverage there, so store where we will be coming back to |
| 423 |
|
| * so we can turn on coverage straight away. We need to |
| 424 |
|
| * store more than one return op because a non collecting |
| 425 |
|
| * sub may call back to a collecting sub. |
| 426 |
|
| */ |
| 427 |
|
| |
| 428 |
80601466 |
▶ | if (MY_CXT.collecting_here && PL_op->op_next) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (MY_CXT.collecting_here && PL_op->op_next) { |
4762 |
80596704 |
80601466 |
| if (MY_CXT.collecting_here && PL_op->op_next) { |
476 |
4286 |
4762 |
|
| 429 |
476 |
| (void)hv_fetch(Return_ops, get_key(PL_op->op_next), KEY_SZ, 1); |
| 430 |
|
| NDEB(D(L, "adding return op %p\n", PL_op->op_next)); |
| 431 |
|
| } |
| 432 |
80601466 |
| } |
| 433 |
|
| |
| 434 |
170 |
| static void store_module(pTHX) { |
| 435 |
|
| dMY_CXT; |
| 436 |
170 |
| dSP; |
| 437 |
|
| |
| 438 |
340 |
▶ | SvSetSV_nosteal(MY_CXT.module, (SV*)newSVpv(SvPV_nolen(TOPs), 0)); |
Branch: 1 branch
| Branch | True | False | Total |
| SvSetSV_nosteal(MY_CXT.module, (SV*)newSVpv(SvPV_nolen(TOPs), 0)); |
170 |
0 |
170 |
|
| 439 |
|
| NDEB(D(L, "require %s\n", SvPV_nolen(MY_CXT.module))); |
| 440 |
170 |
| } |
| 441 |
|
| |
| 442 |
0 |
| static void call_report(pTHX) { |
| 443 |
0 |
| dSP; |
| 444 |
0 |
▶ | PUSHMARK(SP); |
Branch: 1 branch
| Branch | True | False | Total |
| PUSHMARK(SP); |
0 |
0 |
0 |
|
| 445 |
0 |
| call_pv("Devel::Cover::report", G_VOID|G_DISCARD|G_EVAL); |
| 446 |
0 |
| SPAGAIN; |
| 447 |
0 |
| } |
| 448 |
|
| |
| 449 |
13968 |
| static void cover_statement(pTHX_ OP *op) { |
| 450 |
|
| dMY_CXT; |
| 451 |
|
| |
| 452 |
|
| char *ch; |
| 453 |
|
| SV **count; |
| 454 |
|
| IV c; |
| 455 |
|
| |
| 456 |
13968 |
▶ | if (!collecting(Statement)) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!collecting(Statement)) return; |
1818 |
12150 |
13968 |
|
| 457 |
|
| |
| 458 |
12150 |
| ch = get_key(op); |
| 459 |
12150 |
| count = hv_fetch(MY_CXT.statements, ch, KEY_SZ, 1); |
| 460 |
12150 |
▶ | c = SvTRUE(*count) ? SvIV(*count) + 1 : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| c = SvTRUE(*count) ? SvIV(*count) + 1 : 1; |
4355 |
7795 |
12150 |
|
| 461 |
|
| |
| 462 |
|
| NDEB(D(L, "Statement: %s:%ld\n", CopFILE(cCOPx(op)), (long)CopLINE(cCOPx(op)))); |
| 463 |
|
| |
| 464 |
12150 |
| sv_setiv(*count, c); |
| 465 |
|
| NDEB(op_dump(op)); |
| 466 |
|
| } |
| 467 |
|
| |
| 468 |
4799 |
| static void cover_current_statement(pTHX) { |
| 469 |
|
| #if CAN_PROFILE |
| 470 |
4799 |
| cover_time(aTHX); |
| 471 |
|
| #endif |
| 472 |
|
| |
| 473 |
4799 |
| cover_statement(aTHX_ PL_op); |
| 474 |
4799 |
| } |
| 475 |
|
| |
| 476 |
157 |
| static void add_branch(pTHX_ OP *op, int br) { |
| 477 |
|
| dMY_CXT; |
| 478 |
|
| |
| 479 |
|
| AV *branches; |
| 480 |
|
| SV **count; |
| 481 |
|
| int c; |
| 482 |
157 |
| SV **tmp = hv_fetch(MY_CXT.branches, get_key(op), KEY_SZ, 1); |
| 483 |
|
| |
| 484 |
157 |
▶ | if (SvROK(*tmp)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(*tmp)) { |
117 |
40 |
157 |
|
| 485 |
117 |
| branches = (AV *) SvRV(*tmp); |
| 486 |
|
| } else { |
| 487 |
40 |
| *tmp = newRV_inc((SV*) (branches = newAV())); |
| 488 |
40 |
| av_unshift(branches, 2); |
| 489 |
|
| } |
| 490 |
|
| |
| 491 |
157 |
| count = av_fetch(branches, br, 1); |
| 492 |
157 |
▶ | c = SvTRUE(*count) ? SvIV(*count) + 1 : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| c = SvTRUE(*count) ? SvIV(*count) + 1 : 1; |
109 |
48 |
157 |
|
| 493 |
157 |
| sv_setiv(*count, c); |
| 494 |
|
| NDEB(D(L, "Adding branch making %d at %p\n", c, op)); |
| 495 |
157 |
| } |
| 496 |
|
| |
| 497 |
2446 |
| static AV *get_conditional_array(pTHX_ OP *op) { |
| 498 |
|
| dMY_CXT; |
| 499 |
|
| |
| 500 |
|
| AV *conds; |
| 501 |
2446 |
| SV **cref = hv_fetch(MY_CXT.conditions, get_key(op), KEY_SZ, 1); |
| 502 |
|
| |
| 503 |
2446 |
▶ | if (SvROK(*cref)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(*cref)) |
2213 |
233 |
2446 |
|
| 504 |
2213 |
| conds = (AV *) SvRV(*cref); |
| 505 |
|
| else |
| 506 |
233 |
| *cref = newRV_inc((SV*) (conds = newAV())); |
| 507 |
|
| |
| 508 |
2446 |
| return conds; |
| 509 |
|
| } |
| 510 |
|
| |
| 511 |
1094 |
| static void set_conditional(pTHX_ OP *op, int cond, int value) { |
| 512 |
|
| /* |
| 513 |
|
| * The conditional array is composed of six elements: |
| 514 |
|
| * |
| 515 |
|
| * 0 - 1 iff we are in an xor and the first operand was true |
| 516 |
|
| * 1 - not short circuited - second operand is false |
| 517 |
|
| * 2 - not short circuited - second operand is true |
| 518 |
|
| * 3 - short circuited, or for xor second operand is false |
| 519 |
|
| * 4 - for xor second operand is true |
| 520 |
|
| * 5 - 1 iff we are in void context |
| 521 |
|
| */ |
| 522 |
|
| |
| 523 |
1094 |
| SV **count = av_fetch(get_conditional_array(aTHX_ op), cond, 1); |
| 524 |
1094 |
| sv_setiv(*count, value); |
| 525 |
|
| NDEB(D(L, "Setting %d conditional to %d at %p\n", cond, value, op)); |
| 526 |
1094 |
| } |
| 527 |
|
| |
| 528 |
1074 |
| static void add_conditional(pTHX_ OP *op, int cond) { |
| 529 |
1074 |
| SV **count = av_fetch(get_conditional_array(aTHX_ op), cond, 1); |
| 530 |
964 |
▶ | int true_ish = (op->op_type == OP_DOR || op->op_type == OP_DORASSIGN) |
Branch: 1 branch
| Branch | True | False | Total |
| int true_ish = (op->op_type == OP_DOR || op->op_type == OP_DORASSIGN) |
112 |
852 |
964 |
|
| 531 |
2038 |
▶ | ? SvOK(*count) : SvTRUE(*count); |
Branch: 1 branch
| Branch | True | False | Total |
| ? SvOK(*count) : SvTRUE(*count); |
964 |
110 |
1074 |
|
| 532 |
1074 |
▶ | int c = true_ish ? SvIV(*count) + 1 : 1; |
Branch: 1 branch
| Branch | True | False | Total |
| int c = true_ish ? SvIV(*count) + 1 : 1; |
750 |
324 |
1074 |
|
| 533 |
1074 |
| sv_setiv(*count, c); |
| 534 |
|
| NDEB(D(L, "Adding %d conditional making %d at %p\n", cond, c, op)); |
| 535 |
1074 |
| } |
| 536 |
|
| |
| 537 |
|
| #ifdef USE_ITHREADS |
| 538 |
|
| static AV *get_conds(pTHX_ AV *conds) { |
| 539 |
|
| dMY_CXT; |
| 540 |
|
| |
| 541 |
|
| AV *thrconds; |
| 542 |
|
| HV *threads; |
| 543 |
|
| SV *tid, |
| 544 |
|
| **cref; |
| 545 |
|
| char *t; |
| 546 |
|
| |
| 547 |
|
| if (av_exists(conds, 2)) { |
| 548 |
|
| SV **cref = av_fetch(conds, 2, 0); |
| 549 |
|
| threads = (HV *) *cref; |
| 550 |
|
| } else { |
| 551 |
|
| threads = newHV(); |
| 552 |
|
| HvSHAREKEYS_off(threads); |
| 553 |
|
| av_store(conds, 2, (SV *)threads); |
| 554 |
|
| } |
| 555 |
|
| |
| 556 |
|
| tid = newSViv(MY_CXT.tid); |
| 557 |
|
| |
| 558 |
|
| t = SvPV_nolen(tid); |
| 559 |
|
| cref = hv_fetch(threads, t, strlen(t), 1); |
| 560 |
|
| |
| 561 |
|
| if (SvROK(*cref)) |
| 562 |
|
| thrconds = (AV *)SvRV(*cref); |
| 563 |
|
| else |
| 564 |
|
| *cref = newRV_inc((SV*) (thrconds = newAV())); |
| 565 |
|
| |
| 566 |
|
| return thrconds; |
| 567 |
|
| } |
| 568 |
|
| #endif |
| 569 |
|
| |
| 570 |
347 |
| static void add_condition(pTHX_ SV *cond_ref, int value) { |
| 571 |
347 |
| int final = !value; |
| 572 |
347 |
| AV *conds = (AV *) SvRV(cond_ref); |
| 573 |
347 |
| OP *next = INT2PTR(OP *, SvIV(*av_fetch(conds, 0, 0))); |
| 574 |
347 |
| OP *(*addr)(pTHX) = INT2PTR(OP *(*)(pTHX), SvIV(*av_fetch(conds, 1, 0))); |
| 575 |
|
| I32 i; |
| 576 |
|
| |
| 577 |
347 |
▶ | if (!final && next != PL_op) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!final && next != PL_op) |
278 |
69 |
347 |
| if (!final && next != PL_op) |
0 |
278 |
278 |
|
| 578 |
0 |
| croak("next (%p) does not match PL_op (%p)", next, PL_op); |
| 579 |
|
| |
| 580 |
|
| #ifdef USE_ITHREADS |
| 581 |
|
| i = 0; |
| 582 |
|
| conds = get_conds(aTHX_ conds); |
| 583 |
|
| #else |
| 584 |
347 |
| i = 2; |
| 585 |
|
| #endif |
| 586 |
|
| NDEB(D(L, "Looking through %zd conditionals at %p\n", |
| 587 |
|
| av_len(conds) - 1, PL_op)); |
| 588 |
625 |
▶ | for (; i <= av_len(conds); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (; i <= av_len(conds); i++) { |
278 |
347 |
625 |
|
| 589 |
278 |
| OP *op = INT2PTR(OP *, SvIV(*av_fetch(conds, i, 0))); |
| 590 |
278 |
| SV **count = av_fetch(get_conditional_array(aTHX_ op), 0, 1); |
| 591 |
221 |
▶ | int true_ish = (op->op_type == OP_DOR || op->op_type == OP_DORASSIGN) |
Branch: 1 branch
| Branch | True | False | Total |
| int true_ish = (op->op_type == OP_DOR || op->op_type == OP_DORASSIGN) |
2 |
219 |
221 |
|
| 592 |
499 |
▶ | ? SvOK(*count) : SvTRUE(*count); |
Branch: 1 branch
| Branch | True | False | Total |
| ? SvOK(*count) : SvTRUE(*count); |
221 |
57 |
278 |
|
| 593 |
278 |
▶ | int type = true_ish ? SvIV(*count) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| int type = true_ish ? SvIV(*count) : 0; |
94 |
184 |
278 |
|
| 594 |
278 |
| sv_setiv(*count, 0); |
| 595 |
|
| |
| 596 |
|
| /* Check if we have come from an xor with a true first op */ |
| 597 |
278 |
▶ | if (final) value = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if (final) value = 1; |
0 |
278 |
278 |
|
| 598 |
278 |
▶ | if (type == 1) value += 2; |
Branch: 1 branch
| Branch | True | False | Total |
| if (type == 1) value += 2; |
44 |
234 |
278 |
|
| 599 |
|
| |
| 600 |
|
| NDEB(D(L, "Found %p (trueish=%d): %d, %d\n", op, true_ish, type, value)); |
| 601 |
278 |
| add_conditional(aTHX_ op, value); |
| 602 |
|
| } |
| 603 |
|
| |
| 604 |
|
| #ifdef USE_ITHREADS |
| 605 |
|
| i = -1; |
| 606 |
|
| #else |
| 607 |
347 |
| i = 1; |
| 608 |
|
| #endif |
| 609 |
625 |
▶ | while (av_len(conds) > i) av_pop(conds); |
Branch: 1 branch
| Branch | True | False | Total |
| while (av_len(conds) > i) av_pop(conds); |
278 |
347 |
625 |
|
| 610 |
|
| |
| 611 |
|
| NDEB(svdump(conds)); |
| 612 |
|
| NDEB(D(L, "addr is %p, next is %p, PL_op is %p, length is %zd final is %d\n", |
| 613 |
|
| addr, next, PL_op, av_len(conds), final)); |
| 614 |
347 |
▶ | if (!final) next->op_ppaddr = addr; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!final) next->op_ppaddr = addr; |
278 |
69 |
347 |
|
| 615 |
347 |
| } |
| 616 |
|
| |
| 617 |
0 |
| static void dump_conditions(pTHX) { |
| 618 |
|
| HE *e; |
| 619 |
|
| |
| 620 |
|
| MUTEX_LOCK(&DC_mutex); |
| 621 |
0 |
| hv_iterinit(Pending_conditionals); |
| 622 |
0 |
| PDEB(D(L, "Pending_conditionals:\n")); |
| 623 |
|
| |
| 624 |
0 |
▶ | while ((e = hv_iternext(Pending_conditionals))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((e = hv_iternext(Pending_conditionals))) { |
0 |
0 |
0 |
|
| 625 |
|
| I32 len; |
| 626 |
0 |
| char *key = hv_iterkey(e, &len); |
| 627 |
0 |
| SV *cond_ref = hv_iterval(Pending_conditionals, e); |
| 628 |
0 |
| AV *conds = (AV *) SvRV(cond_ref); |
| 629 |
0 |
| OP *next = INT2PTR(OP *, SvIV(*av_fetch(conds, 0,0))); |
| 630 |
0 |
| OP *(*addr)(pTHX) = INT2PTR(OP *(*)(pTHX), SvIV(*av_fetch(conds, 1,0))); |
| 631 |
|
| I32 i; |
| 632 |
|
| |
| 633 |
|
| #ifdef USE_ITHREADS |
| 634 |
|
| i = 0; /* TODO - this can't be right */ |
| 635 |
|
| conds = get_conds(aTHX_ conds); |
| 636 |
|
| #else |
| 637 |
0 |
| i = 2; |
| 638 |
|
| #endif |
| 639 |
|
| |
| 640 |
0 |
| PDEB(D(L, " %s: op %p, next %p (%ld)\n", |
| 641 |
|
| hex_key(key), next, addr, (long)av_len(conds) - 1)); |
| 642 |
|
| |
| 643 |
0 |
▶ | for (; i <= av_len(conds); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (; i <= av_len(conds); i++) { |
0 |
0 |
0 |
|
| 644 |
0 |
| OP *op = INT2PTR(OP *, SvIV(*av_fetch(conds, i, 0))); |
| 645 |
0 |
| SV **count = av_fetch(get_conditional_array(aTHX_ op), 0, 1); |
| 646 |
0 |
▶ | int type = SvTRUE(*count) ? SvIV(*count) : 0; |
Branch: 1 branch
| Branch | True | False | Total |
| int type = SvTRUE(*count) ? SvIV(*count) : 0; |
0 |
0 |
0 |
|
| 647 |
0 |
| sv_setiv(*count, 0); |
| 648 |
|
| |
| 649 |
0 |
| PDEB(D(L, " %2d: %p, %d\n", i - 2, op, type)); |
| 650 |
|
| } |
| 651 |
|
| } |
| 652 |
|
| MUTEX_UNLOCK(&DC_mutex); |
| 653 |
0 |
| } |
| 654 |
|
| |
| 655 |
|
| #if PERL_VERSION > 18 |
| 656 |
|
| /* For if ($a || $b) and unless ($a && $b), rpeep skips past a few |
| 657 |
|
| * logops and messes with Devel::Cover |
| 658 |
|
| * |
| 659 |
|
| * This function will find the skipped op if there is one |
| 660 |
|
| */ |
| 661 |
555 |
| static OP *find_skipped_conditional(pTHX_ OP *o) { |
| 662 |
|
| OP *right, |
| 663 |
|
| *next; |
| 664 |
|
| |
| 665 |
555 |
▶ | if (o->op_type != OP_OR && o->op_type != OP_AND) |
Branch: 2 branches
| Branch | True | False | Total |
| if (o->op_type != OP_OR && o->op_type != OP_AND) |
416 |
139 |
555 |
| if (o->op_type != OP_OR && o->op_type != OP_AND) |
316 |
100 |
416 |
|
| 666 |
316 |
| return NULL; |
| 667 |
|
| |
| 668 |
|
| /* Get to the end of the "a || b || c" block */ |
| 669 |
239 |
▶ | right = OpSIBLING(cLOGOP->op_first); |
Branch: 1 branch
| Branch | True | False | Total |
| right = OpSIBLING(cLOGOP->op_first); |
239 |
0 |
239 |
|
| 670 |
239 |
▶ | while (right && OpSIBLING(cLOGOPx(right))) |
Branch: 3 branches
| Branch | True | False | Total |
| while (right && OpSIBLING(cLOGOPx(right))) |
239 |
0 |
239 |
| while (right && OpSIBLING(cLOGOPx(right))) |
0 |
239 |
239 |
| while (right && OpSIBLING(cLOGOPx(right))) |
0 |
0 |
0 |
|
| 671 |
0 |
▶ | right = OpSIBLING(cLOGOPx(right)); |
Branch: 1 branch
| Branch | True | False | Total |
| right = OpSIBLING(cLOGOPx(right)); |
0 |
0 |
0 |
|
| 672 |
|
| |
| 673 |
239 |
▶ | if (!right) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!right) |
0 |
239 |
239 |
|
| 674 |
0 |
| return NULL; |
| 675 |
|
| |
| 676 |
239 |
| next = right->op_next; |
| 677 |
242 |
▶ | while (next && next->op_type == OP_NULL) |
Branch: 2 branches
| Branch | True | False | Total |
| while (next && next->op_type == OP_NULL) |
242 |
0 |
242 |
| while (next && next->op_type == OP_NULL) |
3 |
239 |
242 |
|
| 678 |
3 |
| next = next->op_next; |
| 679 |
|
| |
| 680 |
239 |
▶ | if (!next) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!next) |
0 |
239 |
239 |
|
| 681 |
0 |
| return NULL; |
| 682 |
|
| |
| 683 |
239 |
▶ | if (o == next) |
Branch: 1 branch
| Branch | True | False | Total |
| if (o == next) |
1 |
238 |
239 |
|
| 684 |
1 |
| return NULL; |
| 685 |
|
| |
| 686 |
238 |
▶ | if (next->op_type != OP_OR && next->op_type != OP_AND) |
Branch: 2 branches
| Branch | True | False | Total |
| if (next->op_type != OP_OR && next->op_type != OP_AND) |
227 |
11 |
238 |
| if (next->op_type != OP_OR && next->op_type != OP_AND) |
212 |
15 |
227 |
|
| 687 |
212 |
| return NULL; |
| 688 |
|
| |
| 689 |
|
| /* if ($a || $b) or unless ($a && $b) */ |
| 690 |
26 |
▶ | if (o->op_type == next->op_type) |
Branch: 1 branch
| Branch | True | False | Total |
| if (o->op_type == next->op_type) |
24 |
2 |
26 |
|
| 691 |
24 |
| return NULL; |
| 692 |
|
| |
| 693 |
2 |
▶ | if ((next->op_flags & OPf_WANT) != OPf_WANT_VOID) |
Branch: 1 branch
| Branch | True | False | Total |
| if ((next->op_flags & OPf_WANT) != OPf_WANT_VOID) |
0 |
2 |
2 |
|
| 694 |
0 |
| return NULL; |
| 695 |
|
| |
| 696 |
2 |
▶ | if (!cLOGOPx(next)->op_other || !o->op_next) |
Branch: 2 branches
| Branch | True | False | Total |
| if (!cLOGOPx(next)->op_other || !o->op_next) |
2 |
0 |
2 |
| if (!cLOGOPx(next)->op_other || !o->op_next) |
0 |
2 |
2 |
|
| 697 |
0 |
| return NULL; |
| 698 |
|
| |
| 699 |
2 |
▶ | if (cLOGOPx(next)->op_other != o->op_next) |
Branch: 1 branch
| Branch | True | False | Total |
| if (cLOGOPx(next)->op_other != o->op_next) |
1 |
1 |
2 |
|
| 700 |
1 |
| return NULL; |
| 701 |
|
| |
| 702 |
1 |
| return next; |
| 703 |
|
| } |
| 704 |
|
| #endif |
| 705 |
|
| |
| 706 |
|
| /* NOTE: caller must protect get_condition* calls by locking DC_mutex */ |
| 707 |
276 |
| static OP *get_condition(pTHX) { |
| 708 |
276 |
| SV **pc = hv_fetch(Pending_conditionals, get_key(PL_op), KEY_SZ, 0); |
| 709 |
552 |
▶ | if (pc && SvROK(*pc)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (pc && SvROK(*pc)) { |
276 |
0 |
276 |
| if (pc && SvROK(*pc)) { |
276 |
0 |
276 |
|
| 710 |
276 |
| dSP; |
| 711 |
|
| int true_ish; |
| 712 |
|
| NDEB(D(L, "get_condition from %p, %p: %p (%s)\n", |
| 713 |
|
| PL_op, (void *)PL_op->op_targ, pc, hex_key(get_key(PL_op)))); |
| 714 |
|
| /* dump_conditions(aTHX); */ |
| 715 |
|
| NDEB(svdump(Pending_conditionals)); |
| 716 |
276 |
▶ | true_ish = (PL_op->op_type == OP_DOR || PL_op->op_type == OP_DORASSIGN) |
Branch: 1 branch
| Branch | True | False | Total |
| true_ish = (PL_op->op_type == OP_DOR || PL_op->op_type == OP_DORASSIGN) |
0 |
276 |
276 |
|
| 717 |
552 |
▶ | ? SvOK(TOPs) : SvTRUE(TOPs); |
Branch: 1 branch
| Branch | True | False | Total |
| ? SvOK(TOPs) : SvTRUE(TOPs); |
276 |
0 |
276 |
|
| 718 |
|
| NDEB(D(L, " get_condition true_ish=%d\n", true_ish)); |
| 719 |
276 |
▶ | add_condition(aTHX_ *pc, true_ish ? 2 : 1); |
Branch: 1 branch
| Branch | True | False | Total |
| add_condition(aTHX_ *pc, true_ish ? 2 : 1); |
137 |
139 |
276 |
|
| 720 |
|
| } else { |
| 721 |
0 |
| PDEB(D(L, "All is lost, I know not where to go from %p, %p: %p (%s)\n", |
| 722 |
|
| PL_op, (void *)PL_op->op_targ, pc, hex_key(get_key(PL_op)))); |
| 723 |
0 |
| dump_conditions(aTHX); |
| 724 |
|
| NDEB(svdump(Pending_conditionals)); |
| 725 |
0 |
| exit(1); |
| 726 |
|
| } |
| 727 |
276 |
| return PL_op; |
| 728 |
|
| } |
| 729 |
2 |
| static OP *get_condition_dor(pTHX) { |
| 730 |
2 |
| SV **pc = hv_fetch(Pending_conditionals, get_key(PL_op), KEY_SZ, 0); |
| 731 |
4 |
▶ | if (pc && SvROK(*pc)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (pc && SvROK(*pc)) { |
2 |
0 |
2 |
| if (pc && SvROK(*pc)) { |
2 |
0 |
2 |
|
| 732 |
2 |
| dSP; |
| 733 |
|
| int true_ish; |
| 734 |
|
| NDEB(D(L, "get_condition_dor from %p, %p: %p (%s)\n", |
| 735 |
|
| PL_op, (void *)PL_op->op_targ, pc, hex_key(get_key(PL_op)))); |
| 736 |
|
| /* dump_conditions(aTHX); */ |
| 737 |
|
| NDEB(svdump(Pending_conditionals)); |
| 738 |
2 |
| true_ish = SvOK(TOPs); |
| 739 |
|
| NDEB(D(L, " get_condition_dor true_ish=%d\n", true_ish)); |
| 740 |
2 |
▶ | add_condition(aTHX_ *pc, true_ish ? 2 : 1); |
Branch: 1 branch
| Branch | True | False | Total |
| add_condition(aTHX_ *pc, true_ish ? 2 : 1); |
2 |
0 |
2 |
|
| 741 |
|
| } else { |
| 742 |
0 |
| PDEB(D(L, "All is lost, I know not where to go from %p, %p: %p (%s)\n", |
| 743 |
|
| PL_op, (void *)PL_op->op_targ, pc, hex_key(get_key(PL_op)))); |
| 744 |
0 |
| dump_conditions(aTHX); |
| 745 |
|
| NDEB(svdump(Pending_conditionals)); |
| 746 |
0 |
| exit(1); |
| 747 |
|
| } |
| 748 |
2 |
| return PL_op; |
| 749 |
|
| } |
| 750 |
|
| |
| 751 |
170 |
| static void finalise_conditions(pTHX) { |
| 752 |
|
| /* |
| 753 |
|
| * Our algorithm for conditions relies on ending up at a particular |
| 754 |
|
| * op which we use to call get_condition(). It's possible that we |
| 755 |
|
| * never get to that op; for example we might return out of a sub. |
| 756 |
|
| * This causes us to lose coverage information. |
| 757 |
|
| * |
| 758 |
|
| * This function is called after the program has been run in order |
| 759 |
|
| * to collect that lost information. |
| 760 |
|
| */ |
| 761 |
|
| |
| 762 |
|
| HE *e; |
| 763 |
|
| |
| 764 |
|
| NDEB(D(L, "finalise_conditions\n")); |
| 765 |
|
| /* dump_conditions(aTHX); */ |
| 766 |
|
| NDEB(svdump(Pending_conditionals)); |
| 767 |
|
| |
| 768 |
|
| MUTEX_LOCK(&DC_mutex); |
| 769 |
170 |
| hv_iterinit(Pending_conditionals); |
| 770 |
|
| |
| 771 |
239 |
▶ | while ((e = hv_iternext(Pending_conditionals))) |
Branch: 1 branch
| Branch | True | False | Total |
| while ((e = hv_iternext(Pending_conditionals))) |
69 |
170 |
239 |
|
| 772 |
69 |
| add_condition(aTHX_ hv_iterval(Pending_conditionals, e), 0); |
| 773 |
|
| MUTEX_UNLOCK(&DC_mutex); |
| 774 |
170 |
| } |
| 775 |
|
| |
| 776 |
179 |
| static void cover_cond(pTHX) |
| 777 |
|
| { |
| 778 |
|
| dMY_CXT; |
| 779 |
179 |
▶ | if (collecting(Branch)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (collecting(Branch)) { |
157 |
22 |
179 |
|
| 780 |
157 |
| dSP; |
| 781 |
157 |
| int val = SvTRUE(TOPs); |
| 782 |
157 |
| add_branch(aTHX_ PL_op, !val); |
| 783 |
|
| } |
| 784 |
179 |
| } |
| 785 |
|
| |
| 786 |
1594 |
| static void cover_logop(pTHX) { |
| 787 |
|
| /* |
| 788 |
|
| * For OP_AND, if the first operand is false, we have short |
| 789 |
|
| * circuited the second, otherwise the value of the op is the |
| 790 |
|
| * value of the second operand. |
| 791 |
|
| * |
| 792 |
|
| * For OP_OR, if the first operand is true, we have short circuited |
| 793 |
|
| * the second, otherwise the value of the op is the value of the |
| 794 |
|
| * second operand. |
| 795 |
|
| * |
| 796 |
|
| * We check the value of the first operand by simply looking on the |
| 797 |
|
| * stack. To check the second operand it is necessary to note the |
| 798 |
|
| * location of the next op after this logop. When we get there, we |
| 799 |
|
| * look at the stack and store the coverage information indexed to |
| 800 |
|
| * this op. |
| 801 |
|
| * |
| 802 |
|
| * This scheme also works for OP_XOR with a small modification |
| 803 |
|
| * because it doesn't short circuit. See the comment below. |
| 804 |
|
| * |
| 805 |
|
| * To find out when we get to the next op we change the op_ppaddr to |
| 806 |
|
| * point to get_condition(), which will do the necessary work and |
| 807 |
|
| * then reset and run the original op_ppaddr. We also store |
| 808 |
|
| * information in the Pending_conditionals hash. This is keyed on |
| 809 |
|
| * the op and the value is an array, the first element of which is |
| 810 |
|
| * the op we are messing with, the second element of which is the |
| 811 |
|
| * op_ppaddr we overwrote, and the subsequent elements are the ops |
| 812 |
|
| * about which we are collecting the condition coverage information. |
| 813 |
|
| * Note that an op may be collecting condition coverage information |
| 814 |
|
| * about a number of conditions. |
| 815 |
|
| */ |
| 816 |
|
| |
| 817 |
|
| dMY_CXT; |
| 818 |
|
| |
| 819 |
|
| NDEB(D(L, "logop() at %p\n", PL_op)); |
| 820 |
|
| NDEB(op_dump(PL_op)); |
| 821 |
|
| |
| 822 |
1594 |
▶ | if (!collecting(Condition)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!collecting(Condition)) |
24 |
1570 |
1594 |
|
| 823 |
24 |
| return; |
| 824 |
|
| |
| 825 |
1570 |
▶ | if (cLOGOP->op_first->op_type == OP_ITER) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (cLOGOP->op_first->op_type == OP_ITER) { |
1050 |
520 |
1570 |
|
| 826 |
|
| /* loop - ignore it for now */ |
| 827 |
|
| } else { |
| 828 |
1050 |
| dSP; |
| 829 |
|
| |
| 830 |
940 |
▶ | int leftval_true_ish = (PL_op->op_type == OP_DOR || PL_op->op_type == OP_DORASSIGN) |
Branch: 1 branch
| Branch | True | False | Total |
| int leftval_true_ish = (PL_op->op_type == OP_DOR || PL_op->op_type == OP_DORASSIGN) |
112 |
828 |
940 |
|
| 831 |
1990 |
▶ | ? SvOK(TOPs) : SvTRUE(TOPs); |
Branch: 1 branch
| Branch | True | False | Total |
| ? SvOK(TOPs) : SvTRUE(TOPs); |
940 |
110 |
1050 |
|
| 832 |
|
| /* We don't count X= as void context because we care about the value |
| 833 |
|
| * of the RHS */ |
| 834 |
1050 |
| int void_context = GIMME_V == G_VOID && |
| 835 |
627 |
▶ | PL_op->op_type != OP_DORASSIGN && |
Branch: 1 branch
| Branch | True | False | Total |
| PL_op->op_type != OP_DORASSIGN && |
515 |
112 |
627 |
|
| 836 |
2159 |
▶ | PL_op->op_type != OP_ANDASSIGN && |
Branch: 2 branches
| Branch | True | False | Total |
| PL_op->op_type != OP_ANDASSIGN && |
627 |
423 |
1050 |
| PL_op->op_type != OP_ANDASSIGN && |
482 |
33 |
515 |
|
| 837 |
482 |
▶ | PL_op->op_type != OP_ORASSIGN; |
Branch: 1 branch
| Branch | True | False | Total |
| PL_op->op_type != OP_ORASSIGN; |
306 |
176 |
482 |
|
| 838 |
|
| NDEB(D(L, "leftval_true_ish: %d, void_context: %d at %p\n", |
| 839 |
|
| leftval_true_ish, void_context, PL_op)); |
| 840 |
|
| NDEB(op_dump(PL_op)); |
| 841 |
|
| |
| 842 |
1050 |
| set_conditional(aTHX_ PL_op, 5, void_context); |
| 843 |
|
| |
| 844 |
1050 |
▶ | if ((PL_op->op_type == OP_AND && leftval_true_ish) || |
Branch: 2 branches
| Branch | True | False | Total |
| if ((PL_op->op_type == OP_AND && leftval_true_ish) || |
306 |
744 |
1050 |
| if ((PL_op->op_type == OP_AND && leftval_true_ish) || |
99 |
207 |
306 |
|
| 845 |
843 |
▶ | (PL_op->op_type == OP_ANDASSIGN && leftval_true_ish) || |
Branch: 2 branches
| Branch | True | False | Total |
| (PL_op->op_type == OP_ANDASSIGN && leftval_true_ish) || |
33 |
810 |
843 |
| (PL_op->op_type == OP_ANDASSIGN && leftval_true_ish) || |
22 |
11 |
33 |
|
| 846 |
832 |
▶ | (PL_op->op_type == OP_OR && !leftval_true_ish) || |
Branch: 2 branches
| Branch | True | False | Total |
| (PL_op->op_type == OP_OR && !leftval_true_ish) || |
240 |
592 |
832 |
| (PL_op->op_type == OP_OR && !leftval_true_ish) || |
139 |
101 |
240 |
|
| 847 |
731 |
▶ | (PL_op->op_type == OP_ORASSIGN && !leftval_true_ish) || |
Branch: 2 branches
| Branch | True | False | Total |
| (PL_op->op_type == OP_ORASSIGN && !leftval_true_ish) || |
176 |
555 |
731 |
| (PL_op->op_type == OP_ORASSIGN && !leftval_true_ish) || |
131 |
45 |
176 |
|
| 848 |
686 |
▶ | (PL_op->op_type == OP_DOR && !leftval_true_ish) || |
Branch: 2 branches
| Branch | True | False | Total |
| (PL_op->op_type == OP_DOR && !leftval_true_ish) || |
110 |
576 |
686 |
| (PL_op->op_type == OP_DOR && !leftval_true_ish) || |
53 |
57 |
110 |
|
| 849 |
629 |
▶ | (PL_op->op_type == OP_DORASSIGN && !leftval_true_ish) || |
Branch: 2 branches
| Branch | True | False | Total |
| (PL_op->op_type == OP_DORASSIGN && !leftval_true_ish) || |
112 |
517 |
629 |
| (PL_op->op_type == OP_DORASSIGN && !leftval_true_ish) || |
110 |
2 |
112 |
|
| 850 |
1122 |
▶ | (PL_op->op_type == OP_XOR)) { |
Branch: 1 branch
| Branch | True | False | Total |
| (PL_op->op_type == OP_XOR)) { |
73 |
554 |
627 |
|
| 851 |
|
| /* no short circuit */ |
| 852 |
|
| |
| 853 |
496 |
▶ | OP *right = OpSIBLING(cLOGOP->op_first); |
Branch: 1 branch
| Branch | True | False | Total |
| OP *right = OpSIBLING(cLOGOP->op_first); |
496 |
0 |
496 |
|
| 854 |
|
| |
| 855 |
|
| NDEB(op_dump(right)); |
| 856 |
|
| |
| 857 |
496 |
▶ | if (void_context || |
Branch: 1 branch
| Branch | True | False | Total |
| if (void_context || |
302 |
194 |
496 |
|
| 858 |
302 |
▶ | right->op_type == OP_NEXT || |
Branch: 1 branch
| Branch | True | False | Total |
| right->op_type == OP_NEXT || |
298 |
4 |
302 |
|
| 859 |
298 |
▶ | right->op_type == OP_LAST || |
Branch: 1 branch
| Branch | True | False | Total |
| right->op_type == OP_LAST || |
296 |
2 |
298 |
|
| 860 |
296 |
▶ | right->op_type == OP_REDO || |
Branch: 1 branch
| Branch | True | False | Total |
| right->op_type == OP_REDO || |
294 |
2 |
296 |
|
| 861 |
294 |
▶ | right->op_type == OP_GOTO || |
Branch: 1 branch
| Branch | True | False | Total |
| right->op_type == OP_GOTO || |
292 |
2 |
294 |
|
| 862 |
292 |
▶ | right->op_type == OP_RETURN || |
Branch: 1 branch
| Branch | True | False | Total |
| right->op_type == OP_RETURN || |
283 |
9 |
292 |
|
| 863 |
283 |
▶ | right->op_type == OP_DIE) { |
Branch: 1 branch
| Branch | True | False | Total |
| right->op_type == OP_DIE) { |
4 |
279 |
283 |
|
| 864 |
|
| /* |
| 865 |
|
| * If we are in void context, or the right side of the op is a |
| 866 |
|
| * branch, we don't care what its value is - it won't be |
| 867 |
|
| * returning one. We're just glad to be here, so we chalk up |
| 868 |
|
| * success. |
| 869 |
|
| */ |
| 870 |
|
| |
| 871 |
|
| NDEB(D(L, "Add conditional 2\n")); |
| 872 |
217 |
| add_conditional(aTHX_ PL_op, 2); |
| 873 |
|
| } else { |
| 874 |
|
| char *ch; |
| 875 |
|
| AV *conds; |
| 876 |
|
| SV **cref, |
| 877 |
|
| *cond; |
| 878 |
|
| OP *next; |
| 879 |
|
| |
| 880 |
279 |
▶ | if (PL_op->op_type == OP_XOR && leftval_true_ish) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (PL_op->op_type == OP_XOR && leftval_true_ish) { |
73 |
206 |
279 |
| if (PL_op->op_type == OP_XOR && leftval_true_ish) { |
44 |
29 |
73 |
|
| 881 |
|
| /* |
| 882 |
|
| * This is an xor. It does not short circuit. We |
| 883 |
|
| * have just executed the first op. When we get to |
| 884 |
|
| * next we will have already done the xor, so we can |
| 885 |
|
| * work out what the value of the second op was. |
| 886 |
|
| * |
| 887 |
|
| * We set a flag in the first element of the array |
| 888 |
|
| * to say that we had a true value from the first |
| 889 |
|
| * op. |
| 890 |
|
| */ |
| 891 |
|
| |
| 892 |
44 |
| set_conditional(aTHX_ PL_op, 0, 1); |
| 893 |
|
| } |
| 894 |
|
| |
| 895 |
|
| #if PERL_VERSION > 14 |
| 896 |
|
| NDEB(D(L, "Getting next\n")); |
| 897 |
558 |
| next = (PL_op->op_type == OP_XOR) |
| 898 |
73 |
| ? PL_op->op_next |
| 899 |
279 |
▶ | : right->op_next; |
Branch: 1 branch
| Branch | True | False | Total |
| : right->op_next; |
73 |
206 |
279 |
|
| 900 |
280 |
▶ | while (next && next->op_type == OP_NULL) |
Branch: 2 branches
| Branch | True | False | Total |
| while (next && next->op_type == OP_NULL) |
279 |
1 |
280 |
| while (next && next->op_type == OP_NULL) |
1 |
278 |
279 |
|
| 901 |
1 |
| next = next->op_next; |
| 902 |
|
| #else |
| 903 |
|
| next = PL_op->op_next; |
| 904 |
|
| #endif |
| 905 |
279 |
▶ | if (!next) return; /* in fold_constants */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!next) return; /* in fold_constants */ |
1 |
278 |
279 |
|
| 906 |
|
| NDEB(op_dump(PL_op)); |
| 907 |
|
| NDEB(op_dump(next)); |
| 908 |
|
| |
| 909 |
278 |
| ch = get_key(next); |
| 910 |
|
| MUTEX_LOCK(&DC_mutex); |
| 911 |
278 |
| cref = hv_fetch(Pending_conditionals, ch, KEY_SZ, 1); |
| 912 |
|
| |
| 913 |
278 |
▶ | if (SvROK(*cref)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (SvROK(*cref)) |
209 |
69 |
278 |
|
| 914 |
209 |
| conds = (AV *)SvRV(*cref); |
| 915 |
|
| else |
| 916 |
69 |
| *cref = newRV_inc((SV*) (conds = newAV())); |
| 917 |
|
| |
| 918 |
278 |
▶ | if (av_len(conds) < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(conds) < 0) { |
69 |
209 |
278 |
|
| 919 |
69 |
| av_push(conds, newSViv(PTR2IV(next))); |
| 920 |
69 |
| av_push(conds, newSViv(PTR2IV(next->op_ppaddr))); |
| 921 |
|
| } |
| 922 |
|
| |
| 923 |
|
| #ifdef USE_ITHREADS |
| 924 |
|
| conds = get_conds(aTHX_ conds); |
| 925 |
|
| #endif |
| 926 |
|
| |
| 927 |
278 |
| cond = newSViv(PTR2IV(PL_op)); |
| 928 |
278 |
| av_push(conds, cond); |
| 929 |
|
| |
| 930 |
|
| NDEB(D(L, "Adding conditional %p (%s) " |
| 931 |
|
| "making %zd at %p (%s), ppaddr: %p\n", |
| 932 |
|
| next, PL_op_name[next->op_targ], av_len(conds) - 1, |
| 933 |
|
| PL_op, hex_key(ch), next->op_ppaddr)); |
| 934 |
|
| /* dump_conditions(aTHX); */ |
| 935 |
|
| NDEB(svdump(Pending_conditionals)); |
| 936 |
|
| NDEB(op_dump(PL_op)); |
| 937 |
|
| NDEB(op_dump(next)); |
| 938 |
|
| |
| 939 |
278 |
| next->op_ppaddr = (next->op_type == OP_NEXTSTATE && ( |
| 940 |
58 |
▶ | PL_op->op_type == OP_DOR || PL_op->op_type == OP_DORASSIGN)) |
Branch: 2 branches
| Branch | True | False | Total |
| PL_op->op_type == OP_DOR || PL_op->op_type == OP_DORASSIGN)) |
58 |
0 |
58 |
| PL_op->op_type == OP_DOR || PL_op->op_type == OP_DORASSIGN)) |
2 |
56 |
58 |
|
| 941 |
336 |
▶ | ? get_condition_dor : get_condition; |
Branch: 1 branch
| Branch | True | False | Total |
| ? get_condition_dor : get_condition; |
58 |
220 |
278 |
|
| 942 |
|
| MUTEX_UNLOCK(&DC_mutex); |
| 943 |
|
| } |
| 944 |
|
| } else { |
| 945 |
|
| /* short circuit */ |
| 946 |
|
| #if PERL_VERSION > 14 |
| 947 |
554 |
▶ | OP *up = OpSIBLING(cLOGOP->op_first)->op_next; |
Branch: 1 branch
| Branch | True | False | Total |
| OP *up = OpSIBLING(cLOGOP->op_first)->op_next; |
554 |
0 |
554 |
|
| 948 |
|
| #if PERL_VERSION > 18 |
| 949 |
|
| OP *skipped; |
| 950 |
|
| #endif |
| 951 |
|
| |
| 952 |
554 |
▶ | while (up && up->op_type == PL_op->op_type) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (up && up->op_type == PL_op->op_type) { |
554 |
0 |
554 |
| while (up && up->op_type == PL_op->op_type) { |
24 |
530 |
554 |
|
| 953 |
|
| NDEB(D(L, "Considering adding %p (%s) -> (%p) " |
| 954 |
|
| "from %p (%s) -> (%p)\n", |
| 955 |
|
| up, PL_op_name[up->op_type], up->op_next, |
| 956 |
|
| PL_op, PL_op_name[PL_op->op_type], PL_op->op_next)); |
| 957 |
24 |
| add_conditional(aTHX_ up, 3); |
| 958 |
24 |
▶ | if (up->op_next == PL_op->op_next) |
Branch: 1 branch
| Branch | True | False | Total |
| if (up->op_next == PL_op->op_next) |
24 |
0 |
24 |
|
| 959 |
24 |
| break; |
| 960 |
0 |
▶ | up = OpSIBLING(cLOGOPx(up)->op_first)->op_next; |
Branch: 1 branch
| Branch | True | False | Total |
| up = OpSIBLING(cLOGOPx(up)->op_first)->op_next; |
0 |
0 |
0 |
|
| 961 |
|
| } |
| 962 |
|
| #endif |
| 963 |
554 |
| add_conditional(aTHX_ PL_op, 3); |
| 964 |
|
| |
| 965 |
|
| #if PERL_VERSION > 18 |
| 966 |
554 |
| skipped = PL_op; |
| 967 |
555 |
▶ | while ((skipped = find_skipped_conditional(aTHX_ skipped)) != NULL) |
Branch: 1 branch
| Branch | True | False | Total |
| while ((skipped = find_skipped_conditional(aTHX_ skipped)) != NULL) |
1 |
554 |
555 |
|
| 968 |
1 |
| add_conditional(aTHX_ skipped, 2); /* Should this ever be 1? */ |
| 969 |
|
| #endif |
| 970 |
|
| } |
| 971 |
|
| } |
| 972 |
|
| } |
| 973 |
|
| |
| 974 |
|
| #if PERL_VERSION > 16 |
| 975 |
|
| /* A sequence of variable declarations may have been optimized |
| 976 |
|
| * to a single OP_PADRANGE. The original sequence may span multiple lines, |
| 977 |
|
| * but only the first line has been marked as covered for now. |
| 978 |
|
| * Mark other OP_NEXTSTATE inside the original sequence of statements. |
| 979 |
|
| */ |
| 980 |
111647121 |
| static void cover_padrange(pTHX) { |
| 981 |
|
| dMY_CXT; |
| 982 |
|
| OP *next, |
| 983 |
|
| *orig; |
| 984 |
111647121 |
▶ | if (!collecting(Statement)) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!collecting(Statement)) return; |
7360 |
111639761 |
111647121 |
|
| 985 |
111639761 |
| next = PL_op->op_next; |
| 986 |
111639761 |
▶ | orig = OpSIBLING(PL_op); |
Branch: 1 branch
| Branch | True | False | Total |
| orig = OpSIBLING(PL_op); |
111639761 |
0 |
111639761 |
|
| 987 |
|
| |
| 988 |
|
| /* Ignore padrange preparing subroutine call */ |
| 989 |
668215304 |
▶ | while (orig && orig != next) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (orig && orig != next) { |
668215304 |
0 |
668215304 |
| while (orig && orig != next) { |
556575543 |
111639761 |
668215304 |
|
| 990 |
556575543 |
▶ | if (orig->op_type == OP_ENTERSUB) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (orig->op_type == OP_ENTERSUB) return; |
0 |
556575543 |
556575543 |
|
| 991 |
556575543 |
| orig = orig->op_next; |
| 992 |
|
| } |
| 993 |
111639761 |
▶ | orig = OpSIBLING(PL_op); |
Branch: 1 branch
| Branch | True | False | Total |
| orig = OpSIBLING(PL_op); |
111639761 |
0 |
111639761 |
|
| 994 |
668215304 |
▶ | while (orig && orig != next) { |
Branch: 2 branches
| Branch | True | False | Total |
| while (orig && orig != next) { |
668215304 |
0 |
668215304 |
| while (orig && orig != next) { |
556575543 |
111639761 |
668215304 |
|
| 995 |
556575543 |
▶ | if (orig->op_type == OP_NEXTSTATE) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (orig->op_type == OP_NEXTSTATE) { |
9169 |
556566374 |
556575543 |
|
| 996 |
9169 |
| cover_statement(aTHX_ orig); |
| 997 |
|
| } |
| 998 |
556575543 |
| orig = orig->op_next; |
| 999 |
|
| } |
| 1000 |
|
| } |
| 1001 |
|
| |
| 1002 |
111660262 |
| static OP *dc_padrange(pTHX) { |
| 1003 |
|
| dMY_CXT; |
| 1004 |
111660262 |
| check_if_collecting(aTHX_ PL_curcop); |
| 1005 |
|
| NDEB(D(L, "dc_padrange() at %p (%d)\n", PL_op, collecting_here(aTHX))); |
| 1006 |
111660262 |
▶ | if (MY_CXT.covering) cover_padrange(aTHX); |
Branch: 1 branch
| Branch | True | False | Total |
| if (MY_CXT.covering) cover_padrange(aTHX); |
111647121 |
13141 |
111660262 |
|
| 1007 |
111660262 |
| return MY_CXT.ppaddr[OP_PADRANGE](aTHX); |
| 1008 |
|
| } |
| 1009 |
|
| #endif |
| 1010 |
|
| |
| 1011 |
2098523830 |
| static OP *dc_nextstate(pTHX) { |
| 1012 |
|
| dMY_CXT; |
| 1013 |
|
| NDEB(D(L, "dc_nextstate() at %p (%d)\n", PL_op, collecting_here(aTHX))); |
| 1014 |
2098523830 |
▶ | if (MY_CXT.covering) check_if_collecting(aTHX_ cCOP); |
Branch: 1 branch
| Branch | True | False | Total |
| if (MY_CXT.covering) check_if_collecting(aTHX_ cCOP); |
2098459684 |
64146 |
2098523830 |
|
| 1015 |
2098523830 |
▶ | if (collecting_here(aTHX)) cover_current_statement(aTHX); |
Branch: 1 branch
| Branch | True | False | Total |
| if (collecting_here(aTHX)) cover_current_statement(aTHX); |
4799 |
2098519031 |
2098523830 |
|
| 1016 |
2098523830 |
| return MY_CXT.ppaddr[OP_NEXTSTATE](aTHX); |
| 1017 |
|
| } |
| 1018 |
|
| |
| 1019 |
0 |
| static OP *dc_dbstate(pTHX) { |
| 1020 |
|
| dMY_CXT; |
| 1021 |
|
| NDEB(D(L, "dc_dbstate() at %p (%d)\n", PL_op, collecting_here(aTHX))); |
| 1022 |
0 |
▶ | if (MY_CXT.covering) check_if_collecting(aTHX_ cCOP); |
Branch: 1 branch
| Branch | True | False | Total |
| if (MY_CXT.covering) check_if_collecting(aTHX_ cCOP); |
0 |
0 |
0 |
|
| 1023 |
0 |
▶ | if (collecting_here(aTHX)) cover_current_statement(aTHX); |
Branch: 1 branch
| Branch | True | False | Total |
| if (collecting_here(aTHX)) cover_current_statement(aTHX); |
0 |
0 |
0 |
|
| 1024 |
0 |
| return MY_CXT.ppaddr[OP_DBSTATE](aTHX); |
| 1025 |
|
| } |
| 1026 |
|
| |
| 1027 |
80617858 |
| static OP *dc_entersub(pTHX) { |
| 1028 |
|
| dMY_CXT; |
| 1029 |
|
| NDEB(D(L, "dc_entersub() at %p (%d)\n", PL_op, collecting_here(aTHX))); |
| 1030 |
80617858 |
▶ | if (MY_CXT.covering) store_return(aTHX); |
Branch: 1 branch
| Branch | True | False | Total |
| if (MY_CXT.covering) store_return(aTHX); |
80601466 |
16392 |
80617858 |
|
| 1031 |
80617858 |
| return MY_CXT.ppaddr[OP_ENTERSUB](aTHX); |
| 1032 |
|
| } |
| 1033 |
|
| |
| 1034 |
726972793 |
| static OP *dc_cond_expr(pTHX) { |
| 1035 |
|
| dMY_CXT; |
| 1036 |
726972793 |
| check_if_collecting(aTHX_ PL_curcop); |
| 1037 |
|
| NDEB(D(L, "dc_cond_expr() at %p (%d)\n", PL_op, collecting_here(aTHX))); |
| 1038 |
726972793 |
▶ | if (MY_CXT.covering && collecting_here(aTHX)) cover_cond(aTHX); |
Branch: 2 branches
| Branch | True | False | Total |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_cond(aTHX); |
726964640 |
8153 |
726972793 |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_cond(aTHX); |
179 |
726964461 |
726964640 |
|
| 1039 |
726972793 |
| return MY_CXT.ppaddr[OP_COND_EXPR](aTHX); |
| 1040 |
|
| } |
| 1041 |
|
| |
| 1042 |
604080548 |
| static OP *dc_and(pTHX) { |
| 1043 |
|
| dMY_CXT; |
| 1044 |
|
| NDEB(D(L, "dc_and() at %p (%d)\n", PL_op, collecting_here(aTHX))); |
| 1045 |
604080548 |
| check_if_collecting(aTHX_ PL_curcop); |
| 1046 |
|
| NDEB(D(L, "dc_and() at %p (%d)\n", PL_curcop, collecting_here(aTHX))); |
| 1047 |
|
| NDEB(D(L, "PL_curcop: %s:%ld\n", CopFILE(PL_curcop), (long)CopLINE(PL_curcop))); |
| 1048 |
604080548 |
▶ | if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
Branch: 2 branches
| Branch | True | False | Total |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
604071484 |
9064 |
604080548 |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
850 |
604070634 |
604071484 |
|
| 1049 |
604080548 |
| return MY_CXT.ppaddr[OP_AND](aTHX); |
| 1050 |
|
| } |
| 1051 |
|
| |
| 1052 |
33 |
| static OP *dc_andassign(pTHX) { |
| 1053 |
|
| dMY_CXT; |
| 1054 |
33 |
| check_if_collecting(aTHX_ PL_curcop); |
| 1055 |
|
| NDEB(D(L, "dc_andassign() at %p (%d)\n", PL_op, collecting_here(aTHX))); |
| 1056 |
33 |
▶ | if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
Branch: 2 branches
| Branch | True | False | Total |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
33 |
0 |
33 |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
33 |
0 |
33 |
|
| 1057 |
33 |
| return MY_CXT.ppaddr[OP_ANDASSIGN](aTHX); |
| 1058 |
|
| } |
| 1059 |
|
| |
| 1060 |
70348364 |
| static OP *dc_or(pTHX) { |
| 1061 |
|
| dMY_CXT; |
| 1062 |
70348364 |
| check_if_collecting(aTHX_ PL_curcop); |
| 1063 |
|
| NDEB(D(L, "dc_or() at %p (%d)\n", PL_op, collecting_here(aTHX))); |
| 1064 |
70348364 |
▶ | if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
Branch: 2 branches
| Branch | True | False | Total |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
70339373 |
8991 |
70348364 |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
240 |
70339133 |
70339373 |
|
| 1065 |
70348364 |
| return MY_CXT.ppaddr[OP_OR](aTHX); |
| 1066 |
|
| } |
| 1067 |
|
| |
| 1068 |
52725865 |
| static OP *dc_orassign(pTHX) { |
| 1069 |
|
| dMY_CXT; |
| 1070 |
52725865 |
| check_if_collecting(aTHX_ PL_curcop); |
| 1071 |
|
| NDEB(D(L, "dc_orassign() at %p (%d)\n", PL_op, collecting_here(aTHX))); |
| 1072 |
52725865 |
▶ | if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
Branch: 2 branches
| Branch | True | False | Total |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
52725864 |
1 |
52725865 |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
176 |
52725688 |
52725864 |
|
| 1073 |
52725865 |
| return MY_CXT.ppaddr[OP_ORASSIGN](aTHX); |
| 1074 |
|
| } |
| 1075 |
|
| |
| 1076 |
110 |
| static OP *dc_dor(pTHX) { |
| 1077 |
|
| dMY_CXT; |
| 1078 |
110 |
| check_if_collecting(aTHX_ PL_curcop); |
| 1079 |
|
| NDEB(D(L, "dc_dor() at %p (%d)\n", PL_op, collecting_here(aTHX))); |
| 1080 |
110 |
▶ | if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
Branch: 2 branches
| Branch | True | False | Total |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
110 |
0 |
110 |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
110 |
0 |
110 |
|
| 1081 |
110 |
| return MY_CXT.ppaddr[OP_DOR](aTHX); |
| 1082 |
|
| } |
| 1083 |
|
| |
| 1084 |
9485 |
| static OP *dc_dorassign(pTHX) { |
| 1085 |
|
| dMY_CXT; |
| 1086 |
9485 |
| check_if_collecting(aTHX_ PL_curcop); |
| 1087 |
|
| NDEB(D(L, "dc_dorassign() at %p (%d)\n", PL_op, collecting_here(aTHX))); |
| 1088 |
9485 |
▶ | if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
Branch: 2 branches
| Branch | True | False | Total |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
9485 |
0 |
9485 |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
112 |
9373 |
9485 |
|
| 1089 |
9485 |
| return MY_CXT.ppaddr[OP_DORASSIGN](aTHX); |
| 1090 |
|
| } |
| 1091 |
|
| |
| 1092 |
79 |
| OP *dc_xor(pTHX) { |
| 1093 |
|
| dMY_CXT; |
| 1094 |
79 |
| check_if_collecting(aTHX_ PL_curcop); |
| 1095 |
|
| NDEB(D(L, "dc_xor() at %p (%d)\n", PL_op, collecting_here(aTHX))); |
| 1096 |
79 |
▶ | if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
Branch: 2 branches
| Branch | True | False | Total |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
79 |
0 |
79 |
| if (MY_CXT.covering && collecting_here(aTHX)) cover_logop(aTHX); |
73 |
6 |
79 |
|
| 1097 |
79 |
| return MY_CXT.ppaddr[OP_XOR](aTHX); |
| 1098 |
|
| } |
| 1099 |
|
| |
| 1100 |
1269491 |
| static OP *dc_require(pTHX) { |
| 1101 |
|
| dMY_CXT; |
| 1102 |
|
| NDEB(D(L, "dc_require() at %p (%d)\n", PL_op, collecting_here(aTHX))); |
| 1103 |
1269491 |
▶ | if (MY_CXT.covering && collecting_here(aTHX)) store_module(aTHX); |
Branch: 2 branches
| Branch | True | False | Total |
| if (MY_CXT.covering && collecting_here(aTHX)) store_module(aTHX); |
1267941 |
1550 |
1269491 |
| if (MY_CXT.covering && collecting_here(aTHX)) store_module(aTHX); |
170 |
1267771 |
1267941 |
|
| 1104 |
1269491 |
| return MY_CXT.ppaddr[OP_REQUIRE](aTHX); |
| 1105 |
|
| } |
| 1106 |
|
| |
| 1107 |
0 |
| static OP *dc_exec(pTHX) { |
| 1108 |
|
| dMY_CXT; |
| 1109 |
|
| NDEB(D(L, "dc_exec() at %p (%d)\n", PL_op, collecting_here(aTHX))); |
| 1110 |
0 |
▶ | if (MY_CXT.covering && collecting_here(aTHX)) call_report(aTHX); |
Branch: 2 branches
| Branch | True | False | Total |
| if (MY_CXT.covering && collecting_here(aTHX)) call_report(aTHX); |
0 |
0 |
0 |
| if (MY_CXT.covering && collecting_here(aTHX)) call_report(aTHX); |
0 |
0 |
0 |
|
| 1111 |
0 |
| return MY_CXT.ppaddr[OP_EXEC](aTHX); |
| 1112 |
|
| } |
| 1113 |
|
| |
| 1114 |
170 |
| static void replace_ops (pTHX) { |
| 1115 |
|
| dMY_CXT; |
| 1116 |
|
| int i; |
| 1117 |
|
| NDEB(D(L, "initialising replace_ops\n")); |
| 1118 |
73100 |
▶ | for (i = 0; i < MAXO; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < MAXO; i++) |
72930 |
170 |
73100 |
|
| 1119 |
72930 |
| MY_CXT.ppaddr[i] = PL_ppaddr[i]; |
| 1120 |
|
| |
| 1121 |
170 |
| PL_ppaddr[OP_NEXTSTATE] = dc_nextstate; |
| 1122 |
170 |
| PL_ppaddr[OP_DBSTATE] = dc_dbstate; |
| 1123 |
170 |
| PL_ppaddr[OP_ENTERSUB] = dc_entersub; |
| 1124 |
|
| #if PERL_VERSION > 16 |
| 1125 |
170 |
| PL_ppaddr[OP_PADRANGE] = dc_padrange; |
| 1126 |
|
| #endif |
| 1127 |
170 |
| PL_ppaddr[OP_COND_EXPR] = dc_cond_expr; |
| 1128 |
170 |
| PL_ppaddr[OP_AND] = dc_and; |
| 1129 |
170 |
| PL_ppaddr[OP_ANDASSIGN] = dc_andassign; |
| 1130 |
170 |
| PL_ppaddr[OP_OR] = dc_or; |
| 1131 |
170 |
| PL_ppaddr[OP_ORASSIGN] = dc_orassign; |
| 1132 |
170 |
| PL_ppaddr[OP_DOR] = dc_dor; |
| 1133 |
170 |
| PL_ppaddr[OP_DORASSIGN] = dc_dorassign; |
| 1134 |
170 |
| PL_ppaddr[OP_XOR] = dc_xor; |
| 1135 |
170 |
| PL_ppaddr[OP_REQUIRE] = dc_require; |
| 1136 |
170 |
| PL_ppaddr[OP_EXEC] = dc_exec; |
| 1137 |
170 |
| } |
| 1138 |
|
| |
| 1139 |
170 |
| static void initialise(pTHX) { |
| 1140 |
|
| dMY_CXT; |
| 1141 |
|
| |
| 1142 |
|
| NDEB(D(L, "initialising\n")); |
| 1143 |
|
| |
| 1144 |
|
| MUTEX_LOCK(&DC_mutex); |
| 1145 |
170 |
▶ | if (!Pending_conditionals) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!Pending_conditionals) { |
170 |
0 |
170 |
|
| 1146 |
170 |
| Pending_conditionals = newHV(); |
| 1147 |
|
| #ifdef USE_ITHREADS |
| 1148 |
|
| HvSHAREKEYS_off(Pending_conditionals); |
| 1149 |
|
| #endif |
| 1150 |
|
| } |
| 1151 |
170 |
▶ | if (!Return_ops) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!Return_ops) { |
170 |
0 |
170 |
|
| 1152 |
170 |
| Return_ops = newHV(); |
| 1153 |
|
| #ifdef USE_ITHREADS |
| 1154 |
|
| HvSHAREKEYS_off(Return_ops); |
| 1155 |
|
| #endif |
| 1156 |
|
| } |
| 1157 |
|
| MUTEX_UNLOCK(&DC_mutex); |
| 1158 |
|
| |
| 1159 |
170 |
| MY_CXT.collecting_here = 1; |
| 1160 |
|
| |
| 1161 |
170 |
▶ | if (!MY_CXT.covering) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!MY_CXT.covering) { |
170 |
0 |
170 |
|
| 1162 |
|
| /* TODO - this probably leaks all over the place */ |
| 1163 |
|
| |
| 1164 |
|
| SV **tmp; |
| 1165 |
|
| |
| 1166 |
170 |
| MY_CXT.cover = newHV(); |
| 1167 |
|
| #ifdef USE_ITHREADS |
| 1168 |
|
| HvSHAREKEYS_off(MY_CXT.cover); |
| 1169 |
|
| #endif |
| 1170 |
|
| |
| 1171 |
170 |
| tmp = hv_fetch(MY_CXT.cover, "statement", 9, 1); |
| 1172 |
170 |
| MY_CXT.statements = newHV(); |
| 1173 |
170 |
| *tmp = newRV_inc((SV*) MY_CXT.statements); |
| 1174 |
|
| |
| 1175 |
170 |
| tmp = hv_fetch(MY_CXT.cover, "branch", 6, 1); |
| 1176 |
170 |
| MY_CXT.branches = newHV(); |
| 1177 |
170 |
| *tmp = newRV_inc((SV*) MY_CXT.branches); |
| 1178 |
|
| |
| 1179 |
170 |
| tmp = hv_fetch(MY_CXT.cover, "condition", 9, 1); |
| 1180 |
170 |
| MY_CXT.conditions = newHV(); |
| 1181 |
170 |
| *tmp = newRV_inc((SV*) MY_CXT.conditions); |
| 1182 |
|
| |
| 1183 |
|
| #if CAN_PROFILE |
| 1184 |
170 |
| tmp = hv_fetch(MY_CXT.cover, "time", 4, 1); |
| 1185 |
170 |
| MY_CXT.times = newHV(); |
| 1186 |
170 |
| *tmp = newRV_inc((SV*) MY_CXT.times); |
| 1187 |
|
| #endif |
| 1188 |
|
| |
| 1189 |
170 |
| tmp = hv_fetch(MY_CXT.cover, "module", 6, 1); |
| 1190 |
170 |
| MY_CXT.modules = newHV(); |
| 1191 |
170 |
| *tmp = newRV_inc((SV*) MY_CXT.modules); |
| 1192 |
|
| |
| 1193 |
170 |
| MY_CXT.files = get_hv("Devel::Cover::Files", FALSE); |
| 1194 |
|
| |
| 1195 |
|
| #ifdef USE_ITHREADS |
| 1196 |
|
| HvSHAREKEYS_off(MY_CXT.statements); |
| 1197 |
|
| HvSHAREKEYS_off(MY_CXT.branches); |
| 1198 |
|
| HvSHAREKEYS_off(MY_CXT.conditions); |
| 1199 |
|
| #if CAN_PROFILE |
| 1200 |
|
| HvSHAREKEYS_off(MY_CXT.times); |
| 1201 |
|
| #endif |
| 1202 |
|
| HvSHAREKEYS_off(MY_CXT.modules); |
| 1203 |
|
| #endif |
| 1204 |
|
| |
| 1205 |
170 |
| MY_CXT.profiling_key_valid = 0; |
| 1206 |
170 |
| MY_CXT.module = newSVpv("", 0); |
| 1207 |
170 |
| MY_CXT.lastfile = newSVpvn("", 1); |
| 1208 |
170 |
| MY_CXT.covering = All; |
| 1209 |
170 |
| MY_CXT.tid = tid++; |
| 1210 |
|
| |
| 1211 |
170 |
| MY_CXT.replace_ops = SvTRUE(get_sv("Devel::Cover::Replace_ops", FALSE)); |
| 1212 |
|
| NDEB(D(L, "running with Replace_ops as %d\n", MY_CXT.replace_ops)); |
| 1213 |
|
| } |
| 1214 |
170 |
| } |
| 1215 |
|
| |
| 1216 |
0 |
| static int runops_cover(pTHX) { |
| 1217 |
|
| dMY_CXT; |
| 1218 |
|
| |
| 1219 |
|
| NDEB(D(L, "entering runops_cover\n")); |
| 1220 |
|
| |
| 1221 |
|
| #if defined HAS_GETTIMEOFDAY |
| 1222 |
0 |
| elapsed(); |
| 1223 |
|
| #elif defined HAS_TIMES |
| 1224 |
|
| cpu(); |
| 1225 |
|
| #endif |
| 1226 |
|
| |
| 1227 |
|
| for (;;) { |
| 1228 |
|
| NDEB(D(L, "running func %p from %p (%s)\n", |
| 1229 |
|
| PL_op->op_ppaddr, PL_op, OP_NAME(PL_op))); |
| 1230 |
|
| |
| 1231 |
0 |
▶ | if (!MY_CXT.covering) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!MY_CXT.covering) |
0 |
0 |
0 |
|
| 1232 |
0 |
| goto call_fptr; |
| 1233 |
|
| |
| 1234 |
|
| /* Nothing to collect when we've hijacked the ppaddr */ |
| 1235 |
|
| { |
| 1236 |
|
| int hijacked; |
| 1237 |
|
| MUTEX_LOCK(&DC_mutex); |
| 1238 |
0 |
| hijacked = PL_op->op_ppaddr == get_condition; |
| 1239 |
|
| MUTEX_UNLOCK(&DC_mutex); |
| 1240 |
0 |
▶ | if (hijacked) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hijacked) |
0 |
0 |
0 |
|
| 1241 |
0 |
| goto call_fptr; |
| 1242 |
|
| } |
| 1243 |
|
| |
| 1244 |
|
| /* Check to see whether we are interested in this file */ |
| 1245 |
|
| |
| 1246 |
0 |
▶ | if (PL_op->op_type == OP_NEXTSTATE) |
Branch: 1 branch
| Branch | True | False | Total |
| if (PL_op->op_type == OP_NEXTSTATE) |
0 |
0 |
0 |
|
| 1247 |
0 |
| check_if_collecting(aTHX_ cCOP); |
| 1248 |
0 |
▶ | else if (PL_op->op_type == OP_ENTERSUB) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (PL_op->op_type == OP_ENTERSUB) |
0 |
0 |
0 |
|
| 1249 |
0 |
| store_return(aTHX); |
| 1250 |
|
| |
| 1251 |
0 |
▶ | if (!collecting_here(aTHX)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!collecting_here(aTHX)) |
0 |
0 |
0 |
|
| 1252 |
0 |
| goto call_fptr; |
| 1253 |
|
| |
| 1254 |
|
| /* |
| 1255 |
|
| * We are about the run the op PL_op, so we'll collect |
| 1256 |
|
| * information for it now |
| 1257 |
|
| */ |
| 1258 |
|
| |
| 1259 |
0 |
| switch (PL_op->op_type) { |
| 1260 |
0 |
| case OP_NEXTSTATE: |
| 1261 |
|
| case OP_DBSTATE: { |
| 1262 |
0 |
| cover_current_statement(aTHX); |
| 1263 |
0 |
| break; |
| 1264 |
|
| } |
| 1265 |
|
| |
| 1266 |
|
| #if PERL_VERSION > 16 |
| 1267 |
0 |
| case OP_PADRANGE: { |
| 1268 |
0 |
| cover_padrange(aTHX); |
| 1269 |
0 |
| break; |
| 1270 |
|
| } |
| 1271 |
|
| #endif |
| 1272 |
|
| |
| 1273 |
0 |
| case OP_COND_EXPR: { |
| 1274 |
0 |
| cover_cond(aTHX); |
| 1275 |
0 |
| break; |
| 1276 |
|
| } |
| 1277 |
|
| |
| 1278 |
0 |
| case OP_AND: |
| 1279 |
|
| case OP_ANDASSIGN: |
| 1280 |
|
| case OP_OR: |
| 1281 |
|
| case OP_ORASSIGN: |
| 1282 |
|
| case OP_DOR: |
| 1283 |
|
| case OP_DORASSIGN: |
| 1284 |
|
| case OP_XOR: { |
| 1285 |
0 |
| cover_logop(aTHX); |
| 1286 |
0 |
| break; |
| 1287 |
|
| } |
| 1288 |
|
| |
| 1289 |
0 |
| case OP_REQUIRE: { |
| 1290 |
0 |
| store_module(aTHX); |
| 1291 |
0 |
| break; |
| 1292 |
|
| } |
| 1293 |
|
| |
| 1294 |
0 |
| case OP_EXEC: { |
| 1295 |
0 |
| call_report(aTHX); |
| 1296 |
0 |
| break; |
| 1297 |
|
| } |
| 1298 |
|
| |
| 1299 |
|
| default: |
| 1300 |
|
| ; /* IBM's xlC compiler on AIX is very picky */ |
| 1301 |
|
| } |
| 1302 |
|
| |
| 1303 |
0 |
| call_fptr: |
| 1304 |
0 |
▶ | if (!(PL_op = PL_op->op_ppaddr(aTHX))) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!(PL_op = PL_op->op_ppaddr(aTHX))) |
0 |
0 |
0 |
|
| 1305 |
0 |
| break; |
| 1306 |
|
| |
| 1307 |
0 |
▶ | PERL_ASYNC_CHECK(); |
Branch: 1 branch
| Branch | True | False | Total |
| PERL_ASYNC_CHECK(); |
0 |
0 |
0 |
|
| 1308 |
|
| } |
| 1309 |
|
| |
| 1310 |
|
| #if CAN_PROFILE |
| 1311 |
0 |
| cover_time(aTHX); |
| 1312 |
|
| #endif |
| 1313 |
|
| |
| 1314 |
0 |
| MY_CXT.collecting_here = 1; |
| 1315 |
|
| |
| 1316 |
|
| NDEB(D(L, "exiting runops_cover\n")); |
| 1317 |
|
| |
| 1318 |
0 |
| TAINT_NOT; |
| 1319 |
0 |
| return 0; |
| 1320 |
|
| } |
| 1321 |
|
| |
| 1322 |
0 |
| static int runops_orig(pTHX) { |
| 1323 |
|
| NDEB(D(L, "entering runops_orig\n")); |
| 1324 |
|
| |
| 1325 |
0 |
▶ | while ((PL_op = PL_op->op_ppaddr(aTHX))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((PL_op = PL_op->op_ppaddr(aTHX))) { |
0 |
0 |
0 |
|
| 1326 |
0 |
▶ | PERL_ASYNC_CHECK(); |
Branch: 1 branch
| Branch | True | False | Total |
| PERL_ASYNC_CHECK(); |
0 |
0 |
0 |
|
| 1327 |
|
| } |
| 1328 |
|
| |
| 1329 |
|
| NDEB(D(L, "exiting runops_orig\n")); |
| 1330 |
|
| |
| 1331 |
0 |
| TAINT_NOT; |
| 1332 |
0 |
| return 0; |
| 1333 |
|
| } |
| 1334 |
|
| |
| 1335 |
|
| #if defined DO_RUNOPS_TRACE |
| 1336 |
|
| static int runops_trace(pTHX) { |
| 1337 |
|
| PDEB(D(L, "entering runops_trace\n")); |
| 1338 |
|
| |
| 1339 |
|
| for (;;) { |
| 1340 |
|
| PDEB(D(L, "running func %p from %p (%s)\n", |
| 1341 |
|
| PL_op->op_ppaddr, PL_op, OP_NAME(PL_op))); |
| 1342 |
|
| |
| 1343 |
|
| if (!(PL_op = PL_op->op_ppaddr(aTHX))) |
| 1344 |
|
| break; |
| 1345 |
|
| |
| 1346 |
|
| PERL_ASYNC_CHECK(); |
| 1347 |
|
| } |
| 1348 |
|
| |
| 1349 |
|
| PDEB(D(L, "exiting runops_trace\n")); |
| 1350 |
|
| |
| 1351 |
|
| TAINT_NOT; |
| 1352 |
|
| return 0; |
| 1353 |
|
| } |
| 1354 |
|
| #endif |
| 1355 |
|
| |
| 1356 |
|
| static char *svclassnames[] = { |
| 1357 |
|
| "B::NULL", |
| 1358 |
|
| "B::IV", |
| 1359 |
|
| "B::NV", |
| 1360 |
|
| "B::RV", |
| 1361 |
|
| "B::PV", |
| 1362 |
|
| "B::PVIV", |
| 1363 |
|
| "B::PVNV", |
| 1364 |
|
| "B::PVMG", |
| 1365 |
|
| "B::BM", |
| 1366 |
|
| "B::GV", |
| 1367 |
|
| "B::PVLV", |
| 1368 |
|
| "B::AV", |
| 1369 |
|
| "B::HV", |
| 1370 |
|
| "B::CV", |
| 1371 |
|
| "B::FM", |
| 1372 |
|
| "B::IO", |
| 1373 |
|
| }; |
| 1374 |
|
| |
| 1375 |
338 |
| static SV *make_sv_object(pTHX_ SV *arg, SV *sv) { |
| 1376 |
|
| IV iv; |
| 1377 |
|
| char *type; |
| 1378 |
|
| |
| 1379 |
338 |
| iv = PTR2IV(sv); |
| 1380 |
338 |
| type = svclassnames[SvTYPE(sv)]; |
| 1381 |
338 |
| sv_setiv(newSVrv(arg, type), iv); |
| 1382 |
338 |
| return arg; |
| 1383 |
|
| } |
| 1384 |
|
| |
| 1385 |
|
| |
| 1386 |
|
| typedef OP *B__OP; |
| 1387 |
|
| typedef AV *B__AV; |
| 1388 |
|
| |
| 1389 |
|
| |
| 1390 |
|
| MODULE = Devel::Cover PACKAGE = Devel::Cover |
| 1391 |
|
| |
| 1392 |
|
| PROTOTYPES: ENABLE |
| 1393 |
|
| |
| 1394 |
|
| void |
| 1395 |
|
| set_criteria(flag) |
| 1396 |
|
| unsigned flag |
| 1397 |
|
| PREINIT: |
| 1398 |
|
| dMY_CXT; |
| 1399 |
|
| PPCODE: |
| 1400 |
512 |
| MY_CXT.covering = flag; |
| 1401 |
|
| /* fprintf(stderr, "Cover set to %d\n", flag); */ |
| 1402 |
512 |
▶ | if (MY_CXT.replace_ops) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (MY_CXT.replace_ops) return; |
512 |
0 |
512 |
|
| 1403 |
0 |
▶ | PL_runops = MY_CXT.covering ? runops_cover : runops_orig; |
Branch: 1 branch
| Branch | True | False | Total |
| PL_runops = MY_CXT.covering ? runops_cover : runops_orig; |
0 |
0 |
0 |
|
| 1404 |
|
| |
| 1405 |
|
| void |
| 1406 |
|
| add_criteria(flag) |
| 1407 |
|
| unsigned flag |
| 1408 |
|
| PREINIT: |
| 1409 |
|
| dMY_CXT; |
| 1410 |
|
| PPCODE: |
| 1411 |
1 |
| MY_CXT.covering |= flag; |
| 1412 |
1 |
▶ | if (MY_CXT.replace_ops) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (MY_CXT.replace_ops) return; |
1 |
0 |
1 |
|
| 1413 |
0 |
▶ | PL_runops = MY_CXT.covering ? runops_cover : runops_orig; |
Branch: 1 branch
| Branch | True | False | Total |
| PL_runops = MY_CXT.covering ? runops_cover : runops_orig; |
0 |
0 |
0 |
|
| 1414 |
|
| |
| 1415 |
|
| void |
| 1416 |
|
| remove_criteria(flag) |
| 1417 |
|
| unsigned flag |
| 1418 |
|
| PREINIT: |
| 1419 |
|
| dMY_CXT; |
| 1420 |
|
| PPCODE: |
| 1421 |
1 |
| MY_CXT.covering &= ~flag; |
| 1422 |
1 |
▶ | if (MY_CXT.replace_ops) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (MY_CXT.replace_ops) return; |
1 |
0 |
1 |
|
| 1423 |
0 |
▶ | PL_runops = MY_CXT.covering ? runops_cover : runops_orig; |
Branch: 1 branch
| Branch | True | False | Total |
| PL_runops = MY_CXT.covering ? runops_cover : runops_orig; |
0 |
0 |
0 |
|
| 1424 |
|
| |
| 1425 |
|
| unsigned |
| 1426 |
|
| get_criteria() |
| 1427 |
|
| PREINIT: |
| 1428 |
|
| dMY_CXT; |
| 1429 |
|
| CODE: |
| 1430 |
514 |
▶ | RETVAL = MY_CXT.covering; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = MY_CXT.covering; |
344 |
170 |
514 |
|
| 1431 |
|
| OUTPUT: |
| 1432 |
|
| RETVAL |
| 1433 |
|
| |
| 1434 |
|
| unsigned |
| 1435 |
|
| coverage_none() |
| 1436 |
|
| CODE: |
| 1437 |
171 |
▶ | RETVAL = None; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = None; |
88 |
83 |
171 |
|
| 1438 |
|
| OUTPUT: |
| 1439 |
|
| RETVAL |
| 1440 |
|
| |
| 1441 |
|
| unsigned |
| 1442 |
|
| coverage_statement() |
| 1443 |
|
| CODE: |
| 1444 |
170 |
▶ | RETVAL = Statement; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = Statement; |
0 |
170 |
170 |
|
| 1445 |
|
| OUTPUT: |
| 1446 |
|
| RETVAL |
| 1447 |
|
| |
| 1448 |
|
| unsigned |
| 1449 |
|
| coverage_branch() |
| 1450 |
|
| CODE: |
| 1451 |
170 |
▶ | RETVAL = Branch; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = Branch; |
170 |
0 |
170 |
|
| 1452 |
|
| OUTPUT: |
| 1453 |
|
| RETVAL |
| 1454 |
|
| |
| 1455 |
|
| unsigned |
| 1456 |
|
| coverage_condition() |
| 1457 |
|
| CODE: |
| 1458 |
170 |
▶ | RETVAL = Condition; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = Condition; |
170 |
0 |
170 |
|
| 1459 |
|
| OUTPUT: |
| 1460 |
|
| RETVAL |
| 1461 |
|
| |
| 1462 |
|
| unsigned |
| 1463 |
|
| coverage_subroutine() |
| 1464 |
|
| CODE: |
| 1465 |
170 |
▶ | RETVAL = Subroutine; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = Subroutine; |
170 |
0 |
170 |
|
| 1466 |
|
| OUTPUT: |
| 1467 |
|
| RETVAL |
| 1468 |
|
| |
| 1469 |
|
| unsigned |
| 1470 |
|
| coverage_path() |
| 1471 |
|
| CODE: |
| 1472 |
170 |
▶ | RETVAL = Path; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = Path; |
170 |
0 |
170 |
|
| 1473 |
|
| OUTPUT: |
| 1474 |
|
| RETVAL |
| 1475 |
|
| |
| 1476 |
|
| unsigned |
| 1477 |
|
| coverage_pod() |
| 1478 |
|
| CODE: |
| 1479 |
170 |
▶ | RETVAL = Pod; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = Pod; |
170 |
0 |
170 |
|
| 1480 |
|
| OUTPUT: |
| 1481 |
|
| RETVAL |
| 1482 |
|
| |
| 1483 |
|
| unsigned |
| 1484 |
|
| coverage_time() |
| 1485 |
|
| CODE: |
| 1486 |
170 |
▶ | RETVAL = Time; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = Time; |
170 |
0 |
170 |
|
| 1487 |
|
| OUTPUT: |
| 1488 |
|
| RETVAL |
| 1489 |
|
| |
| 1490 |
|
| unsigned |
| 1491 |
|
| coverage_all() |
| 1492 |
|
| CODE: |
| 1493 |
88 |
▶ | RETVAL = All; |
Branch: 1 branch
| Branch | True | False | Total |
| RETVAL = All; |
1 |
87 |
88 |
|
| 1494 |
|
| OUTPUT: |
| 1495 |
|
| RETVAL |
| 1496 |
|
| |
| 1497 |
|
| double |
| 1498 |
|
| get_elapsed() |
| 1499 |
|
| CODE: |
| 1500 |
|
| #ifdef HAS_GETTIMEOFDAY |
| 1501 |
340 |
| RETVAL = get_elapsed(); |
| 1502 |
|
| #else |
| 1503 |
|
| RETVAL = 0; |
| 1504 |
|
| #endif |
| 1505 |
|
| OUTPUT: |
| 1506 |
|
| RETVAL |
| 1507 |
|
| |
| 1508 |
|
| SV * |
| 1509 |
|
| coverage(final) |
| 1510 |
|
| unsigned final |
| 1511 |
|
| PREINIT: |
| 1512 |
|
| dMY_CXT; |
| 1513 |
|
| CODE: |
| 1514 |
|
| NDEB(D(L, "Getting coverage %d\n", final)); |
| 1515 |
41446 |
▶ | if (final) finalise_conditions(aTHX); |
Branch: 1 branch
| Branch | True | False | Total |
| if (final) finalise_conditions(aTHX); |
170 |
41276 |
41446 |
|
| 1516 |
41446 |
▶ | if (MY_CXT.cover) |
Branch: 1 branch
| Branch | True | False | Total |
| if (MY_CXT.cover) |
41446 |
0 |
41446 |
|
| 1517 |
41446 |
| RETVAL = newRV_inc((SV*) MY_CXT.cover); |
| 1518 |
|
| else |
| 1519 |
0 |
| RETVAL = &PL_sv_undef; |
| 1520 |
|
| OUTPUT: |
| 1521 |
|
| RETVAL |
| 1522 |
|
| |
| 1523 |
|
| SV * |
| 1524 |
|
| get_key(o) |
| 1525 |
|
| B::OP o |
| 1526 |
|
| CODE: |
| 1527 |
2430 |
| RETVAL = newSV(KEY_SZ + 1); |
| 1528 |
2430 |
| sv_setpvn(RETVAL, get_key(o), KEY_SZ); |
| 1529 |
|
| OUTPUT: |
| 1530 |
|
| RETVAL |
| 1531 |
|
| |
| 1532 |
|
| void |
| 1533 |
|
| set_first_init_and_end() |
| 1534 |
|
| PPCODE: |
| 1535 |
170 |
| set_firsts_if_needed(aTHX); |
| 1536 |
|
| |
| 1537 |
|
| void |
| 1538 |
|
| collect_inits() |
| 1539 |
|
| PREINIT: |
| 1540 |
|
| dMY_CXT; |
| 1541 |
|
| PPCODE: |
| 1542 |
|
| int i; |
| 1543 |
170 |
▶ | if (!MY_CXT.ends) MY_CXT.ends = newAV(); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!MY_CXT.ends) MY_CXT.ends = newAV(); |
170 |
0 |
170 |
|
| 1544 |
|
| NDEB(svdump(MY_CXT.ends)); |
| 1545 |
170 |
▶ | if (PL_initav) |
Branch: 1 branch
| Branch | True | False | Total |
| if (PL_initav) |
170 |
0 |
170 |
|
| 1546 |
513 |
▶ | for (i = 0; i <= av_len(PL_initav); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(PL_initav); i++) { |
343 |
170 |
513 |
|
| 1547 |
343 |
| SV **cv = av_fetch(PL_initav, i, 0); |
| 1548 |
343 |
| SvREFCNT_inc(*cv); |
| 1549 |
343 |
| av_push(MY_CXT.ends, *cv); |
| 1550 |
|
| } |
| 1551 |
|
| |
| 1552 |
|
| void |
| 1553 |
|
| set_last_end() |
| 1554 |
|
| PREINIT: |
| 1555 |
|
| dMY_CXT; |
| 1556 |
|
| PPCODE: |
| 1557 |
|
| int i; |
| 1558 |
170 |
| SV *end = (SV *)get_cv("last_end", 0); |
| 1559 |
170 |
| av_push(PL_endav, end); |
| 1560 |
|
| NDEB(svdump(end)); |
| 1561 |
170 |
▶ | if (!MY_CXT.ends) MY_CXT.ends = newAV(); |
Branch: 1 branch
| Branch | True | False | Total |
| if (!MY_CXT.ends) MY_CXT.ends = newAV(); |
0 |
170 |
170 |
|
| 1562 |
170 |
▶ | if (PL_endav) |
Branch: 1 branch
| Branch | True | False | Total |
| if (PL_endav) |
170 |
0 |
170 |
|
| 1563 |
832 |
▶ | for (i = 0; i <= av_len(PL_endav); i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= av_len(PL_endav); i++) { |
662 |
170 |
832 |
|
| 1564 |
662 |
| SV **cv = av_fetch(PL_endav, i, 0); |
| 1565 |
662 |
| SvREFCNT_inc(*cv); |
| 1566 |
662 |
| av_push(MY_CXT.ends, *cv); |
| 1567 |
|
| } |
| 1568 |
|
| |
| 1569 |
|
| B::AV |
| 1570 |
|
| get_ends() |
| 1571 |
|
| PREINIT: |
| 1572 |
|
| dMY_CXT; |
| 1573 |
|
| CODE: |
| 1574 |
338 |
▶ | if (!MY_CXT.ends) MY_CXT.ends = newAV(); /* TODO: how? */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!MY_CXT.ends) MY_CXT.ends = newAV(); /* TODO: how? */ |
0 |
338 |
338 |
|
| 1575 |
338 |
| RETVAL = MY_CXT.ends; |
| 1576 |
|
| OUTPUT: |
| 1577 |
|
| RETVAL |
| 1578 |
|
| |
| 1579 |
|
| BOOT: |
| 1580 |
|
| { |
| 1581 |
|
| MY_CXT_INIT; |
| 1582 |
|
| #ifdef USE_ITHREADS |
| 1583 |
|
| MUTEX_INIT(&DC_mutex); |
| 1584 |
|
| #endif |
| 1585 |
170 |
| initialise(aTHX); |
| 1586 |
170 |
▶ | if (MY_CXT.replace_ops) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (MY_CXT.replace_ops) { |
170 |
0 |
170 |
|
| 1587 |
170 |
| replace_ops(aTHX); |
| 1588 |
|
| #if defined HAS_GETTIMEOFDAY |
| 1589 |
170 |
| elapsed(); |
| 1590 |
|
| #elif defined HAS_TIMES |
| 1591 |
|
| cpu(); |
| 1592 |
|
| #endif |
| 1593 |
|
| #if defined DO_RUNOPS_TRACE |
| 1594 |
|
| PL_runops = runops_trace; |
| 1595 |
|
| #endif |
| 1596 |
|
| } else { |
| 1597 |
0 |
| PL_runops = runops_cover; |
| 1598 |
|
| } |
| 1599 |
170 |
| PL_savebegin = TRUE; |
| 1600 |
|
| } |