diff options
author | Urban Müller | 2023-05-09 14:54:16 +0200 |
---|---|---|
committer | Urban Müller | 2023-05-09 14:55:48 +0200 |
commit | 2733df892be5436599ba56f60c484f0f4fe9401f (patch) | |
tree | 40157d9f063b9a204e97ccf1cd3be67c9350c15a | |
parent | 7ecdc7cc15a19fe35fd45aa4460be3da23dfd4d1 (diff) | |
download | itools-2733df892be5436599ba56f60c484f0f4fe9401f.tar.gz itools-2733df892be5436599ba56f60c484f0f4fe9401f.tar.bz2 itools-2733df892be5436599ba56f60c484f0f4fe9401f.zip |
implement medium stacks
-rw-r--r-- | it_debug.class | 51 |
1 files changed, 45 insertions, 6 deletions
diff --git a/it_debug.class b/it_debug.class index f5122ea..8f2c441 100644 --- a/it_debug.class +++ b/it_debug.class @@ -223,15 +223,54 @@ static function dump($args, $p = []) */ static function backtrace($p = array()) { - foreach (self::debug_backtrace($p) as $call) + $frames = $p['trace'] ?: ($p['format'] ? array_slice(debug_backtrace(0), $p['skiplevels']) : null); + + if ($p['format'] == "long") + { + foreach ($frames as $frame) + if ($tracesize < 100000 && ($tracesize += strlen(print_r($frame, true))) < 100000) # save mem + $frames[] = $frame; + $result = $frames ? print_r($frames, true) . "\n" : null; + } + else if ($p['format'] == "medium") + { + foreach ($frames as $frame) + { + $locations[] = basename($frame['file']) . ":" . $frame['line']; + + $argstrings = []; + foreach ($frame['args'] as $arg) + { + $t = trim(it::replace(['^array \(\s*' => "[", ',\n\)$' => "]", " +" => " ", "\n" => "", var_export($arg, true)]), " ,"); + $argstrings[] = strlen($t) < 80 ? $t : it::replace(["(.{0,60} |.{0,60}).*" => '$1'], $t) . "..." . (is_array($arg) ? "]" : (is_object($arg) ? "}" :"")); + } + + $allargs = join(", ", $argstrings); + if ($frame['type'] == "->" || $frame['type'] == "::") + $funcs[] = $frame['class'] . $frame['type'] . $frame['function'] . "($allargs)"; + else + $funcs[] = $frame['function'] . "($allargs)"; + + $maxlen = max(it::map('strlen', $locations)); + } + + foreach ($locations as $idx => $location) + $result .= substr($location . " ", 0, $maxlen) . " " . $funcs[$idx] . "\n"; + } + else { - $fn = $call['file']; - $fn = (it::match('auto_prepend', $fn) ? basename(dirname(dirname($fn))) . "/" : (it::match('/(cgi|bin)/', $fn) ? basename(dirname($fn)) . "/" : "")) . basename($fn); - if ($fn) - $result[] = $fn . ":" . $call['line']; + foreach (self::debug_backtrace($p) as $call) + { + $fn = $call['file']; + $fn = (it::match('auto_prepend', $fn) ? basename(dirname(dirname($fn))) . "/" : (it::match('/(cgi|bin)/', $fn) ? basename(dirname($fn)) . "/" : "")) . basename($fn); + if ($fn) + $result[] = $fn . ":" . $call['line']; + } + + $result = implode(" ", (array)$result); } - return implode(" ", (array)$result); + return $result; } static function set($debug_string) |