VScode debug mode shows "Could not find the specified task" - visual-studio-code

When trying to start a Debug session in vscode, it throws an error about not finding a specified task. I've already tried the solutions of other SO questions like this but without success.
launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
...
},
{
"name": "MSEventHubs_Audit",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/audit-events.py",
"console": "integratedTerminal",
"args": [
"config/config.ini",
],
"envFile": "${workspaceFolder}/.env",
"env": {"PYTHONPATH": "${workspaceRoot}"},
"justMyCode": false,
"preLaunchTask": {
"task": "audit_tunnel"
}
},
{
...
},
]
}
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"command": "",
"args": [],
"tasks": [
{
"label": "activate_key",
"type": "shell",
"command": "smartOS_card_pin.sh",
"args": [
"${inputs:cardos_pass}"
],
"group": "build",
},
{
"label": "audit_tunnel",
"type": "shell",
"group": "build",
"command": "ssh",
"args": [
"-NL",
"port1:127.0.0.1:port2",
"my_host"
],
"dependsOn": "activate_key"
},
{
...
}
],
"inputs": [
{
"id": "cardos_pass",
"type": "promptString",
"password": true
}
]
}
I've been looking at it for a while and cannot figure out what I'm doing wrong. The proof my task is known by vscode is when the pop-up message appears
I click 'Configure Task', the 'audit_tunnel' appears as an option to edit.
What am I missing?

Change:
"preLaunchTask": {
"task": "audit_tunnel"
}
To:
"preLaunchTask": "audit_tunnel"

Related

How Do I Set Task as preLaunchTask in .code-workspace?

I have a multi-root workspace with launch configurations and tasks. The tasks run fine on their own, but they don't run when added as a preLaunchTask. VS Code throws the error "Could not find the task".
oving them to a tasks.json file is not an option for me.
Here's the relevant information from my .code-worspace file
{
"folders": [
{
"name": "App",
"path": "app"
},
{
"name": "API",
"path": "api"
},
],
"settings": {},
"launch": {
"configurations": [
{
"name": "Launch App",
"type": "chrome",
"request": "launch",
"preLaunchTask": "npm: start",
"cwd": "${workspaceFolder:App}",
"url": "http://localhost:3000",
"webRoot": "${workspaceFolder:App}/src",
"sourceMapPathOverrides": {
"webpack:///src/*": "${webRoot}/*"
}
}
]
},
"tasks": {
"version": "2.0.0",
"tasks": [
{
"type": "npm",
"script": "start",
"label": "npm: start",
"detail": "react-scripts start",
"options": {
"cwd": "${workspaceFolder:App}"
},
"problemMatcher": []
}
]
}
}
I don't know why, but this only happens if type = npm.
Change:
"type": "npm",
"script": "start",
to:
"type": "shell",
"command": "npm start",

How to Debugger in VSCode?

I added new extension in VSCode. I've added syntax and snippets. It's time for debugging. I searched a lot and couldn't get exactly what I wanted. I want to debug without using tasks.json.
My json files:
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Run",
"request": "attach",
"windows": {
"preLaunchTask": "windows"
},
"linux": {
"preLaunchTask": "linux"
},
"osx": {
"preLaunchTask": "osx"
}
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "windows",
"command": "echo",
"args": ["hello windows"],
"type": "shell"
},
{
"label": "linux",
"command": "echo",
"args": ["hello linux"],
"type": "shell"
},
{
"label": "osx",
"command": "echo",
"args": ["hello macOS"],
"type": "shell"
}
]
}
Thanks for all your answers.

How can i solve "unable to open 'read.c': Unable to read file..." in vscode ubuntu

I'm trying to debug my C program in VScode, then this error appears
How can I fix it?
Unable to open 'read.c': Unable to read file '/build/glibc-eX1tMB/glibc-2.31/sysdeps/unix/sysv/linux/read.c' (Error: Unable to resolve non-existing file '/build/glibc-eX1tMB/glibc-2.31/sysdeps/unix/sysv/linux/read.c').
launch.json file:
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++ build active file",
"miDebuggerPath": "/usr/bin/gdb",
"sourceFileMap": {
"/build/glibc-YYA7BZ": "/usr/src/glibc"
}
}
]
}
tasks.json file:
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc-9 build active file",
"command": "/usr/bin/gcc-9",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
},
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": "build",
"detail": "compiler: /usr/bin/gcc"
}
],
"version": "2.0.0"
}

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.

Debugging with Bazel in Visual Studio Code with Ubuntu

I read this Bazel VS Code tutorial.
Currently, I have a problem with reproducing the tutorial on my system.
I am using Ubuntu 18.04 and bazel 0.27.0 and Visual Studio Code (Version 1.35.1)
My files:
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "Build Example (Debug)",
"type": "shell",
"command": "bazel build :example -c dbg",
"linux": {
"command": "bazel build :example -c dbg --spawn_strategy=standalone",
},
"group": {
"kind": "build",
"isDefault": true
},
}
]
}
My launch.json:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Example",
"type": "cppdbg",
"request": "launch",
"preLaunchTask": "Build Example (Debug)",
"program": "${workspaceFolder}/bazel-out/k8-dbg/bin/example",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/bazel-out/k8-dbg/bin/example.runfiles/__main__/",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"sourceFileMap": {
"/home/newton/.cache/bazel/_bazel_newton/7a12d285425fc99da0ce87e2a08f2f36/execroot/__main__/": "${workspaceFolder}"
}
}
]
}
The following screenshot shows in the lower left corner that an error is reported when I try to start debugging: "Unable to read file (Error: File not found..."
I am looking for any suggestion on how to fix this and to make it work.
See this.
Here's my config:
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": "bazel build --compilation_mode=dbg //...",
"group": {
"kind": "build",
"isDefault": true
},
}
]
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "ExampleMihai",
"preLaunchTask": "build",
"type": "cppdbg",
"request": "launch",
"program": "/home/mihai/.cache/bazel/_bazel_mihai/89c1625b12241e64b746e0e58fdc7159/execroot/__main__/bazel-out/k8-dbg/bin/unit/test_static_string",
"args": [],
"stopAtEntry": false,
"cwd": "/home/mihai/git/containers",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
]
},
]
}
I use sourceFileMap to fix the "unable to read file" error on Linux. The following configuration uses the "official" paths in bazel-bin/:
{
"version": "0.2.0",
"configurations": [
{
"name": "launch",
"type": "cppdbg",
"preLaunchTask": "build",
"request": "launch",
"program": "${workspaceFolder}/bazel-bin/example/example",
"cwd": "${workspaceFolder}/bazel-bin/example/example.runfiles/__main__",
"linux": {
"sourceFileMap": {
"/proc/self/cwd": "${workspaceFolder}",
}
}
}
]
}