Glob pattern for program path in launch configuration - visual-studio-code

I wonder if there is a way to make a launch configuration with a "pattern" program name?
In my project, I build my program by automatically adding the version at the end of the program name. For example: myprogram-x.x (I work on Ubuntu, so no .exe). So today my launch.json looks like :
"name": "config name",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/path/to/build/myprogram-5.3",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/path/to/build/",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
As I always have only one file of the program in the build directory, I would like to use a pattern. Instead of having to change my launch configuration to match the last version when it change, I would like to use the * or anything else to always match the file no matter the version. Something like:
"name": "config name",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/path/to/build/myprogram-*",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/path/to/build/",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
I did not see anything like that in VS Code tutorial or documentation, although pattern are usable in some other configuration field. I did not see anything related to the program path variable. Is there a way to do something like that?

You can just modify your build process to also create a symlink for development purposes where it doesn't have the version suffix and points to the executable.
Note that CMake has a cross-platform commandline command to create symlinks: create_symlink <old> <new>, and it also has a CMake command to create symlinks at configure time: file(CREATE_LINK).

Related

Setting working directory in VSCode 14.6.x when using CMake Tools to something else then build directory

Since the update of CMake Tools 1.4.2 (Incorrect run folder #1395) the working directory of the launched binary isn't the workspace directory anymore, but the build directory (due to that files loaded with relative paths are not found anymore).
I tried to figure out in the release notes and the settings if there were some changes that cause that behavior, but I'm not able to find a reason or a solution for that.
The setup is:
Linux
VSCode 1.14.1
CMake Tools 1.4.2
I tried to set the cwd using launch.json, but I'm not able to get it to work.
My launch.json currently looks that way:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Does anyone know how the working directory can be changed?
For debugging it can be changed with:
"cmake.debugConfig": {
"cwd": "${workspaceFolder}"
},
For a regular run/launch it is currently not possible without changing the source of the extension.

getting "MIDebuggerPath" error setting up VSCode

i am struggling to get my vscode working. it pops up this error.
"Unable to start debugging. Launch options string provided by the project system is invalid. Unable to determine path to debugger. Please specify the Unable to start debugging. Launch options string provided by the project system is invalid. Unable to determine path to debugger. Please specify the "MIDebuggerPath" option. option."
the code should be working alright, but there must be something im missing and my research in youtube tutorials was not very helpful.
pd im using OSX
here is my launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Debug",
"type": "cppdbg",
"request": "launch",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "gdb",
"program": "${workspaceFolder}/bin/main"
},
"osx": {
"MIMode": "lldb",
"miDebuggerPath": "lldb-mi",
"program": "${workspaceFolder}/bin/main"
},
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "gdb.exe",
"program": "${workspaceFolder}/bin/main.exe"
},
"preLaunchTask": "build"
}
]
}
I had the same problem, it was solved by installing GDB (it does not come bundled with VS Code). In your case it seems like it is looking for lldb, here as a stackoverflow question that discusses installing lldb on osx.

How do I switch language in Visual Studio Code?

I am playing with a few programming languages within Visual Studio Code. My initial language is Python, and then I added Go in there within their own respective folders. When I run the Go file, it tries to interpret with Python, which obviously would fail.
Could I have different languages within the same project and separate them by different interpreter?
How do I point one folder to run with Python, the other to run with Go?
Thanks.
I've gotten it to work. The Configuration settings control what you are building. It is set within the launch.json file, and you can have different languages with the same project and run them in different interpreter/compiler.
This is what I have in my launch.json.
"version": "0.2.0",
"configurations": [
{
"name": "GO: Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {},
"args": []
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]

Can not change debug environment automatically on visual studio code with config

For example, my root workstation directory is /home/chain/Project. And I have two separate projects which is python and website. My launch.json goes:
{
"version": "0.2.0",
"configurations":
[
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceRoot}/python_project_source/test.py",
"cwd": "${workspaceRoot}/python_project_source",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "${workspaceRoot}/website/test.html",
"webRoot": "${workspaceRoot}/website"
}
]
}
As expected when I select test.py and press 'F5' it can switch to python debug environment, and when I select test.html the Chrome will be opened.
The fact is, VS code only remember the environment I debugged last time rather than change it automatically. So the only thing I do now is adding some comments to one environment (/* */) when I need to compile the other.:(
Is there something wrong in my launch.json?
Automatically switching the debug environment based on the file (or file-type) is not a current feature of Visual Studio Code, I believe.
You'll have to manually switch the launch configuration depending on the type of debugging task you want to perform.
And, of course, you could consider writing a feature request: https://github.com/Microsoft/vscode

Debugging Perl with Visual Studio Code

I have just started with Perl today and installed ActivePerl 5.24.1 and everything went well. I was able to create my test program testPerl.pl with simple a print command and run it through console.
Now I wanted to use Visual Studio Code to run my Perl script, and so I opened the project folder [testPerl.pl location] with Visual Studio Code and tried to debug the code. I have installed the Perl-Debug extension in the editor and when I hit F5, Visual Studio Code asked me to Select Environment and I chose the Perl Debug option, which actually created the launch.json file for me with the below contents.
{
"version": "0.0.2",
"configurations": [
{
"type": "perl",
"request": "launch",
"exec": "perl",
"name": "Perl-Debug",
"root": "${workspaceRoot}/",
"program": "${workspaceRoot}/${command.AskForProgramName}",
"inc": [],
"stopOnEntry": true
}
]
}
I have kept default values as it, and when I hit F5 again, it asked me for a command with default value test.pl. It is because of ${command.AskForProgramName}, I assume. I entered my file name testPerl.pl in the command, but then nothing happens. It starts and ends without any print in console.
How can I actually configure this launch.json file or is there another way I need to do this?
I tried with a newer version of the plugin: Perl Debug version 0.2.0.
This works out of the box. The proposed configuration looks as follows:
{
// 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": [
{
"type": "perl",
"request": "launch",
"name": "Perl-Debug local",
"program": "${workspaceFolder}/${relativeFile}",
"exec": "perl",
"execArgs": [],
"root": "${workspaceRoot}/",
"inc": [],
"args": [],
"env": {},
"stopOnEntry": true
},
{
"type": "perl",
"request": "launch",
"name": "Perl-Debug remote",
"program": "${workspaceFolder}/${relativeFile}",
"root": "${workspaceRoot}/",
"stopOnEntry": true,
"port": 5000
}
]
}
Do note I tried this out on a Mac, with Visual Studio Code version 1.24.0.
I ran Visual Studio Code on a Mac and changed
"program": "${workspaceRoot}/${command.AskForProgramName}"
to
"program": "${file}"
to get the current file to debug.