Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cwd not work correctly #329

Closed
wss29 opened this issue Jul 1, 2024 · 9 comments
Closed

cwd not work correctly #329

wss29 opened this issue Jul 1, 2024 · 9 comments

Comments

@wss29
Copy link

wss29 commented Jul 1, 2024

  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 Add support for setting the cwd of the gdb process #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
@jonahgraham
Copy link
Contributor

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?

@wss29
Copy link
Author

wss29 commented Jul 3, 2024

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

@jonahgraham
Copy link
Contributor

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

@wss29
Copy link
Author

wss29 commented Jul 5, 2024

Hi @jonahgraham
GDB works ok in cmd, it is strange why adapter not work
image

@jonahgraham
Copy link
Contributor

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.

@wss29
Copy link
Author

wss29 commented Jul 5, 2024

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

@jonahgraham
Copy link
Contributor

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.

@wss29
Copy link
Author

wss29 commented Jul 6, 2024

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

@jonahgraham
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants