summaryrefslogtreecommitdiff
path: root/inc/infoutils.php
diff options
context:
space:
mode:
authorAndreas Gohr <andi@splitbrain.org>2007-03-05 23:34:58 +0100
committerAndreas Gohr <andi@splitbrain.org>2007-03-05 23:34:58 +0100
commitdb09e31e6f0b665e3638f37ca0c5b0890dfcc5a9 (patch)
tree1690eaa6502eb6a4823796ac46d301e700b9c9e7 /inc/infoutils.php
parentd14bceaa1acadf8ed9dca783421662ae36bcef5d (diff)
downloadrpg-db09e31e6f0b665e3638f37ca0c5b0890dfcc5a9.tar.gz
rpg-db09e31e6f0b665e3638f37ca0c5b0890dfcc5a9.tar.bz2
dbg_backtrace() function added
This adds a useful debugging function for printing function call backtraces. darcs-hash:20070305223458-7ad00-865f0cedcd1d904e98d3e89820102657f685712c.gz
Diffstat (limited to 'inc/infoutils.php')
-rw-r--r--inc/infoutils.php35
1 files changed, 35 insertions, 0 deletions
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 <gary_owen@bigfoot.com>
+ */
+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);
+}
+