Prints a debug backtrace.

When there are classes found inside the backtrace,
they will be analysed.

@param array|null $backtrace
An already existing backtrace.

@api
165868
public static function backtrace(array $backtrace = null)
    {
        Pool::createPool();

        // Disabled?
        if (static::$pool->config->getSetting(Fallback::SETTING_DISABLED) ||
            AbstractController::$analysisInProgress ||
            Config::$disabledByPhp
        ) {
            return;
        }

        AbstractController::$analysisInProgress = true;

        static::$pool->createClass('Brainworxx\\Krexx\\Controller\\BacktraceController')
            ->noFatalForKrexx()
            ->backtraceAction($backtrace)
            ->reFatalAfterKrexx();

        AbstractController::$analysisInProgress = false;
    }
1133589
public function isAllowedDebugCall($data)
    {
        // Check if the class itself is blacklisted.
        foreach ($this->classBlacklist as $classname) {
            if (is_a($data, $classname) === true) {
                // No debug methods for you.
                return false;
            }
        }

        // Nothing found?
        return true;
    }
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;
    }
967268
public static function trace($str)
    {
        $dbg = debug_backtrace();
        phpCAS :: log($str . ' [' . basename($dbg[0]['file']) . ':' . $dbg[0]['line'] . ']');
    }
486101
def debug(trace=True, backtrace=1, other=None, output=sys.stderr):
    """"""
    from pprint import pprint
    import traceback
    def debugdeco(func):
        def tracer(frame, event, arg):
            print>>output, '--- Tracer: %s, %r' % (event, arg)
            traceback.print_stack(frame, 1, output)
            return tracer
        def wrapped(*a, **k):
            print>>output
            print>>output, '--- Calling %s.%s with:' % (
                getattr(func, '__module__', ''),
                func.__name__
            )
            for i in enumerate(a):
                print>>output, '    | %s: %s' % i
            print>>output, '    | ',
            pprint(k, output)
            print>>output, '    From:'
            for i in traceback.format_stack(sys._getframe(1), backtrace):
                print>>output, i,
            if other:
                print>>output, '---      [ %r ]' % (other(func,a,k))
            if trace: sys.settrace(tracer)
            ret = func(*a, **k)
            if trace: sys.settrace(None)
            #~ a = list(a)
            print>>output, '--- %s.%s returned: %r' % (
                getattr(func, '__module__', ''),
                func.__name__,
                #~ ret not in a and ret or "ARG%s"%a.index(ret)
                ret
            )
            return ret
        return wrapped
    return debugdeco
466966
public function debug($message, $args=array())
    {
        $backtrace        = debug_backtrace();
        $args['FILENAME'] = $backtrace[0]['file'];
        $args['LINENO']   = $backtrace[0]['line'];
        $this->log($message, $args, 'LOG_DEBUG');

    }
1152711
public function getBacktrace( $trace )
    {
        $traces = [ ];

        $i = 1;

        foreach ( $trace as $t )
        {
            $traceString = '';

            if ( !isset( $t[ 'file' ] ) )
            {
                $t[ 'file' ] = 'unknown';
            }
            if ( !isset( $t[ 'line' ] ) )
            {
                $t[ 'line' ] = 0;
            }
            if ( !isset( $t[ 'function' ] ) )
            {
                $t[ 'function' ] = 'unknown';
            }

            $traceString .= '#' .
                $i . ' ' .
                $t[ 'file' ] . '(' .
                $t[ 'line' ] . '): ';

            if ( isset( $t[ 'object' ] ) && is_object( $t[ 'object' ] ) )
            {
                $traceString .= get_class( $t[ 'object' ] ) . '->';
            }

            $traceString .= $t[ 'function' ] . '()';

            $traces[ ] = $traceString;

            $i++;
        }

        return $traces;
    }
1047493
protected function _debug( $message, $args = null ) {
		$message = '[Factory] ' . $message;

		if ( func_num_args() == 1 ) {
			Debug::debug( $message );
		} else {
			$args = array_slice( func_get_args(), 1 );
			Debug::debugf( $message, $args );
		}
	}
271094
public static function filter_backtrace($bt, $ignoredFunctions = null)
    {
        $defaultIgnoredFunctions = array(
            'SilverStripe\\Logging\\Log::log',
            'SilverStripe\\Dev\\Backtrace::backtrace',
            'SilverStripe\\Dev\\Backtrace::filtered_backtrace',
            'Zend_Log_Writer_Abstract->write',
            'Zend_Log->log',
            'Zend_Log->__call',
            'Zend_Log->err',
            'SilverStripe\\Dev\\DebugView->writeTrace',
            'SilverStripe\\Dev\\CliDebugView->writeTrace',
            'SilverStripe\\Dev\\Debug::emailError',
            'SilverStripe\\Dev\\Debug::warningHandler',
            'SilverStripe\\Dev\\Debug::noticeHandler',
            'SilverStripe\\Dev\\Debug::fatalHandler',
            'errorHandler',
            'SilverStripe\\Dev\\Debug::showError',
            'SilverStripe\\Dev\\Debug::backtrace',
            'exceptionHandler'
        );

        if ($ignoredFunctions) {
            foreach ($ignoredFunctions as $ignoredFunction) {
                $defaultIgnoredFunctions[] = $ignoredFunction;
            }
        }

        while ($bt && in_array(self::full_func_name($bt[0]), $defaultIgnoredFunctions)) {
            array_shift($bt);
        }

        $ignoredArgs = static::config()->get('ignore_function_args');

        // Filter out arguments
        foreach ($bt as $i => $frame) {
            $match = false;
            if (!empty($bt[$i]['class'])) {
                foreach ($ignoredArgs as $fnSpec) {
                    if (is_array($fnSpec) &&
                        ('*' == $fnSpec[0] || $bt[$i]['class'] == $fnSpec[0]) &&
                        $bt[$i]['function'] == $fnSpec[1]
                    ) {
                        $match = true;
                    }
                }
            } else {
                if (in_array($bt[$i]['function'], $ignoredArgs)) {
                    $match = true;
                }
            }
            if ($match) {
                foreach ($bt[$i]['args'] as $j => $arg) {
                    $bt[$i]['args'][$j] = '<filtered>';
                }
            }
        }

        return $bt;
    }
1212453
public static function renderBacktrace($error)
	{
		JLog::add('JError::renderBacktrace() is deprecated.', JLog::WARNING, 'deprecated');

		$contents = null;
		$backtrace = $error->getTrace();

		if (is_array($backtrace))
		{
			ob_start();
			$j = 1;
			echo '<table cellpadding="0" cellspacing="0" class="Table">';
			echo '		<tr>';
			echo '				<td colspan="3" class="TD"><strong>Call stack</strong></td>';
			echo '		</tr>';
			echo '		<tr>';
			echo '				<td class="TD"><strong>#</strong></td>';
			echo '				<td class="TD"><strong>Function</strong></td>';
			echo '				<td class="TD"><strong>Location</strong></td>';
			echo '		</tr>';

			for ($i = count($backtrace) - 1; $i >= 0; $i--)
			{
				echo '		<tr>';
				echo '				<td class="TD">' . $j . '</td>';

				if (isset($backtrace[$i]['class']))
				{
					echo '		<td class="TD">' . $backtrace[$i]['class'] . $backtrace[$i]['type'] . $backtrace[$i]['function'] . '()</td>';
				}
				else
				{
					echo '		<td class="TD">' . $backtrace[$i]['function'] . '()</td>';
				}

				if (isset($backtrace[$i]['file']))
				{
					echo '				<td class="TD">' . $backtrace[$i]['file'] . ':' . $backtrace[$i]['line'] . '</td>';
				}
				else
				{
					echo '				<td class="TD">&#160;</td>';
				}

				echo '		</tr>';
				$j++;
			}

			echo '</table>';
			$contents = ob_get_contents();
			ob_end_clean();
		}

		return $contents;
	}
1140894
public static function format_backtrace($backtrace) {
		global $CFG;
		$html = '';
		$i = count($backtrace);
		foreach ($backtrace as $trace) {
			$file = (isset($trace['file'])) ? str_replace($CFG->base_absroot, '', $trace['file']) : 'unknown';
			$line = 'Line: '. ((isset($trace['line'])) ? $trace['line'] : '-');
			$func = ((isset($trace['function'])) ? $trace['function'] : '');
			ini_set('html_errors', 0);
			$argstr = [];
			if (!empty($trace['args']) && is_array($trace['args'])) {
				foreach ($trace['args'] as $arg) {
					ob_start();
					var_dump($arg);
					$stringval = ob_get_contents();
					ob_end_clean();
					$argstr[] = $stringval;
				}
			}
			$args = implode(', ', $argstr);
			$func .= '('.$args.')';
			if (\pdyn\base\Utils::is_cli_env() === true) {
				$html .= $i."\t".$file."\t".$line."\t".$func."\n";
			} else {
				$html .= '<tr>';
					$html .= '<td style="vertical-align:top">'.$i.'</td>';
					$html .= '<td style="vertical-align:top">'.$file.'</td>';
					$html .= '<td style="vertical-align:top">'.$line.'</td>';
					$html .= '<td><pre style="margin:0;">'.$func.'</pre></td>';
				$html .= '</tr>';
			}
			$i--;
		}
		return (\pdyn\base\Utils::is_cli_env() === true)
			? "**********\n".$html."**********\n"
			: '<table cellspacing="5" style="color:inherit">'.$html.'</table>';
	}
453746
public function getBacktrace($exception = null)
    {
        $skipLimit = false;

        if ($exception instanceof \Exception || $exception instanceof \Throwable) {
            $backtrace = $exception->getTrace();
            foreach ($backtrace as $index => $backtraceCall) {
                unset($backtrace[$index]['args']);
            }
        } elseif (version_compare(PHP_VERSION, '5.4.0') >= 0) {
            $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, $this->backtraceLimit);
            $skipLimit = true;
        } else {
            $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
        }

        if ($this->backtraceLimit > 0 && !$skipLimit) {
            $backtrace = array_slice($backtrace, 0, $this->backtraceLimit);
        }

        return $backtrace;
    }
1103472
public function dispatchDebug($data, $tags = null, $ignoreTraceCalls = 0) {
		if($this->isActive()) {
			$message = new DebugMessage();
			$message->data = $this->dumper->dump($data);
			if($tags) {
				$message->tags = explode('.', $tags);
			}
			if($this->detectTraceAndSource && $ignoreTraceCalls !== null) {
				$message->trace = $this->fetchTrace(debug_backtrace(), $message->file, $message->line, $ignoreTraceCalls);
			}
			$this->sendMessage($message);
		}
	}
1011890
public static function showTrace(array $options = [])
    {
        $options = array_merge([
            'trace_offset' => 0,
            'reverse'      => false,
        ], $options);

        $backtrace = ($options['reverse'] ? array_reverse(debug_backtrace()) : debug_backtrace());

        $output     = '';
        $traceIndex = ($options['reverse'] ? 1 : count($backtrace));
        foreach ($backtrace as $trace) {
            $output .= $traceIndex . ': ';
            $output .= self::getCalledFromTrace($trace);
            $output .= "\n";

            $traceIndex += ($options['reverse'] ? 1 : -1);
        }

        self::output($output, $options);
    }
919060
public function traceClose(int $idx = null, int $errCode = null, string $errMessage = null): void
    {
        if (null === $idx) {
            $idx = count($this->buffTrace) - 1;
        }
        
        if (!array_key_exists($idx, $this->buffTrace)) {
            throw new DebugIndexNotExistsException();
        }
        
        $this->buffTrace[$idx]['time'] = microtime(true) - $this->buffTrace[$idx]['time'];
        $this->buffTrace[$idx]['result'] = (null === $errCode ? 'OK' : '(' . $errCode . ') ' . $errMessage);
    }
833726
public static function normalize($backtrace)
    {
        if (!static::isThrowable($backtrace)) {
            return $backtrace;
        }
        return array_merge([[
            'function' => '[NA]',
            'file'     => $backtrace->getFile(),
            'line'     => $backtrace->getLine(),
            'args'     => []
        ]], $backtrace->getTrace());
    }
1191408
public function log($msg)
    {
        $backtrace = debug_backtrace();
        if (!isset($backtrace[1]['function'])) {
            return;
        }

        $i = 1;
        $stackSize = count($backtrace);
        do {
            $callingMethod = $backtrace[$i]['function'];
            $i++;
        } while ($callingMethod == "log" && $i < $stackSize);

        if (!$msg || !$this->isLogEnabledForMethod($callingMethod)) {
            return;
        }

        $this->getLogger()->info($msg);
    }