| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,33 @@ | |||
| 1 | + --TEST-- | ||
| 2 | + Test for bug #1571: Stack traces don't show file/line for closures in namespaces | ||
| 3 | + --INI-- | ||
| 4 | + xdebug.default_enable=1 | ||
| 5 | + xdebug.auto_trace=0 | ||
| 6 | + xdebug.collect_params=4 | ||
| 7 | + xdebug.collect_return=1 | ||
| 8 | + xdebug.collect_assignments=0 | ||
| 9 | + xdebug.auto_profile=0 | ||
| 10 | + xdebug.profiler_enable=0 | ||
| 11 | + xdebug.show_mem_delta=0 | ||
| 12 | + xdebug.trace_format=0 | ||
| 13 | + --FILE-- | ||
| 14 | + <?php | ||
| 15 | + namespace A; | ||
| 16 | + | ||
| 17 | + $tf = xdebug_start_trace(sys_get_temp_dir() . '/'. uniqid('xdt', TRUE)); | ||
| 18 | + | ||
| 19 | + $a = function(){ | ||
| 20 | + | ||
| 21 | + }; | ||
| 22 | + $a(1, $a); | ||
| 23 | + | ||
| 24 | + xdebug_stop_trace(); | ||
| 25 | + echo file_get_contents($tf); | ||
| 26 | + unlink($tf); | ||
| 27 | + ?> | ||
| 28 | + --EXPECTF-- | ||
| 29 | + TRACE START [%d-%d-%d %d:%d:%d] | ||
| 30 | + %w%f %w%d -> A\{closure:%sbug01571-001.php:6-8}(1, class Closure { }) %sbug01571-001.php:9 | ||
| 31 | + %w%f %w%d -> xdebug_stop_trace() %sbug01571-001.php:11 | ||
| 32 | + %w%f %w%d | ||
| 33 | + TRACE END [%d-%d-%d %d:%d:%d] | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,6 @@ | |||
| 1 | + <?php | ||
| 2 | + namespace Testing; | ||
| 3 | + | ||
| 4 | + $cb = function($a) { usleep(500); return $a * 3; }; | ||
| 5 | + $cb(4); | ||
| 6 | + ?> | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,42 @@ | |||
| 1 | + --TEST-- | ||
| 2 | + Test for bug #1571: Profiler doesn't show file/line for closures in namespaces | ||
| 3 | + --INI-- | ||
| 4 | + xdebug.profiler_enable=1 | ||
| 5 | + --FILE-- | ||
| 6 | + <?php | ||
| 7 | + require_once('bug01571-002.inc'); | ||
| 8 | + | ||
| 9 | + echo file_get_contents(xdebug_get_profiler_filename()); | ||
| 10 | + ?> | ||
| 11 | + --EXPECTF-- | ||
| 12 | + version: 1 | ||
| 13 | + creator: xdebug %d.%s (PHP %s) | ||
| 14 | + cmd: %sbug01571-002.php | ||
| 15 | + part: 1 | ||
| 16 | + positions: line | ||
| 17 | + | ||
| 18 | + events: Time Memory | ||
| 19 | + | ||
| 20 | + fl=(1) php:internal | ||
| 21 | + fn=(1) php::usleep | ||
| 22 | + 4 %d %i | ||
| 23 | + | ||
| 24 | + fl=(2) %sbug01571-002.inc | ||
| 25 | + fn=(2) Testing\{closure:%sbug01571-002.inc:4-4} | ||
| 26 | + 4 %d %i | ||
| 27 | + cfl=(1) | ||
| 28 | + cfn=(1) | ||
| 29 | + calls=1 0 0 | ||
| 30 | + 4 %d %i | ||
| 31 | + | ||
| 32 | + fl=(2) | ||
| 33 | + fn=(3) require_once::%sbug01571-002.inc | ||
| 34 | + 1 %d %i | ||
| 35 | + cfl=(2) | ||
| 36 | + cfn=(2) | ||
| 37 | + calls=1 0 0 | ||
| 38 | + 5 %d %i | ||
| 39 | + | ||
| 40 | + fl=(1) | ||
| 41 | + fn=(4) php::xdebug_get_profiler_filename | ||
| 42 | + 4 %d %i | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,30 @@ | |||
| 1 | + --TEST-- | ||
| 2 | + Test for bug #1571: Code Coverage doesn't show file/line for closures in namespaces | ||
| 3 | + --INI-- | ||
| 4 | + xdebug.default_enable=1 | ||
| 5 | + xdebug.auto_trace=0 | ||
| 6 | + xdebug.auto_profile=0 | ||
| 7 | + xdebug.profiler_enable=0 | ||
| 8 | + xdebug.overload_var_dump=0 | ||
| 9 | + --FILE-- | ||
| 10 | + <?php | ||
| 11 | + namespace Testing; | ||
| 12 | + | ||
| 13 | + $pathname = stream_resolve_include_path(__FILE__); | ||
| 14 | + xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE | XDEBUG_CC_BRANCH_CHECK); | ||
| 15 | + | ||
| 16 | + $cb = function($a) { | ||
| 17 | + usleep(500); | ||
| 18 | + return $a * 3; | ||
| 19 | + }; | ||
| 20 | + $cb(4); | ||
| 21 | + | ||
| 22 | + $coverage = xdebug_get_code_coverage(); | ||
| 23 | + xdebug_stop_code_coverage(); | ||
| 24 | + print_r(array_keys($coverage[$pathname]['functions'])); | ||
| 25 | + ?> | ||
| 26 | + --EXPECTF-- | ||
| 27 | + Array | ||
| 28 | + ( | ||
| 29 | + [0] => Testing\{closure:%sbug01571-003.php:7-10} | ||
| 30 | + ) | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -757,13 +757,8 @@ void xdebug_build_fname_from_oparray(xdebug_func *tmp, zend_op_array *opa TSRMLS | |||
| 757 | 757 | memset(tmp, 0, sizeof(xdebug_func)); | |
| 758 | 758 | ||
| 759 | 759 | if (opa->function_name) { | |
| 760 | - if (strcmp(STR_NAME_VAL(opa->function_name), "{closure}") == 0) { | ||
| 761 | - tmp->function = xdebug_sprintf( | ||
| 762 | - "{closure:%s:%d-%d}", | ||
| 763 | - STR_NAME_VAL(opa->filename), | ||
| 764 | - opa->line_start, | ||
| 765 | - opa->line_end | ||
| 766 | - ); | ||
| 760 | + if (xdebug_function_name_is_closure(STR_NAME_VAL(opa->function_name))) { | ||
| 761 | + tmp->function = xdebug_wrap_closure_location_around_function_name(opa, STR_NAME_VAL(opa->function_name)); | ||
| 767 | 762 | closure = 1; | |
| 768 | 763 | } else { | |
| 769 | 764 | tmp->function = xdstrdup(STR_NAME_VAL(opa->function_name)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -952,6 +952,40 @@ static int find_line_number_for_current_execute_point(zend_execute_data *edata T | |||
| 952 | 952 | return 0; | |
| 953 | 953 | } | |
| 954 | 954 | ||
| 955 | + int xdebug_function_name_is_closure(char *fname) | ||
| 956 | + { | ||
| 957 | + int length = strlen(fname); | ||
| 958 | + int closure_length = strlen("{closure}"); | ||
| 959 | + | ||
| 960 | + if (length < closure_length) { | ||
| 961 | + return 0; | ||
| 962 | + } | ||
| 963 | + | ||
| 964 | + if (strcmp(fname + length - closure_length, "{closure}") == 0) { | ||
| 965 | + return 1; | ||
| 966 | + } | ||
| 967 | + | ||
| 968 | + return 0; | ||
| 969 | + } | ||
| 970 | + | ||
| 971 | + char* xdebug_wrap_closure_location_around_function_name(zend_op_array *opa, char *fname) | ||
| 972 | + { | ||
| 973 | + xdebug_str tmp = XDEBUG_STR_INITIALIZER; | ||
| 974 | + char *tmp_loc_info; | ||
| 975 | + | ||
| 976 | + xdebug_str_addl(&tmp, fname, strlen(fname) - 1, 0); | ||
| 977 | + | ||
| 978 | + tmp_loc_info = xdebug_sprintf( | ||
| 979 | + ":%s:%d-%d}", | ||
| 980 | + opa->filename->val, | ||
| 981 | + opa->line_start, | ||
| 982 | + opa->line_end | ||
| 983 | + ); | ||
| 984 | + xdebug_str_add(&tmp, tmp_loc_info, 1); | ||
| 985 | + | ||
| 986 | + return tmp.d; | ||
| 987 | + } | ||
| 988 | + | ||
| 955 | 989 | void xdebug_build_fname(xdebug_func *tmp, zend_execute_data *edata TSRMLS_DC) | |
| 956 | 990 | { | |
| 957 | 991 | memset(tmp, 0, sizeof(xdebug_func)); | |
@@ -988,13 +1022,8 @@ void xdebug_build_fname(xdebug_func *tmp, zend_execute_data *edata TSRMLS_DC) | |||
| 988 | 1022 | } | |
| 989 | 1023 | } | |
| 990 | 1024 | if (edata->func->common.function_name) { | |
| 991 | - if (strcmp(edata->func->common.function_name->val, "{closure}") == 0) { | ||
| 992 | - tmp->function = xdebug_sprintf( | ||
| 993 | - "{closure:%s:%d-%d}", | ||
| 994 | - edata->func->op_array.filename->val, | ||
| 995 | - edata->func->op_array.line_start, | ||
| 996 | - edata->func->op_array.line_end | ||
| 997 | - ); | ||
| 1025 | + if (xdebug_function_name_is_closure(edata->func->common.function_name->val)) { | ||
| 1026 | + tmp->function = xdebug_wrap_closure_location_around_function_name(&edata->func->op_array, edata->func->common.function_name->val); | ||
| 998 | 1027 | } else if (strncmp(edata->func->common.function_name->val, "call_user_func", 14) == 0) { | |
| 999 | 1028 | const char *fname = NULL; | |
| 1000 | 1029 | int lineno = 0; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,8 @@ | |||
| 23 | 23 | ||
| 24 | 24 | #define XDEBUG_STACK_NO_DESC 0x01 | |
| 25 | 25 | ||
| 26 | + int xdebug_function_name_is_closure(char *fname); | ||
| 27 | + char* xdebug_wrap_closure_location_around_function_name(zend_op_array *opa, char *fname); | ||
| 26 | 28 | void xdebug_build_fname(xdebug_func *tmp, zend_execute_data *edata TSRMLS_DC); | |
| 27 | 29 | function_stack_entry *xdebug_add_stack_frame(zend_execute_data *zdata, zend_op_array *op_array, int type TSRMLS_DC); | |
| 28 | 30 | void xdebug_append_error_head(xdebug_str *str, int html, const char *error_type_str TSRMLS_DC); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments