Commit: 7b3bfa5784cf36647f21a72ceb9741e40927a5b6 Author: Nikita Popov <ni...@php.net> Sun, 3 Jun 2012 02:00:11 +0200 Parents: 6117f4c7c0abe3721c2371600a97641003de21a7 Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7b3bfa5784cf36647f21a72ceb9741e40927a5b6 Log: Improve backtraces from generators The current situation is still not perfect, as the generator function itself does not appear in the stack trace. This makes sense in some way, but it would probably be more helpful if it would show up (with the bound arguments) after the $generator->xyz() call. This could be misleading too though as the function is not *really* called there. Changed paths: A Zend/tests/generators/backtrace.phpt M Zend/zend_generators.c Diff: diff --git a/Zend/tests/generators/backtrace.phpt b/Zend/tests/generators/backtrace.phpt new file mode 100644 index 0000000..cbf8de1 --- /dev/null +++ b/Zend/tests/generators/backtrace.phpt @@ -0,0 +1,25 @@ +--TEST-- +Printing the stack trace in a generator +--FILE-- +<?php + +function f1() { + debug_print_backtrace(); +} + +function *f2() { + f1(); +} + +function f3($gen) { + $gen->rewind(); // trigger run +} + +$gen = f2(); +f3($gen); + +?> +--EXPECTF-- +#0 f1() called at [%s:%d] +#1 Generator->rewind() called at [%s:%d] +#2 f3(Generator Object ()) called at [%s:%d] diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c index 01b93ef..df204fa 100644 --- a/Zend/zend_generators.c +++ b/Zend/zend_generators.c @@ -317,6 +317,10 @@ static void zend_generator_resume(zval *object, zend_generator *generator TSRMLS EG(scope) = generator->execute_data->current_scope; EG(called_scope) = generator->execute_data->current_called_scope; + /* Set prev_execute_data to the current execute_data to get halfways + * reasonable backtraces */ + generator->execute_data->prev_execute_data = original_execute_data; + /* Go to next opcode (we don't want to run the last one again) */ generator->execute_data->opline++; -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php