Followed the VS Code Hello World example from Microsoft and have it compiling and running fine via cygwin g++. But when I try and run it in gdb and set a break point in the code it doesn't stop at the breakpoint. So I set "stopAtEntry": true, in launch.json and it stops and provides a CALL STACK and when I click on main() frame it get an error that the file doesn't exist.
Notice the path where it thinks the file is located:
"C:>cygwin\bin\C☐>Users>lehrian>Documents>CProjects>HelloWorld>helloworld.cpp"
I click "Create File" it creates the file at that location with a high order ascii character in the path. And if I paste my code into that file VSCode shows the code with the debug marker but I can't set additional breakpoints by clicking in the file.
I have tried using "sourceFileMap" to map the folder C:\cygwin\bin to \cygdrive but that only affects the path to the left of C☐>Users>... The problem seems to lie with the fact that VS Code wants to use the full Windows path to the cpp file name but gdb isn't interpreting the c:\ part correctly.
Does anyone have a solution? Can anyone recreate this issue? I do have the example code running and debugging correctly on Linux.
For completeness here is my 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": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/helloworld.exe",
"args": [],
"stopAtEntry": true,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "c:/cygwin/bin/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
}
]
}
]
}
and tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\cygwin\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
[EDIT] Looking through the debug log I see the following line:
--> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (1655) ->1023^done,stack=[frame={level=\"0\",addr=\"0x000000010040108d\",func=\"main\",file=\"C:\\\\Users\\\\lehrian\\\\Documents\\\\CProjects\\\\HelloWorld\\\\helloworld.cpp\",fullname=\"/cygdrive/c/Users/lehrian/Documents/CProjects/HelloWorld/C:\\\\Users\\\\lehrian\\\\Documents\\\\CProjects\\\\HelloWorld\\\\helloworld.cpp\",line=\"5\",arch=\"i386:x86-64\"}]\r\n"},"seq":709} 1: (1655) ->1023^done,stack=[frame={level="0",addr="0x000000010040108d",func="main",file="C:\\Users\\lehrian\\Documents\\CProjects\\HelloWorld\\helloworld.cpp",fullname="/cygdrive/c/Users/lehrian/Documents/CProjects/HelloWorld/C:\\Users\\lehrian\\Documents\\CProjects\\HelloWorld\\helloworld.cpp",line="5",arch="i386:x86-64"}] --> E (output): {"type":"event","event":"output","body":{"category":"console","output":"1: (1655) ->(gdb)\r\n"},"seq":711} 1: (1655) ->(gdb)
It appears that VSCode is using fullname that includes the full path to the file via cygwin and then appending the full path to the file via its Windows path. It should only be using the cygwin path. Is there a way to specify this in a preference or an option or a setting?
I have finally figured out the issue and the solution is simple. Change the "args" in the tasks.json file from:
to
The "-g" argument tells the compiler to include the path to the source file in the output exe so gdb can locate the source code. Apparently ${file} includes the full path and gdb pukes on it. Changing it to ${relativeFile} resolves the issue.