How to get a backtrace in Drupal, without problems like out-of-memory when huge objects are in the trace?
I find this useful as a less memory intensive Drupal-friendly way to backtrace PHP as a one-off code snippet to temporarily drop into a troublesome location without installing modules or server-side tools:

  $trace = debug_backtrace();
  $backtrace_lite = array();
  foreach( $trace as $call ) {
    $backtrace_lite[] = $call['function']."    ".$call['file']."    line ".$call['line'];
  }
  debug( $backtrace_lite, "TRACE", true );


It gets the backtrace into Drupal's debugging system, but strips it down to the essentials to avoid failures when massive objects are involved.

For handy reference, the other keys within each row of the debug_backtrace() object are:


class
object
type
args




Note - this answer was first posted in the now-deleted too-broad question How do I debug Drupal?