Index: trunk/kernel/include/debugger.php =================================================================== diff -u -r1200 -r1222 --- trunk/kernel/include/debugger.php (.../debugger.php) (revision 1200) +++ trunk/kernel/include/debugger.php (.../debugger.php) (revision 1222) @@ -1,818 +1,821 @@ $rq_value) + if(!class_exists('Debugger')) { - if( substr($rq_name,0,6)=='debug_' ) + function dbg_ConstOn($const_name) { - define('DBG_ZEND_PRESENT',1); - break; - } - } - - dbg_safeDefine('DBG_ZEND_PRESENT',0); - - // set default values for debugger constants - $dbg_constMap=Array('DBG_OPTIONS'=>0, - 'DBG_USE_HIGHLIGHT'=>1, - 'DBG_USE_SHUTDOWN_FUNC'=>DBG_ZEND_PRESENT?0:1, - 'DBG_HANDLE_ERRORS'=>DBG_ZEND_PRESENT?0:1, - 'DBG_SHOW_MEMORY_USAGE'=>1, - 'DOC_ROOT'=>$_SERVER['DOCUMENT_ROOT'], - 'WINDOWS_ROOT'=>'w:'); - - foreach($dbg_constMap as $dbg_constName=>$dbg_constValue) - { - dbg_safeDefine($dbg_constName,$dbg_constValue); - } - - if(!defined('WINDOWS_EDITOR')) - { - $dbg_editor = 0; - $dbg_editors[0] = Array('editor' => 'c:\Program Files\UltraEdit\uedit32.exe', 'params' => '%F/%L'); - $dbg_editors[1] = Array('editor' => 'c:\Program Files\Zend\ZendStudio-4.0Beta\bin\ZDE.exe', 'params' => '%F'); - define('WINDOWS_EDITOR',$dbg_editors[$dbg_editor]['editor'].' '.$dbg_editors[$dbg_editor]['params']); - unset($dbg_editors,$dbg_editor); - } - - class Debugger - { - /** - * Debugger data for building report - * - * @var Array - */ - var $Data = Array(); - var $ProfilerData = Array(); - var $RecursionStack = Array(); // prevent recursion when processing debug_backtrace() function results - - var $TraceNextError=false; - - var $Options = 0; - var $OptionsMap = Array('shutdown_func' => 1, 'error_handler' => 2, - 'output_buffer' => 4, 'highlight_output' => 8); - - - var $longErrors=Array(); - - /** - * Amount of memory used by debugger itself - * - * @var Array - * @access private - */ - var $memoryUsage=Array(); - - function Debugger() - { - ini_set('display_errors',dbg_ConstOn('DBG_ZEND_PRESENT')?0:1); - $this->memoryUsage['error_handling']=0; // memory amount used by error handler - $this->appendRequest(); + return defined($const_name)&&constant($const_name); } - function initOptions() + function dbg_safeDefine($const_name,$const_value) { - + if(!defined($const_name)) define($const_name,$const_value); } - function mapLongError($msg) + // Detect fact, that this session beeing debugged by Zend Studio + foreach($_REQUEST as $rq_name=>$rq_value) { - $key=$this->generateID(); - $this->longErrors[$key]=$msg; - return $key; - } - - function setOption($name,$value) - { - if( !isset($this->OptionsMap[$name]) ) die('undefined debugger option: ['.$name.']
'); - if($value) + if( substr($rq_name,0,6)=='debug_' ) { - $this->Options|=$this->OptionsMap[$name]; - } - else - { - $this->Options=$this->Options&~$this->OptionsMap[$name]; - } + define('DBG_ZEND_PRESENT',1); + break; + } } - function getOption($name) + dbg_safeDefine('DBG_ZEND_PRESENT',0); + + // set default values for debugger constants + $dbg_constMap=Array('DBG_OPTIONS'=>0, + 'DBG_USE_HIGHLIGHT'=>1, + 'DBG_USE_SHUTDOWN_FUNC'=>DBG_ZEND_PRESENT?0:1, + 'DBG_HANDLE_ERRORS'=>DBG_ZEND_PRESENT?0:1, + 'DBG_SHOW_MEMORY_USAGE'=>1, + 'DOC_ROOT'=>$_SERVER['DOCUMENT_ROOT'], + 'WINDOWS_ROOT'=>'w:'); + + foreach($dbg_constMap as $dbg_constName=>$dbg_constValue) { - if( !isset($this->OptionsMap[$name]) ) die('undefined debugger option: ['.$name.']
'); - return ($this->Options & $this->OptionsMap[$name]) == $this->OptionsMap[$name]; + dbg_safeDefine($dbg_constName,$dbg_constValue); } - /** - * Set's flag, that next error that occurs will - * be prepended by backtrace results - * - */ - function traceNext() + // only for IE, in case if no windows php script editor defined + if(!defined('WINDOWS_EDITOR')) { - $this->TraceNextError=true; + $dbg_editor = 0; + $dbg_editors[0] = Array('editor' => 'c:\Program Files\UltraEdit\uedit32.exe', 'params' => '%F/%L'); + $dbg_editors[1] = Array('editor' => 'c:\Program Files\Zend\ZendStudio-4.0Beta\bin\ZDE.exe', 'params' => '%F'); + define('WINDOWS_EDITOR',$dbg_editors[$dbg_editor]['editor'].' '.$dbg_editors[$dbg_editor]['params']); + unset($dbg_editors,$dbg_editor); } - - function dumpVars() + + class Debugger { - $dumpVars = func_get_args(); - foreach($dumpVars as $varValue) + /** + * Debugger data for building report + * + * @var Array + */ + var $Data = Array(); + var $ProfilerData = Array(); + var $RecursionStack = Array(); // prevent recursion when processing debug_backtrace() function results + + var $TraceNextError=false; + + var $Options = 0; + var $OptionsMap = Array('shutdown_func' => 1, 'error_handler' => 2, + 'output_buffer' => 4, 'highlight_output' => 8); + + + var $longErrors=Array(); + + /** + * Amount of memory used by debugger itself + * + * @var Array + * @access private + */ + var $memoryUsage=Array(); + + function Debugger() { - $this->Data[] = Array('value' => $varValue, 'debug_type' => 'var_dump'); + ini_set('display_errors',dbg_ConstOn('DBG_ZEND_PRESENT')?0:1); + $this->memoryUsage['error_handling']=0; // memory amount used by error handler + $this->appendRequest(); } - } - - function prepareHTML($dataIndex) - { - $Data =& $this->Data[$dataIndex]; - if($Data['debug_type'] == 'html') return $Data['html']; - switch($Data['debug_type']) + function initOptions() { - case 'error': - $fileLink = $this->getFileLink($Data['file'],$Data['line']); - $ret = ''.$this->getErrorNameByCode($Data['no']).': '.$Data['str']; - $ret .= ' in '.$fileLink.' on line '.$Data['line'].''; - return $ret; - break; - case 'var_dump': - $ret = $this->highlightString( print_r($Data['value'], true) ); - return addslashes($ret); - break; + } + + function mapLongError($msg) + { + $key=$this->generateID(); + $this->longErrors[$key]=$msg; + return $key; + } + + function setOption($name,$value) + { + if( !isset($this->OptionsMap[$name]) ) die('undefined debugger option: ['.$name.']
'); + if($value) + { + $this->Options|=$this->OptionsMap[$name]; + } + else + { + $this->Options=$this->Options&~$this->OptionsMap[$name]; + } + } + + function getOption($name) + { + if( !isset($this->OptionsMap[$name]) ) die('undefined debugger option: ['.$name.']
'); + return ($this->Options & $this->OptionsMap[$name]) == $this->OptionsMap[$name]; + } + + /** + * Set's flag, that next error that occurs will + * be prepended by backtrace results + * + */ + function traceNext() + { + $this->TraceNextError=true; + } + + function dumpVars() + { + $dumpVars = func_get_args(); + foreach($dumpVars as $varValue) + { + $this->Data[] = Array('value' => $varValue, 'debug_type' => 'var_dump'); + } + } + + function prepareHTML($dataIndex) + { + $Data =& $this->Data[$dataIndex]; + if($Data['debug_type'] == 'html') return $Data['html']; + + switch($Data['debug_type']) + { + case 'error': + $fileLink = $this->getFileLink($Data['file'],$Data['line']); + $ret = ''.$this->getErrorNameByCode($Data['no']).': '.$Data['str']; + $ret .= ' in '.$fileLink.' on line '.$Data['line'].''; + return $ret; + break; - case 'trace': - ini_set('memory_limit','500M'); - $trace =& $Data['trace']; + case 'var_dump': + $ret = $this->highlightString( print_r($Data['value'], true) ); + return addslashes($ret); + break; + + case 'trace': + ini_set('memory_limit','500M'); + $trace =& $Data['trace']; + + //return 'sorry'; + //return $this->highlightString(print_r($trace,true)); + + + $i = 0; $traceCount = count($trace); + $ret = ''; + while($i < $traceCount) + { + $traceRec =& $trace[$i]; + $argsID = 'trace_args_'.$dataIndex.'_'.$i; + if(isset($traceRec['file'])) + { + $func_name=isset($traceRec['class'])?$traceRec['class'].$traceRec['type'].$traceRec['function']:$traceRec['function']; + $ret .= 'Function: '.$this->getFileLink($traceRec['file'],$traceRec['line'],$func_name); + $ret .= ' in '.basename($traceRec['file']).' on line '.$traceRec['line'].'
'; + } + else + { + $ret .= 'no file information available'; + } + + // ensure parameter value is not longer then 200 symbols + $this->processTraceArguments($traceRec['args']); + $args = $this->highlightString(print_r($traceRec['args'], true)); + $ret .= ''; + $i++; + } + return $ret; + break; - //return 'sorry'; - //return $this->highlightString(print_r($trace,true)); - - - $i = 0; $traceCount = count($trace); - $ret = ''; - while($i < $traceCount) + case 'profiler': + $profileKey = $Data['profile_key']; + $Data =& $this->ProfilerData[$profileKey]; + $runtime = ($Data['ends'] - $Data['begins']); // in seconds + return 'Name: '.$Data['description'].'
Runtime: '.$runtime.'s'; + break; + + default: + return 'incorrect debug data'; + break; + } + } + + function processTraceArguments(&$traceArgs) + { + if(!$traceArgs) return ''; + foreach ($traceArgs as $argID => $argValue) + { + if( is_array($argValue) || is_object($argValue) ) { - $traceRec =& $trace[$i]; - $argsID = 'trace_args_'.$dataIndex.'_'.$i; - if(isset($traceRec['file'])) + if(is_object($argValue) && !in_array(get_class($argValue),$this->RecursionStack) ) + { + // object & not in stack - ok + array_push($this->RecursionStack, get_class($argValue)); + settype($argValue,'array'); + $this->processTraceArguments($argValue); + array_pop($this->RecursionStack); + } + elseif(is_object($argValue) && in_array(get_class($argValue),$this->RecursionStack) ) { - $func_name=isset($traceRec['class'])?$traceRec['class'].$traceRec['type'].$traceRec['function']:$traceRec['function']; - $ret .= 'Function: '.$this->getFileLink($traceRec['file'],$traceRec['line'],$func_name); - $ret .= ' in '.basename($traceRec['file']).' on line '.$traceRec['line'].'
'; + // object & in stack - recursion + $traceArgs[$argID] = '**** RECURSION ***'; } - else + else { - $ret .= 'no file information available'; + // normal array here + $this->processTraceArguments($argValue); } - - // ensure parameter value is not longer then 200 symbols - $this->processTraceArguments($traceRec['args']); - $args = $this->highlightString(print_r($traceRec['args'], true)); - $ret .= ''; - $i++; } - return $ret; - break; - - case 'profiler': - $profileKey = $Data['profile_key']; - $Data =& $this->ProfilerData[$profileKey]; - $runtime = ($Data['ends'] - $Data['begins']); // in seconds - return 'Name: '.$Data['description'].'
Runtime: '.$runtime.'s'; - break; - - default: - return 'incorrect debug data'; - break; - } - } - - function processTraceArguments(&$traceArgs) - { - if(!$traceArgs) return ''; - foreach ($traceArgs as $argID => $argValue) - { - if( is_array($argValue) || is_object($argValue) ) - { - if(is_object($argValue) && !in_array(get_class($argValue),$this->RecursionStack) ) - { - // object & not in stack - ok - array_push($this->RecursionStack, get_class($argValue)); - settype($argValue,'array'); - $this->processTraceArguments($argValue); - array_pop($this->RecursionStack); - } - elseif(is_object($argValue) && in_array(get_class($argValue),$this->RecursionStack) ) - { - // object & in stack - recursion - $traceArgs[$argID] = '**** RECURSION ***'; - } else { - // normal array here - $this->processTraceArguments($argValue); + $traceArgs[$argID] = $this->cutStringForHTML($traceArgs[$argID]); } } + } + + function cutStringForHTML($string) + { + if( strlen($string) > 200 ) $string = substr($string,0,50).' ...'; + return $string; + } + + /** + * Format SQL Query using predefined formatting + * and highlighting techniques + * + * @param string $sql + * @return string + */ + function formatSQL($sql) + { + $sql = preg_replace('/(\n|\t| )+/is',' ',$sql); + $sql = preg_replace('/(CREATE TABLE|DROP TABLE|SELECT|UPDATE|SET|REPLACE|INSERT|DELETE|VALUES|FROM|LEFT JOIN|INNER JOIN|LIMIT|WHERE|HAVING|GROUP BY|ORDER BY) /is', "\n\t$1 ",$sql); + return $this->highlightString($sql); + } + + function highlightString($string) + { + if( defined('DBG_USE_HIGHLIGHT')&&DBG_USE_HIGHLIGHT ) + { + $string = highlight_string('', true); + return preg_replace('/<\?(.*)php (.*)\?>/s','$2',$string); + } else { - $traceArgs[$argID] = $this->cutStringForHTML($traceArgs[$argID]); + return $string; } } - } - - function cutStringForHTML($string) - { - if( strlen($string) > 200 ) $string = substr($string,0,50).' ...'; - return $string; - } - - /** - * Format SQL Query using predefined formatting - * and highlighting techniques - * - * @param string $sql - * @return string - */ - function formatSQL($sql) - { - $sql = preg_replace('/(\n|\t| )+/is',' ',$sql); - $sql = preg_replace('/(CREATE TABLE|DROP TABLE|SELECT|UPDATE|SET|REPLACE|INSERT|DELETE|VALUES|FROM|LEFT JOIN|INNER JOIN|LIMIT|WHERE|HAVING|GROUP BY|ORDER BY) /is', "\n\t$1 ",$sql); - return $this->highlightString($sql); - } - - function highlightString($string) - { - if( defined('DBG_USE_HIGHLIGHT')&&DBG_USE_HIGHLIGHT ) + + function getFileLink($file, $lineno = 1, $title = '') { - $string = highlight_string('', true); - return preg_replace('/<\?(.*)php (.*)\?>/s','$2',$string); + if(!$title) $title = $file; + $is_mozilla=strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'firefox')!==false?true:false; + if($is_mozilla) + { + return ''.$title.''; + } + else + { + return ''.$title.''; + } + } - else + + function getLocalFile($remoteFile) { - return $string; + return str_replace(DOC_ROOT, WINDOWS_ROOT, $remoteFile); } - } - - function getFileLink($file, $lineno = 1, $title = '') - { - if(!$title) $title = $file; - $is_mozilla=strpos(strtolower($_SERVER['HTTP_USER_AGENT']),'firefox')!==false?true:false; - if($is_mozilla) + + function appendTrace() { - return ''.$title.''; + $trace = debug_backtrace(); + array_shift($trace); + $this->Data[] = Array('trace' => $trace, 'debug_type' => 'trace'); } - else + + function appendHTML($html) { - return ''.$title.''; + $this->Data[] = Array('html' => $html,'debug_type' => 'html'); } - } - - function getLocalFile($remoteFile) - { - return str_replace(DOC_ROOT, WINDOWS_ROOT, $remoteFile); - } - - function appendTrace() - { - $trace = debug_backtrace(); - array_shift($trace); - $this->Data[] = Array('trace' => $trace, 'debug_type' => 'trace'); - } - - function appendHTML($html) - { - $this->Data[] = Array('html' => $html,'debug_type' => 'html'); - } - - /** - * Change debugger info that was already generated before. - * Returns true if html was set. - * - * @param int $index - * @param string $html - * @param string $type = {'append','prepend','replace'} - * @return bool - */ - function setHTMLByIndex($index,$html,$type='append') - { - if( !isset($this->Data[$index]) || $this->Data[$index]['debug_type'] != 'html' ) + /** + * Change debugger info that was already generated before. + * Returns true if html was set. + * + * @param int $index + * @param string $html + * @param string $type = {'append','prepend','replace'} + * @return bool + */ + function setHTMLByIndex($index,$html,$type='append') { - return false; + if( !isset($this->Data[$index]) || $this->Data[$index]['debug_type'] != 'html' ) + { + return false; + } + + switch ($type) + { + case 'append': + $this->Data[$index]['html'] .= '
'.$html; + break; + case 'prepend': + $this->Data[$index]['html'] = $this->Data[$index]['html'].'
'.$html; + break; + case 'replace': + $this->Data[$index]['html'] = $html; + break; + } + return true; } - switch ($type) + /** + * Move $debugLineCount lines of input from debug output + * end to beginning. + * + * @param int $debugLineCount + */ + function moveToBegin($debugLineCount) { - case 'append': - $this->Data[$index]['html'] .= '
'.$html; - break; - case 'prepend': - $this->Data[$index]['html'] = $this->Data[$index]['html'].'
'.$html; - break; - case 'replace': - $this->Data[$index]['html'] = $html; - break; + $lines = array_splice($this->Data,count($this->Data)-$debugLineCount,$debugLineCount); + $this->Data = array_merge($lines,$this->Data); } - return true; - } - - /** - * Move $debugLineCount lines of input from debug output - * end to beginning. - * - * @param int $debugLineCount - */ - function moveToBegin($debugLineCount) - { - $lines = array_splice($this->Data,count($this->Data)-$debugLineCount,$debugLineCount); - $this->Data = array_merge($lines,$this->Data); - } - - function appendRequest() - { - $script = $_SERVER['PATH_TRANSLATED']; - $this->appendHTML('ScriptName: '.$this->getFileLink($script,1,basename($script)).' ('.dirname($script).')'); - ob_start(); - ?> - - - - - $value) - { - if( !is_array($value) && trim($value) == '' ) + + function appendRequest() + { + $script = $_SERVER['PATH_TRANSLATED']; + $this->appendHTML('ScriptName: '.$this->getFileLink($script,1,basename($script)).' ('.dirname($script).')'); + ob_start(); + ?> +
SrcNameValue
+ + + + $value) { - $value = 'no value'; + if( !is_array($value) && trim($value) == '' ) + { + $value = 'no value'; + } + else + { + $value = htmlspecialchars(print_r($value, true)); + } + $src = isset($_GET[$key]) ? 'GE' : (isset($_POST[$key]) ? 'PO' : (isset($_COOKIE[$key]) ? 'CO' : '?') ); + echo ''; } - else - { - $value = htmlspecialchars(print_r($value, true)); - } - $src = isset($_GET[$key]) ? 'GE' : (isset($_POST[$key]) ? 'PO' : (isset($_COOKIE[$key]) ? 'CO' : '?') ); - echo ''; - } - ?> -
SrcNameValue
'.$src.''.$key.''.$value.'
'.$src.''.$key.''.$value.'
- appendHTML( ob_get_contents() ); - ob_end_clean(); - } - - function appendSession() - { - if( isset($_SESSION)&&$_SESSION ) + ?> + + appendHTML( ob_get_contents() ); + ob_end_clean(); + } + + function appendSession() { - $this->appendHTML('PHP Session: ['.ini_get('session.name').']'); - $this->dumpVars($_SESSION); - $this->moveToBegin(2); - } - } - - function profileStart($key, $description) - { - $timeStamp = $this->getMoment(); - $this->ProfilerData[$key] = Array('begins' => $timeStamp, 'ends' => 5000, 'debuggerRowID' => count($this->Data), 'description' => $description); - $this->Data[] = array('profile_key' => $key, 'debug_type' => 'profiler'); - } - - function profileFinish($key) - { - $this->ProfilerData[$key]['ends'] = $this->getMoment(); - } - - function getMoment() - { - list($usec, $sec) = explode(' ', microtime()); - return ((float)$usec + (float)$sec); - } - - function generateID() - { - list($usec, $sec) = explode(" ",microtime()); - - $id_part_1 = substr($usec, 4, 4); - $id_part_2 = mt_rand(1,9); - $id_part_3 = substr($sec, 6, 4); - $digit_one = substr($id_part_1, 0, 1); - if ($digit_one == 0) { - $digit_one = mt_rand(1,9); - $id_part_1 = ereg_replace("^0","",$id_part_1); - $id_part_1=$digit_one.$id_part_1; + if( isset($_SESSION)&&$_SESSION ) + { + $this->appendHTML('PHP Session: ['.ini_get('session.name').']'); + $this->dumpVars($_SESSION); + $this->moveToBegin(2); + } } - return $id_part_1.$id_part_2.$id_part_3; - } - - - function getErrorNameByCode($errorCode) - { - switch($errorCode) + + function profileStart($key, $description) { - case E_USER_ERROR: - return 'Fatal Error'; - break; - - case E_WARNING: - case E_USER_WARNING: - return 'Warning'; - break; - - case E_NOTICE: - case E_USER_NOTICE: - return 'Notice'; - break; - - default: - return ''; - break; + $timeStamp = $this->getMoment(); + $this->ProfilerData[$key] = Array('begins' => $timeStamp, 'ends' => 5000, 'debuggerRowID' => count($this->Data), 'description' => $description); + $this->Data[] = array('profile_key' => $key, 'debug_type' => 'profiler'); } - } - - /** - * Generates report - * - */ - function printReport($returnResult = false) - { - if( dbg_ConstOn('DBG_ZEND_PRESENT') ) return; - dbg_safeDefine('DBG_RAISE_ON_WARNINGS',0); - $this->memoryUsage['debugger_start']=memory_get_usage(); - // show php session if any - $this->appendSession(); + function profileFinish($key) + { + $this->ProfilerData[$key]['ends'] = $this->getMoment(); + } - // ensure, that 1st line of debug output always is this one: - $this->appendHTML('Hide Debugger'); - $this->moveToBegin(1); + function getMoment() + { + list($usec, $sec) = explode(' ', microtime()); + return ((float)$usec + (float)$sec); + } - $i = 0; $lineCount = count($this->Data); - ob_start(); - ?> - - - - memoryUsage['debugger_finish']=memory_get_usage(); - $this->memoryUsage['print_report']=$this->memoryUsage['debugger_finish']-$this->memoryUsage['debugger_start']; - $this->memoryUsage['total']=$this->memoryUsage['print_report']+$this->memoryUsage['error_handling']; - $this->memoryUsage['application']=memory_get_usage()-$this->memoryUsage['total']; - if($returnResult) - { - $ret = ob_get_contents(); - ob_clean(); - if( dbg_ConstOn('DBG_SHOW_MEMORY_USAGE') ) $ret.=$this->getMemoryUsageReport(); - return $ret; + + + document.onkeydown = keyProcessor; + window.onresize = resizeDebugLayer; + window.onscroll = resizeDebugLayer; + window.focus(); + if( typeof($isFatalError) != 'undefined' && $isFatalError == 1 || ) + { + toggleDebugLayer(); + } + if( typeof($isFatalError) != 'undefined' && $isFatalError == 1) + { + document.getElementById('debug_layer').scrollTop = 10000000; + } + + memoryUsage['debugger_finish']=memory_get_usage(); + $this->memoryUsage['print_report']=$this->memoryUsage['debugger_finish']-$this->memoryUsage['debugger_start']; + $this->memoryUsage['total']=$this->memoryUsage['print_report']+$this->memoryUsage['error_handling']; + $this->memoryUsage['application']=memory_get_usage()-$this->memoryUsage['total']; + if($returnResult) + { + $ret = ob_get_contents(); + ob_clean(); + if( dbg_ConstOn('DBG_SHOW_MEMORY_USAGE') ) $ret.=$this->getMemoryUsageReport(); + return $ret; + } + else + { + ob_end_flush(); + if( dbg_ConstOn('DBG_SHOW_MEMORY_USAGE') ) echo $this->getMemoryUsageReport(); + } } - else + + /** + * Format's memory usage report by debugger + * + * @return string + * @access private + */ + function getMemoryUsageReport() { - ob_end_flush(); - if( dbg_ConstOn('DBG_SHOW_MEMORY_USAGE') ) echo $this->getMemoryUsageReport(); + $info=Array('printReport'=>'print_report', + 'saveError'=>'error_handling', + 'Total'=>'total', + 'Application'=>'application'); + $ret=Array(); + foreach($info as $title => $value_key) + { + $ret[]=$title.': '.$this->formatSize($this->memoryUsage[$value_key]).''; + } + return implode('
',$ret); } - } - - /** - * Format's memory usage report by debugger - * - * @return string - * @access private - */ - function getMemoryUsageReport() - { - $info=Array('printReport'=>'print_report', - 'saveError'=>'error_handling', - 'Total'=>'total', - 'Application'=>'application'); - $ret=Array(); - foreach($info as $title => $value_key) - { - $ret[]=$title.': '.$this->formatSize($this->memoryUsage[$value_key]).''; - } - return implode('
',$ret); - } - - - /** - * User-defined error handler - * - * @param int $errno - * @param string $errstr - * @param string $errfile - * @param int $errline - * @param array $errcontext - */ - function saveError($errno, $errstr, $errfile = '', $errline = '', $errcontext = '') - { - $memory_used=Array(); - $memory_used['begin']=memory_get_usage(); - $errorType = $this->getErrorNameByCode($errno); - if(!$errorType) + + /** + * User-defined error handler + * + * @param int $errno + * @param string $errstr + * @param string $errfile + * @param int $errline + * @param array $errcontext + */ + function saveError($errno, $errstr, $errfile = '', $errline = '', $errcontext = '') { - trigger_error('Unknown error type ['.$errno.']', E_USER_ERROR); - return false; + $memory_used=Array(); + $memory_used['begin']=memory_get_usage(); + + $errorType = $this->getErrorNameByCode($errno); + if(!$errorType) + { + trigger_error('Unknown error type ['.$errno.']', E_USER_ERROR); + return false; + } + + $long_id_pos=strrpos($errstr,'#'); + if($long_id_pos!==false) + { + // replace short message with long one (due triger_error limitations on message size) + $long_id=substr($errstr,$long_id_pos+1,strlen($errstr)); + $errstr=$this->longErrors[$long_id]; + unset($this->longErrors[$long_id]); + } + + if( strpos($errfile,'eval()\'d code') !== false ) + { + $errstr = '[EVAL, line '.$errline.']: '.$errstr; + $tmpStr = $errfile; + $pos = strpos($tmpStr,'('); + $errfile = substr($tmpStr,0,$pos); + $pos++; + $errline = substr($tmpStr,$pos,strpos($tmpStr,')',$pos)-$pos); + } + if($this->TraceNextError) + { + $this->appendTrace(); + $this->TraceNextError=false; + } + $this->Data[] = Array('no' => $errno, 'str' => $errstr, 'file' => $errfile, 'line' => $errline, 'context' => $errcontext, 'debug_type' => 'error'); + $memory_used['end']=memory_get_usage(); + $this->memoryUsage['error_handling']+=$memory_used['end']-$memory_used['begin']; + if( substr($errorType,0,5) == 'Fatal') + { + echo ''; + exit; + } } - $long_id_pos=strrpos($errstr,'#'); - if($long_id_pos!==false) + function saveToFile($msg) { - // replace short message with long one (due triger_error limitations on message size) - $long_id=substr($errstr,$long_id_pos+1,strlen($errstr)); - $errstr=$this->longErrors[$long_id]; - unset($this->longErrors[$long_id]); + $fp = fopen($_SERVER['DOCUMENT_ROOT'].'/vb_debug.txt', 'a'); + fwrite($fp,$msg."\n"); + fclose($fp); } - if( strpos($errfile,'eval()\'d code') !== false ) + /** + * Formats file/memory size in nice way + * + * @param int $bytes + * @return string + * @access public + */ + function formatSize($bytes) { - $errstr = '[EVAL, line '.$errline.']: '.$errstr; - $tmpStr = $errfile; - $pos = strpos($tmpStr,'('); - $errfile = substr($tmpStr,0,$pos); - $pos++; - $errline = substr($tmpStr,$pos,strpos($tmpStr,')',$pos)-$pos); + if ($bytes >= 1099511627776) { + $return = round($bytes / 1024 / 1024 / 1024 / 1024, 2); + $suffix = "TB"; + } elseif ($bytes >= 1073741824) { + $return = round($bytes / 1024 / 1024 / 1024, 2); + $suffix = "GB"; + } elseif ($bytes >= 1048576) { + $return = round($bytes / 1024 / 1024, 2); + $suffix = "MB"; + } elseif ($bytes >= 1024) { + $return = round($bytes / 1024, 2); + $suffix = "KB"; + } else { + $return = $bytes; + $suffix = "Byte"; + } + $return .= ' '.$suffix; + return $return; } - if($this->TraceNextError) - { - $this->appendTrace(); - $this->TraceNextError=false; - } - $this->Data[] = Array('no' => $errno, 'str' => $errstr, 'file' => $errfile, 'line' => $errline, 'context' => $errcontext, 'debug_type' => 'error'); - $memory_used['end']=memory_get_usage(); - $this->memoryUsage['error_handling']+=$memory_used['end']-$memory_used['begin']; - if( substr($errorType,0,5) == 'Fatal') - { - echo ''; - exit; - } + } - - function saveToFile($msg) + + if( !function_exists('memory_get_usage') ) { - $fp = fopen($_SERVER['DOCUMENT_ROOT'].'/vb_debug.txt', 'a'); - fwrite($fp,$msg."\n"); - fclose($fp); + function memory_get_usage(){ return -1; } } - /** - * Formats file/memory size in nice way - * - * @param int $bytes - * @return string - * @access public - */ - function formatSize($bytes) - { - if ($bytes >= 1099511627776) { - $return = round($bytes / 1024 / 1024 / 1024 / 1024, 2); - $suffix = "TB"; - } elseif ($bytes >= 1073741824) { - $return = round($bytes / 1024 / 1024 / 1024, 2); - $suffix = "GB"; - } elseif ($bytes >= 1048576) { - $return = round($bytes / 1024 / 1024, 2); - $suffix = "MB"; - } elseif ($bytes >= 1024) { - $return = round($bytes / 1024, 2); - $suffix = "KB"; - } else { - $return = $bytes; - $suffix = "Byte"; - } - $return .= ' '.$suffix; - return $return; - } - + $debugger = new Debugger(); + if(dbg_ConstOn('DBG_HANDLE_ERRORS')) set_error_handler( array(&$debugger,'saveError') ); + if(dbg_ConstOn('DBG_USE_SHUTDOWN_FUNC')) register_shutdown_function( array(&$debugger,'printReport') ); } - - if( !function_exists('memory_get_usage') ) - { - function memory_get_usage(){ return -1; } - } - - function dbg_ConstOn($const_name) - { - return defined($const_name)&&constant($const_name); - } - - function dbg_safeDefine($const_name,$const_value) - { - if(!defined($const_name)) define($const_name,$const_value); - } - - $debugger = new Debugger(); - if(dbg_ConstOn('DBG_HANDLE_ERRORS')) set_error_handler( array(&$debugger,'saveError') ); - if(dbg_ConstOn('DBG_USE_SHUTDOWN_FUNC')) register_shutdown_function( array(&$debugger,'printReport') ); - ?> \ No newline at end of file