/** * Constructs the exception. * @link http://php.net/manual/en/errorexception.construct.php * @param $message [optional] * @param $code [optional] * @param $severity [optional] * @param $filename [optional] * @param $lineno [optional] * @param $previous [optional] */ public function __construct($message = '', $code = 0, $severity = 1, $filename = __FILE__, $lineno = __LINE__, \Exception $previous = null) { parent::__construct($message, $code, $severity, $filename, $lineno, $previous); if (function_exists('xdebug_get_function_stack')) { $trace = array_slice(array_reverse(xdebug_get_function_stack()), 3, -1); foreach ($trace as &$frame) { if (!isset($frame['function'])) { $frame['function'] = 'unknown'; } // XDebug < 2.1.1: http://bugs.xdebug.org/view.php?id=695 if (!isset($frame['type']) || $frame['type'] === 'static') { $frame['type'] = '::'; } elseif ($frame['type'] === 'dynamic') { $frame['type'] = '->'; } // XDebug has a different key name if (isset($frame['params']) && !isset($frame['args'])) { $frame['args'] = $frame['params']; } } $ref = new \ReflectionProperty('Exception', 'trace'); $ref->setAccessible(true); $ref->setValue($this, $trace); } }
/** * Logs a message. * * @param string Message * @param string Message priority * @param string Message priority name */ public function log($message, $priority, $priorityName) { if (!sfConfig::get('sf_web_debug')) { return; } // if we have xdebug, add some stack information $debug_stack = array(); if (function_exists('xdebug_get_function_stack')) { foreach (xdebug_get_function_stack() as $i => $stack) { if (isset($stack['function']) && !in_array($stack['function'], array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug', 'log')) || !isset($stack['function'])) { $tmp = ''; if (isset($stack['function'])) { $tmp .= 'in "' . $stack['function'] . '" '; } $tmp .= 'from "' . $stack['file'] . '" line ' . $stack['line']; $debug_stack[] = $tmp; } } } // get log type in {} $type = 'sfOther'; if (preg_match('/^\\s*{([^}]+)}\\s*(.+?)$/', $message, $matches)) { $type = $matches[1]; $message = $matches[2]; } // build the object containing the complete log information. $logEntry = array('priority' => $priority, 'priorityString' => $priorityName, 'time' => time(), 'message' => $message, 'type' => $type, 'debugStack' => $debug_stack); // send the log object. $this->webDebug->log($logEntry); }
/** * Logs a message. * * @param string Message * @param string Message priority * @param string Message priority name */ public function log($message, $priority, $priorityName) { if (!sfConfig::get('sf_web_debug')) { return; } // if we have xdebug, add some stack information $debug_stack = array(); // disable xdebug when an HTTP debug session exists (crashes Apache, see #2438) if (function_exists('xdebug_get_function_stack') && !isset($_GET['XDEBUG_SESSION_START']) && !isset($_COOKIE['XDEBUG_SESSION'])) { foreach (xdebug_get_function_stack() as $i => $stack) { if (isset($stack['function']) && !in_array($stack['function'], array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug', 'log')) || !isset($stack['function'])) { $tmp = ''; if (isset($stack['function'])) { $tmp .= 'in "' . $stack['function'] . '" '; } $tmp .= 'from "' . $stack['file'] . '" line ' . $stack['line']; $debug_stack[] = $tmp; } } } // get log type in {} $type = 'sfOther'; if (preg_match('/^\\s*{([^}]+)}\\s*/', $message, $matches)) { $type = $matches[1]; $message = preg_replace('/^(\\s*{' . $type . '}\\s*)/', '', $message); } // build the object containing the complete log information. $logEntry = array('priority' => $priority, 'priorityString' => $priorityName, 'time' => time(), 'message' => $message, 'type' => $type, 'debugStack' => $debug_stack); // send the log object. $this->webDebug->log($logEntry); }
public static function response(Exception $e) { try { $class = get_class($e); $code = $e->getCode(); $message = $e->getMessage(); $file = $e->getFile(); $line = $e->getLine(); $trace = $e->getTrace(); if ($e instanceof HTTP_Exception and $trace[0]["function"] == "factory") { extract(array_shift($trace)); } if ($e instanceof ErrorException) { if (function_exists("xdebug_get_function_stack") and $code == E_ERROR) { $trace = array_slice(array_reverse(xdebug_get_function_stack()), 4); foreach ($trace as &$frame) { /** * XDebug pre 2.1.1 doesn"t currently set the call type key * http://bugs.xdebug.org/view.php?id=695 */ if (!isset($frame["type"])) { $frame["type"] = "??"; } if ("dynamic" === $frame["type"]) { $frame["type"] = "->"; } elseif ("static" === $frame["type"]) { $frame["type"] = "::"; } if (isset($frame["params"]) and !isset($frame["args"])) { $frame["args"] = $frame["params"]; } } } if (isset(JsonApiApplication_Exception::$php_errors[$code])) { $code = JsonApiApplication_Exception::$php_errors[$code]; } } /** * The stack trace becomes unmanageable inside PHPUnit. * * The error view ends up several GB in size, taking * serveral minutes to render. */ if (defined("PHPUnit_MAIN_METHOD") or defined("PHPUNIT_COMPOSER_INSTALL") or defined("__PHPUNIT_PHAR__")) { $trace = array_slice($trace, 0, 2); } $view = View::factory(JsonApiApplication_Exception::$error_view, get_defined_vars()); $response = Response::factory(); $response->status($e instanceof HTTP_Exception ? $e->getCode() : 500); $response->headers("Content-Type", JsonApiApplication_Exception::$error_view_content_type . "; charset=" . JsonApiApplication::$charset); $response->body($view->render()); } catch (Exception $e) { $response = Response::factory(); $response->status(500); $response->headers("Content-Type", "text/plain"); $response->body(JsonApiApplication_Exception::text($e)); } return $response; }
public function __construct($message, $code, $severity, $filename, $lineno, $traceOffset = null, $traceArgs = true, array $trace = null) { parent::__construct($message, $code, $severity, $filename, $lineno); if (null !== $trace) { if (!$traceArgs) { foreach ($trace as &$frame) { unset($frame['args'], $frame['this'], $frame); } } $this->setTrace($trace); } elseif (null !== $traceOffset) { if (function_exists('xdebug_get_function_stack')) { $trace = xdebug_get_function_stack(); if (0 < $traceOffset) { array_splice($trace, -$traceOffset); } foreach ($trace as &$frame) { if (!isset($frame['type'])) { // XDebug pre 2.1.1 doesn't currently set the call type key http://bugs.xdebug.org/view.php?id=695 if (isset($frame['class'])) { $frame['type'] = '::'; } } elseif ('dynamic' === $frame['type']) { $frame['type'] = '->'; } elseif ('static' === $frame['type']) { $frame['type'] = '::'; } // XDebug also has a different name for the parameters array if (!$traceArgs) { unset($frame['params'], $frame['args']); } elseif (isset($frame['params']) && !isset($frame['args'])) { $frame['args'] = $frame['params']; unset($frame['params']); } } unset($frame); $trace = array_reverse($trace); } elseif (function_exists('symfony_debug_backtrace')) { $trace = symfony_debug_backtrace(); if (0 < $traceOffset) { array_splice($trace, 0, $traceOffset); } } else { $trace = array(); } $this->setTrace($trace); } }
function fatal_handler() { global $system_conf; $errfile = "unknown file"; $errstr = "shutdown"; $errno = E_CORE_ERROR; $errline = 0; $error = error_get_last(); $stack = array(); if (function_exists('xdebug_get_function_stack')) { foreach (array_slice(xdebug_get_function_stack(), 1, -1) as $row) { if (isset($row['class'])) { $row['type'] = isset($row['type']) && $row['type'] === 'dynamic' ? '->' : '::'; } if (isset($row['params'])) { $row['args'] = $row['params']; } $stack[] = $row; } } if ($error !== NULL) { $errno = $error["type"]; $errfile = $error["file"]; $errline = $error["line"]; $errstr = $error["message"]; } global $phpminer_request_is_ajax, $phpminer_error_handler_messages; ErrorHandler::cc_error_handler($errno, $errstr, $errfile, $errline, "", true, $stack); $error = $phpminer_error_handler_messages; if (empty($error)) { return; } if ($phpminer_request_is_ajax) { $code = 560; $data = sys_get_temp_dir() . '/phpminer_' . uniqid() . '.bugreport'; $return = array("code" => $code, "desc" => null, "data" => $data); if (is_array($error)) { $error = implode("\n", $error); } file_put_contents($data, "PHPMiner version: " . implode('.', $system_conf['version']) . "\n" . $error); echo json_encode($return); die; } echo implode("<br>", $error); die; }
/** * Formats and echoes the exception for the command line * * @param \Exception $exception The exception object * @return void */ public function handleException(\Exception $exception) { $pathPosition = strpos($exception->getFile(), 'ext/'); $filePathAndName = $pathPosition !== FALSE ? substr($exception->getFile(), $pathPosition) : $exception->getFile(); $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : ''; echo PHP_EOL . 'Uncaught Exception in TYPO3 CMS ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL; echo 'thrown in file ' . $filePathAndName . PHP_EOL; echo 'in line ' . $exception->getLine() . PHP_EOL; if ($exception instanceof \TYPO3\Flow\Exception) { echo 'Reference code: ' . $exception->getReferenceCode() . PHP_EOL; } $indent = ' '; while (($exception = $exception->getPrevious()) !== NULL) { echo PHP_EOL . $indent . 'Nested exception:' . PHP_EOL; $pathPosition = strpos($exception->getFile(), 'Packages/'); $filePathAndName = $pathPosition !== FALSE ? substr($exception->getFile(), $pathPosition) : $exception->getFile(); $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : ''; echo PHP_EOL . $indent . 'Uncaught Exception in Flow ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL; echo $indent . 'thrown in file ' . $filePathAndName . PHP_EOL; echo $indent . 'in line ' . $exception->getLine() . PHP_EOL; if ($exception instanceof \TYPO3\Flow\Exception) { echo 'Reference code: ' . $exception->getReferenceCode() . PHP_EOL; } $indent .= ' '; } if (function_exists('xdebug_get_function_stack')) { $backtraceSteps = xdebug_get_function_stack(); } else { $backtraceSteps = debug_backtrace(); } for ($index = 0; $index < count($backtraceSteps); $index++) { echo PHP_EOL . '#' . $index . ' '; if (isset($backtraceSteps[$index]['class'])) { echo $backtraceSteps[$index]['class']; } if (isset($backtraceSteps[$index]['function'])) { echo '::' . $backtraceSteps[$index]['function'] . '()'; } echo PHP_EOL; if (isset($backtraceSteps[$index]['file'])) { echo ' ' . $backtraceSteps[$index]['file'] . (isset($backtraceSteps[$index]['line']) ? ':' . $backtraceSteps[$index]['line'] : '') . PHP_EOL; } } echo PHP_EOL; exit(1); }
/** @internal */ public static function fixStack($exception) { if (function_exists('xdebug_get_function_stack')) { $stack = array(); foreach (array_slice(array_reverse(xdebug_get_function_stack()), 2, -1) as $row) { $frame = array('file' => $row['file'], 'line' => $row['line'], 'function' => isset($row['function']) ? $row['function'] : '*unknown*', 'args' => array()); if (!empty($row['class'])) { $frame['type'] = isset($row['type']) && $row['type'] === 'dynamic' ? '->' : '::'; $frame['class'] = $row['class']; } $stack[] = $frame; } $ref = new \ReflectionProperty('Exception', 'trace'); $ref->setAccessible(TRUE); $ref->setValue($exception, $stack); } return $exception; }
protected function storeCallerInfo() { if (!function_exists('xdebug_get_function_stack')) { return; } ini_set('xdebug.collect_params', '1'); $stack = xdebug_get_function_stack(); ini_set('xdebug.collect_params', 0); if (count($stack) <= self::STACK_POSITION) { return; } $traceLine = $stack[count($stack) - self::STACK_POSITION]; if (!isset($traceLine['file'])) { return; } $this->file = $traceLine['file']; $this->line = $traceLine['line']; $this->addMetaStep($traceLine, $stack); }
/** * Dump stack trace, only working when XDebug is present. * * @param string $message The message to be logged * @param int $loglevel The log level * @link http://www.xdebug.org/ xdebug.org */ function print_function_stack($message, $loglevel = MIDCOM_LOG_DEBUG) { if (!$this->_enabled || $this->_loglevel < $loglevel) { return; } if (function_exists('xdebug_get_function_stack')) { $stack = array_reverse(xdebug_get_function_stack()); } else { $stack = debug_backtrace(false); } //the last two levels are already inside the debugging system, so skip those array_shift($stack); array_shift($stack); $stacktrace = ""; foreach ($stack as $number => $frame) { $stacktrace .= $number + 1; if (isset($frame['file'])) { $stacktrace .= ": {$frame['file']}:{$frame['line']} "; } if (array_key_exists('class', $frame)) { $stacktrace .= "{$frame['class']}::{$frame['function']}"; } else { if (array_key_exists('function', $frame)) { $stacktrace .= $frame['function']; } else { $stacktrace .= 'require, include or eval'; } } $stacktrace .= "\n"; } unset($stack); $this->log(trim($message) . "\n{$stacktrace}", $loglevel); }
public static function error(Exception $e, $sql, $params = array(), $shardID = 0) { $paramsArray = Z_Array::array2string($params); $error = $e->getMessage(); $errno = $e->getCode(); $str = "{$error}\n\n" . "Shard: {$shardID}\n\n" . "Query:\n{$sql}\n\n" . "Params:\n{$paramsArray}\n\n"; if (function_exists('xdebug_get_function_stack')) { $str .= Z_Array::array2string(xdebug_get_function_stack()); } if (strpos($error, "Can't connect to MySQL server") !== false) { throw new Exception($str, Z_ERROR_SHARD_UNAVAILABLE); } throw new Exception($str, $errno); }
function _setTightness($top, $bot) { if (count($this->_content) == 1) { $li =& $this->_content[0]; $li->setTightness($top, $bot); } else { // This is where php5 usually brakes. // wrong duplicated <li> contents if (DEBUG and DEBUG & _DEBUG_PARSER and check_php_version(5)) { if (count($this->_content) != 2) { echo "<pre>"; /* $class = new Reflection_Class('XmlElement'); // Print out basic information printf( "===> The %s%s%s %s '%s' [extends %s]\n". " declared in %s\n". " lines %d to %d\n". " having the modifiers %d [%s]\n", $class->isInternal() ? 'internal' : 'user-defined', $class->isAbstract() ? ' abstract' : '', $class->isFinal() ? ' final' : '', $class->isInterface() ? 'interface' : 'class', $class->getName(), var_export($class->getParentClass(), 1), $class->getFileName(), $class->getStartLine(), $class->getEndline(), $class->getModifiers(), implode(' ', Reflection::getModifierNames($class->getModifiers())) ); // Print class properties printf("---> Properties: %s\n", var_export($class->getProperties(), 1)); */ echo 'count($this->_content): ', count($this->_content), "\n"; echo "\$this->_content[0]: "; var_dump($this->_content[0]); for ($i = 1; $i < min(5, count($this->_content)); $i++) { $c =& $this->_content[$i]; echo '$this->_content[', $i, "]: \n"; echo "_tag: "; var_dump($c->_tag); echo "_content: "; var_dump($c->_content); echo "_properties: "; var_dump($c->_properties); } debug_print_backtrace(); if (DEBUG & _DEBUG_APD) { if (function_exists("xdebug_get_function_stack")) { var_dump(xdebug_get_function_stack()); } } echo "</pre>"; } } if (!check_php_version(5)) { assert(count($this->_content) == 2); } $dt =& $this->_content[0]; $dd =& $this->_content[1]; $dt->setTightness($top, false); $dd->setTightness(false, $bot); } }
/** * Returns the xdebug stack. * * @return array The xdebug stack as an array * * @deprecated Use {@link getDebugBacktrace()} instead. Will be removed in symfony 1.4. */ protected function getXDebugStack() { // if we have xdebug and dev has not disabled the feature, add some stack information if (!$this->xdebugLogging || !function_exists('xdebug_get_function_stack')) { return array(); } $debugStack = array(); foreach (xdebug_get_function_stack() as $i => $stack) { if ( (isset($stack['function']) && !in_array($stack['function'], array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug', 'log'))) || !isset($stack['function']) ) { $tmp = ''; if (isset($stack['function'])) { $tmp .= sprintf('in "%s" ', $stack['function']); } $tmp .= sprintf('from "%s" line %s', $stack['file'], $stack['line']); $debugStack[] = $tmp; } } return $debugStack; }
/** * Logs a message. * * @param string $message Message * @param string $priority Message priority */ protected function doLog($message, $priority) { // if we have xdebug and dev has not disabled the feature, add some stack information $debugStack = array(); if ($this->xdebugLogging && function_exists('xdebug_get_function_stack')) { foreach (xdebug_get_function_stack() as $i => $stack) { if (isset($stack['function']) && !in_array($stack['function'], array('emerg', 'alert', 'crit', 'err', 'warning', 'notice', 'info', 'debug', 'log')) || !isset($stack['function'])) { $tmp = ''; if (isset($stack['function'])) { $tmp .= sprintf('in "%s" ', $stack['function']); } $tmp .= sprintf('from "%s" line %s', $stack['file'], $stack['line']); $debugStack[] = $tmp; } } } // get log type in {} $type = 'sfOther'; if (preg_match('/^\\s*{([^}]+)}\\s*(.+?)$/', $message, $matches)) { $type = $matches[1]; $message = $matches[2]; } // send the log object containing the complete log information $this->webDebug->log(array('priority' => $priority, 'time' => time(), 'message' => $message, 'type' => $type, 'debugStack' => $debugStack)); }
public static function showCallStack() { echo 'CallStack - File: ' . xdebug_call_file(); echo '<br />Class: ' . xdebug_call_class(); echo '<br />Function: ' . xdebug_call_function(); echo '<br />Line: ' . xdebug_call_line(); echo '<br />Depth of Stacks: ' . xdebug_get_stack_depth(); echo '<br />Content of Stack: ' . xdebug_var_dump(xdebug_get_function_stack()); }
/** * Gets the backgrace from an exception. * * If xdebug is installed * * @param Exception $e * @return array */ protected function getTrace(\Exception $e) { $traces = $e->getTrace(); // Get trace from xdebug if enabled, failure exceptions only trace to the shutdown handler by default if (!$e instanceof \ErrorException) { return $traces; } if (!Misc::isLevelFatal($e->getSeverity())) { return $traces; } if (!extension_loaded('xdebug') || !xdebug_is_enabled()) { return array(); } // Use xdebug to get the full stack trace and remove the shutdown handler stack trace $stack = array_reverse(xdebug_get_function_stack()); $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); $traces = array_diff_key($stack, $trace); return $traces; }
private function getDeeperStackTrace($foo, $bar) { return xdebug_get_function_stack(); }
/** * Output some text about where a redirect attempt was made to for debugging purposes * * @param string $redirect_to The URL that will be redirected to * @return string|null If debug is off then the original URL will be returned, otherwise this function will exit() */ public function debug_wp_redirect($redirect_to) { if ($this->debug) { echo "<p>Redirect: <a href='{$redirect_to}'>{$redirect_to}</a></p>"; var_dump(xdebug_get_function_stack()); exit; } }
public function getTrace($start = 1, $trace = null) { 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 = []; $j = 0; for ($i = (int) $start; isset($trace[$i]); ++$i, ++$j) { $params = ""; if (isset($trace[$i]["args"]) or isset($trace[$i]["params"])) { if (isset($trace[$i]["args"])) { $args = $trace[$i]["args"]; } else { $args = $trace[$i]["params"]; } foreach ($args as $name => $value) { $params .= (is_object($value) ? get_class($value) . " " . (method_exists($value, "__toString") ? $value->__toString() : "object") : gettype($value) . " " . @strval($value)) . ", "; } } $messages[] = "#{$j} " . (isset($trace[$i]["file"]) ? $this->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"] . "(" . substr($params, 0, -2) . ")"; } return $messages; }
/** * @param Erfurt_Sparql_SimpleQuery $queryObject * @param array $options keys: Erfurt_Store::USE_CACHE, Erfurt_Store::RESULTFORMAT, Erfurt_Store::USE_AC * * @throws Erfurt_Exception Throws an exception if query is no string. * * @return mixed Returns a result depending on the query, e.g. an array or a boolean value. */ public function sparqlQuery($queryObject, $options = array()) { $logger = $this->_getQueryLogger(); $type = gettype($queryObject); $typeStr = 'type: ' . $type . ($type == 'object' ? ', class: ' . get_class($queryObject) : ''); $logger->debug('query in (' . $typeStr . '): ' . (string) $queryObject); $queryString = $this->_prepareQuery($queryObject, $options); //dont use the query object afterwards anymore - only the string //querying SparqlEngine or retrieving Result from QueryCache $resultFormat = $options[Erfurt_Store::RESULTFORMAT]; $queryCache = Erfurt_App::getInstance()->getQueryCache(); $logger->debug('query after rewriting: ' . $queryString); if (!isset($options[Erfurt_Store::USE_CACHE]) || $options[Erfurt_Store::USE_CACHE]) { $sparqlResult = $queryCache->load($queryString, $resultFormat); } else { $sparqlResult = Erfurt_Cache_Frontend_QueryCache::ERFURT_CACHE_NO_HIT; } if ($sparqlResult == Erfurt_Cache_Frontend_QueryCache::ERFURT_CACHE_NO_HIT) { $logger->debug('uncached'); // TODO: check if adapter supports requested result format $startTime = microtime(true); $sparqlResult = $this->_backendAdapter->sparqlQuery($queryString, $options); //check for the correct format if ($resultFormat == Erfurt_Store::RESULTFORMAT_EXTENDED && !isset($sparqlResult['results']['bindings'])) { if (isset($sparqlResult['bindings'])) { //fix it if possible $sparqlResult['results'] = array(); $sparqlResult['results']['bindings'] = $sparqlResult['bindings']; } else { if (count($sparqlResult) === 0) { // empty result $sparqlResult['results'] = array(); $sparqlResult['results']['bindings'] = array(); } else { //var_dump($queryString);exit; //exit; throw new Erfurt_Store_Exception('invalid query result.'); } } } self::$_queryCount++; $duration = microtime(true) - $startTime; if (defined('_EFDEBUG')) { $isSlow = true; if ($duration > 1) { $slow = ' WARNING SLOW '; $isSlow = true; } else { $slow = ''; } if ($isSlow) { $additionalInfo = ''; if (function_exists('xdebug_get_function_stack')) { $stack = xdebug_get_function_stack(); foreach ($stack as $i => $info) { $class = ''; if (isset($info['class'])) { $class = $info['class']; } $function = 'UNKNOWN_FUNCTION'; if (isset($info['function'])) { $function = $info['function']; } $additionalInfo .= $class . '@' . $function . ':' . $info['line'] . PHP_EOL; } } $q = $queryString; $q = str_replace(PHP_EOL, ' ', $q); $logger->debug('SPARQL *****************' . round(1000 * $duration, 2) . ' msec ' . $slow . PHP_EOL . $q . PHP_EOL . $additionalInfo); } } else { $logger->debug('cached'); } $queryCache->save($queryString, $resultFormat, $sparqlResult, $duration); } return $sparqlResult; }
/** * @param TikiDb $db * @param $query * @param $values * @param $result */ function handle(TikiDb $db, $query, $values, $result) { global $smarty, $prefs; $msg = $db->getErrorMessage(); $q = $query; if (is_array($values)) { foreach ($values as $v) { if (is_null($v)) { $v = 'NULL'; } else { $v = "'" . addslashes($v) . "'"; } $pos = strpos($q, '?'); if ($pos !== false) { $q = substr($q, 0, $pos) . "{$v}" . substr($q, $pos + 1); } } } if (function_exists('xdebug_get_function_stack')) { /** * @param $stack * @return string */ function mydumpstack($stack) { $o = ''; foreach ($stack as $line) { $o .= '* ' . $line['file'] . " : " . $line['line'] . " -> " . $line['function'] . "(" . var_export($line['params'], true) . ")<br />"; } return $o; } $stacktrace = mydumpstack(xdebug_get_function_stack()); } else { $stacktrace = false; } require_once 'installer/installlib.php'; $installer = new Installer(); require_once 'tiki-setup.php'; $smarty->assign('msg', $msg); $smarty->assign('base_query', $query); $smarty->assign('values', $values); $smarty->assign('built_query', $q); $smarty->assign('stacktrace', $stacktrace); $smarty->assign('requires_update', $installer->requiresUpdate()); header("Cache-Control: no-cache, pre-check=0, post-check=0"); $smarty->display('database-connection-error.tpl'); $this->log($msg . ' - ' . $q); die; }
function WikiDB_Page(&$wikidb, $pagename) { $this->_wikidb =& $wikidb; $this->_pagename = $pagename; if (DEBUG) { if (!(is_string($pagename) and $pagename != '')) { if (function_exists("xdebug_get_function_stack")) { echo "xdebug_get_function_stack(): "; var_dump(xdebug_get_function_stack()); } elseif (function_exists("debug_backtrace")) { // >= 4.3.0 printSimpleTrace(debug_backtrace()); } trigger_error("empty pagename", E_USER_WARNING); return false; } } else { assert(is_string($pagename) and $pagename != ''); } }
/** * Get a Response object representing the exception * * @uses Kohana_Exception::text * @param Exception $e * @return Response */ public static function response(Exception $e) { try { // Get the exception information $class = get_class($e); $code = $e->getCode(); $message = $e->getMessage(); $file = $e->getFile(); $line = $e->getLine(); $trace = $e->getTrace(); /** * HTTP_Exceptions are constructed in the HTTP_Exception::factory() * method. We need to remove that entry from the trace and overwrite * the variables from above. */ if ($e instanceof HTTP_Exception and $trace[0]['function'] == 'factory') { extract(array_shift($trace)); } if ($e instanceof ErrorException) { /** * If XDebug is installed, and this is a fatal error, * use XDebug to generate the stack trace */ if (function_exists('xdebug_get_function_stack') and $code == E_ERROR) { $trace = array_slice(array_reverse(xdebug_get_function_stack()), 4); foreach ($trace as &$frame) { /** * XDebug pre 2.1.1 doesn't currently set the call type key * http://bugs.xdebug.org/view.php?id=695 */ if (!isset($frame['type'])) { $frame['type'] = '??'; } // XDebug also has a different name for the parameters array if (isset($frame['params']) and !isset($frame['args'])) { $frame['args'] = $frame['params']; } } } if (isset(Kohana_Exception::$php_errors[$code])) { // Use the human-readable error name $code = Kohana_Exception::$php_errors[$code]; } } /** * The stack trace becomes unmanageable inside PHPUnit. * * The error view ends up several GB in size, taking * serveral minutes to render. */ if (defined('PHPUnit_MAIN_METHOD')) { $trace = array_slice($trace, 0, 2); } // Instantiate the error view. $view = View::factory(Kohana_Exception::$error_view, get_defined_vars()); // Prepare the response object. $response = Response::factory(); // Set the response status $response->status($e instanceof HTTP_Exception ? $e->getCode() : 500); // Set the response headers $response->headers('Content-Type', Kohana_Exception::$error_view_content_type . '; charset=' . Kohana::$charset); // Set the response body $response->body($view->render()); } catch (Exception $e) { /** * Things are going badly for us, Lets try to keep things under control by * generating a simpler response object. */ $response = Response::factory(); $response->status(500); $response->headers('Content-Type', 'text/plain'); $response->body(Kohana_Exception::text($e)); } return $response; }
/** * Get a stack trace from either PHP or xdebug if present * @return string */ function error_get_stack_trace() { $t_trace = ''; if (extension_loaded('xdebug')) { #check for xdebug presence $t_stack = xdebug_get_function_stack(); # reverse the array in a separate line of code so the # array_reverse() call doesn't appear in the stack $t_stack = array_reverse($t_stack); array_shift($t_stack); #remove the call to this function from the stack trace foreach ($t_stack as $t_frame) { $t_trace .= (isset($t_frame['file']) ? basename($t_frame['file']) : 'UnknownFile') . ' L' . (isset($t_frame['line']) ? $t_frame['line'] : '?') . ' ' . (isset($t_frame['function']) ? $t_frame['function'] : 'UnknownFunction'); $t_args = array(); if (isset($t_frame['params']) && count($t_frame['params']) > 0) { $t_trace .= ' Params: '; foreach ($t_frame['params'] as $t_value) { $t_args[] = error_build_parameter_string($t_value); } $t_trace .= '(' . implode($t_args, ', ') . ')'; } else { $t_trace .= '()'; } $t_trace .= "\n"; } } else { $t_stack = debug_backtrace(); array_shift($t_stack); #remove the call to this function from the stack trace array_shift($t_stack); #remove the call to the error handler from the stack trace foreach ($t_stack as $t_frame) { $t_trace .= (isset($t_frame['file']) ? basename($t_frame['file']) : 'UnknownFile') . ' L' . (isset($t_frame['line']) ? $t_frame['line'] : '?') . ' ' . (isset($t_frame['function']) ? $t_frame['function'] : 'UnknownFunction'); $t_args = array(); if (isset($t_frame['args'])) { foreach ($t_frame['args'] as $t_value) { $t_args[] = error_build_parameter_string($t_value); } $t_trace .= '(' . implode($t_args, ', ') . ')'; } else { $t_trace .= '()'; } $t_trace .= "\n"; } } return $t_trace; }
/** * Returns a stack trace iterator for the current call. * * Returns a * - {@link ezcDebugXdebugStacktraceIterator} if Xdebug is available * - {@link ezcDebugPhpStacktraceIterator} otherwise * representing a stack trace of the current function environment. * * @return ezcDebugStacktraceIterator */ private function getStackTrace() { if (extension_loaded('xdebug')) { return new ezcDebugXdebugStacktraceIterator(xdebug_get_function_stack(), 2, $this->options); } else { return new ezcDebugPhpStacktraceIterator(debug_backtrace(), 2, $this->options); } }
/** * Get stack calls * * @return array */ private static function getStackCalls() { $i = 1; $result = []; foreach (xdebug_get_function_stack() as $node) { if (isset($node['line']) === true) { $result[] = "{$i}. " . basename($node['file']) . ":" . $node['function'] . "(" . $node['line'] . ")"; } $i++; } return $result; }
function b() { var_dump(xdebug_get_function_stack()); // Displays the function's call flow or stack. }
/** * Returns the xdebug stack. * * @return array|string The xdebug stack as an array or string if unavailable / error */ protected function getXdebugStack() { if (!$this->_xdebugAvailable) { return 'xdebug not installed'; } $debugStack = array(); foreach (xdebug_get_function_stack() as $i => $stack) { if (!isset($stack['function'])) { $stack['function'] = ''; } if (!empty($stack['function'])) { // if the function == queryEnd from above, exit the loop to // skip the last two entries of queryEnd and getXDebugStack if ($stack['function'] == 'queryEnd') { break; } // add the class name too if (isset($stack['class']) && !empty($stack['class'])) { $stack['function'] = $stack['class'] . '::' . $stack['function']; } $stack['function'] = sprintf('in "%s" ', $stack['function']); } $debugStack[] = sprintf('%scalled from %s at line %s', $stack['function'], $stack['file'], $stack['line']); } if (empty($debugStack)) { $debugStack = 'backtrace unavailable'; } return $debugStack; }
function error_print_stack_trace() { if (extension_loaded('xdebug')) { #check for xdebug presence $t_stack = xdebug_get_function_stack(); # reverse the array in a separate line of code so the # array_reverse() call doesn't appear in the stack $t_stack = array_reverse($t_stack); array_shift($t_stack); #remove the call to this function from the stack trace print '<center><table class="width75">'; foreach ($t_stack as $t_frame) { print '<tr ' . helper_alternate_class() . '>'; print '<td>' . string_html_entities($t_frame['file']) . '</td><td>' . $t_frame['line'] . '</td><td>' . (isset($t_frame['function']) ? $t_frame['function'] : '???') . '</td>'; $t_args = array(); if (isset($t_frame['params'])) { foreach ($t_frame['params'] as $t_value) { $t_args[] = error_build_parameter_string($t_value); } } print '<td>( ' . string_html_entities(implode($t_args, ', ')) . ' )</td></tr>'; } print '</table></center>'; } else { $t_stack = debug_backtrace(); array_shift($t_stack); #remove the call to this function from the stack trace array_shift($t_stack); #remove the call to the error handler from the stack trace print '<center><table class="width75">'; print '<tr><th>Filename</th><th>Line</th><th>Function</th><th>Args</th></tr>'; foreach ($t_stack as $t_frame) { print '<tr ' . helper_alternate_class() . '>'; print '<td>' . string_html_entities($t_frame['file']) . '</td><td>' . (isset($t_frame['line']) ? $t_frame['line'] : '-') . '</td><td>' . $t_frame['function'] . '</td>'; $t_args = array(); if (isset($t_frame['args'])) { foreach ($t_frame['args'] as $t_value) { $t_args[] = error_build_parameter_string($t_value); } } print '<td>( ' . string_html_entities(implode($t_args, ', ')) . ' )</td></tr>'; } print '</table></center>'; } }
function helper($arg) { var_dump(xdebug_get_function_stack()); }