vs code: file not found when trying to debug - debugging

I'm trying to debug a main.cpp file that resides in a folder that has spaces in its filename: "Jim and the Skyscrapers".
The error message reads:
Unable to open 'Jim': File not found
And it also gives me the option of creating this "Jim" file.
The debug process works only if I rename the file to "JimAndTheSkyscrapers" so that it doesn't have any spaces.
The way i reference the path in the launch.json and c_cpp_properties.json files is by using the environment variable: ${workspaceFolder}.
As a debugger, I use cygwin's gdb.
I think the problem is: either the debugger parses filepaths in a manner that doesn't allow spaces, either it's a vs code problem. Knowing which one it is would be of great help.
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{"name": "OUTPUT_PATH", "value": "results.txt"}
],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/cygwin64/bin/gdb.exe",
"preLaunchTask": "build",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.13.26128/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++14",
"intelliSenseMode": "msvc-x64"
}
],
"version": 4
}

Related

How have VS Code/Intellisense recognize glib C/C++ on Windows 10

I am wracking my brain trying to figure out how to have VS Code recognize glib.
#include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (Q:\code\srctext\text_lexer.c).C/C++(1696)
cannot open source file "glibconfig.h" (dependency of "glib-2.0/gmodule.h")C/C++(1696)
I have manually built glib and have the following *.dll and *.pdb files:
gio-2.0-0
glib-2.0-0
gmodule-2.0-0
gobject-2.0-0
gthread-2.0-0
but I do not know if this is necessary to include when vcpkg has it installed?
I have installed glib using vcpkg (Package glib:x86-windows is already installed).
Thanks!
I'm not sure what combination of corrections did the trick, but the errors went away when my c_cpp_properties.json file looked like below.
c_cpp_properties.json
{
"configurations": [
{
"name": "Win32Debug",
"includePath": [
"${workspaceFolder}/include/debug/**",
"C:/sync/name/code/projects/frameworks/projectA/projectA/include/**",
"C:/sync/name/code/libraries/c c++/GTK/glib/lib/glib-2.0/include",
"C:/sync/name/code/libraries/c c++/GTK/glib/include/glib-2.0"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"cStandard": "c17",
"cppStandard": "c++20",
"intelliSenseMode": "windows-gcc-x86",
"browse": {
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": "${default}",
"path": [
"${workspaceFolder}/include/debug/**",
"C:/sync/name/code/projects/frameworks/projectA/projectA/include/debug/**",
"C:/sync/name/code/libraries/c c++/GTK/glib/lib/glib-2.0/include",
"C:/sync/name/code/libraries/c c++/GTK/glib/include/glib-2.0"
]
},
"compilerArgs": [],
"compilerPath": "C:/msys64/mingw64/bin/gcc.exe",
"forcedInclude": [
"${default}"
]
},
{
"name": "Win64Debug",
"includePath": [
"${workspaceFolder}/include/debug/**",
"D:/backup/sync/name/code/projects/frameworks/projectA/projectA/include/debug/**",
"D:/backup/sync/name/code/libraries/c c++/GTK/glib/lib/glib-2.0/include",
"D:/backup/sync/name/code/libraries/c c++/GTK/glib/include/glib-2.0"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.18362.0",
"compilerPath": "C:/msys64/mingw64/bin/gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-gcc-x64",
"compilerArgs": [],
"browse": {
"path": [
"${workspaceFolder}/include/debug/**",
"C:/sync/name/code/projects/frameworks/projectA/projectA/include/debug/**",
"C:/sync/name/code/libraries/c c++/GTK/glib/lib/glib-2.0/include",
"C:/sync/name/code/libraries/c c++/GTK/glib/include/glib-2.0"
],
"limitSymbolsToIncludedHeaders": true
}
}
],
"version": 4
}
Not sure if tasks.json had any influence (frankly Visual Code's inner workings are an opaque impenetrable blob to my attempts at understanding), but just in case:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++ g++.exe build",
"command": "C:\\msys64\\mingw64\\bin\\g++.exe",
"args": [
"/property:GenerateFullPaths=true",
"/t:build",
"/consoleloggerparameters:NoSummary",
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"--include-directory=C:/sync/name/code/libraries/c c++/GTK/glib/lib/**"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "silent"
},
"problemMatcher": [
"$gcc"
]
}
]
}

gcc: error: unrecognized command line option ‘--interpreter=mi’ in Visual Studio Code

I just installed Visual Studio Code in Ubuntu 18.04 LTS based ElementaryOS 5.1 Hera, and set up the environment for C/C++. Launch.json and tasks.json look all fine but on debugging, the following errors are triggered:
gcc: error: unrecognized command line option ‘--interpreter=mi’
gcc: error: unrecognized command line option ‘--tty=/dev/pts/0’
gcc: fatal error: no input files compilation terminated.
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": "gcc - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"console": "externalTerminal",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: gcc build active file",
"miDebuggerPath": "/usr/bin/gcc"
}
]
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: gcc build active file",
"command": "/usr/bin/gcc",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
Is there any way to fix this?

debug clang (lldb) under vscode/windows

I'm trying to debug the helloworld project
#include <stdio.h>
int
main (void)
{
printf ("Hello, world!\n");
return 0;
}
which is built using clang. I use vs-code to take these actions. Here is my task.json file:
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "C/C++: clang.exe build active file",
"command": "C:\\msys64\\mingw64\\bin\\clang.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
As a build task, it works but then with launch.json to debug it seems with no progress. Here is my 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": "clang.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\lldb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: clang.exe build active file"
}
]
}
How to set-up debugger under vs-code with the use of clang/lldb?
It got stall within this command
PS C:\c_helloworld> & 'c:\.vscode\extensions\ms-vscode.cpptools-0.30.0-insiders5\debugAdapters\bin\WindowsDebugLauncher.exe' '--stdin=Microsoft-MIEngine-In-2oaooq4b.u01' '--stdout=Microsoft-MIEngine-Out-ojuis1aj.kfb' '--stderr=Microsoft-MIEngine-Error-tcxqgdhj.tgp' '--pid=Microsoft-MIEngine-Pid-nam4qmgr.r4y' '--dbgExe=C:\msys64\mingw64\bin\lldb.exe' '--interpreter=mi'

How to debug C++ code in Visual studio code

Anyone using Visual studio code for programming in C++? Please tell me how can i manage to do the debugging of my code in visual studio code when I'm compiling it using g++ compiler.
C++ Debugging requires a couple of steps to configure VSCode for it. Once done then C++ code can be easily debugged with F5.
I wrote a post which guides how to run and debug C/C++ files in VSCode.
https://medium.com/#jerrygoyal/run-debug-intellisense-c-c-in-vscode-within-5-minutes-3ed956e059d6
For debugging multiple cpp files inside the project directory.
Your launch.json and task.json should look like this
tasks.json
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
launch.json
{
"name": "g++.exe - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}

VScode compile C++ on windows the exe not found

I want to ask how to debug a simple hello world output from a C++ file, on the launch file I have to put the executable but I have only created a C++ file, how to compile it, I have tried everything, please help.
{
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
// compiles and links with debugger information
"args": ["-g", "-o", "main.exe", "main.cpp"],
// without debugger information
// "args": ["-o", "hello.exe", "hello.cpp"],
"showOutput": "always"
}
Pretty old question but here's a clear explanation for anyone in future.
Issue is that the debugger was looking for a.exe but your build file will probably be named different.
Changing the values of program variable to "${workspaceFolder}\\${fileBasenameNoExtension}.exe" will fix this issue. This should be in the tasks.json and the launch.json.
This env variable takes care that the right name is substituted. Now set a breakpoint and press f5.
Further details here and here.
Here's a full preview of a working launch.json
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "C:\\MinGw\\bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:\\MinGw\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
And a full preview of tasks.json.
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
NOTE: As explained here and here, you might want to set "externalConsole": true if your code needs input from user.

Resources