function ddebug_backtrace

Same name in other branches
  1. 4.x devel.module \ddebug_backtrace()
  2. 5.x devel.module \ddebug_backtrace()

Prints the function call stack.

Parameters

$return: Pass TRUE to return the formatted backtrace rather than displaying it in the browser via kprint_r().

$pop: How many items to pop from the top of the stack; useful when calling from an error handler.

$options: Options to pass on to PHP's debug_backtrace(), depending on your PHP version.

Return value

string|NULL The formatted backtrace, if requested, or NULL.

See also

http://php.net/manual/en/function.debug-backtrace.php

1 call to ddebug_backtrace()
backtrace_error_handler in ./devel.module
Displays backtrace showing the route of calls to the current error.

File

./devel.module, line 2150

Code

function ddebug_backtrace($return = FALSE, $pop = 0, $options = TRUE) {
    if (user_access('access devel information')) {
        $backtrace = debug_backtrace($options);
        while ($pop-- > 0) {
            array_shift($backtrace);
        }
        $counter = count($backtrace);
        if (!empty($backtrace[$counter - 1]['file'])) {
            $path = $backtrace[$counter - 1]['file'];
            $path = substr($path, 0, strlen($path) - 10);
            $paths[$path] = strlen($path) + 1;
        }
        $paths[DRUPAL_ROOT] = strlen(DRUPAL_ROOT) + 1;
        $nbsp = " ";
        // Show message if error_level is ERROR_REPORTING_DISPLAY_SOME or higher.
        // (This is Drupal's error_level, which is different from $error_level,
        // and we purposely ignore the difference between _SOME and _ALL,
        // see #970688!)
        if (variable_get('error_level', 1) >= 1) {
            while (!empty($backtrace)) {
                $call = array();
                if (isset($backtrace[0]['file'])) {
                    $call['file'] = $backtrace[0]['file'];
                    foreach ($paths as $path => $len) {
                        if (strpos($backtrace[0]['file'], $path) === 0) {
                            $call['file'] = substr($backtrace[0]['file'], $len);
                        }
                    }
                    $call['file'] .= ':' . $backtrace[0]['line'];
                }
                if (isset($backtrace[1])) {
                    if (isset($backtrace[1]['class'])) {
                        $function = $backtrace[1]['class'] . $backtrace[1]['type'] . $backtrace[1]['function'] . '()';
                    }
                    else {
                        $function = $backtrace[1]['function'] . '()';
                    }
                    $backtrace[1] += array(
                        'args' => array(),
                    );
                    $call['args'] = $backtrace[1]['args'];
                }
                else {
                    $function = 'main()';
                    $call['args'] = $_GET;
                }
                $nicetrace[($counter <= 10 ? $nbsp : '') . --$counter . ': ' . $function] = $call;
                array_shift($backtrace);
            }
            if ($return) {
                return $nicetrace;
            }
            kprint_r($nicetrace);
        }
    }
}