How to customize launch and debug configurations - nRF Connect for VS Code
Skip to content

How to customize launch and debug configurations

You can customize and bind specific actions when launching the debugger in VS Code, similarly to the build and flash task configuration.

To tweak the debugging configuration for your specific setup, open and edit a launch.json file. This allows you to launch the debugger with custom debugging setup, including:

You can read more about the general uses of launch configurations in VS Code's documentation.

There are two ways to open a launch.json file and start adding custom debugging configurations.

How to open launch.json from the Actions View

To start customizing from the Actions View, complete the following steps:

  1. Hover your cursor over Debug.
  2. Click the cogwheel icon called Configure debugging.

How to open launch.json from the menu bar

To start customizing from the top-level menu bar, complete the following steps:

  1. Go to Run > Add Configuration....
    A list of debuggers appears.
  2. Choose nRF Connect.

Examples

The following example shows a launch.json file using the nrf-connect debug type.

launch.json with the nrf-connect debug type
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "nrf-connect",
            "request": "launch",
            "name": "Launch active build configuration",
            "config": "${activeConfig}",
            "runToEntryPoint": "main",
            "preLaunchTask": "nRF Connect: Build active configuration"
        },
        {
            "name": "Launch build_nrf52840dk_nrf52840",
            "type": "nrf-connect",
            "request": "launch",
            "config": "c:\\Users\\joe\\workspace\\apps\\hello_world\\build_nrf52840",
            "runToEntryPoint": "main"
        }
    ]
}

The following example shows a launch.json file using the nrf-connect debug type, like in the previous example, but with the configuration that allows you to launch the debugger against a debugging server that is already running. This is done by changing the value of the request configuration field to attach and removing the runToEntryPoint configuration field.

launch.json with the nrf-connect debug type, with attaching to target enabled
{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "nrf-connect",
            "request": "attach",
            "name": "Launch active build configuration",
            "config": "${activeConfig}"
        }
    ]
}

The following example shows a configuration that lets you set up a debug session against a remote GDB server. The server is already running on the IP address 10.0.0.84, port 2331, using the serverAddress and flash configuration fields:

launch.json with the nrf-connect debug type, with the remote debugging enabled
{
    "configurations": [
        {
            "type": "nrf-connect",
            "request": "attach",
            "config": "${activeConfig}",
            "serverpath": null,
            "serverAddress": "10.0.0.84:2331",
            "flash": false
        }
    ]
}