Index: xdebug.c =================================================================== RCS file: /repository/xdebug/xdebug.c,v retrieving revision 1.305 diff -u -r1.305 xdebug.c --- xdebug.c 10 Mar 2006 12:10:26 -0000 1.305 +++ xdebug.c 11 Mar 2006 01:56:38 -0000 @@ -90,25 +90,8 @@ #endif #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 0) -int (*old_exit_handler)(ZEND_OPCODE_HANDLER_ARGS); - -static int (*old_jmp_handler)(ZEND_OPCODE_HANDLER_ARGS); -static int (*old_jmpz_handler)(ZEND_OPCODE_HANDLER_ARGS); -static int (*old_is_identical_handler)(ZEND_OPCODE_HANDLER_ARGS); -static int (*old_is_not_identical_handler)(ZEND_OPCODE_HANDLER_ARGS); -static int (*old_is_equal_handler)(ZEND_OPCODE_HANDLER_ARGS); -static int (*old_is_not_equal_handler)(ZEND_OPCODE_HANDLER_ARGS); -static int (*old_is_smaller_handler)(ZEND_OPCODE_HANDLER_ARGS); -static int (*old_is_smaller_or_equal_handler)(ZEND_OPCODE_HANDLER_ARGS); - -static int xdebug_jmp_handler(ZEND_OPCODE_HANDLER_ARGS); -static int xdebug_jmpz_handler(ZEND_OPCODE_HANDLER_ARGS); -static int xdebug_is_identical_handler(ZEND_OPCODE_HANDLER_ARGS); -static int xdebug_is_not_identical_handler(ZEND_OPCODE_HANDLER_ARGS); -static int xdebug_is_equal_handler(ZEND_OPCODE_HANDLER_ARGS); -static int xdebug_is_not_equal_handler(ZEND_OPCODE_HANDLER_ARGS); -static int xdebug_is_smaller_handler(ZEND_OPCODE_HANDLER_ARGS); -static int xdebug_is_smaller_or_equal_handler(ZEND_OPCODE_HANDLER_ARGS); +typedef int (*opcode_handler_t) (ZEND_OPCODE_HANDLER_ARGS); +opcode_handler_t old_handlers[256]; #endif #ifdef ZEND_ENGINE_2 @@ -452,58 +435,53 @@ #ifdef ZEND_ENGINE_2 /* Needed for code coverage as Zend doesn't always add EXT_STMT when expected */ # if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1) || PHP_MAJOR_VERSION >= 6 -#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; \ - zend_op_array *op_array = execute_data->op_array; \ -\ - 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 ZEND_USER_OPCODE_DISPATCH; \ +static int xdebug_opcode_handler(ZEND_OPCODE_HANDLER_ARGS) +{ + if (XG(do_code_coverage)) { + zend_op *cur_opcode; + int lineno; + char *file; + int file_len; + zend_op_array *op_array = execute_data->op_array; + + 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 ZEND_USER_OPCODE_DISPATCH; } #else -#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); \ -} -#endif -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) +static int xdebug_opcode_handler(ZEND_OPCODE_HANDLER_ARGS) +{ + zend_op *cur_opcode; + cur_opcode = *EG(opline_ptr); + + if (XG(do_code_coverage)) { + int lineno; + char *file; + int file_len; + + lineno = cur_opcode->lineno; + + file = op_array->filename; + file_len = strlen(file); + + xdebug_count_line(file, lineno, 0 TSRMLS_CC); + } + return old_handlers[cur_opcode->opcode](ZEND_OPCODE_HANDLER_ARGS_PASSTHRU); +} +#endif #endif PHP_MINIT_FUNCTION(xdebug) { + int i; + ZEND_INIT_MODULE_GLOBALS(xdebug, php_xdebug_init_globals, php_xdebug_shutdown_globals); REGISTER_INI_ENTRIES(); #if 0 @@ -534,39 +512,15 @@ new_error_cb = xdebug_error_cb; /* Overload the "exit" opcode */ + for (i = 0; i < 256; i ++) { #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 0) - 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; + old_handlers[i] = zend_opcode_handlers[i]; + zend_opcode_handlers[i] = xdebug_opcode_handler; #endif #if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 1) || PHP_MAJOR_VERSION >= 6 - zend_set_user_opcode_handler(ZEND_EXIT, xdebug_exit_handler); - zend_set_user_opcode_handler(ZEND_JMP, xdebug_jmp_handler); - zend_set_user_opcode_handler(ZEND_JMPZ, xdebug_jmpz_handler); - zend_set_user_opcode_handler(ZEND_IS_IDENTICAL, xdebug_is_identical_handler); - zend_set_user_opcode_handler(ZEND_IS_NOT_IDENTICAL, xdebug_is_not_identical_handler); - zend_set_user_opcode_handler(ZEND_IS_EQUAL, xdebug_is_equal_handler); - zend_set_user_opcode_handler(ZEND_IS_NOT_EQUAL, xdebug_is_not_equal_handler); - zend_set_user_opcode_handler(ZEND_IS_SMALLER, xdebug_is_smaller_handler); - zend_set_user_opcode_handler(ZEND_IS_SMALLER_OR_EQUAL, xdebug_is_smaller_or_equal_handler); + zend_set_user_opcode_handler(i, xdebug_opcode_handler); #endif + } if (zend_xdebug_initialised == 0) { zend_error(E_WARNING, "Xdebug MUST be loaded as a Zend extension"); @@ -1012,9 +966,11 @@ } } +#ifndef ZEND_ENGINE_2 if (XG(do_code_coverage)) { xdebug_count_line(tmp->filename, tmp->lineno, 0 TSRMLS_CC); } +#endif if (XG(profiler_aggregate)) { char *func_name = show_fname(tmp->function, 0, 0 TSRMLS_CC); @@ -1338,10 +1300,6 @@ } } - if (XG(do_code_coverage) && XG(code_coverage_unused)) { - xdebug_prefil_code_coverage(fse, op_array TSRMLS_CC); - } - /* If we're in an eval, we need to create an ID for it. This ID however * depends on the debugger mechanism in use so we need to call a function * in the handler for it */ @@ -1923,6 +1887,10 @@ zend_op_array *op_array; op_array = old_compile_file(file_handle, type TSRMLS_CC); + + if (op_array && XG(do_code_coverage) && XG(code_coverage_unused)) { + xdebug_prefil_code_coverage(NULL, op_array TSRMLS_CC); + } return op_array; } @@ -2256,7 +2224,7 @@ zend_error_cb = old_error_cb; #ifdef ZEND_ENGINE_2 # if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 0) - zend_opcode_handlers[ZEND_EXIT] = old_exit_handler; + zend_opcode_handlers[ZEND_EXIT] = old_handlers[ZEND_EXIT]; # endif zend_throw_exception_hook = NULL; #endif @@ -2547,9 +2515,11 @@ file = op_array->filename; file_len = strlen(file); +#ifndef ZEND_ENGINE_2 if (XG(do_code_coverage)) { xdebug_count_line(file, lineno, 0 TSRMLS_CC); } +#endif if (XG(remote_enabled)) {