How to set ROS_PACKAGE_PATH environment variable before starting debug environment in VSCode? - debugging

I would like to add /home/sanya/work/ORB_SLAM3/Examples/ROS to the ROS_PACKAGE_PATH variable before the ROS debug session starts. If it isn't added, the debugger won't start, because it cannot find the package.
I would like to export the variable before the ROS debug starts.
What I already tried:
I tried to add it as an environment variable in the launch.json in two different ways:
first way:
{
"name": "ROS: Launch + build (release)",
"type": "ros",
"request": "launch",
"target": "/home/sanya/work/ORB_SLAM3/Examples/ROS/ORB_SLAM3/launch/ORB_SLAM3_bag.launch",
"env": {"ROS_PACKAGE_PATH": "/opt/ros/melodic/share:/home/sanya/work/ORB_SLAM3/Examples/ROS"}
}
second way:
{
"name": "ROS: Launch + build (release)",
"type": "ros",
"request": "launch",
"target": "/home/sanya/work/ORB_SLAM3/Examples/ROS/ORB_SLAM3/launch/ORB_SLAM3_bag.launch",
"environment": [{"name": "ROS_PACKAGE_PATH", "value": "/opt/ros/melodic/share:/home/sanya/work/ORB_SLAM3/Examples/ROS"}]
}
I tried to add it to an .env file, and set the envFile property in launch.json:
.env file:
ROS_PACKAGE_PATH=/opt/ros/melodic/share:/home/sanya/work/ORB_SLAM3/Examples/ROS
launch.json file:
{
"name": "ROS: Launch + build (release)",
"type": "ros",
"request": "launch",
"target": "/home/sanya/work/ORB_SLAM3/Examples/ROS/ORB_SLAM3/launch/ORB_SLAM3_bag.launch",
"envFile": "${workspaceFolder}/.env"
}
I tried adding a prelaunchTask:
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/sanya/work/ORB_SLAM3_multi/Examples/ROS
This option works— the export happens (I ran echo $ROS_PACKAGE_PATH after to check)— but the debug session starts in a different terminal (if I understand correctly) and the variable won't be set to the correct value in the debug session.
The only thing that has worked is adding it to the .bashrc file. This isn't really ok for me, because I have a modified version of the same library, and I would like to use them both (I will benchmark the modified version against the original), and I wouldn't like to modify the .bashrc file everytime when switching between the 2 versions.
Is there another option to export variables to the VSCode debug environment?

(I maintain the Microsoft VSCode ROS extension.)
The extension inherits most of the environment from the ROS environment it is launched from, so if you need to set environment variables (or relocate ROS), you can set them in a terminal and launch code from the terminal.
I create a feature request - https://github.com/ms-iot/vscode-ros/issues/646, and assigned it to our 0.8.0 which I'm working on now.

Related

How to know the run command that vscode creates from launch.json?

I have a launch.json like below:
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {},
"args": ["server"]
}
]
}
When I launch it using the debug view on VScode it works fine but I need to change the program attribute to relative path of the respective file from my workspace location, strange behaviour is observed, other components in the same package start throwing undefined func error. Probably something goes wrong with current working dir or go module setup.
In order to investigate further, I need to know the command that is generated from this launch.json file. It should be something like go run ...
I have checked the output and debug console, both of them shows nothing about the launch command.
If you know how to see launch command, please help.
You can find the generated command in Visual Studio Code's debug output. When you have started a debug session, open the Debug Console by clicking on the Debug Console icon in the View Bar or by pressing Ctrl + Shift + Y. The debug output will include the generated command line.

Integrated terminal: update environment variable

This is my first day using vscode with beego.
I used IntelliJ otherwise, which has a setting to specify custom paths for GOPATH.
Vscode does not seem to have this option of allowing multiple GOPATHs, and I thought I could try to append GOPATH variable for all integrated terminal sessions.
I've added following to settings.json
"terminal.integrated.env.osx": {
"GOPATH": "/Users/hk/go:/Users/hk/Documents/code/go/go-beego"
}
However, it has no effect on tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "go: run beego",
"type": "shell",
"command": "echo \"gopath is $GOPATH\" | bee run portal"
}
]
}
Output of tasks
gopath is /Users/hk/go
FATAL ▶ 0001 No application 'portal'
found in your GOPATH.
The terminal process terminated with exit code: 255
EDIT: The integrated terminal does not honour the following:
"go.gopath": "/Users/hk/go:/Users/hk/Documents/code/go/go-beego",

can't debug bash scripts using VSCode

I've installed VSCode with Bash debug extension.
Before that, I've installed bashdb and I've verified its version using (bashdb --version) and it's 4.4.
Now, the extension creates an empty file called launch.json.
I wrote the following to start debugging, but still, nothing happened
{
"version": "0.2.0",
"scriptPath": "${command:SelectScriptName}",
"configurations": [
],
"compounds": [
{
"type": "bashdb",
"name": "Compound",
"configurations": []
}
]
}
What should I do to enable debugging?
Regards,
With the bashdb extension installed, add the following block to the launch.json file. This configuration allows you to debug the script you have currently open on VS Code. So, in order to start debugging a script you must have it open on VS Code, and type F5 to start debugging it. Alternatively, and also with the same script open on VS Code, you can open the Run and Debug menu, on the VS Code left bar, and click Play.
{
"type": "bashdb",
"request": "launch",
"name": "Bash-Debug (simplest configuration)",
"cwd": "${workspaceFolder}",
"program": "${file}",
"showDebugOutput": true,
"terminalKind": "integrated"
}
Adding the args parameter to the above block, allows you to pass an array with arguments to the script while debugging.
I tested this code with the Bash Debug extension:
{
"version": "0.2.0",
"configurations":
[
{
"type": "bashdb",
"request": "launch",
"name": "Bash-Debug (select script from list of sh files)",
"cwd": "${workspaceFolder}",
"program": "${command:SelectScriptName}",
"args": []
}
]
}
Visual Studio Code displays a list of script from your project, and you can pick the one you want to run. You can alternatively choose a "Bash-Debug (hardcoded script name)" configuration, which allow to hardcode the script path.
If you want to debug a Bash script I recommend you execute your script with -x flag. For example:
bash -x script.sh
or into the script add:
set -x
<DEBUG_CODE_LINES>
set +x

How do you debug the cucumber step definitions w/ Visual Studio Code?

I'm using the protractor-cucumber-framework to create a testbed environment for our QA team. I've searched around and been able to find zero help in implementing VS Code's debugging capability for use in this code. Has anyone does this? I'd really like to step away from console.log() statements.
1) Upgrade your Nodejs to 8 and later
2) Create a folder .vscode under your project base directory
3) Create a file launch.json under .vscode
4) Copy below content into launch.json
{
// Use IntelliSense to learn about possible Node.js debug attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [{
"type": "node",
"request": "launch",
"name": "gie",
"program": "${workspaceFolder}/node_modules/protractor/built/cli.js",
"cwd": "${workspaceFolder}",
"args": [
"config/gie.config.js",
"--browser=chrome"
]
}]
}
The ${workspaceFolder} represent your project base directory
The first value in args is your protractor config file, you can use relative path to ${workspaceFolder}
The second and next value in args is command options as you type in command line to run test.
My Environment: VSCode 1.8.1, Nodejs v8.9.0, Protractor 5.2.0,

How to extend $PATH in launch.json in Visual Studio Code?

I have some shell scripts, which I would like to execute by name from code during debugging in Visual Studio Code. I need to extend $PATH environment variable to make it happened. Currently, I have following json in launch.json.
{
"name": "Debug-Linux",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {
"PATH": "$PATH:$(pwd)/../bin/"
},
"showLog": true
}
Also, I've tried
"env": {
"PATH": "${env.PATH}:$(pwd)/../bin/"
},
But, it does not work. How can I extend $PATH environment variable in launch.json in Visual Studio Code?
On Windows platform I found that Visual Studio Code seems to be case-sensitive. If the name of the variable is not spelled exactly as it is spelled on your machine, Visual Studio Code will ignore your variable from the launch.json.
For example, to properly set path environment variable when it is spelled Path, you would need to add the following to launch.json.
"env": {
"Path": "${env:Path};${workspaceFolder}\\node_modules\\.bin"
},
See Launch.json attributes and Variable Substitution in Visual Studio Code documentation for more information.
Here what's mentioned there about the variable casing under Variable Substitution:
Note: Be sure to match the environment variable name's casing, for example ${env:Path} on Windows.
This is odd, because Windows is case-insensitive to the names of environment variables
According to the documentation, you should use ${env:PATH} instead of ${env.PATH}.
I finally gave up on making that work, but the workaround I have done is to just paste the DOS command to set the path in the terminal before a debugging session. Something like:
set PATH=C:\Python27\Lib\site-packages\pywin32_system32;%PATH%
A little bit ugly, but at least it lets me work. I add that as a comment to my launch.json so I have it readily available. Not completely sure that would transfer cleanly for your Linux environment, but worth a try (with the appropriate syntax changes for the shell you are using, of course).
I use this:
{
"version": "0.2.0",
"configurations": [
{
"name": "gbdt debugger",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "$PYTHONPATH:/home/work/modeldebug/"
},
}
]
}

Resources