Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue #2226: xdebug_get_function_stack(['from_exception']) does not always find stored trace #941

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/develop/stack.c
Expand Up @@ -1307,9 +1307,11 @@ PHP_FUNCTION(xdebug_get_function_stack)

value = zend_hash_str_find(options, "from_exception", sizeof("from_exception") - 1);
if (value && Z_TYPE_P(value) == IS_OBJECT && instanceof_function(Z_OBJCE_P(value), zend_ce_throwable)) {
if (Z_OBJ_P(value) == XG_DEV(last_exception_trace).obj_ptr[0]) {
Z_TRY_ADDREF(XG_DEV(last_exception_trace).stack_trace[0]);
ZVAL_COPY_VALUE(return_value, &XG_DEV(last_exception_trace).stack_trace[0]);
zval *z_previous_exception = last_exception_find_trace(Z_OBJ_P(value));

if (z_previous_exception) {
Z_TRY_ADDREF(*z_previous_exception);
ZVAL_COPY_VALUE(return_value, z_previous_exception);
} else {
array_init(return_value);
}
Expand Down
44 changes: 44 additions & 0 deletions tests/develop/bug02226-exceptions.phpt
@@ -0,0 +1,44 @@
--TEST--
Test for bug #2195: xdebug_get_function_stack(['from_exception']) (!opcache)
--SKIPIF--
<?php
require __DIR__ . '/../utils.inc';
check_reqs('!opcache');
?>
--INI--
xdebug.mode=develop
xdebug.auto_profile=0
xdebug.var_display_max_depth=4
--FILE--
<?php
class Handlers
{
function __construct(private string $title, private float $PIE) {}

static function exceptionHandler($exception)
{
echo "In exceptionHandler:\n";
$stack = xdebug_get_function_stack( [ 'from_exception' => $exception ] );
echo "\tThere are ", count( $stack ), " stack frames\n";
}
}

class Error_Entry
{
public function __construct($base, $errno)
{
try {
throw new Exception("Numbers: {$base}/{$errno}\n");
} catch (Throwable $t) {
}
throw new Exception("Second: {$base}/{$errno}\n");
}
}

set_exception_handler(['Handlers', 'exceptionHandler']);
$e = new Error_Entry(1, 2);

?>
--EXPECTF--
In exceptionHandler:
There are 2 stack frames