Local Variables are not showing in VS Code while debugging - c++

I am really sorry if this question is been asked before, but I couldn't get a solution.
The following is my launch.json and Adding a picture as well. And I am really sure about it that the Program file path and debugger path is correct. The main issue is that I can not see the values of local variables even though I have marked breakpoints.
{
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/a.exe",//Program File path is correct
"args": [],
"stopAtEntry": true,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "C:/MinGW/bin/gdb.exe",//And I am sure this is correct as well
"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
}
]
}
]
}

Related

How to redirect the std output of a C++ program into a file in VSCode on Mac OS by "launch.json"?

I'm trying to let the output of a C++ program to go into a file, say, "image.ppm". Actually, using the following launch.json file works pretty well on my Ubuntu 20.04.
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/raytracing",
"args": [">image.ppm"],
"postDebugTask": "open_image_linux",
"stopAtEntry": false,
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"cwd": "${workspaceFolder}",
// "preLaunchTask": "C/C++: g++ build active file",
"preLaunchTask": "Build",
"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
}
]
},
When I try to implement a similar procedure on Mac OS, something wried happened, here is my new launch.json file:
{
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/raytracing",
"args": [">image.ppm"],
"postDebugTask": "open_image_mac",
"stopAtEntry": false,
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"cwd": "${workspaceFolder}",
// "preLaunchTask": "C/C++: g++ build active file",
"preLaunchTask": "Build",
"setupCommands": [
{
"description": "Enable pretty-printing for lldb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-lldb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
}
As can be seen, I just changed the debugger from gdb to lldb since gdb doesn't natively support Apple Silicon right now. However, the image.ppm will not be created after the execution of the program, while the output of the program goes into the debug console, like this:
I think, intrinsically, "args": [">image.ppm"], should work, since it works smoothly on Linux. I guess the reason may be related to the different features of gdb and lldb. Since when I run the program in VSCode on Ubuntu, nothing will be shown in the debug console. But I don't know how could I solve this problem.

VSC C++ debugging keeps loading but never starts

In VSC, for a C++ program, I've configured the launch.json file for debuging as:
{
// 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": "my_target",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bazel-ddad_fca/bazel-out/k8-dbg/bin/my_target",
"args": [
"input_file",
"output_file"
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/bazel-ddad_fca/bazel-out/k8-dbg/bin/my_target.runfiles/working_folder",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Skip std",
"text": "skip -rfu ^std::([a-zA-Z0-9_]+)\<.*\>::~?\\1 *\\(",
"ignoreFailures": true
},
{
"description": "Skip files std",
"text": "skip -gfi /usr/include/c++/*/bits/*.h",
"ignoreFailures": true
}
],
"sourceFileMap": {
"/proc/self/cwd/external/": "${workspaceFolder}//external",
"/proc/self/cwd/": "${workspaceFolder}"
}
},
]
}
but when I launch the debug, the vsc debugger keeps initialising but never starts.
I don't know what's causing it. I've tried to reinstall C++ extensions but it did not solve my issue.
Does anyone know what it could be related to or experience the same?

"program.exe doesn't exist" in VSCode when i try to use an external window

EDIT : the g++ is in my path, it isn't the problem.
I have been trying to use a launch.json to run my c++ programs in the external terminal, but every time it gives me an error program.exe doesn't exist although it works fine in the VS Code terminal.
Here is how the launch.json is configured:
{
"configurations": [
{
"name": "run and debug",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\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
}
]
}
]
}

GDB failed with message:"PATH_to_exe" not in executable format: file format not recognized

I have just installed VScode and msys2 to run C++ through the instruction here: https://code.visualstudio.com/docs/languages/cpp.
I wrote a simple code to print out "helloworld". However, when I tried to run it, it showed this message: [
enter image description here
But when I compiled it by DevC++, it run smoothly without any problem. I dont know what's wrong with my VScode installation or configuration.
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": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "enter program name, for example ${workspaceFolder}/a.exe",
"processId": "${command:pickProcess}",
"MIMode": "gdb",
"miDebuggerPath": "/path/to/gdb",
"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
}
]
},
{
"name": "(gdb) Bash on Windows Attach",
"type": "cppdbg",
"request": "attach",
"program": "enter program name, for example ${workspaceFolder}/a.exe",
"processId": "${command:pickRemoteProcess}",
"pipeTransport": {
"debuggerPath": "/usr/bin/gdb",
"pipeProgram": "${env:windir}\\system32\\bash.exe",
"pipeArgs": ["-c"],
"pipeCwd": ""
},
"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
}
]
},
{
"name": "cpp.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:\\msys64\\mingw64\\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
}
],
"preLaunchTask": "C/C++: cpp.exe build active file"
}
]
}
I doubt that it might come from the Win32 configuration in Vscode, since my Window11 is 64-bit. But there is no other options in VScode, and for Python it ran well.
I will very appreciate if someone can help me fix this.

What to in VScode do after launch JSON file C++

I'm learning a basic to c++ in Vscode but I'm having issues with debugging, I followed everything downloaded MinGW, edit the environment path variable value to C:\MingGW\Bin. I tried but when I try to run it opens a launch.JSON what do I do after that? When I run > start debugging I get two options, I click on C++(GDB/LLDB). It opens a JSON file it reads :
{
// 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/path/to/gdb",
"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
}
]
}
]
}
I don't know what do to next please help...