Toggle Breakpoint does not work in Visual Studio Code - visual-studio-code

When I try to set a breakpoint nothing happens; I put my cursor on the println! line and press F9.
fn main() {
println!("Hello, world!");
}
I works on another machine where Visual Studio 2017 is installed, so I suspect this might the problem.
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "cargo build",
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"panel": "dedicated",
"clear": true
},
"problemMatcher": {
"owner": "rust",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.+):(\\d+):(\\d+):\\s+(\\d+):(\\d+)\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"endLine": 4,
"endColumn": 5,
"severity": 6,
"message": 7
}
}
},
{
"label": "clean",
"type": "shell",
"command": "cargo clean"
},
{
"label": "run",
"type": "shell",
"command": "cargo run",
"presentation": {
"panel": "dedicated",
"clear": true
},
"problemMatcher": []
},
{
"label": "test",
"type": "shell",
"command": "cargo test",
"group": {
"kind": "test",
"isDefault": true
},
"presentation": {
"panel": "dedicated",
"clear": true
},
"problemMatcher": [
{
"owner": "rust",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"pattern": {
"regexp": "^(.+):(\\d+):(\\d+):\\s+(\\d+):(\\d+)\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"endLine": 4,
"endColumn": 5,
"severity": 6,
"message": 7
}
},
{
"owner": "rust",
"fileLocation": [
"relative",
"${workspaceRoot}"
],
"severity": "error",
"pattern": {
"regexp": "^.*panicked\\s+at\\s+'(.*)',\\s+(.*):(\\d+)$",
"message": 1,
"file": 2,
"line": 3
}
}
]
}
]
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceFolder}/target/debug/${workspaceRootFolderName}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/target/debug/",
"environment": [],
"externalConsole": true,
},
]
}
I have Visual Studio 2019 installed:
>cl --version
Microsoft (R) C/C++ Optimizing Compiler Version 19.20.27508.1 for x64
Copyright (C) Microsoft Corporation. All rights reserved.
I have these Visual Studio Code extensions installed:
C/C++ 0.22.1
Rust (rls) 0.6.0
I am using Rust 1.33.0.

try setting the setting value "debug.allowBreakpointsEverywhere" to true

Related

How to enable auto stop when the prelaunchtask in launch.json is failed?

still launch
build error
In launch.json:
{
"type": "lldb",
"request": "launch",
"name": "lldb-debug",
"program": "${command:cmake.getLaunchTargetPath}",
"args": [],
"cwd": "${workspaceFolder}",
"stdio": null,
"preLaunchTask": "cmake build",
},
In task.json:
{
"type": "cmake",
"label": "cmake build",
"command": "build",
"targets": [
"all"
],
"group": "build",
"problemMatcher": {
"fileLocation": "autoDetect",
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
},
"owner": "cpp",
},
"detail": "CMake build task"
},
The debug still start when the task is failed to build. How to make it auto stop when task is failed?

VS Code cannot find similar task, only the last one

The closest to my issue is this SO question, but I think something else is going on here. I have two launch configurations each which call a similar preLaunch task, start-local and start-dev. The body of these two tasks is almost identical, except that VS Code can only find whichever of these is declared last in the task.json file. I tested this by duplicating the first task and simply changing the label, and none but the last task can ever be found. Is this a bug or am I doing something wrong? Pasting my configs for reference:
VS Code Version: 1.72.2
OS Version: MacOS 12.6
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Start Dev",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder}",
"preLaunchTask": "start-dev",
"postDebugTask": "Terminate All Tasks"
},
{
"name": "Start Local",
"type": "chrome",
"request": "launch",
"url": "http://localhost:3001",
"webRoot": "${workspaceFolder}",
"preLaunchTask": "start-local",
"postDebugTask": "Terminate All Tasks"
},
]
}
task.json
{
"version": "2.0.0",
"tasks": [
{
"label": "start-local",
"type": "npm",
"script": "start",
"isBackground": true,
"problemMatcher": {
"owner": "npm",
"background": {
"activeOnStart": true,
"beginsPattern": ".*",
"endsPattern": "To ignore, add.*eslint-disable-next-line to the line before.*"
},
"pattern": {
"regexp": ""
}
},
"dependsOrder": "sequence",
"dependsOn": [
"setup-local-env"
]
},
{
"label": "setup-local-env",
"command": "echo REACT_APP_STAGE=local > ./.env; echo BROWSER=none >> ./.env",
"type": "shell",
"presentation": {
"echo": false,
"reveal": "never",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false,
"close": true
}
},
{
"label": "start-dev",
"type": "npm",
"script": "start",
"isBackground": true,
"problemMatcher": {
"owner": "npm",
"background": {
"activeOnStart": true,
"beginsPattern": ".*",
"endsPattern": "To ignore, add.*eslint-disable-next-line to the line before.*"
},
"pattern": {
"regexp": ""
}
},
"dependsOrder": "sequence",
"dependsOn": [
"setup-dev-env"
]
},
{
"label": "setup-dev-env",
"command": "echo REACT_APP_STAGE=dev > ./.env; echo BROWSER=none >> ./.env",
"type": "shell",
"presentation": {
"echo": false,
"reveal": "never",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false,
"close": true
}
},
{
"label": "Terminate All Tasks",
"command": "echo ${input:terminate}",
"type": "shell",
"problemMatcher": []
},
],
"inputs": [
{
"id": "terminate",
"type": "command",
"command": "workbench.action.tasks.terminate",
"args": "terminateAll"
}
]
}

VSCode, Define custom variables to use in tasks, lauch and cpp properties

I am setting up VSCode for Embedded development with Nordic NRF52.
I have noticed that in the nrf_sdk there are examples for several boards and several soft devices.
I have seen that it is possible to reference env variables that have been previously defined both in tasks, launch and extension properties, such as: c_cpp, stm32-for-vscode. But what about having a section in the workspace file defined as my_vars so the workspace file looks like this?
{
"my_vars": {
"BOARD_NAME": "NRF52840_MDK_USB_DONGLE",
"MCU_NAME": "NRF52840",
"SOFT_DEVICE": "S140",
"BOARD_VARIANT_PATH": "/pca10059/mbr"
},
"launch": {
"version": "0.2.0",
"configurations": [
{
"name": "Cortex Debug",
"cwd": "${workspaceRoot}",
"executable": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc/_build/${my_vars:MCU_NAME}_xxaa.out",
"request": "launch",
"type": "cortex-debug",
"servertype": "jlink",
"device": "nrf52",
"interface": "swd",
"ipAddress": null,
"serialNumber": null,
"armToolchainPath": "${env:VSARM}/armcc/bin/"
},
]
},
"folders": [
{
"path": "."
}
],
"settings":{
// "C_Cpp.name": "nRF52840 DK",
"C_Cpp.default.includePath": [
"${workspaceFolder}/**",
"${env:GNU_GCC}/arm-none-eabi/include",
"${env:NRF_SDK}/modules/**",
"${env:NRF_SDK}/components/**"
],
"C_Cpp.default.defines": [
"${my_vars:BOARD_NAME}",
"CONFIG_GPIO_AS_PINRESET",
"INITIALIZE_USER_SECTIONS",
"FLOAT_ABI_HARD",
"NRF52",
"${my_vars:MCU_NAME}_XXAA",
"NRF_SD_BLE_API_VERSION=6",
"${my_vars:SOFT_DEVICE}",
"SOFTDEVICE_PRESENT",
"SWI_DISABLE0"
],
"C_Cpp.default.compilerPath": "${env:GNU_GCC}/bin/arm-none-eabi-gcc",
"C_Cpp.default.cStandard": "c11",
"C_Cpp.default.cppStandard": "c++17",
"C_Cpp.default.intelliSenseMode": "clang-x64"
},
"tasks": {
"version": "2.0.0",
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"tasks": [
{
"label": "nRF52 build",
"type": "shell",
"command": "make",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "nRF52 build clean",
"type": "shell",
"command": "make clean",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "nRF52 flash",
"type": "shell",
"command": "make flash",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "nRF52 dfu upload",
"type": "shell",
"command": "make bootload",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
},
{
"label": "nRF52 flash_softdevice",
"type": "shell",
"command": "make flash_softdevice",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
},
},
{
"label": "nRF52 sdk_config",
"type": "shell",
"command": "make sdk_config",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"problemMatcher": []
},
{
"label": "nRF52 erase",
"type": "shell",
"command": "make erase",
"options": {
"cwd": "${workspaceFolder}${my_vars:BOARD_VARIANT_PATH}/armgcc"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
},
}
]
}
}
I tried having a task which is set_env, which in my case, since I am in Windows, run a batch script that does:
set BOARD_NAME=NRF52840_MDK_USB_DONGLE
set MCU_NAME=NRF52840
set SOFT_DEVICE=S140
set BOARD_VARIANT_PATH=/pca10059/mbr
This will ease a lot playing around with the SDK examples and could be potential work for a NRF52 VSCode extension, as https://marketplace.visualstudio.com/items?itemName=bmd.stm32-for-vscode does.
You've undoubtedly solved this problem by now, but hopefully I can save someone else some searching.
There is a top-level section called env that holds global variables that you can reference in your configs.
Here's an example from MSDN.
{
"env": {
"myDefaultIncludePath": ["${workspaceFolder}", "${workspaceFolder}/include"],
"myCompilerPath": "/usr/local/bin/gcc-7"
},
"configurations": [
{
"name": "Mac",
"intelliSenseMode": "clang-x64",
"includePath": ["${myDefaultIncludePath}", "/another/path"],
"macFrameworkPath": ["/System/Library/Frameworks"],
"defines": ["FOO", "BAR=100"],
"forcedInclude": ["${workspaceFolder}/include/config.h"],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"compileCommands": "/path/to/compile_commands.json",
"browse": {
"path": ["${workspaceFolder}"],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
Have a look at the extension Command Variable.
It can use the content of a file as key-value pairs.

How to compile/build multiple cpp files in a folder in vscode?

I have multiple cpp files in my workspace folder. I want to write my Tasks.json file to pick up all the cpp files in the folder to build them so that linker can link them.
I want to write a generic task.json configuration for this so that I can have multiple folder sin my workspace folder.
Is it possible?
My current Task.json file
"version": "2.0.0",
"tasks": [
// MAC OS Build
{
"type": "shell",
"label": "MAC g++ build active file",
"presentation": {
"echo": true,
"reveal": "always",
"focus": true,
"panel": "shared",
"showReuseMessage": true,
"clear": true
},
"command": "/usr/bin/g++",
"args": [
"-Wall",
"-Wno-c++11-extensions",
"-std=c++14",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
},
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceFolder}"],
"pattern": {
"regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
},

Visual Studio Code - tslint - pattern matcher

I tried to implement the pattern matcher for tslint but it is going haywire. I am certain that regex is specified correctly, yet VSC keeps highlighting incorrect files. Here is my tasks.json file:
{
"version": "0.1.0",
"command": "gulp",
"isShellCommand": true,
"args": [
],
"tasks": [
{
"taskName": "build",
"args": [],
"isBuildCommand": true,
"problemMatcher": [
{
"owner": "gulp",
"fileLocation": ["absolute"],
"pattern": {
"regexp": "^\\[[^>]* > ([^(]*)\\((\\d*),(\\d*)\\): (error) (.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
{
"owner": "gulp",
"fileLocation": ["relative", "${workspaceRoot}/src/"],
"pattern": {
"regexp": "^\\([a-z\\-]*\\) ([^\\[]*)\\[([\\d]*), ([\\d]*)\\]: (.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 1,
"message": 4
}
}
]
}
]
}
Solved in version 0.2.0. It was a bug.
No only do you have to understand regular expressions, but you have to remember to escape for json too!
To get this working from the straight output from tslint rather than the gulp version, I had to use:
^(.*\.ts)\[(\d+), (\d+)\]: (.*)$
In the json this becomes:
"problemMatcher": {
"owner": "tslint",
"fileLocation": [
"absolute"
],
"severity": "warning",
"pattern": {
"regexp": "^(.*\\.ts)\\[(\\d+), (\\d+)\\]: (.*)$",
"file": 1,
"line": 2,
"column": 3,
"message": 4
}
}