Skip to content

Commit

Permalink
Merge pull request #300 from oligriffiths/patch/xdebug-backtrace
Browse files Browse the repository at this point in the history
Implemented backtrace for fatal errors using xdebug
  • Loading branch information
denis-sokolov committed Jul 22, 2015
2 parents 494fa73 + 3935598 commit 35e765d
Showing 1 changed file with 49 additions and 1 deletion.
50 changes: 49 additions & 1 deletion src/Whoops/Exception/Inspector.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getPreviousExceptionInspector()
public function getFrames()
{
if ($this->frames === null) {
$frames = $this->exception->getTrace();
$frames = $this->getTrace($this->exception);

// If we're handling an ErrorException thrown by Whoops,
// get rid of the last frame, which matches the handleError method,
Expand Down Expand Up @@ -125,6 +125,54 @@ public function getFrames()
return $this->frames;
}

/**
* Gets the backgrace from an exception.
*
* If xdebug is installed
*
* @param Exception $e
* @return array
*/
protected function getTrace(\Exception $e)
{
$traces = $e->getTrace();

// Get trace from xdebug if enabled, failure exceptions only trace to the shutdown handler by default
if (!$e instanceof \ErrorException) {
return $traces;
}

switch ($e->getSeverity()) {
case E_ERROR:
case E_RECOVERABLE_ERROR:
case E_PARSE:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_USER_ERROR:
$fatal = true;
break;

default:
$fatal = false;
break;
}

if (!$fatal) {
return $traces;
}

if (!extension_loaded('xdebug') || !xdebug_is_enabled()) {
return array();
}

// Use xdebug to get the full stack trace and remove the shutdown handler stack trace
$stack = array_reverse(xdebug_get_function_stack());
$trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
$traces = array_diff_key($stack, $trace);

return $traces;
}

/**
* Given an exception, generates an array in the format
* generated by Exception::getTrace()
Expand Down

0 comments on commit 35e765d

Please sign in to comment.