Debugging

Debugging & Remote Attach (VS Code) — Deep Guide

This page shows local and remote debugging setups for Python, Node.js, Java, PHP, and .NET using VS Code, including remote attach and container/VM workflows.


1) Python (debugpy)

Local attach

  1. pip install debugpy

  2. Inject into the target app:

import debugpy
print('[*] starting debug server on 0.0.0.0:5678')
debugpy.listen(('0.0.0.0', 5678))
debugpy.wait_for_client()  # optional if you want to break immediately
  1. VS Code → Run & Debuglaunch.json:

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "Attach (debugpy)",
      "type": "python",
      "request": "attach",
      "host": "127.0.0.1",
      "port": 5678
    }
  ]
}

Remote attach (SSH/VM/container)

  • Open folder via Remote‑SSH / Dev Containers.

  • Expose 5678 (VM security groups / container port mapping).

  • Same launch.json but host is remote IP.

Breakpoints & Watch

  • Set breakpoints in source files; use Call Stack and Variables panes.


2) Node.js (Inspector)

Start with inspector

VS Code attach

Debugging WebSockets & front‑end

  • Use Chrome DevTools (Sources, Network → WS frames); set breakpoints in bundled JS via source maps.


3) Java (JDWP)

Enable remote debug flags

Add to JVM args:

VS Code (Extension Pack for Java)

Tips

  • If classpaths differ, attach to correct process; use break on thrown exceptions.


4) PHP (Xdebug)

Install & configure

  1. pecl install xdebug or enable distro pkg.

  2. php.ini:

  1. Restart web server.

VS Code

Install PHP Debug extension; launch.json:

Remote

  • Set xdebug.client_host to your workstation IP; open port 9003; map paths with pathMappings if containerized.


5) .NET (vsdbg)

Remote debugging Linux

  1. Download vsdbg:

  1. Start your app with symbols (dotnet run).

  2. VS Code launch.json:

Windows

  • Use processId attach; ensure Just My Code disabled for mixed sources.


6) Remote Attach JavaScript file (front‑end)

Live editing & breakpoints

  • Open site in Chrome → Sources → locate bundle → set breakpoints.

  • For remote files, enable workspace mapping in DevTools → use local copies.

VS Code Edge/Chrome Debugging


7) Containers & SSH

  • Use Dev Containers to mount repo; include debug servers in Dockerfile.

  • Remote‑SSH: ~/.ssh/config host entries; open debug ports in security groups.

8) Breakpoint Strategy

  • Start at controllers; add conditional breakpoints on user == 'admin' branches.

  • Watch values: session objects, cookies, JWT claims.

Tip: In exam VMs, avoid noisy logs; use minimal debug prints and remove them after analysis.

Last updated