After those tricks about codesigning, I've got to make gdb run on my mac (10.14.6), but only in terminal, and it gives no response in vs code.
Everything works just fine in terminal, like setting breakpoints, printing variables and running the executables, but it gets stuck in vs code, and nothing shows up in the variable and call stack sections.
Here's my launch.json:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/usr/local/bin/gdb",
/* "setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
], */
"preLaunchTask": "Build"
}
]
}
vs code
terminal
Related
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.
I'm trying to use the debugger in vs code. I have problems to activate and run it.
This is my code:
#include <gtest/gtest.h>
// Demonstrate some basic assertions.
TEST(HelloTest, BasicAssertions) {
// Expect two strings not to be equal.
EXPECT_STRNE("hello", "world");
// Expect equality.
EXPECT_EQ(7 * 6, 42);
}
VSCode reports that the program path is missing or invalid, even though I copied the address of the .exe file to the program path of launch.json, then GDB reports that the .exe file not in file format recognized. Any idea would be appreciate much. TY
This is the code in my launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++ Runner: Debug Session",
"type": "cppdbg",
"request": "launch",
"args": [
""
],
"stopAtEntry": false,
"cwd": "c:/Users/ABC/Desktop/Test",
"environment": [],
"program": "c:/Users/ABC/Desktop/Test/hello_test.exe",
"internalConsoleOptions": "openOnSessionStart",
"MIMode": "gdb",
"miDebuggerPath": "C:/msys64/mingw64/bin/gdb.exe",
"externalConsole": false,
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
so i have a problem with debugging a program in VS Code in Ubuntu. When i try that i get this message launch:program 'enter program name, for example /home/daniel/Desktop/OOP/Test/a.out'does not exist and i have an option to see the launch.json file. So any ideas what is the problem? And whats wrong?
Here is the 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) Launch",
"type": "cppdbg",
"request": "launch",
"program": "enter program name, for example ${workspaceFolder}/a.out",
"args": [],
"stopAt`enter code here`Entry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Try changing the line
"program": "enter program name, for example ${workspaceFolder}/a.out",
to this
"program": "/home/daniel/Desktop/OOP/Test/a.out",
Althougt I had installed dub,dmd. I can run test.d in terminal.But I can't run file test.d in visual studio code.
Maybe should change launch.son 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) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/mct.d",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
Launch.json file
"program": "${workspaceRoot}/mct.d"
This should be a path to the executable, not the source file. Try:
"program": "${workspaceRoot}/mct.exe"
I'm using Visual Studio Code to compile C and C ++ files but I just want to build the project without doing other actions, can that be in VS Code? Or will it always try to run the project? Here is my tasks.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": "vde.exe build",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "\\usr\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "vde.exe build active file"
}
]
}