diff --git a/src/coverage/code_coverage.c b/src/coverage/code_coverage.c index f8b8e0602..cef5088a4 100644 --- a/src/coverage/code_coverage.c +++ b/src/coverage/code_coverage.c @@ -842,6 +842,7 @@ static void add_cc_function(void *ret, xdebug_hash_element *e) xdebug_coverage_function *function = (xdebug_coverage_function*) e->ptr; zval *retval = (zval*) ret; zval *function_info; + zend_string *trait_scope = NULL; XDEBUG_MAKE_STD_ZVAL(function_info); array_init(function_info); @@ -851,7 +852,14 @@ static void add_cc_function(void *ret, xdebug_hash_element *e) add_paths(function_info, function->branch_info); } - add_assoc_zval_ex(retval, function->name, HASH_KEY_STRLEN(function->name), function_info); + if ((trait_scope = xdebug_get_trait_scope(function->name)) != NULL) { + char *with_scope = xdebug_sprintf("%s->%s", ZSTR_VAL(trait_scope), function->name); + + add_assoc_zval_ex(retval, with_scope, strlen(with_scope), function_info); + } else { + add_assoc_zval_ex(retval, function->name, HASH_KEY_STRLEN(function->name), function_info); + } + efree(function_info); } diff --git a/src/lib/lib.c b/src/lib/lib.c index e802bd4e1..ee21cb812 100644 --- a/src/lib/lib.c +++ b/src/lib/lib.c @@ -93,6 +93,8 @@ void xdebug_library_rinit(void) XG_LIB(dumped) = 0; XG_LIB(do_collect_errors) = 0; + + XG_LIB(trait_location_map) = xdebug_hash_alloc(256, (xdebug_hash_dtor_t) zend_string_release); } void xdebug_library_post_deactivate(void) @@ -101,6 +103,7 @@ void xdebug_library_post_deactivate(void) xdebug_llist_destroy(XG_LIB(headers), NULL); XG_LIB(headers) = NULL; + xdebug_hash_destroy(XG_LIB(trait_location_map)); xdebug_close_log(); xdebug_str_free(XG_LIB(diagnosis_buffer)); @@ -703,9 +706,26 @@ void xdebug_llist_string_dtor(void *dummy, void *elem) } } -zend_string* xdebug_wrap_location_around_function_name(const char *prefix, zend_op_array *opa, zend_string *fname) +zend_string *xdebug_get_trait_scope(const char *function) +{ + zend_string *trait_scope; + + if ( + function[0] != '{' && + function[strlen(function)-1] == '}' && + xdebug_hash_find(XG_LIB(trait_location_map), function, strlen(function), (void *) &trait_scope) + ) { + return trait_scope; + } + + return NULL; +} + +zend_string *xdebug_wrap_location_around_function_name(const char *prefix, zend_op_array *opa, zend_string *fname) { - return zend_strpprintf( + void *dummy; + + zend_string *wrapped = zend_strpprintf( 0, "%s{%s:%s:%d-%d}", ZSTR_VAL(fname), @@ -714,6 +734,12 @@ zend_string* xdebug_wrap_location_around_function_name(const char *prefix, zend_ opa->line_start, opa->line_end ); + + if (!xdebug_hash_find(XG_LIB(trait_location_map), ZSTR_VAL(wrapped), ZSTR_LEN(wrapped), &dummy)) { + xdebug_hash_add(XG_LIB(trait_location_map), ZSTR_VAL(wrapped), ZSTR_LEN(wrapped), zend_string_copy(opa->scope->name)); + } + + return wrapped; } zend_string* xdebug_wrap_closure_location_around_function_name(zend_op_array *opa, zend_string *fname) diff --git a/src/lib/lib.h b/src/lib/lib.h index 2a05b509f..e5f4a9e81 100644 --- a/src/lib/lib.h +++ b/src/lib/lib.h @@ -235,6 +235,10 @@ typedef struct _xdebug_library_globals_t { char *log_open_timestring; xdebug_str *diagnosis_buffer; + /* Trait location map */ + xdebug_hash *trait_location_map; + + /* Opcode overrite handlers */ user_opcode_handler_t original_opcode_handlers[256]; xdebug_multi_opcode_handler_t *opcode_multi_handlers[256]; xdebug_set *opcode_handlers_set; @@ -335,6 +339,8 @@ int xdebug_call_original_opcode_handler_if_set(int opcode, XDEBUG_OPCODE_HANDLER char *xdebug_lib_get_output_dir(void); void xdebug_llist_string_dtor(void *dummy, void *elem); + +zend_string *xdebug_get_trait_scope(const char *function); zend_string* xdebug_wrap_location_around_function_name(const char *prefix, zend_op_array *opa, zend_string *fname); zend_string* xdebug_wrap_closure_location_around_function_name(zend_op_array *opa, zend_string *fname); diff --git a/tests/coverage/bug01938.phpt b/tests/coverage/bug01938.phpt index bf84f2b90..3121384b5 100644 --- a/tests/coverage/bug01938.phpt +++ b/tests/coverage/bug01938.phpt @@ -36,7 +36,7 @@ App\Bar->useTrait - paths - 0: HIT -returnsTrue{trait-method:%sbug01938-FooTrait.inc:9-12} +App\FooTrait->returnsTrue{trait-method:%sbug01938-FooTrait.inc:9-12} - branches - 00; OP: 00-%d; line: %d-%d HIT%S - paths