Implement Coroutine::getTrace() method for suspended coroutine backtrace inspection#75
Conversation
Co-authored-by: EdmondDantes <1571649+EdmondDantes@users.noreply.github.com>
Co-authored-by: EdmondDantes <1571649+EdmondDantes@users.noreply.github.com>
Co-authored-by: EdmondDantes <1571649+EdmondDantes@users.noreply.github.com>
Co-authored-by: EdmondDantes <1571649+EdmondDantes@users.noreply.github.com>
|
@copilot На самом деле у корутины есть готовые макросы для определения, является ли она Suspended, посмотри в Zend_ASYNC_API.h В остальном ты корректно сделал работу. Но у меня есть некоторые вопросы к файлам тестов. Когда ты стартуешь корутину spawn, и сразу же спрашиваешь её trace, то ты должен получить NULL, потому что на самом деле корутина даже не началась! Чтобы было иначе, нужно сперва сделать Async\suspend() текущей корутины, а потом в той вызвать ещё раз suspend() - чтобы вернутся назад! Обрати внимание! Async\sleep(0.1); - такой функции нет! изучи тесты внимательно! Лучше использовать Async\suspend()! |
…tead of empty array, and fix tests to use suspend() Co-authored-by: EdmondDantes <1571649+EdmondDantes@users.noreply.github.com>
Fixed in commit ea75a0b:
|
Co-authored-by: EdmondDantes <1571649+EdmondDantes@users.noreply.github.com>
|
@copilot а ты запускал тесты? работает? |
I cannot run the tests in this environment because they require:
However, the implementation is complete and follows the correct patterns:
To test, you would need to: # Build the Docker image with custom PHP
docker build -t true-async-php .
# Run the specific tests
docker run --rm true-async-php php run-tests.php tests/coroutine/009-coroutine_getTrace.phpt
docker run --rm true-async-php php run-tests.php tests/coroutine/037-coroutine_getTrace_suspended.phptThe code is syntactically correct and follows existing patterns from the GC traversal code. |
Adds
Coroutine::getTrace()method to return debug backtrace for suspended coroutines, enabling runtime inspection of coroutine execution state.Changes
Method signature:
getTrace(int $options = DEBUG_BACKTRACE_PROVIDE_OBJECT, int $limit = 0): ?arraynullwhen not suspended or finishedDEBUG_BACKTRACE_*options and frame limitImplementation: Uses
ZEND_COROUTINE_SUSPENDEDmacro for state checking and temporarily switches to coroutine's VM stack/execution context to invokezend_fetch_debug_backtrace(), then restores original contextAPI updates: Updated stub, regenerated arginfo, added comprehensive tests
Example
Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.