Do a backtrace analysis.

@param array $backtrace
The backtrace, which may (or may not) come from other sources.
If omitted, a new debug_backtrace() will be retrieved.

@return string
The rendered backtrace.
331956
public function process(&$backtrace = array())
    {
        if (empty($backtrace) === true) {
            $backtrace = $this->getBacktrace();
        }

        $output = '';
        $maxStep = (int) $this->pool->config->getSetting(Fallback::SETTING_MAX_STEP_NUMBER);
        $stepCount = count($backtrace);

        // Remove steps according to the configuration.
        if ($maxStep < $stepCount) {
            $this->pool->messages->addMessage('omittedBacktrace', array(($maxStep + 1), $stepCount));
        } else {
            // We will not analyse more steps than we actually have.
            $maxStep = $stepCount;
        }

        for ($step = 1; $step <= $maxStep; ++$step) {
            $output .= $this->pool->render->renderExpandableChild(
                $this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Model')
                    ->setName($step)
                    ->setType(static::TYPE_STACK_FRAME)
                    ->addParameter(static::PARAM_DATA, $backtrace[$step - 1])
                    ->injectCallback(
                        $this->pool->createClass('Brainworxx\\Krexx\\Analyse\\Callback\\Analyse\\BacktraceStep')
                    )
            );
        }

        return $output;
    }
665206
protected function getCallerFromStackTrace()
    {
        $trace = collect(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))->forget(0);

        return $trace->first(function ($frame) {
            if (! isset($frame['file'])) {
                return false;
            }

            return ! Str::contains($frame['file'],
                base_path('vendor'.DIRECTORY_SEPARATOR.$this->ignoredVendorPath())
            );
        });
    }
1208496
private static function getHTMLBackTrace($backtrace)
    {
        $str = '';

        foreach ($backtrace as $step) {
            if ($step['function'] != 'getHTMLBackTrace' && $step['function'] != 'handle_error') {
                $str .= '<tr><td style="border-bottom: 1px solid #EEEEEE">';
                $str .= ((isset($step['class'])) ? htmlspecialchars($step['class'], ENT_NOQUOTES, 'UTF-8') : '').
                ((isset($step['type'])) ? htmlspecialchars($step['type'], ENT_NOQUOTES, 'UTF-8') : '').htmlspecialchars($step['function'], ENT_NOQUOTES, 'UTF-8').'(';

                if (is_array($step['args'])) {
                    $drawn = false;
                    $params = '';
                    foreach ($step['args'] as $param) {
                        $params .= self::getPhpVariableAsText($param);
                        //$params .= var_export($param, true);
                        $params .= ', ';
                        $drawn = true;
                    }
                    $str .= htmlspecialchars($params, ENT_NOQUOTES, 'UTF-8');
                    if ($drawn == true) {
                        $str = substr($str, 0, strlen($str) - 2);
                    }
                }
                $str .= ')';
                $str .= '</td><td style="border-bottom: 1px solid #EEEEEE">';
                $str .= ((isset($step['file'])) ? htmlspecialchars(self::displayFile($step['file']), ENT_NOQUOTES, 'UTF-8') : '');
                $str .= '</td><td style="border-bottom: 1px solid #EEEEEE">';
                $str .= ((isset($step['line'])) ? $step['line'] : '');
                $str .= '</td></tr>';
            }
        }

        return $str;
    }
1234684
public function renderBacktrace()
	{
		$contents  = null;
		$backtrace = $this->error->getTrace();

		if (is_array($backtrace))
		{
			ob_start();

			$j = 1;

			$html = array();
			$html[] = '<table class="backtrace">';
			$html[] = '	<caption>Call stack</caption>';
			$html[] = '	<thead>';
			$html[] = '		<tr>';
			$html[] = '			<th scope="col">#</th>';
			$html[] = '			<th scope="col">Function</th>';
			$html[] = '			<th scope="col">Location</th>';
			$html[] = '		</tr>';
			$html[] = '	</thead>';
			$html[] = '	<tbody>';
			$html[] = '		<tr>';
			$html[] = '			<th scope="row">0</th>';
			$html[] = '			<td><span class="msg">!! ' . $this->error->getMessage() . ' !!</span></td>';
			$html[] = '			<td><span class="fl">' . $this->rooted($this->error->getFile()) . '</span>:<span class="ln">' . $this->error->getLine() . '</span></td>';
			$html[] = '		</tr>';
			for ($i = count($backtrace) - 1; $i >= 0; $i--)
			{
				$html[] = '		<tr>';
				$html[] = '			<th scope="row">' . $j . '</th>';
				if (isset($backtrace[$i]['class']))
				{
					$html[] = '			<td><span class="cls">' . $backtrace[$i]['class'] . '</span><span class="opn">' . $backtrace[$i]['type'] . '</span><span class="mtd">' . $backtrace[$i]['function'] . '</span>()</td>';
				}
				else
				{
					$html[] = '			<td><span class="fnc">' . $backtrace[$i]['function'] . '</span>()</td>';
				}
				if (isset($backtrace[$i]['file']))
				{
					$html[] = '			<td><span class="fl">' . $this->rooted($backtrace[$i]['file']) . '</span>:<span class="ln">' . $backtrace[$i]['line'] . '</span></td>';
				}
				else
				{
					$html[] = '			<td>&#160;</td>';
				}
				$html[] = '		</tr>';
				$j++;
			}
			$html[] = '	</tbody>';
			$html[] = '</table>';

			echo "\n" . implode("\n", $html) . "\n";
			$contents = ob_get_contents();
			ob_end_clean();
		}
		return $contents;
	}
1246888
public static function renderFromTrace( $trace )
	{
		if( !is_array( $trace ) )
			throw new InvalidArgumentException( "Trace must be an array" );
		if( !count( $trace ) )
			return '';
		$i	= 0;
		$j	= 0;
		$list	= array();
		foreach( $trace as $key => $trace )
		{
			$step	= self::renderTraceStep( $trace, $i++, $j );
			if( !$step )
				continue;
			$list[]	= UI_HTML_Tag::create( 'li', $step );
			$j++;
		}
		return UI_HTML_Tag::create( 'ol', implode( $list ), array( 'class' => 'trace' ) );
	}
259168
public function filterTrace($str) {
		if (empty($this->_options['backtrace_filters'])) {
			return $str;
		}

		foreach ($this->_options['backtrace_filters'] as $pattern => $replacement) {
			$str = preg_replace($pattern, $replacement, $str);
		}

		return $str;
	}
449889
public function backtraceAction(array $backtrace = null)
    {
        if ($this->pool->emergencyHandler->checkMaxCall() === true) {
            // Called too often, we might get into trouble here!
            return $this;
        }

        $this->pool->reset();

        // Find caller.
        $caller = $this->callerFinder->findCaller(static::TRACE_BACKTRACE, array());
        $this->pool->scope->setScope($caller[static::TRACE_VARNAME]);

        $analysis = $this->pool
            ->createClass('Brainworxx\\Krexx\\Analyse\\Routing\\Process\\ProcessBacktrace')
            ->process($backtrace);

        // Detect the encoding on the start-chunk-string of the analysis
        // for a complete encoding picture.
        $this->pool->chunks->detectEncoding($analysis);

        // Now that our analysis is done, we must check if there was an emergency
        // break.
        if ($this->pool->emergencyHandler->checkEmergencyBreak() === true) {
            return $this;
        }

        // Add the caller as metadata to the chunks class. It will be saved as
        // additional info, in case we are logging to a file.
        $this->pool->chunks->addMetadata($caller);

        // We need to get the footer before the generating of the header,
        // because we need to display messages in the header from the configuration.
        $footer = $this->outputFooter($caller);

        $this->outputService
            ->addChunkString($this->pool->render->renderHeader(static::TRACE_BACKTRACE, $this->outputCssAndJs()))
            ->addChunkString($analysis)
            ->addChunkString($footer)
            ->finalize();

        return $this;
    }
470399
protected function backtrace($string, $level = 1)
    {
        if (isset($this->trace[$string])) {
            return $this;
        }

        $info = [
            'position' => null,
            'called' => null,
            'args' => [],
        ];

        if (function_exists('debug_backtrace')) {
            $defaultTrace = [
                'file' => null,
                'line' => null,
                'function' => null,
                'class' => null,
                'object' => null,
                'type' => null,
                'args' => [],
            ];

            $trace = debug_backtrace();

            // Find where called this object
            if (isset($trace[$level])) {
                $traceData = array_merge($defaultTrace, $trace[$level]);

                $ref = null;

                if (method_exists($traceData['class'], $traceData['function'])) {
                    $ref = new \ReflectionMethod($traceData['class'], $traceData['function']);
                } elseif (function_exists($traceData['function'])) {
                    $ref = new \ReflectionFunction($traceData['function']);
                }

                $info['position'] = [
                    'file' => $ref ? $ref->getFileName() : $traceData['file'],
                    'class' => $traceData['class'],
                    'function' => $traceData['function'],
                    'line' => $ref ? $ref->getStartLine() : $traceData['line'],
                ];
            }

            if (isset($trace[$level - 1])) {
                $traceData = array_merge($defaultTrace, $trace[$level - 1]);

                $info['called'] = [
                    'file' => $traceData['file'],
                    'class' => $traceData['class'],
                    'function' => $traceData['function'],
                    'line' => $traceData['line'],
                    'args' => $traceData['args'],
                ];

                $info['args'] = $traceData['args'];
            }
        }

        return $info;
    }
509449
protected function getNextPage()
	{
		$backtrace = debug_backtrace();
		return $this->getNextPageFromList(Utils::getReturnTypes($backtrace[1]['class'], $backtrace[1]['function']), $backtrace[1]['class']);
	}
683064
public static function getPluginNameFromBacktrace($backtrace)
    {
        foreach ($backtrace as $tracepoint) {
            // try and discern the plugin name
            if (isset($tracepoint['class'])) {
                $className = self::getPluginNameFromNamespace($tracepoint['class']);
                if ($className) {
                    return $className;
                }
            }
        }
        return false;
    }
1246839
public static function debug(array $args)
    {
        $str = "\r\n";
        $str .= self::startBlackText() .
            self::startYellowBackground() .
            self::getCallingFileName() . '::' . self::getCallingFileLine() .
            "\033[0m" . "\r\n";

        foreach ($args as $arg) {
            $str .=
                self::startBlackText() .
                self::startYellowBackground() .
                self::getParameter($arg) .
                "\033[0m" . "\r\n";
        }

        return $str . "\r\n";
    }
887218
protected static function registerDump($representation, $backtrace)
    {
        $dump = new Dump($representation, $backtrace[0]['file'], $backtrace[0]['line']);

        static::$instances[] = $dump;

        return $dump;
    }
1019250
public function formatStackTrace( ezcDebugStacktraceIterator $stackTrace )
    {
        $res = array();
        foreach ( $stackTrace as $index => $element )
        {
            $function = ( isset( $element['class'] ) ? "{$element['class']}::" : '' )
            . $element['function'] . '('
            . implode( ', ', $element['params'] )
            . ')';
            $location = "{$element['file']}:{$element['line']}";
            $res[$index] = $function.' ('.$location.')';
        }
        return  $res;
    }
409866
static public function backtrace($deep=0)
    {
        $bt = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT, $deep + 1);
        if (isset($bt[$deep])) {
            return $bt[$deep];
        }

        return array();
    }
255255
public function getBetterTrace() {
        $trace = $this->betterTrace;

        if (!$trace) {
            // transform the original stacktrace into a better one
            $trace = DebugHelper::fixTrace($this->getTrace(), $this->getFile(), $this->getLine());

            // drop the first frame if the exception was created in the registered error handler
            if (DebugHelper::getFQFunctionName($trace[0]) == ErrorHandler::class.'::handleError') {
                \array_shift($trace);

                // if the error was triggered by include/require/_once: fix the next frame, it's wrong
                if (sizeof($trace) > 1) {
                    $function = DebugHelper::getFQFunctionName($trace[0]);
                    if ($function=='include' || $function=='include_once' || $function=='require' || $function=='require_once') {
                        if (isset($trace[0]['file']) && isset($trace[1]['file'])) {
                            if ($trace[0]['file'] == $trace[1]['file']) {
                                if (isset($trace[0]['line']) && isset($trace[1]['line'])) {
                                    if ($trace[0]['line'] == $trace[1]['line']) {
                                        unset($trace[0]['file'], $trace[0]['line']);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // store the new stacktrace
            $this->betterTrace = $trace;
        }
        return $trace;
    }
1158030
private static function getDebugFile()
    {
        $trace = \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);

        foreach (\array_reverse($trace) as $stackFrame) {
            if (!self::isDebugCall($stackFrame)) {
                continue;
            }

            if (\preg_match('/eval\(/', $stackFrame['file'])) {
                \preg_match_all('/([^\(]+)\((\d+)/', $stackFrame['file'], $matches);

                return $matches[1][0];
            }

            return $stackFrame['file'];
        }
    }
794594
public function renderTrace($debug_backtrace)
    {
        $renderTrace = '';
        $renderTrace .= '<span class="fs-label">';
        foreach ($debug_backtrace as $index => $trace) {
            $renderTrace .= '#' . $index . ' ';
            if (!empty($trace['file'])) {
                $renderTrace .= $trace['file'];
            }
            if (!empty($trace['line'])) {
                $renderTrace .= '(' . $trace['line'] . ') ';
            }
            if (!empty($trace['class'])) {
                $renderTrace .= $trace['class'] . '::';
            }
            $renderTrace .= $trace['function'] . '()'
                . '<br>';
        }
        $renderTrace .= '</span>';
        return $renderTrace;
    }