MSDN Docs

Debugger Tool Overview

The Debugger is a powerful, cross‑platform tool that allows developers to inspect, step through, and diagnose code at runtime. It integrates seamlessly with Visual Studio, VS Code, and the command line, supporting languages such as C#, C++, JavaScript, and Python.

Installation

Use the following commands to install the Debugger on your platform.

dotnet tool install -g dotnet-debugger
# or for VS Code
code --install-extension ms-vscode.debugger

Getting Started

Launch the debugger from the terminal or IDE. Below is a quick example for a .NET console application.

dotnet new console -n SampleApp
cd SampleApp
dotnet build
dotnet debugger run

Key Features

  • Live variable inspection
  • Conditional breakpoints
  • Step‑in/step‑out, run to cursor
  • Remote debugging over SSH
  • Performance profiling integration

Breakpoints

Set a breakpoint by clicking the gutter in your editor or using the command line:

dotnet debugger breakpoint set --file Program.cs --line 15

Watch & Variables

Add expressions to the watch window to monitor changes during execution.

dotnet debugger watch add "myObject.Count"
dotnet debugger watch list

Remote Debugging

Configure SSH access to a remote host and attach the debugger.

dotnet debugger attach --remote user@remotehost --process 1234

API Reference

CommandDescription
runStart the application under the debugger
breakpoint setCreate a new breakpoint
watch addAdd an expression to the watch list
attachAttach to a running process
continueResume execution after a stop

Code Samples

Example: Debugging a faulty loop.

int Sum(int[] values)
{
    int total = 0;
    for(int i = 0; i <= values.Length; i++) // Off‑by‑one bug
    {
        total += values[i];
    }
    return total;
}

Set a breakpoint on the for line, run the program, and inspect i and total values to locate the error.

FAQ

Can I debug native C++ code?
Yes, the debugger supports native code on Windows, Linux, and macOS.
How do I debug multi‑process applications?
Use dotnet debugger attach on each process, then switch between them in the UI.
Is there a way to script debugging actions?
Yes, you can write scripts using the dotnet debugger CLI commands.