Skip to content

Debugging Guides -- Python, JavaScript, Go & Rust

DodaTech Updated 2026-06-22 5 min read

Debugging is the systematic process of finding and resolving bugs -- this guide teaches you how to use debuggers, logging, and stack traces across Python, JavaScript, Go, and Rust.

What You'll Learn

Why It Matters

Spending 30 seconds setting a breakpoint is faster than spending 10 minutes adding print statements. Professional debugging skills separate senior developers from the rest.

Real-World Use

When your Python web API returns a 500 error, your Node server leaks memory, or your Rust binary panics, knowing the right debugger tool saves hours of guesswork.

Common Debugging Scenarios Table

Scenario Tool Approach
Python script crashing pdb / ipdb Set breakpoint with breakpoint() and inspect locals
Node.js memory leak Chrome DevTools / --inspect Take heap snapshots and compare
Go race condition -race flag / delve Run with race detector and use dlv for stepping
Rust panic RUST_BACKTRACE=1 / gdb Enable full backtrace and debug core dump
JavaScript browser bug Browser DevTools Use Sources tab breakpoints and watch expressions

Step-by-Step Fixes

Fix 1: Debug Python with pdb

# buggy.py
def divide_list(nums, divisor):
    result = []
    for i in range(len(nums) + 1):  # off-by-one
        breakpoint()  # Python 3.7+ built-in debugger
        result.append(nums[i] / divisor)
    return result

print(divide_list([10, 20, 30], 10))
# Debugger session
(Pdb) p i          # print variable i
(Pdb) p nums[i]    # print nums[i]
(Pdb) p len(nums)  # print length
(Pdb) q            # quit and fix the off-by-one

Expected output:

3  # len(nums) shows the fix needed: remove +1

Fix 2: Debug JavaScript in Node.js

// buggy.js
const express = require('express');
const app = express();

app.get('/data', (req, res) => {
    const data = { items: undefined };
    res.json(data.items.map(i => i.name)); // TypeError
});

// Run with: node --inspect-brk buggy.js
// Open chrome://inspect in Chrome

Expected behavior: Chrome DevTools pauses at the first line. Step through with F10 and inspect data.items to see it is undefined.

Fix 3: Debug Go with Race Detection

// buggy.go
package main
import (
    "fmt"
    "sync"
)

func main() {
    var counter int
    var wg sync.WaitGroup
    for i := 0; i < 1000; i++ {
        wg.Add(1)
        go func() {
            counter++  // data race
            wg.Done()
        }()
    }
    wg.Wait()
    fmt.Println(counter)
}
# Run with race detector
go run -race buggy.go

Expected output:

==================
WARNING: DATA RACE
Read at 0x00c0000140a8 by goroutine 8:
  main.main.func1()
      /home/user/buggy.go:12 +0x45
==================

Fix 4: Debug Rust with Full Backtrace

// buggy.rs
fn main() {
    let v = vec![1, 2, 3];
    println!("{}", v[10]); // index out of bounds
}
RUST_BACKTRACE=1 cargo run

Expected output:

thread 'main' panicked at 'index out of bounds: the len is 3 but the index is 10', src/main.rs:3:20
stack backtrace:
   0: rust_begin_unwind
   1: core::panicking::panic_fmt
   2: core::panicking::panic_bounds_check
   3: buggy::main

Fix 5: Log-Based Debugging in Any Language

# Structured logging for debugging
import logging
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s: %(message)s')

def process_order(order_id, items):
    logging.debug(f"Processing order {order_id} with {len(items)} items")
    for item in items:
        logging.debug(f"  Item: {item.get('sku')} x {item.get('qty')}")

Expected output:

2026-06-22 10:00:00 DEBUG: Processing order 12345 with 3 items
2026-06-22 10:00:00 DEBUG:   Item: SKU-001 x 2

Debugging Tool Selection Flowchart

flowchart TD
    A[Bug Detected] --> B{What type of issue?}
    B -->|Crash/Exception| C[Read stack trace]
    C --> D[Set breakpoint at crash line]
    B -->|Wrong Output| E[Add logging at each step]
    E --> F[Compare actual vs expected values]
    B -->|Slow Performance| G[Use profiler/cpu flamegraph]
    G --> H[Identify hot spots]
    B -->|Memory Leak| I[Take heap snapshot]
    I --> J[Compare snapshots over time]
    D --> K[Bug Found]
    F --> K
    H --> K
    J --> K

Prevention Tips

  • Use breakpoint() in Python instead of print() statements -- it stops execution so you can inspect everything
  • Add the -race flag to all your Go test commands during development
  • Set RUST_BACKTRACE=1 permanently in your shell profile: export RUST_BACKTRACE=1
  • Learn your IDE's debugger keyboard shortcuts -- they are faster than clicking
  • Write unit tests for every bug you fix to prevent regression

Practice Questions

  1. What is the difference between breakpoint() in Python and a print statement? Answer: breakpoint() opens an interactive pdb session where you can inspect all variables, step line by line, and execute arbitrary code. Print statements only show what you explicitly logged.

  2. How do you enable the Go race detector? Answer: Pass the -race flag to go run, go build, or go test. Example: go run -race main.go.

  3. What does RUST_BACKTRACE=1 do? Answer: It tells Rust to print a full stack trace when a panic occurs, showing every function call from the panic site back to main.

  4. How do you attach Chrome DevTools to a Node.js process? Answer: Start with node --inspect-brk app.js, then open chrome://inspect in Chrome and click "Open dedicated DevTools for Node".

  5. Challenge: Write a Python function that intentionally has a bug, then write a debugging session transcript showing how you would use pdb to find and fix the bug. Answer:

    # buggy.py
    def calculate_average(grades):
        total = sum(grades)
        return total / len(grades)
    
    # Grades: [90, 80, 100] -> expected 90, but...
    # Debug with: python3 -m pdb buggy.py
    # (Pdb) b calculate_average
    # (Pdb) c
    # (Pdb) p grades
    # (Pdb) p total
    # (Pdb) p len(grades)
    

Quick Reference

Language Debugger Start Command Key Command
Python pdb python3 -m pdb script.py n next, s step into, p print
JavaScript Node --inspect node --inspect-brk app.js F10 step over, F11 step into
Go dlv (Delve) dlv debug main.go next, step, locals
Rust gdb/lldb rust-lldb target/debug/binary run, bt, frame variable
Any RUST_BACKTRACE export RUST_BACKTRACE=1 Read the stack trace top-to-bottom

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro