Skip to content

Commit

Permalink
removed Helpers::fixStack()
Browse files Browse the repository at this point in the history
xdebug_get_function_stack() is available only if xdebug.mode=develop is set.
Inside a shutdown handler, it returns the complete callstack only when called from the CLI.
When used in a browser, the callstack is printed out and the function then does not return it.
The callstack output can be disabled using html_errors=0, but the function still won't return it.
  • Loading branch information
dg committed Mar 31, 2024
1 parent b9d385a commit 9d6efa2
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 42 deletions.
2 changes: 1 addition & 1 deletion src/Tracy/Debugger/Debugger.php
Expand Up @@ -289,7 +289,7 @@ public static function shutdownHandler(): void
{
$error = error_get_last();
if (in_array($error['type'] ?? null, [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE, E_RECOVERABLE_ERROR, E_USER_ERROR], true)) {
self::exceptionHandler(Helpers::fixStack(new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line'])));
self::exceptionHandler(new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']));
} elseif (($error['type'] ?? null) === E_COMPILE_WARNING) {
error_clear_last();
self::errorHandler($error['type'], $error['message'], $error['file'], $error['line']);
Expand Down
31 changes: 0 additions & 31 deletions src/Tracy/Helpers.php
Expand Up @@ -114,37 +114,6 @@ public static function findTrace(array $trace, array|string $method, ?int &$inde
}


/** @internal */
public static function fixStack(\Throwable $exception): \Throwable
{
if (function_exists('xdebug_get_function_stack')) {
$stack = [];
$trace = @xdebug_get_function_stack(); // @ xdebug compatibility warning
$trace = array_slice(array_reverse($trace), 2, -1);
foreach ($trace as $row) {
$frame = [
'file' => $row['file'],
'line' => $row['line'],
'function' => $row['function'] ?? '*unknown*',
'args' => [],
];
if (!empty($row['class'])) {
$frame['type'] = isset($row['type']) && $row['type'] === 'dynamic' ? '->' : '::';
$frame['class'] = $row['class'];
}

$stack[] = $frame;
}

$ref = new \ReflectionProperty('Exception', 'trace');
$ref->setAccessible(true);
$ref->setValue($exception, $stack);
}

return $exception;
}


/** @internal */
public static function errorTypeToString(int $type): string
{
Expand Down
11 changes: 1 addition & 10 deletions tests/Tracy/Debugger.E_COMPILE_ERROR.console.phpt
Expand Up @@ -24,16 +24,7 @@ $onFatalErrorCalled = false;

register_shutdown_function(function () use (&$onFatalErrorCalled) {
Assert::true($onFatalErrorCalled);
Assert::match(extension_loaded('xdebug') ?
'ErrorException: Cannot re-assign $this in %a%
Stack trace:
#0 %a%: third()
#1 %a%: second()
#2 %a%: first()
#3 {main}
Tracy is unable to log error: Logging directory is not specified.
' :
'ErrorException: Cannot re-assign $this in %a%
Assert::match('ErrorException: Cannot re-assign $this in %a%
Stack trace:
#0 [internal function]: Tracy\\Debugger::shutdownHandler()
#1 {main}
Expand Down

0 comments on commit 9d6efa2

Please sign in to comment.