getting "MIDebuggerPath" error setting up VSCode - visual-studio-code

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.

Related

Cygwin GDB debugger cannot find debug files

I am using VS Code and I try to debug an executable with cygwin gdb compiled with cygwin gcc.
The problem is that it searches for the files within the build folder:
C:\XXX\build\gcc\C\XXX\test\source\test_source.cpp
Of course it cannot find it there, because the sources are not in the build folder, but one folder above.
This is the launch.json I use:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\build\\gcc\\XXX\\test\\XXX.exe",
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\T_cygwin\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
This all happens on Windows. I tried out using mingw64 directly where this problem does not occur. So I assume it has to do something with Unix paths. Is there a way to find the right debug files?

Glob pattern for program path in launch configuration

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).

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.

Cannot Debug C++ in VS Code

I want to debug my C++ code in VSCode, but after I pressed F5, the external console didn't pop up as expected.
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C++ Debug",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": true,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"internalConsoleOptions": "neverOpen",
"MIMode": "gdb",
"miDebuggerPath": "E:\\MinGW\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "Compile for Debug"
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "Compile for Debug",
"type": "shell",
"command": "g++",
"args": [
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}",
"-g",
"-Wall",
"-Wextra",
"-Wl,--stack=1024000000"
]
}
]
}
When I press F5, the window looks like this:
enter image description here
It seems that the debug session runs normally (the bar in the red box), but as you can see, the external console doesn't appear.
P.S. My system is Windows 10 (x64), and the vscode is the latest.
Finally, I know how to solve that. It seems a bug of C/C++ extension.
I just set the option "Beta: Use Unicode UTF-8 for worldwide language support" in Windows OFF, and everything works.
More details can be found here.
Thanks a lot to Github user #everything411.
From what I can tell looking at your picture, is that I the program stopped at your break point (I don't use the same version so I'm not entirely sure). You have to click next for your program to finish compiling. If you just want to see what your output is, no break points or anything, hit Crtl + F5.
You can follow this link to learn how to use C++ debugger in Linux:
VS Code Debugger for C++
This tutorial is the official tutorial by the Microsoft VS Code Community.
Follow the steps and you will get to know how to debug C++ files.
Note: You need to have a project folder and keep you .cpp inside it.

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.