Parses the debug backtrace for the applicable file and line

@return  array
@since   2.0.0
196701
public static function parseBacktrace()
	{
		$file = '-';
		$line = 0;

		// Loop through the backtrace items
		foreach (self::getBacktrace() as $item)
		{
			// Looking for the last instance of one of the following classes...
			// this will be our indicator of the command that originated this query
			if (isset($item['class'])
			 && ($item['class'] == 'Hubzero\Database\Relational'
			 ||  $item['class'] == 'Hubzero\Database\Relationship\Relationship'
			 ||  $item['class'] == 'Hubzero\Database\Rows'))
			{

				$file = (isset($item['file'])) ? str_replace(PATH_CORE, '', $item['file']) : $file;
				$line = (isset($item['line'])) ? $item['line'] : $line;
			}
		}

		return array($file, $line);
	}
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;
    }
623893
public function loadCallLocationInfo()
    {
        $this->callFile = null;
        $this->callLine = null;

        $backtraceFlags = DEBUG_BACKTRACE_PROVIDE_OBJECT;
        if (version_compare(PHP_VERSION, '5.3.6', '>=')) {
            $backtraceFlags = DEBUG_BACKTRACE_IGNORE_ARGS;
        }

        $backtrace = debug_backtrace($backtraceFlags);

        $backtraceCount = count($backtrace);
        $idx = $backtraceCount - 1;
        $found = false;

        $container = $this->application->container;

        $helpers = array_merge(
            $container->getParameter('helpers'),
            $container->hasParameter('extra_helpers') ? $container->getParameter('extra_helpers') : array()
        );

        while ($idx > 0 && !$found) {
            $callable = isset($backtrace[$idx]['class']) ? $backtrace[$idx]['class'] . ':' . $backtrace[$idx]['function'] : $backtrace[$idx]['function'];

            if (in_array($callable, $helpers)) {
                $this->callFile = isset($backtrace[$idx]['file']) ? $backtrace[$idx]['file'] : null;
                $this->callLine = isset($backtrace[$idx]['line']) ? $backtrace[$idx]['line'] : null;

                if (!is_null($this->callLineFileCallback)) {
                    list($this->callFile, $this->callLine) = call_user_func_array($this->callLineFileCallback, array(
                        $this->callFile,
                        $this->callLine
                    ));
                }

                $xdebugLink = ini_get('xdebug.file_link_format');
                if (!empty($xdebugLink)) {
                    $this->xdebugLink = str_replace(array('%f', '%l'), array($this->callFile, $this->callLine), $xdebugLink);
                }

                return;
            }

            $idx--;
        }

    }
371116
private function mapStacktrace() : array
    {
        $stacktrace = [];

        foreach ($this->throwable->getTrace() as $trace) {
            $item = [
              'function' => $trace['function'] ?? '(closure)'
            ];

            if (isset($trace['line']) === true) {
                $item['lineno'] = $trace['line'];
            }

            if (isset($trace['file']) === true) {
                $item += [
                    'filename' => basename($trace['file']),
                    'abs_path' => $trace['file']
                ];
            }

            if (isset($trace['class']) === true) {
                $item['module'] = $trace['class'];
            }
            
            if (isset($trace['type']) === true) {
                $item['type'] = $trace['type'];
            }

            if (!isset($item['lineno'])) {
                $item['lineno'] = 0;
            }

            if (!isset($item['filename'])) {
                $item['filename'] = '(anonymous)';
            }

            array_push($stacktrace, $item);
        }

        return $stacktrace;
    }
761427
public static function inspect()
	{
		$backtrace = debug_backtrace();

		// If being called from within, show the file above in the backtrack
		if (strpos($backtrace[0]['file'], 'core/classes/debug.php') !== false)
		{
			$callee = $backtrace[1];
			$label = \Inflector::humanize($backtrace[1]['function']);
		}
		else
		{
			$callee = $backtrace[0];
			$label = 'Debug';
		}

		$arguments = func_get_args();
		$total_arguments = count($arguments);

		$callee['file'] = \Fuel::clean_path($callee['file']);

		if ( ! static::$js_displayed)
		{
			echo <<<JS
<script type="text/javascript">function fuel_debug_toggle(a){if(document.getElementById){if(document.getElementById(a).style.display=="none"){document.getElementById(a).style.display="block"}else{document.getElementById(a).style.display="none"}}else{if(document.layers){if(document.id.display=="none"){document.id.display="block"}else{document.id.display="none"}}else{if(document.all.id.style.display=="none"){document.all.id.style.display="block"}else{document.all.id.style.display="none"}}}};</script>
JS;
			static::$js_displayed = true;
		}
		echo '<div class="fuelphp-inspect" style="font-size: 13px;background: #EEE !important; border:1px solid #666; color: #000 !important; padding:10px;">';
		echo '<h1 style="border-bottom: 1px solid #CCC; padding: 0 0 5px 0; margin: 0 0 5px 0; font: bold 120% sans-serif;">'.$callee['file'].' @ line: '.$callee['line'].'</h1>';
		echo '<pre style="overflow:auto;font-size:100%;">';
		$i = 0;
		foreach ($arguments as $argument)
		{
			echo '<strong>'.$label.' #'.(++$i).' of '.$total_arguments.'</strong>:<br />';
				echo static::format('...', $argument);
			echo '<br />';
		}

		echo "</pre>";
		echo "</div>";
	}
628883
public function getTraceSaveAsString()
    {
        $traces   = $this->getTrace();
        $messages = ['STACK TRACE DETAILS : '];

        foreach ($traces as $index => $trace) {
            $message = sprintf('#%d ', $index + 1);

            /** @noinspection UnSafeIsSetOverArrayInspection */
            if (isset($trace['file'])) {
                if (!is_string($trace['file'])) {
                    $message .= '[Unknown Function]: ';
                } else {
                    $line = 0;

                    /** @noinspection UnSafeIsSetOverArrayInspection */
                    if (isset($trace['line']) && is_int($trace['line'])) {
                        $line = $trace['line'];
                    }

                    $message .= sprintf('%s(%d): ', $trace['file'], $line);
                }
            } else {
                $message .= '[Internal Function]: ';
            }

            /** @noinspection UnSafeIsSetOverArrayInspection */
            if (isset($trace['class']) && is_string($trace['class'])) {
                $message .= $trace['class'] . ' ';
            }

            /** @noinspection UnSafeIsSetOverArrayInspection */
            if (isset($trace['type']) && is_string($trace['type'])) {
                $message .= $trace['type'] . ' ';
            }

            /** @noinspection UnSafeIsSetOverArrayInspection */
            if (isset($trace['function']) && is_string($trace['function'])) {
                $message .= $trace['function'] . '(';

                /** @noinspection UnSafeIsSetOverArrayInspection */
                if (isset($trace['args']) && count($trace['args']) > 0) {
                    /** @var array $arguments */
                    $arguments    = $trace['args'];
                    $argVariables = [];

                    foreach ($arguments as $argument) {
                        $argVariables[] = $this->switchType($argument);
                    }

                    $message .= implode(', ', $argVariables);
                }

                $message .= ')';
            }

            $messages[] = trim($message);
        }

        return implode("\n", $messages);
    }
333624
public function getTraceAsString() {
		$lines = array ();
		for( $i = 0; $i < count($this->trace); $i++ ){
			$a = $this->trace[$i];
			$call = "{$a['function']}()";
			if( isset($a['class']) ){
				$call = "{$a['class']}{$a['type']}$call";
			}
			$lines[] = "#$i {$a['file']}({$a['line']}): $call";
		} 
		$lines[] = "#$i {main}";
		return implode( "\n", $lines );
	}
221129
protected function getBacktrace(\Exception $exception)
    {
        $backtrace = array();

        $backtrace[] = '---';
        $backtrace[] = $this->getErrorMessage($exception);
        $backtrace[] = '---';

        // Allow marshalling of the trace: PHP marks getTraceAsString as final :-(
        if (method_exists($exception, 'getPreviousTraceAsString')) {
            $backtrace = array_merge($backtrace, explode("\n", $exception->getPreviousTraceAsString()));
        } else {
            $backtrace = array_merge($backtrace, explode("\n", $exception->getTraceAsString()));
        }

        if (($previous = $exception->getPrevious())) {
            $backtrace = array_merge($backtrace, $this->getBacktrace($previous)); // Recurse
        }

        return $backtrace;
    }
591017
public static function caller ( )
	{
		$backtrace = V(debug_backtrace());

		foreach ($backtrace as $line) {
			$line = A($line);

			if ($line->class === 'Bacon\Log') continue;

			return A([
				'class'  => $line->class,
				'file'   => $line->file,
				'method' => $line->function,
				'object' => $line->object
			]);
		}

		/*
		if (isset($backtrace[2]['class'])) {
			return $backtrace[2]['class'];
		} elseif (isset($backtrace[2]['file'])) {
			return $backtrace[2]['file'];
		} else {
			return $backtrace[0]['file'];
		}
		 */
	}
624396
public function backtrace($backtrace = [])
    {
        if (!func_num_args()) {
            return $this->_backtrace;
        }
        if ($this->_backtrace = $backtrace) {
            foreach ($this->_backtrace as $trace) {
                if (isset($trace['file'])) {
                    $this->_file = preg_replace('~' . preg_quote(getcwd(), '~') . '~', '', '.' . $trace['file']);
                    $this->_line = $trace['line'];
                    break;
                }
            }
        }
        return $this;
    }
821430
public static function backTrace() {

        $str = "<br />[backTrace]";
        foreach (debug_backtrace() as $row) {
            $str .= "<br />FILE: "
                    . $row['file'] . " FUNC: " . $row['function']
                    . " LINE: " . $row['line'] . " ARGS: "
                    . print_r($row['args'], true);
        }
        return $str;
    }
1129740
protected function getBacktrace()
    {
        $traces = array();
        if ($this->traceLevel > 0) {
            $count = 0;
            $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
            array_pop($backtrace); // remove the last trace since it would be the entry script, not very useful
            foreach ($backtrace as $trace) {
                if (isset($trace['file'], $trace['line']) && strpos($trace['file'], FM_APP_PATH) !== 0) {
                    unset($trace['object'], $trace['args']);
                    $traces[] = $trace;
                    if (++$count >= $this->traceLevel) {
                        break;
                    }
                }
            }
        }
        return $traces;
    }
1217469
private function formatBacktrace() {

		$backtrace = $this -> error -> getBacktrace();
		
		if(null !== $backtrace) {

			array_shift($backtrace);
			array_shift($backtrace);

			foreach($backtrace as $index => $stack) {

				foreach(['type', 'args'] as $type) {

					if(true === isset($backtrace[$index][$type])) {
						unset($backtrace[$index][$type]);
					}
				}
			}
		}

		return $backtrace;
	}
39094
public function getTrace()
    {
        return $this->map(function ($item, $key) {
            // Convert arguments into something more readable
            if (!empty($item['args'])) {
                $args = array_map(function ($item) {
                    switch (true) {
                        case $item === null:
                            return 'null';
                        case $item === true:
                            return 'true';
                        case $item === false:
                            return 'false';
                        case is_array($item):
                            if (!count($item)) {
                                return 'array(0)';
                            } elseif (array_keys($item) !== range(0, count($item) -1)) {
                                return 'associative-array(' . count($item) . ')';
                            }
                            return 'sequential-array(' . count($item) . ')';
                        case is_object($item):
                            return get_class($item);
                        case is_string($item):
                            return "\"{$item}\"";
                        case is_numeric($item):
                            return $item;
                    }

                    return "\"{$item}\"";
                }, $item['args']);
            } else {
                $args = [];
            }

            return sprintf(
                '#%d %s%s%s(%s) called at [%s:%d]',
                $key,
                !empty($item['class']) ? $item['class'] : null,
                !empty($item['type']) ? $item['type'] : null,
                !empty($item['function']) ? $item['function'] : null,
                implode(', ', $args),
                !empty($item['file']) ? $item['file'] : null,
                !empty($item['line']) ? $item['line'] : null
            );
        });
    }
289251
public static function debugTrail() {
		$trail = debug_backtrace();
		$trail = array_reverse($trail);
		array_pop($trail);

		$path = array();
		foreach ($trail as $dat) {
			$pathFragment = $dat['class'] . $dat['type'] . $dat['function'];
				// add the path of the included file
			if (in_array($dat['function'], array('require', 'include', 'require_once', 'include_once'))) {
				$pathFragment .= '(' . substr($dat['args'][0], strlen(PATH_site)) . '),' . substr($dat['file'], strlen(PATH_site));
			}
			$path[] = $pathFragment . '#' . $dat['line'];
		}

		return implode(' // ', $path);
	}
87878
public function getDebugLocation()
    {
        $location = '';
        if ($this->class && ($this->method || $this->property)) {
            $location .= $this->fullyQualifiedName($this->class);
            if ($this->method) {
                $location .= ($this->static ? '::' : '->') . $this->method . '()';
            } elseif ($this->property) {
                $location .= ($this->static ? '::$' : '->') . $this->property;
            }
        }
        if ($this->filename) {
            if ($location !== '') {
                $location .= ' in ';
            }
            $location .= $this->filename;
        }
        if ($this->line) {
            if ($location !== '') {
                $location .= ' on';
            }
            $location .= ' line ' . $this->line;
            if ($this->character) {
                $location .= ':' . $this->character;
            }
        }

        return $location;
    }
812028
public function ___debugInfo()
    {
        return array(
            'name'  => isset($this->propertyNode) ? $this->propertyNode->name->toString() : 'unknown',
            'class' => $this->className
        );
    }