FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fixed issue #1571: File/line information is not shown for closures in… · boocent/sdebug@5a57570 · GitHub

Repository navigation

Commit 5a57570

Browse files
committed
Fixed issue #1571: File/line information is not shown for closures in namespaces
1 parent ec820e9 commit 5a57570

7 files changed

Lines changed: 151 additions & 14 deletions

File tree

‎tests/bug01571-001.phpt‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff 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]

‎tests/bug01571-002.inc‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
?>

‎tests/bug01571-002.phpt‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff 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

‎tests/bug01571-003.phpt‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
)

‎xdebug_code_coverage.c‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -757,13 +757,8 @@ void xdebug_build_fname_from_oparray(xdebug_func *tmp, zend_op_array *opa TSRMLS
757757
memset(tmp, 0, sizeof(xdebug_func));
758758

759759
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));
767762
closure = 1;
768763
} else {
769764
tmp->function = xdstrdup(STR_NAME_VAL(opa->function_name));

‎xdebug_stack.c‎

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,40 @@ static int find_line_number_for_current_execute_point(zend_execute_data *edata T
952952
return 0;
953953
}
954954

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+
955989
void xdebug_build_fname(xdebug_func *tmp, zend_execute_data *edata TSRMLS_DC)
956990
{
957991
memset(tmp, 0, sizeof(xdebug_func));
@@ -988,13 +1022,8 @@ void xdebug_build_fname(xdebug_func *tmp, zend_execute_data *edata TSRMLS_DC)
9881022
}
9891023
}
9901024
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);
9981027
} else if (strncmp(edata->func->common.function_name->val, "call_user_func", 14) == 0) {
9991028
const char *fname = NULL;
10001029
int lineno = 0;

‎xdebug_stack.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
#define XDEBUG_STACK_NO_DESC 0x01
2525

26+
int xdebug_function_name_is_closure(char *fname);
27+
char* xdebug_wrap_closure_location_around_function_name(zend_op_array *opa, char *fname);
2628
void xdebug_build_fname(xdebug_func *tmp, zend_execute_data *edata TSRMLS_DC);
2729
function_stack_entry *xdebug_add_stack_frame(zend_execute_data *zdata, zend_op_array *op_array, int type TSRMLS_DC);
2830
void xdebug_append_error_head(xdebug_str *str, int html, const char *error_type_str TSRMLS_DC);

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL