Skip to content

Commit 9d6efa2

Browse files
committed
removed Helpers::fixStack()
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.
1 parent b9d385a commit 9d6efa2

File tree

3 files changed

+2
-42
lines changed

3 files changed

+2
-42
lines changed

src/Tracy/Debugger/Debugger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ public static function shutdownHandler(): void
289289
{
290290
$error = error_get_last();
291291
if (in_array($error['type'] ?? null, [E_ERROR, E_CORE_ERROR, E_COMPILE_ERROR, E_PARSE, E_RECOVERABLE_ERROR, E_USER_ERROR], true)) {
292-
self::exceptionHandler(Helpers::fixStack(new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line'])));
292+
self::exceptionHandler(new ErrorException($error['message'], 0, $error['type'], $error['file'], $error['line']));
293293
} elseif (($error['type'] ?? null) === E_COMPILE_WARNING) {
294294
error_clear_last();
295295
self::errorHandler($error['type'], $error['message'], $error['file'], $error['line']);

src/Tracy/Helpers.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -114,37 +114,6 @@ public static function findTrace(array $trace, array|string $method, ?int &$inde
114114
}
115115

116116

117-
/** @internal */
118-
public static function fixStack(\Throwable $exception): \Throwable
119-
{
120-
if (function_exists('xdebug_get_function_stack')) {
121-
$stack = [];
122-
$trace = @xdebug_get_function_stack(); // @ xdebug compatibility warning
123-
$trace = array_slice(array_reverse($trace), 2, -1);
124-
foreach ($trace as $row) {
125-
$frame = [
126-
'file' => $row['file'],
127-
'line' => $row['line'],
128-
'function' => $row['function'] ?? '*unknown*',
129-
'args' => [],
130-
];
131-
if (!empty($row['class'])) {
132-
$frame['type'] = isset($row['type']) && $row['type'] === 'dynamic' ? '->' : '::';
133-
$frame['class'] = $row['class'];
134-
}
135-
136-
$stack[] = $frame;
137-
}
138-
139-
$ref = new \ReflectionProperty('Exception', 'trace');
140-
$ref->setAccessible(true);
141-
$ref->setValue($exception, $stack);
142-
}
143-
144-
return $exception;
145-
}
146-
147-
148117
/** @internal */
149118
public static function errorTypeToString(int $type): string
150119
{

tests/Tracy/Debugger.E_COMPILE_ERROR.console.phpt

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,7 @@ $onFatalErrorCalled = false;
2424

2525
register_shutdown_function(function () use (&$onFatalErrorCalled) {
2626
Assert::true($onFatalErrorCalled);
27-
Assert::match(extension_loaded('xdebug') ?
28-
'ErrorException: Cannot re-assign $this in %a%
29-
Stack trace:
30-
#0 %a%: third()
31-
#1 %a%: second()
32-
#2 %a%: first()
33-
#3 {main}
34-
Tracy is unable to log error: Logging directory is not specified.
35-
' :
36-
'ErrorException: Cannot re-assign $this in %a%
27+
Assert::match('ErrorException: Cannot re-assign $this in %a%
3728
Stack trace:
3829
#0 [internal function]: Tracy\\Debugger::shutdownHandler()
3930
#1 {main}

0 commit comments

Comments
 (0)