How to use advanced debugging techniques¶
This page describes advanced debugging techniques, which can be useful after you become familiar with the basic Debugging concepts.
How to change the default debugger¶
If you want to use Cortex-Debug, you can change the debugging settings in the Extension Settings. When the Cortex-Debug option is selected, the Debug button in the Actions View will use this tool to debug applications.
To enable Cortex-Debug:
- Click on the Extensions icon from the Activity Bar.
- Find the nRF Connect for VS Code and click on the Settings icon on the bottom right corner of the extension.
- Click on Extension Settings.
- Scroll down to
Nrf-connect > Debugging: Backend
. -
In the drop-down menu, click on Cortex-Debug.
How to use custom launch and debug configurations¶
Similar to the build and flash task configuration, you can customize and bind specific actions when launching the debugger in VS Code.
You can tweak the debugging configuration for your specific setup by opening and editing a launch.json
file.
This allows you to launch the debugger with custom debugging setup details.
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 add custom nRF Debug configurations:
How to customize from the Actions View¶
To customize from the Actions View, complete the following steps:
- Hover your cursor over Debug.
- Click the cogwheel icon called Configure debugging.
How to customize from the menu bar¶
To customize from the top-level menu bar, complete the following steps:
- Go to Run > Add Configuration.... A list of debuggers appears.
- Choose
nRF Connect
.
The following example shows a launch.json
file using 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"
}
]
}
Additional configuration¶
You can also add additional configuration fields in the launch.json
for debugging with the extension's nRF Debug.
These configuration fields allow you to do the following actions:
- Launch against a server that already runs.
- Target non-localhost servers.
- Use servers other than SEGGER's (for example, west debug).
- Run without a configured toolchain.
See the Debugging UI and settings reference page for a detailed description of available configuration fields and the variables that they accept.
For example, the following configuration lets you set up a debug session against a remote GDB server that's already running on IP address 10.0.0.84
, port 2331
, using the serverAddress
and flash
configuration fields:
{
"configurations": [
{
"type": "nrf-connect",
"request": "Remote debug",
"config": "${activeConfig}",
"serverpath": null,
"serverAddress": "10.0.0.84:2331",
"flash": false
}
]
}
How to customize the debugger Memory Viewer¶
You can add a custom memory region to nRF Debug's Memory Viewer. This displays the defined device's memory address within its own region tab. This is useful if you want to view a specific memory address on your device, rather than viewing all memory addresses within the flash and RAM.
Complete the following steps to add a custom memory region tab:
- Click on the Configure debugging button (the cog wheel) that is to the right of Debug in the extension's Actions View.
This opens the
launch.json
in your current workspace. -
Extend the configuration by adding a
memorySections
array to it.
The following example shows how to add a 1-KB custom section that starts at the address0xCAFE0000
:Add custom memory section"memorySections": [ { "name": "Custom section", "start": "0xCAFE0000", "size": 1024 }
- The
start
property defines the start address of the section. - The
size
property defines the number of bytes from the start address that the property should span. - Either integers or hex strings can be used for
start
, and only integers are valid forsize
.
A validation check is run against these values and a warning message will be shown if they are invalid.
The
launch.json
file should now include amemorySections
array and look like the following:Full configuration{ "configurations": [ { "type": "nrf-connect", "request": "launch", "config": "${activeConfig}", "name": "Launch nRF Connect application", "memorySections": [ { "name": "Custom section", "start": "0xCAFE0000", "size": 1024 } ] } ] }
- The
-
Save the file.
- Click on Debug from the Actions View.
- Once the Debug toolbar appears in the editor, click on the Pause button.
- Open the nRF Debug Panel View from the Panel (Ctrl-J).
You can now see the custom region tab in the Memory Viewer.