[xdebug-dev] svn: /xdebug/trunk/ tests/closure-stack-trace.phpt tests/closure-trace.phpt xdebug_stack.c

From: Derick Rethans <derick[@]derickrethans.nl>
Date: Thu, 16 Dec 2010 23:50:50 +0000

derick Thu, 16 Dec 2010 23:50:50 +0000

Revision: http://svn.xdebug.org/cgi-bin/viewvc.cgi?view=rev&revision=3376&root=xdebug

Log:
- Added better support for closures in stack traces and function traces.

Changed paths:
    A xdebug/trunk/tests/closure-stack-trace.phpt
    A xdebug/trunk/tests/closure-trace.phpt
    U xdebug/trunk/xdebug_stack.c

Added: xdebug/trunk/tests/closure-stack-trace.phpt
===================================================================
--- xdebug/trunk/tests/closure-stack-trace.phpt (rev 0)
+++ xdebug/trunk/tests/closure-stack-trace.phpt 2010-12-16 23:50:50 UTC (rev 3376)
@@ -0,0 +1,33 @@
+--TEST--
+Test for closure file and location in stack traces
+--INI--
+xdebug.default_enable=1
+xdebug.profiler_enable=0
+xdebug.auto_trace=0
+xdebug.trace_format=0
+xdebug.collect_vars=1
+xdebug.collect_params=4
+xdebug.collect_return=1
+xdebug.collect_assignments=1
+--FILE--
+<?php
+function test1()
+{
+ $f = function($a, $b) {
+ $Q = strlen($a * $b);
+ trigger_error('foo');
+ };
+
+ $f(5, 25);
+}
+
+test1();
+?>
+--EXPECTF--
+Notice: foo in %sclosure-stack-trace.php on line 6
+
+Call Stack:
+%w%f %w%d 1. {main}() %sclosure-stack-trace.php:0
+%w%f %w%d 2. test1() %sclosure-stack-trace.php:12
+%w%f %w%d 3. {closure:%sclosure-stack-trace.php:4-7}($a = 5, $b = 25) /home/derick/dev/php/xdebug.git/trunk/tests/closure-stack-trace.php:9
+%w%f %w%d 4. trigger_error('foo') %sclosure-stack-trace.php:6

Added: xdebug/trunk/tests/closure-trace.phpt
===================================================================
--- xdebug/trunk/tests/closure-trace.phpt (rev 0)
+++ xdebug/trunk/tests/closure-trace.phpt 2010-12-16 23:50:50 UTC (rev 3376)
@@ -0,0 +1,42 @@
+--TEST--
+Test for closure file and location in stack traces
+--INI--
+xdebug.default_enable=1
+xdebug.profiler_enable=0
+xdebug.auto_trace=0
+xdebug.trace_format=0
+xdebug.collect_vars=1
+xdebug.collect_params=4
+xdebug.collect_return=1
+xdebug.collect_assignments=1
+--FILE--
+<?php
+$tf = xdebug_start_trace('/tmp/'. uniqid('xdt', TRUE));
+
+function test1()
+{
+ $f = function($a, $b) {
+ return strlen($a * $b);
+ };
+
+ $f(5, 25);
+}
+
+test1();
+xdebug_stop_trace();
+echo file_get_contents($tf);
+unlink($tf);
+?>
+--EXPECTF--
+TRACE START [%d-%d-%d %d:%d:%d]
+ => $tf = '/tmp/%s.xt' %sclosure-trace.php:2
+%w%f %w%d -> test1() %sclosure-trace.php:13
+ => $f = class Closure { } %sclosure-trace.php:8
+%w%f %w%d -> {closure:%sclosure-trace.php:6-8}($a = 5, $b = 25) %sclosure-trace.php:10
+%w%f %w%d -> strlen(125) %sclosure-trace.php:7
+ >=> 3
+ >=> 3
+ >=> NULL
+%w%f %w%d -> xdebug_stop_trace() %sclosure-trace.php:14
+%w%f %w%d
+TRACE END [%d-%d-%d %d:%d:%d]

Modified: xdebug/trunk/xdebug_stack.c
===================================================================
--- xdebug/trunk/xdebug_stack.c 2010-12-16 23:50:42 UTC (rev 3375)
+++ xdebug/trunk/xdebug_stack.c 2010-12-16 23:50:50 UTC (rev 3376)
@@ -772,7 +772,16 @@
                         } else {
                                 tmp->type = XFUNC_NORMAL;
                         }
- tmp->function = xdstrdup(edata->function_state.function->common.function_name);
+ if (strcmp(edata->function_state.function->common.function_name, "{closure}") == 0) {
+ tmp->function = xdebug_sprintf(
+ "{closure:%s:%d-%d}",
+ edata->function_state.function->op_array.filename,
+ edata->function_state.function->op_array.line_start,
+ edata->function_state.function->op_array.line_end
+ );
+ } else {
+ tmp->function = xdstrdup(edata->function_state.function->common.function_name);
+ }
                 } else {
 #if PHP_VERSION_ID >= 50399
                         switch (edata->opline->extended_value) {
Received on Thu Dec 16 2010 - 23:50:50 GMT

This archive was generated by hypermail 2.2.0 : Sun Jun 24 2018 - 04:00:03 BST