diff options
Diffstat (limited to 'it_debug.class')
-rw-r--r-- | it_debug.class | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/it_debug.class b/it_debug.class index c4bc8db..efbf7cc 100644 --- a/it_debug.class +++ b/it_debug.class @@ -59,16 +59,37 @@ static function echo($args) echo self::dump($args); } +static function debug_backtrace($p = []) { + if (!is_array($p)) + $p = array('skiplevels' => $p); + + $p += array('levels' => 0, 'skiplevels'=> 0, 'skipfiles' => "###"); + + foreach ($p['trace'] ?: debug_backtrace(@constant('DEBUG_BACKTRACE_IGNORE_ARGS')) as $call) + { + if (!$result && it::match('it_debug\.class$', $call['file'])) + continue; + if (!$result && it::match($p['skipfiles'], $call['file'])) + continue; + if (!$result && $p['skiplevels']-- > 0) + continue; + $result[] = $call; + if (--$p['levels'] == 0) + break; + } + return $result; +} + /** * Get source line of grandparent calling this function * @param $stacksoffs go up an extra $stacksoffs levels */ -static function srcline($stackoffs = 0) +static function srcline($p = array()) { - $stack = debug_backtrace(@constant('DEBUG_BACKTRACE_IGNORE_ARGS')); - $line = $stack[1 + $stackoffs]['line']; - $file = $stack[1 + $stackoffs]['file']; + $stack = self::debug_backtrace($p); + $line = $stack[1]['line']; + $file = $stack[1]['file']; if (!isset($GLOBALS['it_debug::dump source'][$file])) $GLOBALS['it_debug::dump source'][$file] = @it::file($file); @@ -104,7 +125,7 @@ static function dump($args, $p = []) { $p += ['html' => !EDC('edplain') && (self::$force_html || $_SERVER['REMOTE_ADDR']), 'color' => true]; $htmlspecialchars = array("&" => "&", '<' => "<", '>' => ">"); - $args = count($args) ? $args : [it_debug::backtrace(['skiplevels' => 2])]; + $args = count($args) ? $args : [it_debug::backtrace(['skiplevels' => 1])]; if ((preg_match('/csv|txt|gif|jpg/', $_SERVER['PHP_SELF']) || preg_grep('#text/(calendar|css|javascript|json|plain|rfc822|xml)|application/#', headers_list()) || $GLOBALS['debug_edplain']) && !$GLOBALS['debug_edhtml']) ; @@ -113,7 +134,7 @@ static function dump($args, $p = []) else if (defined('STDOUT') && posix_isatty(STDOUT) && $p['color']) list($blue, $noblue, $red, $nored, $ansiok) = getenv('IT_ED_BRIGHT') ? array("\033[34m", "\033[m", "\033[33m", "\033[m", 1) : array("\033[34m", "\033[m", "\033[31m", "\033[m", 1); - $src = it_debug::srcline(1); + $src = it_debug::srcline(); list($dummy, $function, $paramlist) = preg_match('#\b(D|ED|EDC|EDX)\s*\((.*)#i', $src, $parts) ? $parts : array(); $paramtokens = token_get_all("<?php $paramlist"); array_shift($paramtokens); @@ -185,7 +206,7 @@ static function dump($args, $p = []) $r = str_repeat(" ", count(debug_backtrace(@constant('DEBUG_BACKTRACE_IGNORE_ARGS')))-3) . $r; # not it_html::Q(); we dont wanna load it_html in ultraclassloader debugging - $title = htmlspecialchars(it_debug::backtrace(array('skiplevels' => 2)), ENT_COMPAT, "ISO-8859-1"); # skip this func as well as ED()/EDX() + $title = htmlspecialchars(it_debug::backtrace(array('skiplevels' => 1)), ENT_COMPAT, "ISO-8859-1"); # skip this func as well as ED()/EDX() if ($p['html']) return "<pre title='$title' style='color:#c00; text-align:left; background:white; border-bottom:1px solid #ddd; z-index:9999; position:relative; line-height:1'>$r</pre>\n"; @@ -202,21 +223,11 @@ static function dump($args, $p = []) */ static function backtrace($p = array()) { - if (!is_array($p)) - $p = array('skiplevels' => $p); - - $p += array('levels' => 0, 'skiplevels'=> 0, 'skipfiles' => "###"); - - foreach ($p['trace'] ?: array_slice(debug_backtrace(@constant('DEBUG_BACKTRACE_IGNORE_ARGS')), $p['skiplevels']) as $call) + foreach (self::debug_backtrace($p) as $call) { - if (($fn = $call['file']) && !it::match($p['skipfiles'], $call['file'])) - { - $fn = (it::match('auto_prepend', $fn) ? basename(dirname(dirname($fn))) . "/" : (it::match('/(cgi|bin)/', $fn) ? basename(dirname($fn)) . "/" : "")) . basename($fn); - $result[] = $fn . ":" . $call['line']; - - if (--$p['levels'] == 0) - break; - } + $fn = $call['file']; + $fn = (it::match('auto_prepend', $fn) ? basename(dirname(dirname($fn))) . "/" : (it::match('/(cgi|bin)/', $fn) ? basename(dirname($fn)) . "/" : "")) . basename($fn); + $result[] = $fn . ":" . $call['line']; } return implode(" ", (array)$result); |