Skip to content
Joey Wang
Menu

Search

Full Stack Development

Debugging in Ruby, Python, and PHP: byebug, pdb, and Xdebug

Compares Ruby's byebug, Python's pdb, and PHP's Xdebug side by side, with the core commands and a working example for each language.

· 2 min read

engineering #debugging#ruby#python#php

Audio summary

Every language ships a debugger, but the commands and the feel of using them differ enough that switching stacks mid-week trips people up. Here is what byebug in Ruby, pdb in Python, and Xdebug in PHP actually give you, side by side.

Ruby Debugging

Ruby’s byebug (or the newer debug gem) is the standard choice. Core commands:

  • next – moves to the next line in the same context.
  • step – steps into the next function call.
  • continue – runs until the next breakpoint.
  • break – sets a breakpoint at a line.
  • catch – stops execution when an exception is raised.
  • display – prints an expression’s value automatically at each stop.
  • info – shows variables, breakpoints, and the current stack frame.
  • list – shows the surrounding code.
  • trace – enables call tracing.
require 'byebug'

def test_method
  a = 5
  b = 10
  byebug # Set a breakpoint here
  c = a + b
  puts c
end

test_method

Python Debugging

Python’s built-in pdb covers most needs; ipdb adds readline niceties and debugpy wires things into VS Code. Core commands:

  • n (next) – moves to the next line.
  • s (step) – steps into a function call.
  • c (continue) – runs until the next breakpoint.
  • b (break) – sets a breakpoint at a line.
  • tbreak – a one-time breakpoint.
  • p – prints an expression’s value.
  • l (list) – shows code context.
  • w (where) – shows the call stack.
  • q (quit) – exits the debugger.
import pdb

def test_function():
    a = 5
    b = 10
    pdb.set_trace()  # Set a breakpoint
    c = a + b
    print(c)

test_function()

PHP Debugging

PHP debugging usually means Xdebug, with var_dump() and print_r() covering the quick-and-dirty cases. Xdebug’s core operations:

  • step_over – advances a line without entering function calls.
  • step_into – steps into function calls.
  • step_out – steps out of the current function.
  • run – continues to the next breakpoint.
  • breakpoint_set – sets a breakpoint at a line.
  • stack_get – shows the call stack.
  • context_get – shows local variables.
  • eval – evaluates an expression.
<?php
debugger_connect();

function testFunction() {
    $a = 5;
    $b = 10;
    xdebug_break(); // Set a breakpoint
    $c = $a + $b;
    echo $c;
}

testFunction();
?>

Comparison

FeatureRuby (byebug)Python (pdb)PHP (Xdebug)
Step executionnext, stepn, sstep_over, step_into
Breakpointsbreakbbreakpoint_set
Exception catchingcatchccontext_get
Stack traceinfowstack_get
Context infodisplaypeval

All three get the job done. Ruby’s command set is the most direct to pick up, Python’s pdb is close behind and ships with the language, and PHP’s Xdebug does the same job but needs an extension installed and configured before it feels as immediate as the other two.