Merge branch 'release/3.5'

This commit is contained in:
Dylan K. Taylor 2018-12-20 20:02:16 +00:00
commit a2e4fdc8a2
5 changed files with 36 additions and 20 deletions

View File

@ -159,7 +159,7 @@ class CrashDump{
$error = $lastExceptionError; $error = $lastExceptionError;
}else{ }else{
$error = (array) error_get_last(); $error = (array) error_get_last();
$error["trace"] = Utils::getTrace(4); //Skipping CrashDump->baseCrash, CrashDump->construct, Server->crashDump $error["trace"] = Utils::printableCurrentTrace(3); //Skipping CrashDump->baseCrash, CrashDump->construct, Server->crashDump
$errorConversion = [ $errorConversion = [
E_ERROR => "E_ERROR", E_ERROR => "E_ERROR",
E_WARNING => "E_WARNING", E_WARNING => "E_WARNING",

View File

@ -2206,7 +2206,7 @@ class Server{
"fullFile" => $e->getFile(), "fullFile" => $e->getFile(),
"file" => $errfile, "file" => $errfile,
"line" => $errline, "line" => $errline,
"trace" => Utils::getTrace(0, $trace) "trace" => Utils::printableTrace($trace)
]; ];
global $lastExceptionError, $lastError; global $lastExceptionError, $lastError;

View File

@ -90,7 +90,7 @@ class LoginPacket extends DataPacket{
$logger = \GlobalLogger::get(); $logger = \GlobalLogger::get();
$logger->debug(get_class($e) . " was thrown while decoding connection request in login (protocol version " . ($this->protocol ?? "unknown") . "): " . $e->getMessage()); $logger->debug(get_class($e) . " was thrown while decoding connection request in login (protocol version " . ($this->protocol ?? "unknown") . "): " . $e->getMessage());
foreach(Utils::getTrace(0, $e->getTrace()) as $line){ foreach(Utils::printableTrace($e->getTrace()) as $line){
$logger->debug($line); $logger->debug($line);
} }
} }

View File

@ -210,7 +210,7 @@ class MainLogger extends \AttachableThreadedLogger{
$errfile = Utils::cleanPath($errfile); $errfile = Utils::cleanPath($errfile);
$message = get_class($e) . ": \"$errstr\" ($errno) in \"$errfile\" at line $errline"; $message = get_class($e) . ": \"$errstr\" ($errno) in \"$errfile\" at line $errline";
$stack = Utils::getTrace(0, $trace); $stack = Utils::printableTrace($trace);
$this->synchronized(function() use ($type, $message, $stack) : void{ $this->synchronized(function() use ($type, $message, $stack) : void{
$this->log($type, $message); $this->log($type, $message);

View File

@ -461,24 +461,13 @@ class Utils{
} }
/** /**
* @param int $start * @param array $trace
* @param array|null $trace
* *
* @return array * @return array
*/ */
public static function getTrace($start = 0, $trace = null){ public static function printableTrace(array $trace) : array{
if($trace === null){
if(function_exists("xdebug_get_function_stack")){
$trace = array_reverse(xdebug_get_function_stack());
}else{
$e = new \Exception();
$trace = $e->getTrace();
}
}
$messages = []; $messages = [];
$j = 0; for($i = 0; isset($trace[$i]); ++$i){
for($i = (int) $start; isset($trace[$i]); ++$i, ++$j){
$params = ""; $params = "";
if(isset($trace[$i]["args"]) or isset($trace[$i]["params"])){ if(isset($trace[$i]["args"]) or isset($trace[$i]["params"])){
if(isset($trace[$i]["args"])){ if(isset($trace[$i]["args"])){
@ -491,12 +480,39 @@ class Utils{
return (is_object($value) ? get_class($value) . " object" : gettype($value) . " " . (is_array($value) ? "Array()" : Utils::printable(@strval($value)))); return (is_object($value) ? get_class($value) . " object" : gettype($value) . " " . (is_array($value) ? "Array()" : Utils::printable(@strval($value))));
}, $args)); }, $args));
} }
$messages[] = "#$j " . (isset($trace[$i]["file"]) ? self::cleanPath($trace[$i]["file"]) : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . Utils::printable($params) . ")"; $messages[] = "#$i " . (isset($trace[$i]["file"]) ? self::cleanPath($trace[$i]["file"]) : "") . "(" . (isset($trace[$i]["line"]) ? $trace[$i]["line"] : "") . "): " . (isset($trace[$i]["class"]) ? $trace[$i]["class"] . (($trace[$i]["type"] === "dynamic" or $trace[$i]["type"] === "->") ? "->" : "::") : "") . $trace[$i]["function"] . "(" . Utils::printable($params) . ")";
} }
return $messages; return $messages;
} }
/**
* @param int $skipFrames
*
* @return array
*/
public static function currentTrace(int $skipFrames = 0) : array{
++$skipFrames; //omit this frame from trace, in addition to other skipped frames
if(function_exists("xdebug_get_function_stack")){
$trace = array_reverse(xdebug_get_function_stack());
}else{
$e = new \Exception();
$trace = $e->getTrace();
}
for($i = 0; $i < $skipFrames; ++$i){
unset($trace[$i]);
}
return array_values($trace);
}
/**
* @param int $skipFrames
*
* @return array
*/
public static function printableCurrentTrace(int $skipFrames = 0) : array{
return self::printableTrace(self::currentTrace(++$skipFrames));
}
public static function cleanPath($path){ public static function cleanPath($path){
return str_replace(["\\", ".php", "phar://", str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PATH), str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PLUGIN_PATH)], ["/", "", "", "", ""], $path); return str_replace(["\\", ".php", "phar://", str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PATH), str_replace(["\\", "phar://"], ["/", ""], \pocketmine\PLUGIN_PATH)], ["/", "", "", "", ""], $path);
} }