From db09e31e6f0b665e3638f37ca0c5b0890dfcc5a9 Mon Sep 17 00:00:00 2001 From: Andreas Gohr Date: Mon, 5 Mar 2007 23:34:58 +0100 Subject: dbg_backtrace() function added This adds a useful debugging function for printing function call backtraces. darcs-hash:20070305223458-7ad00-865f0cedcd1d904e98d3e89820102657f685712c.gz --- inc/infoutils.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'inc') diff --git a/inc/infoutils.php b/inc/infoutils.php index ab6e3fdc3..d6da2989d 100644 --- a/inc/infoutils.php +++ b/inc/infoutils.php @@ -257,3 +257,38 @@ function dbglog($msg){ } } +/** + * Print a reversed, prettyprinted backtrace + * + * @author Gary Owen + */ +function dbg_backtrace(){ + // Get backtrace + $backtrace = debug_backtrace(); + + // Unset call to debug_print_backtrace + array_shift($backtrace); + + // Iterate backtrace + $calls = array(); + $depth = count($backtrace) - 1; + foreach ($backtrace as $i => $call) { + $location = $call['file'] . ':' . $call['line']; + $function = (isset($call['class'])) ? + $call['class'] . $call['type'] . $call['function'] : $call['function']; + + $params = ''; + if (isset($call['args'])) { + $params = implode(', ', $call['args']); + } + + $calls[$depth - $i] = sprintf('%s(%s) called at [%s]', + $function, + str_replace("\n", '\n', $params), + $location); + } + ksort($calls); + + return implode("\n", $calls); +} + -- cgit v1.2.3