Returns the formatted debug backtrace

@author Art <a.molcanovas@gmail.com>

@param array  $trace The debug backtrace
@param string $label Trace label style

@return string
487184
protected function getTrace($trace, $label) {
            ob_start();
            $trace = array_slice($trace, $this->config->traceDepth * -1);

            // @codeCoverageIgnoreStart
            if ($this->isCLI) {
                $this->traceCLI($trace, $label);
            } else {
                // @codeCoverageIgnoreEnd
                $this->traceHTML($trace);
            }

            return ob_get_clean();
        }
47255
static public function trace($value='[think]',$label='',$level='DEBUG',$record=false) {
        static $_trace =  array();
        if('[think]' === $value){ // 获取trace信息
            return $_trace;
        }else{
            $info   =   ($label?$label.':':'').print_r($value,true);
            $level  =   strtoupper($level);
            
            if((defined('IS_AJAX') && IS_AJAX) || !C('SHOW_PAGE_TRACE')  || $record) {
                Log::record($info,$level,$record);
            }else{
                if(!isset($_trace[$level]) || count($_trace[$level])>C('TRACE_MAX_RECORD')) {
                    $_trace[$level] =   array();
                }
                $_trace[$level][]   =   $info;
            }
        }
    }
847603
private function formatStackTrace(array $trace, $prefix = '')
    {
        $traceAsString = '';
        foreach ($trace as $line) {
            if (isset($line['class']) && isset($line['type']) && isset($line['function'])) {
                $traceAsString .= sprintf('%s%s%s()', $line['class'], $line['type'], $line['function']).PHP_EOL;
            } elseif (isset($line['class'])) {
                $traceAsString .= sprintf('%s', $line['class']).PHP_EOL;
            } elseif (isset($line['function'])) {
                $traceAsString .= sprintf('%s()', $line['function']).PHP_EOL;
            }

            if (isset($line['file']) && isset($line['line'])) {
                $traceAsString .= sprintf('  > %s:%d', $this->makePathRelative($line['file']), $line['line']).PHP_EOL;
            }
        }

        $traceAsString = $this->formatTextBlock($traceAsString, $prefix, true);

        return $traceAsString;
    }
186620
public function traceLog(string $key = null, $message = null)
    {
        if ($this->trace_log_enabled) {
            if (is_array($message) || is_object($message)) {
                $text = print_r($message, true);
            } elseif ($message === null) {
                $text = "[null]";
            } elseif ($message === false) {
                $text = "[false]";
            } elseif ($message === true) {
                $text = "[true]";
            } else {
                $text = $message;
            }
            error_log("=== " . ($key !== null ? "$key: " : '') . $text);
        }

        if ($key === null) {
            if ($this->trace_log_buffer === null) {
                $this->trace_log_buffer = array();
            }
            if (array_key_exists(self::MESSAGES_STACK, $this->trace_log_buffer)) {
                $this->trace_log_buffer[self::MESSAGES_STACK][] = $message;
            } else {
                $this->trace_log_buffer[self::MESSAGES_STACK] = array($message);
            }
        } else {
            $this->trace_log_buffer[$key] = $message;
        }
    }
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>';
	}
898724
private function renderTrace($trace)
    {
        foreach ($trace as $i => $entry) {
            $s = '';
            if (!empty($entry['file'])) {
                $s .= $this->stripFile($entry['file']);
                if (!empty($entry['line'])) {
                    $s .= ' (line ' . $entry['line'] . ')';
                }
            }
            if (!empty($entry['function'])) {
                $class = !empty($entry['class']) ? $entry['class'] . $entry['type'] : '';
                $args  = !empty($entry['args']) ? $this->dumpArgs($entry['args']) : '' ;
                $s .= ':<br/>&nbsp;&nbsp;&nbsp;' . $class . $entry['function'] . '(' . $args . ')';
            }
            $trace[$i] = '<li>' . $s . '</li>';
        }

        return '<code><ul>' . implode('<br/>', $trace) . '</ul></code>';
    }
639502
public function mark($label)
    {
        $prefix = XTAINJoomlaBundle::STOPWATCH_PREFIX;
        $stopName = null;
        if (preg_match('/^(before|after)/', $label)) {
            $stopName = lcfirst(preg_replace('/^(before|after)/', '', $label));
        }
        if (self::$stopwatch !== null) {
            if ($stopName !== null) {
                if (self::$stopwatch->isStarted($prefix . $stopName)) {
                    self::$stopwatch->stop($prefix . $stopName);
                } else {
                    self::$stopwatch->start($prefix . $stopName, XTAINJoomlaBundle::STOPWATCH_CATEGORY_NAME);
                    if (preg_match('/^(after)/', $label)) {
                        self::$stopwatch->stop($prefix . $stopName, XTAINJoomlaBundle::STOPWATCH_CATEGORY_NAME);
                    }
                }
            } else {
                self::$stopwatch->start($prefix . $label, XTAINJoomlaBundle::STOPWATCH_CATEGORY_NAME);
            }
        }

        return parent::mark($label);
    }
835169
public function getStackTraceFrames(array $trace): array
    {
        return \Raven_Stacktrace::get_stack_info(
            $trace,
            $this->client->trace,
            [],
            $this->client->message_limit,
            $this->client->getPrefixes(),
            $this->client->getAppPath(),
            $this->client->getExcludedAppPaths(),
            $this->serializer,
            $this->reprSerializer
        );
    }
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' ) );
	}
309200
public function traceAt($levels, $replace = false)
    {
        $prev = $this->tracedErrors;
        $this->tracedErrors = (int) $levels;
        if (!$replace) {
            $this->tracedErrors |= $prev;
        }

        return $prev;
    }
786291
protected function getErrorDetails(\Exception $e, $trace = false)
    {
        $msg = $e->getMessage();
        if ($e instanceof DfException) {
            $context = $e->getContext();
            if (is_array($context)) {
                $context = print_r($context, true);
            }
            if (!empty($context)) {
                $msg .= "\nContext: " . $context;
            }
        }

        if ($trace === true) {
            $msg .= "\nTrace:\n" . $e->getTraceAsString();
        }

        return $msg;
    }
366146
public static function normalizeBacktrace(array $trace)
    {
        $trace = new Data($trace);

        $args = [];

        foreach ($trace['args'] as $arg) {
            if (is_array($arg)) {
                $arg = 'Array';
            } elseif (is_object($arg)) {
                $arg = ReflectionHelper::getShortName($arg);
            } elseif (is_string($arg)) {
                if (Mbstring::strlen($arg) > 20) {
                    $arg = Utf8String::substr($arg, 0, 20) . '...';
                }

                $arg = Str::wrap($arg);
            } elseif ($arg === null) {
                $arg = 'NULL';
            } elseif (is_bool($arg)) {
                $arg = $arg ? 'TRUE' : 'FALSE';
            }

            $args[] = $arg;
        }

        return [
            'file' => !empty($trace['file']) ? static::replaceRoot($trace['file']) . ' (' . $trace['line'] . ')' : null,
            'function' => ($trace['class'] ? $trace['class'] . $trace['type'] : null) . $trace['function'] .
                sprintf('(%s)', implode(', ', $args)),
            'pathname' => $trace['file'],
            'line' => $trace['line']
        ];
    }
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'];
        }
    }
428477
public static function debugBacktraceString($trace = null) {
		$result = [];
		if (!\Debug::$debug) return $result;
		$i = 1;
		// if trace is not provided
		if (empty($trace)) {
			$trace = debug_backtrace();
			unset($trace[0]);
		}
		foreach($trace as $v) {
			$stack = '#' . $i . ' ' . (isset($v['file']) ? $v['file'] : 'Unknown');
			if (isset($v['line'])) {
				$stack.= '(' . $v['line'] . ')';
			}
			// do not show error handler
			if (!(isset($v['class']) && $v['class'] == 'error' && $v['function'] == 'error_handler')) {
				$stack.= ': ';
				if(isset($v['class'])) {
					$stack.= $v['class'] . $v['type'];
				}
				$params = [];
				if (isset($v['args'])) {
					foreach ($v['args'] as $v2) {
						if (gettype($v2) == 'string') {
							$params[] = str_replace(["\n", "\r", "\t"], ' ', $v2);
						} else if (is_array($v2)) {
							$temp = var_export_condensed($v2, ['skip_objects' => true]);
							$params[] = substr($temp, 0, 100) . '...';
						} else {
							$params[] = var_export_condensed($v2, ['skip_objects' => true]);
						}
					}
				}
				$stack.= $v['function'] . '(' . implode(', ', $params) . ');';
			}
			$i++;
			$result[] = $stack;
		}
		return $result;
	}
358798
private function _trace($trace = null)
    {
        $trace = $trace ?: debug_backtrace();
        foreach( $trace as $er) {
            $func = isset($er['function'])? $er['function']: '';
            $file = isset($er['file']) ? $er['file'] : '';

            # last two sections of the path
            if ($file) {
                $file  = $this->limitPath($file);
                $line  = isset($er['line'])? $er['line']: '';
                $class = isset($er['class'])? $er['class']: '';
                if ($class == 'IrfanTOOR\Debug' && $func=='_trace')
                    continue;

                $ftag = ($class != '') ? $class . '=>' . $func . '()' : $func . '()';
                $txt = '-- file: ' . $file . ', line: ' . $line . ', ' . $ftag;
                if ($this->terminal)
                    $this->console->writeln( $txt, 'dark');
                else
                    echo '<code style="color:#999">' . $txt . '</code><br>';
            }
        }
    }
1360065
public static function trace()
    {
        if (!self::$enabled_mode) {
            return 0;
        }

        Utils::normalizeAliases(self::$aliases);

        $args = \func_get_args();

        $call_info = self::getCallInfo(self::$aliases, \debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS), \count($args));

        $statics = self::getStatics();

        if (\in_array('~', $call_info['modifiers'], true)) {
            $statics['enabled_mode'] = self::MODE_TEXT;
        }

        $kintstance = self::createFromStatics($statics);
        if (!$kintstance) {
            // Should never happen
            return 0; // @codeCoverageIgnore
        }

        if (\in_array('-', $call_info['modifiers'], true)) {
            while (\ob_get_level()) {
                \ob_end_clean();
            }
        }

        $kintstance->setStatesFromStatics($statics);
        $kintstance->setStatesFromCallInfo($call_info);

        $trimmed_trace = array();
        $trace = \debug_backtrace(true);

        foreach ($trace as $frame) {
            if (Utils::traceFrameIsListed($frame, self::$aliases)) {
                $trimmed_trace = array();
            }

            $trimmed_trace[] = $frame;
        }

        $output = $kintstance->dumpAll(
            array($trimmed_trace),
            array(BasicObject::blank('Kint\\Kint::trace()', 'debug_backtrace(true)'))
        );

        if (self::$return || \in_array('@', $call_info['modifiers'], true)) {
            return $output;
        }

        echo $output;

        if (\in_array('-', $call_info['modifiers'], true)) {
            \flush(); // @codeCoverageIgnore
        }

        return 0;
    }
942820
protected function labelFormatted($label)
    {
        return "\n" . $this->util->cursor->startOfCurrentLine() . $this->util->cursor->deleteCurrentLine() . $label;
    }