Skip to content

Commit

Permalink
- Override some more opcodes as there is not always EXT_STMT when you…
Browse files Browse the repository at this point in the history
… expect

  it. This should give better results for code coverage.

SVN Rev: 1566
  • Loading branch information
derickr committed Oct 29, 2004
1 parent 84021cf commit 8d6392a
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 20 deletions.
2 changes: 1 addition & 1 deletion test.sh
@@ -1 +1 @@
TEST_PHP_EXECUTABLE=`which php-5.1dev` php-5.1dev -dxdebug.auto_trace=0 /dat/dev/php/php-5.1dev/run-tests.php tests/*.phpt
TEST_PHP_EXECUTABLE=`which php-5.0dev` php-5.0dev -dxdebug.auto_trace=0 /dat/dev/php/php-5.0dev/run-tests.php tests/*.phpt
18 changes: 12 additions & 6 deletions tests/coverage.phpt
Expand Up @@ -24,29 +24,35 @@ xdebug.trace_format=0
--EXPECTF--
This is a YYYY-MM-DD format.
This is a YYYYMMDD HHii format.
array(12) {
array(15) {
[2]=>
int(1)
[4]=>
int(4)
int(1)
[7]=>
int(2)
int(1)
[8]=>
int(1)
[9]=>
int(1)
[10]=>
int(1)
[11]=>
int(1)
[12]=>
int(1)
[17]=>
int(2)
int(1)
[18]=>
int(2)
int(1)
[20]=>
int(1)
[21]=>
int(1)
[22]=>
int(4)
int(1)
[23]=>
int(1)
[25]=>
int(1)
}
16 changes: 8 additions & 8 deletions tests/coverage2.phpt
Expand Up @@ -28,37 +28,37 @@ array(%d) {
[2]=>
int(1)
[4]=>
int(4)
int(1)
[5]=>
int(-1)
[6]=>
int(-1)
[7]=>
int(2)
int(1)
[8]=>
int(1)
[9]=>
int(-1)
int(1)
[10]=>
int(1)
[11]=>
int(1)
[12]=>
int(-1)
int(1)
[14]=>
int(-1)
[17]=>
int(2)
int(1)
[18]=>
int(2)
int(1)
[20]=>
int(1)
[21]=>
int(1)
[22]=>
int(4)
int(1)
[23]=>
int(-1)
int(1)
[25]=>
int(1)
}
67 changes: 67 additions & 0 deletions tests/coverage3.phpt
@@ -0,0 +1,67 @@
--TEST--
Test with Code Coverage with unused lines
--INI--
xdebug.default_enable=1
xdebug.auto_trace=0
xdebug.trace_options=0
xdebug.trace_output_dir=/tmp
xdebug.collect_params=1
xdebug.collect_return=0
xdebug.auto_profile=0
xdebug.profiler_enable=0
xdebug.dump_globals=0
xdebug.show_mem_delta=0
xdebug.trace_format=0
xdebug.extended_info=1
--FILE--
<?php
function a($b)
{
if ($b == 0)
{
return true;
}
else
if ($b == 1)
{
return false;
}
};

xdebug_start_code_coverage(true);

a(1);

xdebug_stop_code_coverage(false);
var_dump(xdebug_get_code_coverage());
?>
--EXPECTF--
array(1) {
["/dat/dev/php/xdebug/tests/coverage3.php"]=>
array(12) {
[2]=>
int(-1)
[4]=>
int(1)
[5]=>
int(1)
[6]=>
int(-1)
[7]=>
int(-1)
[9]=>
int(1)
[10]=>
int(1)
[11]=>
int(1)
[12]=>
int(-1)
[13]=>
int(-1)
[17]=>
int(1)
[19]=>
int(1)
}
}
66 changes: 66 additions & 0 deletions xdebug.c
Expand Up @@ -87,8 +87,27 @@ void xdebug_error_cb(int type, const char *error_filename, const uint error_line

#ifdef ZEND_ENGINE_2
void xdebug_throw_exception_hook(zval *exception TSRMLS_DC);

int xdebug_exit_handler(ZEND_OPCODE_HANDLER_ARGS);
int (*old_exit_handler)(ZEND_OPCODE_HANDLER_ARGS);

static int xdebug_jmp_handler(ZEND_OPCODE_HANDLER_ARGS);
static int (*old_jmp_handler)(ZEND_OPCODE_HANDLER_ARGS);
static int xdebug_jmpz_handler(ZEND_OPCODE_HANDLER_ARGS);
static int (*old_jmpz_handler)(ZEND_OPCODE_HANDLER_ARGS);

static int xdebug_is_identical_handler(ZEND_OPCODE_HANDLER_ARGS);
static int (*old_is_identical_handler)(ZEND_OPCODE_HANDLER_ARGS);
static int xdebug_is_not_identical_handler(ZEND_OPCODE_HANDLER_ARGS);
static int (*old_is_not_identical_handler)(ZEND_OPCODE_HANDLER_ARGS);
static int xdebug_is_equal_handler(ZEND_OPCODE_HANDLER_ARGS);
static int (*old_is_equal_handler)(ZEND_OPCODE_HANDLER_ARGS);
static int xdebug_is_not_equal_handler(ZEND_OPCODE_HANDLER_ARGS);
static int (*old_is_not_equal_handler)(ZEND_OPCODE_HANDLER_ARGS);
static int xdebug_is_smaller_handler(ZEND_OPCODE_HANDLER_ARGS);
static int (*old_is_smaller_handler)(ZEND_OPCODE_HANDLER_ARGS);
static int xdebug_is_smaller_or_equal_handler(ZEND_OPCODE_HANDLER_ARGS);
static int (*old_is_smaller_or_equal_handler)(ZEND_OPCODE_HANDLER_ARGS);
#endif

static zval *get_zval(znode *node, temp_variable *Ts, int *is_var);
Expand Down Expand Up @@ -437,6 +456,24 @@ PHP_MINIT_FUNCTION(xdebug)
#ifdef ZEND_ENGINE_2
old_exit_handler = zend_opcode_handlers[ZEND_EXIT];
zend_opcode_handlers[ZEND_EXIT] = xdebug_exit_handler;

old_jmp_handler = zend_opcode_handlers[ZEND_JMP];
old_jmpz_handler = zend_opcode_handlers[ZEND_JMPZ];
old_is_identical_handler = zend_opcode_handlers[ZEND_IS_IDENTICAL];
old_is_not_identical_handler = zend_opcode_handlers[ZEND_IS_NOT_IDENTICAL];
old_is_equal_handler = zend_opcode_handlers[ZEND_IS_EQUAL];
old_is_not_equal_handler = zend_opcode_handlers[ZEND_IS_NOT_EQUAL];
old_is_smaller_handler = zend_opcode_handlers[ZEND_IS_SMALLER];
old_is_smaller_or_equal_handler = zend_opcode_handlers[ZEND_IS_SMALLER_OR_EQUAL];

zend_opcode_handlers[ZEND_JMP] = xdebug_jmp_handler;
zend_opcode_handlers[ZEND_JMPZ] = xdebug_jmpz_handler;
zend_opcode_handlers[ZEND_IS_IDENTICAL] = xdebug_is_identical_handler;
zend_opcode_handlers[ZEND_IS_NOT_IDENTICAL] = xdebug_is_not_identical_handler;
zend_opcode_handlers[ZEND_IS_EQUAL] = xdebug_is_equal_handler;
zend_opcode_handlers[ZEND_IS_NOT_EQUAL] = xdebug_is_not_equal_handler;
zend_opcode_handlers[ZEND_IS_SMALLER] = xdebug_is_smaller_handler;
zend_opcode_handlers[ZEND_IS_SMALLER_OR_EQUAL] = xdebug_is_smaller_or_equal_handler;
#endif

if (zend_xdebug_initialised == 0) {
Expand Down Expand Up @@ -1506,6 +1543,35 @@ void xdebug_throw_exception_hook(zval *exception TSRMLS_DC)
}
}

/* Needed for code coverage as Zend doesn't always add EXT_STMT when expected */
#define XDEBUG_OPCODE_OVERRIDE(f) static int xdebug_##f##_handler(ZEND_OPCODE_HANDLER_ARGS) \
{ \
if (XG(do_code_coverage)) { \
zend_op *cur_opcode; \
int lineno; \
char *file; \
int file_len; \
\
cur_opcode = *EG(opline_ptr); \
lineno = cur_opcode->lineno; \
\
file = op_array->filename; \
file_len = strlen(file); \
\
xdebug_count_line(file, lineno, 0 TSRMLS_CC); \
} \
return old_##f##_handler(ZEND_OPCODE_HANDLER_ARGS_PASSTHRU); \
}
XDEBUG_OPCODE_OVERRIDE(jmp)
XDEBUG_OPCODE_OVERRIDE(jmpz)
XDEBUG_OPCODE_OVERRIDE(is_identical)
XDEBUG_OPCODE_OVERRIDE(is_not_identical)
XDEBUG_OPCODE_OVERRIDE(is_equal)
XDEBUG_OPCODE_OVERRIDE(is_not_equal)
XDEBUG_OPCODE_OVERRIDE(is_smaller)
XDEBUG_OPCODE_OVERRIDE(is_smaller_or_equal)

/* Opcode handler for exit, to be able to clean up the profiler */
int xdebug_exit_handler(ZEND_OPCODE_HANDLER_ARGS)
{
if (XG(profiler_enabled)) {
Expand Down
12 changes: 7 additions & 5 deletions xdebug_code_coverage.c
Expand Up @@ -114,11 +114,13 @@ PHP_FUNCTION(xdebug_stop_code_coverage)
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "|l", &cleanup) == FAILURE) {
return;
}
if (cleanup) {
xdebug_hash_destroy(XG(code_coverage));
XG(code_coverage) = xdebug_hash_alloc(32, xdebug_coverage_file_dtor);
if (XG(do_code_coverage)) {
if (cleanup) {
xdebug_hash_destroy(XG(code_coverage));
XG(code_coverage) = xdebug_hash_alloc(32, xdebug_coverage_file_dtor);
}
XG(do_code_coverage) = 0;
}
XG(do_code_coverage) = 0;
}


Expand All @@ -145,7 +147,7 @@ static void add_line(void *ret, xdebug_hash_element *e)
if (line->executable && (line->count == 0)) {
add_index_long(retval, line->lineno, -1);
} else {
add_index_long(retval, line->lineno, line->count);
add_index_long(retval, line->lineno, 1);
}
}

Expand Down

0 comments on commit 8d6392a

Please sign in to comment.