eclipse-cdt-cloud/cdt-gdb-adapter

cwd not work correctly

Closed this issue · 9 comments

  1. I have a cpp-debug-workspace project in D disk
  2. I run task 'compile example' to build a.exe. set breakpoint in a.cpp and debug it, everything is ok
  3. I copy D:\cpp-debug-workspace to D:\cpp-debug-workspace1
  4. I set "cwd": "D:\cpp-debug-workspace1" in launch.json
  5. debug it again, I get error "No source file named d:\cpp-debug-workspace1\a.cpp." but the file is indeed there
    image
  6. I have seen #306, it says 'cwd' work, but I tried it, and not work
  7. 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,

  1. I build in d:\cpp-debug-workspace and debug works ok,
  2. I copied to d:\cpp-debug-workspace1, and set the path to lowercase explicitly, but debug still did not work
    image
  3. I looked at the gdb logs and found the err "No source file named d:\cpp-debug-workspace1\a.cpp." still there,
    image

b.log
cpp-debug-workspace1.zip

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
image

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
image

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.
image

I think that cwd is working as expected, I am therefore closing this issue.