★ wanayoo — archive 1999 https://code.visualstudio.com/docs/debuggingNouvelle recherche | Portail wanayoo

Debugging

One of the key features of Visual Studio Code is debugging support. VSCode's built-in debugger helps accelerate your edit, compile and debug loop.

Debug

Today we have good debugging support for Node.js. At //build we highlighted the support we are adding for ASP.NET 5 and we plan to add more.

Folow these guides to set up debugging and to do a first run-through with a sample application:

Once you are all set up this page will take you through the debugging scenarios we support.

Launch Configurations

To debug your app in VSCode, you'll first need to setup your launch configuration file - launch.json. By clicking on the launch or the configure actions, VSCode will generate a default launch.json. In VSCode we support launching your app, or attaching to an already running app. For attaching, "address" and "port" must be specified.

You can add new or modify existing configurations inside launch.json (use hover and code assist to help).

{
    "version": "0.1.0",
    // List of configurations. Add new configurations or edit existing ones.  
    // ONLY "node" and "mono" are supported, change "type" to switch.
    "configurations": [
        {
            // Name of configuration; appears in the launch configuration drop down menu.
            "name": "Launch server.js",
            // Type of configuration. Possible values: "node", "mono".
            "type": "node",
            // Workspace relative or absolute path to the program.
            "program": "src/server/server.js",
            // Automatically stop program after launch.
            "stopOnEntry": true,
            // Command line arguments passed to the program.
            "args": [],
            // Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
            "cwd": ".",
            // Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
            "runtimeExecutable": null,
            // Environment variables passed to the program.
            "env": { }
        },      
        {
            "name": "Launch server on port",
            "type": "node",
            "program": "src/server/server.js",
            "args": ["--port=8080"]
        },
        {
            "name": "Attach",
            "type": "node",
            // TCP/IP address. Default is "localhost".
            "address": "localhost",
            // Port to attach to.
            "port": 5858
        }
    ]
}

Choose the active configuration using the dropdown in the debug view. Once you have your launch configuration set, start your debug session with F5.

Breakpoints

Breakpoints can be toggled by clicking on the editor margin. Breakpoint management can be done in the debug view.

Debug Breakpoints

Data inspection

Variables can be inspected in the debug view, or using a hover which only supports simple inspection.

Debug Variables

Debug actions

Once a debug sessions starts, debug actions pane will appear on the top of the editor.

Debug Actions

  • continue / pause F5
  • step over F10
  • step into F11
  • step out ⇧F11 (Windows, Linux Shift+F11)
  • stop ⇧F5 (Windows, Linux Shift+F5)

Next Steps

Try all this out and more in the Node.js and ASP.NET 5 sections.

  • Node.js - End to end Node scenario with a sample app
  • ASP.NET 5 - End to end sample showing off our ASP.NET 5 and .NET 5 support with a sample app
  • Tasks - Running tasks with Gulp, Grunt and Jake. Showing Errors and Warnings

Common Questions

Q: What Node.js version is required for Node.js debugging?

A: Version 0.12 is recommended, though most functionality is supported in 0.10 as well (except break on exceptions).

Q: Do I need some additional setup for debugging on Mac and Linux?

A: Yes, you need Mono version greater than 3.12.

Q: I do not see any launch configurations in the debug view drop down, what is wrong?

A: The most common problem is that you did not set up launch.json yet or there is a syntax error in the launch.json file.