View Issue Details

IDProjectCategoryView StatusLast Update
0002046XdebugTracingpublic2021-12-01 15:39
Reportereater Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Platformx86_64OSVoid Linux 
Product Version3.1.1 
Fixed in Version3.1.2 
Summary0002046: Segault on xdebug_get_function_stack inside a Fiber
Description

When I call xdebug_get_function_stack inside a Fiber I expect to see the function stack originating from the Fiber entry point

instead php segfaults instantly

Steps To Reproduce

Run the following on PHP 8.1.0RC6 with xdebug 3.1.1

<?php

var_dump(xdebug_get_function_stack());
$f = new Fiber(function() {
var_dump(debug_backtrace());
var_dump(xdebug_get_function_stack());
});

$f->start();

Additional Information

From preliminary inspection it looks like xdebug tries to retrieve the file of the Fiber (see https://github.com/xdebug/xdebug/blob/3.1.1/src/develop/stack.c#L1069 )

but the closure has no file associated with it as can been seen in PHP's backtrace, thus segfaulting on copying it

relevant valgrind/gdb excerpts (full logs in attachments)

valgrind:
==7423== Invalid read of size 1
==7423== at 0x60FDA75: zend_string_copy (zend_string.h:191)
==7423== by 0x60FDA75: zif_xdebug_get_function_stack (stack.c:1069)
==7423== by 0x60D991C: xdebug_execute_internal (base.c:897)
==7423== by 0x5D1B1B: ZEND_DO_FCALL_SPEC_RETVAL_USED_HANDLER (zend_vm_execute.h:1872)
==7423== by 0x5D1B1B: execute_ex (zend_vm_execute.h:54541)
==7423== by 0x60D9081: xdebug_execute_ex (base.c:779)
==7423== by 0x55A7CF: zend_call_function (zend_execute_API.c:896)
==7423== by 0x5FD132: zend_fiber_execute (zend_fibers.c:475)
==7423== by 0x5FDE66: zend_fiber_trampoline (zend_fibers.c:287)
==7423== Address 0x4 is not stack'd, malloc'd or (recently) free'd

gdb:
Program received signal SIGSEGV, Segmentation fault.
zif_xdebug_get_function_stack (execute_data=<optimized out>, return_value=0x5555568acc20) at /builddir/xdebug-3.1.1/src/develop/stack.c:1069

TagsNo tags attached.
Operating System
PHP Version8.1.0-8.1.4

Relationships

duplicate of 0002036 closedderick Segfault on fiber switch in finally block in garbage collected fiber 

Activities

derick

2021-11-22 11:00

administrator   ~0006160

I can indeed reproduce this with Xdebug 3.1.1, but not with the latest code in the xdebug_3_1 branch. I think this is a duplicated of 0002036.

If you can try the latest xdebug_3_1 (or master) branch from GitHub to verify, that'd be great.

The fix for 0002036 will be in Xdebug 3.1.2, which I am intending to release this week.

eater

2021-11-22 11:15

reporter   ~0006161

Indeed works for me on master! thanks :)