Documentation
Workflows/Debugging

Debugging

ThinkCode provides a comprehensive set of debugging tools to help you identify, understand, and fix issues in your code quickly and efficiently. This guide covers everything from basic debugging techniques to advanced strategies for complex applications.

Debugging Fundamentals

ThinkCode's debugging environment combines traditional debugging capabilities with AI-enhanced features to streamline troubleshooting:

  • Multi-language Support: Debug across JavaScript, TypeScript, Python, Java, C#, and more
  • Integrated Experience: Access debugging tools directly within your editing environment
  • AI-Assisted Analysis: Leverage AI to interpret errors and suggest fixes
  • Visual Debugging: Visualize program state and data structures during execution

Starting a Debugging Session

Configure Launch Settings

Before debugging, configure your launch settings:

  1. Select the "Run and Debug" view in the Activity Bar (⌘/Ctrl + Shift + D)
  2. Click "create a launch.json file" if you don't have one already
  3. Choose your environment/language
  4. Customize the configuration based on your project requirements

Example launch.json for a Node.js application:

{
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Debug Current File",
      "program": "${file}",
      "skipFiles": ["<node_internals>/**"],
      "console": "integratedTerminal"
    },
    {
      "type": "node",
      "request": "launch",
      "name": "Debug Server",
      "program": "${workspaceFolder}/src/server.js",
      "env": {
        "NODE_ENV": "development"
      }
    }
  ]
}

Initiate Debugging

Start a debugging session using one of these methods:

  1. Click the "Run and Debug" button in the debug view
  2. Select a configuration from the dropdown menu and click the play button
  3. Use the keyboard shortcut F5 (or fn+F5 on some machines)
  4. Right-click a file in the editor and select "Start Debugging"

Essential Debugging Features

Breakpoints

Control program execution with various breakpoint types:

  1. Line Breakpoints: Click in the gutter to set a breakpoint on a specific line
  2. Conditional Breakpoints: Right-click a breakpoint and set a condition that must be true for the breakpoint to trigger
  3. Logpoint Breakpoints: Instead of pausing execution, log a message to the console when reached
  4. Function Breakpoints: Break when entering a specific function
  5. Exception Breakpoints: Pause execution when exceptions occur

Example of setting a conditional breakpoint:

  • Right-click the gutter and select "Add Conditional Breakpoint"
  • Enter a condition like user.id === 123 to pause only for a specific user

Execution Control

Navigate through your code with precision:

  • Continue (F5): Resume execution until the next breakpoint
  • Step Over (F10): Execute the current line and move to the next line
  • Step Into (F11): Enter a function call to debug inside the function
  • Step Out (Shift+F11): Complete the current function and return to the caller
  • Restart (Shift+F5): Stop and restart the debugging session
  • Stop (Shift+F5): Terminate the debugging session

Examining Variables and State

Inspect your program's state during debugging:

  1. Variables Panel: View all variables in the current scope
  2. Watch Panel: Monitor specific expressions throughout execution
  3. Call Stack: Trace the sequence of function calls
  4. Hover Inspection: Hover over variables in the editor to see their values
  5. Data Visualizers: Use specialized visualizers for complex data structures

Advanced Debugging Techniques

Remote Debugging

Debug applications running on remote servers or devices:

  1. Configure the remote environment with the appropriate debugging hooks
  2. Set up port forwarding if necessary
  3. Create a remote debugging configuration in your launch.json
  4. Connect ThinkCode to the remote debugging service

Example remote debugging configuration for Node.js:

{
  "type": "node",
  "request": "attach",
  "name": "Attach to Remote",
  "address": "192.168.1.100",
  "port": 9229,
  "localRoot": "${workspaceFolder}",
  "remoteRoot": "/app"
}

Multi-Process and Multi-Thread Debugging

Debug complex applications with multiple processes or threads:

  1. Set "compounds" in your launch configuration to start multiple debuggers
  2. Use the Call Stack view to switch between threads
  3. Use clear naming in the launch configuration for easy identification

Example compound configuration:

{
  "version": "0.2.0",
  "compounds": [
    {
      "name": "Full Stack: Server + Client",
      "configurations": ["Debug Server", "Debug Client"],
      "stopAll": true
    }
  ]
}

Browser Debugging

Debug web applications directly within ThinkCode:

  1. Install the appropriate browser debugging extension
  2. Configure a launch configuration for your web application
  3. Use both the browser and server debugging features simultaneously
  4. Examine network requests, DOM changes, and JavaScript execution

Example Chrome debugging configuration:

{
  "type": "chrome",
  "request": "launch",
  "name": "Launch Chrome",
  "url": "http://localhost:3000",
  "webRoot": "${workspaceFolder}/client",
  "sourceMapPathOverrides": {
    "webpack:///src/*": "${webRoot}/*"
  }
}

AI-Enhanced Debugging

ThinkCode integrates AI capabilities to supercharge your debugging workflow:

Error Analysis

Get AI-powered insights into errors:

  1. When an exception occurs, click the "AI Analysis" button in the debug console
  2. The AI will explain the error, potential causes, and suggested fixes
  3. Apply suggested fixes directly from the AI interface

Runtime Inspection

Understand complex program states:

  1. Select variables or expressions in the Variables panel
  2. Click "Explain Value" to get AI insights about the data structure
  3. Identify patterns, anomalies, or potential issues in the data

Automated Fix Suggestions

Let AI help resolve issues:

  1. When execution pauses at an error, click "Suggest Fix"
  2. Review multiple potential solutions provided by the AI
  3. Apply a fix directly or use it as a starting point for your solution

Debug Log Analysis

Make sense of complex logs:

  1. Select log output in the Debug Console
  2. Right-click and select "Analyze Logs"
  3. Get a summarized explanation of the log patterns and anomalies

Debugging Specific Languages and Frameworks

JavaScript and TypeScript

Debug modern JS/TS applications with specialized features:

  • Source Maps: Navigate and debug transpiled code as if it were the original
  • Framework Support: Debug React, Vue, Angular with framework-aware features
  • DOM Debugging: Inspect and modify DOM elements during execution
  • Asynchronous Debugging: Track promises and async/await control flow

Python

Debug Python applications with precision:

  • Virtual Environment Integration: Automatically detect and use your project's venv
  • Jupyter Notebook Support: Debug cells within notebooks
  • Variable Explorer: Visualize complex Python data structures
  • Django and Flask Templates: Set breakpoints in template files

Java

Comprehensive Java debugging features:

  • Hot Code Replacement: Apply code changes during a debug session
  • Conditional Breakpoints with Evaluation: Use complex conditions with method calls
  • Stream Debugging: Visualize Java Stream operations
  • Exception Breakpoints: Break on specific exception types

C# and .NET

Debug .NET applications efficiently:

  • .NET Core Support: Debug across platforms with .NET Core
  • Edit and Continue: Modify code during debugging sessions
  • Memory Dump Analysis: Inspect memory snapshots
  • Entity Framework Queries: View generated SQL and results

Debugging Best Practices

Efficient Debugging Workflows

Optimize your debugging process:

  1. Start Narrow: Begin with a focused, reproducible test case
  2. Use Logging Strategically: Add log points rather than breakpoints for non-interactive debugging
  3. Leverage Watch Expressions: Monitor complex conditions across execution
  4. Save Debug Configurations: Create and save configurations for common scenarios
  5. Use Keyboard Shortcuts: Speed up your workflow with keyboard navigation

Collaborative Debugging

Debug effectively with your team:

  1. Share Launch Configurations: Commit your .vscode/launch.json to version control
  2. Document Environment Requirements: List all prerequisites for debugging
  3. Use Debug Sessions: Start a shared debugging session with teammates
  4. Record and Share: Capture debugging sessions for asynchronous collaboration

Performance Debugging

Identify and resolve performance issues:

  1. CPU Profiling: Identify performance bottlenecks
  2. Memory Profiling: Detect memory leaks and excessive allocations
  3. Timeline Analysis: Visualize execution time across functions
  4. Network Monitoring: Analyze API calls and response times

Troubleshooting Debugging Problems

Common Issues and Solutions

Resolve frequent debugging challenges:

  1. Cannot Hit Breakpoints

    • Verify source maps are correctly configured
    • Check if the code being executed matches your source files
    • Rebuild the project to ensure latest changes are included
  2. Debugging Is Slow

    • Reduce the number of breakpoints and watch expressions
    • Close unnecessary debug panels
    • Adjust exception catching settings
    • Consider using logpoints instead of breakpoints
  3. Variables Not Showing Correctly

    • Verify the scope is accessible at the current execution point
    • Check if the variable has been optimized away in production builds
    • Use immediate window to evaluate expressions

Further Resources


Mastering ThinkCode's debugging tools will dramatically improve your ability to identify and resolve issues quickly. By combining traditional debugging techniques with AI-enhanced capabilities, you can create a powerful workflow that minimizes the time spent troubleshooting and maximizes your productive coding time.