Skip to content

Commit 90c664c

Browse files
committed
WIP: Recording soft fails for individual opcodes
1 parent 89261cb commit 90c664c

File tree

5 files changed

+12
-6
lines changed

5 files changed

+12
-6
lines changed

src/coverage/branch_info.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ void xdebug_branch_info_free(xdebug_branch_info *branch_info)
5555
free(branch_info);
5656
}
5757

58-
void xdebug_branch_info_update(xdebug_branch_info *branch_info, unsigned int pos, unsigned int lineno, unsigned int outidx, unsigned int jump_pos)
58+
void xdebug_branch_info_update(xdebug_branch_info *branch_info, unsigned int pos, unsigned int lineno, unsigned int outidx, unsigned int jump_pos, bool soft_fail)
5959
{
6060
xdebug_set_add(branch_info->ends, pos);
6161
if (outidx < XDEBUG_BRANCH_MAX_OUTS) {
@@ -65,6 +65,7 @@ void xdebug_branch_info_update(xdebug_branch_info *branch_info, unsigned int pos
6565
}
6666
}
6767
branch_info->branches[pos].start_lineno = lineno;
68+
branch_info->branches[pos].soft_fail = soft_fail;
6869
}
6970

7071
static void only_leave_first_catch(zend_op_array *opa, xdebug_branch_info *branch_info, int position)

src/coverage/branch_info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ typedef struct _xdebug_branch {
4141
unsigned int end_op;
4242
unsigned int outs_count;
4343
int outs[XDEBUG_BRANCH_MAX_OUTS];
44+
bool soft_fails[XDEBUG_BRANCH_MAX_OUTS];
4445
} xdebug_branch;
4546

4647
typedef struct _xdebug_path {

src/coverage/code_coverage.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ static zend_always_inline bool xdebug_string_equals_cstr(const zend_string *s1,
321321
# define xdebug_string_equals_literal zend_string_equals_literal
322322
#endif
323323

324-
static int xdebug_find_jumps(zend_op_array *opa, unsigned int position, size_t *jump_count, int *jumps)
324+
static int xdebug_find_jumps(zend_op_array *opa, unsigned int position, size_t *jump_count, int *jumps, bool *soft_fail_jumps)
325325
{
326326
#if ZEND_USE_ABS_JMP_ADDR
327327
zend_op *base_address = &(opa->opcodes[0]);
@@ -361,6 +361,7 @@ static int xdebug_find_jumps(zend_op_array *opa, unsigned int position, size_t *
361361
} else if (opcode.opcode == ZEND_FE_RESET_R || opcode.opcode == ZEND_FE_RESET_RW) {
362362
jumps[0] = position + 1;
363363
jumps[1] = XDEBUG_ZNODE_JMP_LINE(opcode.op2, position, base_address);
364+
soft_fail_jumps[1] = true;
364365
*jump_count = 2;
365366
return 1;
366367

@@ -512,10 +513,14 @@ static void xdebug_analysis_branch(zend_op_array *opa, unsigned int position, xd
512513
while (position < opa->last) {
513514
size_t jump_count = 0;
514515
int jumps[XDEBUG_BRANCH_MAX_OUTS];
516+
bool soft_fail_jumps[XDEBUG_BRANCH_MAX_OUTS];
515517
size_t i;
516518

519+
/* Clean out soft_fail_jumps */
520+
memset(soft_fail_jumps, 0, sizeof(soft_fail_jumps));
521+
517522
/* See if we have a jump instruction */
518-
if (xdebug_find_jumps(opa, position, &jump_count, jumps)) {
523+
if (xdebug_find_jumps(opa, position, &jump_count, jumps, soft_fail_jumps)) {
519524
/* Record the highest jump if we have branch information*/
520525
if (branch_info && jump_count > branch_info->highest_out) {
521526
branch_info->highest_out = jump_count;
@@ -524,7 +529,7 @@ static void xdebug_analysis_branch(zend_op_array *opa, unsigned int position, xd
524529
for (i = 0; i < jump_count; i++) {
525530
if (jumps[i] == XDEBUG_JMP_EXIT || jumps[i] != XDEBUG_JMP_NOT_SET) {
526531
if (branch_info) {
527-
xdebug_branch_info_update(branch_info, position, opa->opcodes[position].lineno, i, jumps[i]);
532+
xdebug_branch_info_update(branch_info, position, opa->opcodes[position].lineno, i, jumps[i], soft_fail_jumps[i]);
528533
}
529534
if (jumps[i] != XDEBUG_JMP_EXIT) {
530535
xdebug_analysis_branch(opa, jumps[i], set, branch_info);

src/coverage/code_coverage_private.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ typedef struct xdebug_coverage_file {
6464

6565
xdebug_branch_info *xdebug_branch_info_create(unsigned int size);
6666

67-
void xdebug_branch_info_update(xdebug_branch_info *branch_info, unsigned int pos, unsigned int lineno, unsigned int outidx, unsigned int jump_pos);
67+
void xdebug_branch_info_update(xdebug_branch_info *branch_info, unsigned int pos, unsigned int lineno, unsigned int outidx, unsigned int jump_pos, bool soft_fail);
6868
void xdebug_branch_post_process(zend_op_array *opa, xdebug_branch_info *branch_info);
6969
void xdebug_branch_find_paths(xdebug_branch_info *branch_info);
7070

tests/coverage/foreach.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ showLanguages
5454
- paths
5555
- 0 3 4 3 9: HIT
5656
- 0 3 9: HIT
57-
- 0 9: X
5857

5958
showLanguages
6059
- branches

0 commit comments

Comments
 (0)