cwd not work correctly
Closed this issue · 9 comments
- I have a cpp-debug-workspace project in D disk
- I run task 'compile example' to build a.exe. set breakpoint in a.cpp and debug it, everything is ok
- I copy D:\cpp-debug-workspace to D:\cpp-debug-workspace1
- I set "cwd": "D:\cpp-debug-workspace1" in launch.json
- debug it again, I get error "No source file named d:\cpp-debug-workspace1\a.cpp." but the file is indeed there
- I have seen #306, it says 'cwd' work, but I tried it, and not work
- I use cdd-gdb- version 0.108 in windows 10 system to debug
my project link as follow , it is a simple c++ project
cpp-debug-workspace.zip
I notice (from #330) that you are using a very old version of GDB - 7.6. A number of bugs related to path mapping has been fixed in GDB since then. Do you rely on such an old version of GDB? Can you use a more recent version?
Hi @jonahgraham
I updated my gdb to the latest 14.1 version, and debug in vscode but it seems that cwd still does not work,
This is weird - I will try to spin this up on a Windows machine when I get a chance.
Does GDB itself work outside of the adapter.
i.e. can you start c:\msys64\ucrt64\bin\gdb.exe d:\cpp-debug-workspace1\build\a
and then do break d:\cpp-debug-workspace1\a.cpp:34
in a terminal? Does that work?
I'm not sure what cwd setting has to do with the error since absolute paths are being passed to break insert:
[02:13:00.999 UTC] GDB command: 6 -break-insert --source "d:\\cpp-debug-workspace1\\a.cpp" --line 34
[02:13:01.014 UTC] GDB result: 6 error,msg="No source file named d:\\cpp-debug-workspace1\\a.cpp."
Hi @jonahgraham
GDB works ok in cmd, it is strange why adapter not work
Can you do break d:\cpp-debug-workspace1\a.cpp:34
? In your screenshot it shows break 34
which means breakpoint on the current file. You can also compare with break a.cpp:34
and break ..\a.cpp:34
.
Hi @jonahgraham
use break d:\cpp-debug-workspace1\a.cpp:34
will get 'No source file named d:\cpp-debug-workspace1\a.cpp.' I do not understand why, the a.cpp is indeed in d:\cpp-debug-workspace1
Sorry that I didn't work out what was happening sooner, the issue you are seeing is a combination of the relocated directory and the compilation paths used (the ..
).
You are building from the build
directory, so your cwd
should be ${workspaceFolder}/build
after you relocate so that the paths are mapped the same way.
Alternatively (and arguably a better solution) is to substitute the paths with a command like:
set substitute-path d:\cpp-debug-workspace d:\cpp-debug-workspace1
That command can be added to initCommands
in the launch.json.
Hi @jonahgraham
thanks a great, combine set substitute-path and cwd in launch.json , I can debug the a.cpp file in d:\cpp-debug-workspace1.
I think that cwd is working as expected, I am therefore closing this issue.