vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

'cwd' option is not respected in launch.json

Open andreasjhkarlsson opened this issue 4 years ago • 42 comments

Bug type: General

  • OS and Version: macOS 11.2.3
  • VS Code Version: 1.59.1
  • C/C++ Extension Version: 1.6.0

After updating to 1.6.0 of this extension the cwd option stopped working for all of my launch.json configs. Example config:

        {
            "name": "TEST",
            "request": "launch",
            "type": "cppdbg",
            "program": "/tmp/a.out",
            "args": [""],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/components/Media/",
            "environment": [
                //{"name": "ASAN_OPTIONS", "value": "detect_container_overflow=0"} // Uncomment when using address sanitizier
            ], 
            "externalConsole": false,
            "MIMode": "lldb"
        },  

To verify I created a test program like:

#include <unistd.h>
#include <iostream>

int main()
{
char a[2048];
getcwd(a, 2048);
std::cout << a << std::endl;
}

which on 1.6.0 prints the incorrect "/private/tmp" when launching through vscode. If I manually downgrade to 1.5.1 I get the expected output (the actual cwd specified in the launch.json file).

andreasjhkarlsson avatar Sep 01 '21 13:09 andreasjhkarlsson

I can confirm that this is specific to cppdbg 1.6.0 - i.e. does not happen with cppdbg [1.4.1-1.5.1] - but that it is not specific to VS Code 1.59.1 - i.e. same problem happens, with cppdbg 1.6.0 only, with vscode (1.57.1-1.58.2].

-exec shell pwd at the vscode Debug Console also shows the same problem, current directory is the location of the program file, not the location specified in cwd.

(Not sure if it is relevant or not, but I am also on macOS, 11.5.)

mikebeaton avatar Sep 01 '21 17:09 mikebeaton

quoting from here: https://github.com/microsoft/vscode/issues/27157 "cwd is nothing that VS Code knows about. A debug extension owns the schema for its launch attributes and only some define cwd (and VS Code cannot make any assumptions about the semantics of cwd anyway; it can only guess..."

elahehrashedi avatar Sep 01 '21 21:09 elahehrashedi

@elahehrashedi - Thanks for the additional info - so it's a good thing that this issue is on the repository of the cppdbg extension and not of VS Code then, right?

mikebeaton avatar Sep 02 '21 08:09 mikebeaton

It seems that this is still an issue in version 1.8.5 (pre-release). Is there any workaround for this? I just want the debug configuration to launch the program with a current working directory of {$workspaceFolder}, but it seems to always start from the CMake build directory :-(

ennorehling avatar Feb 10 '22 12:02 ennorehling

@WardenGnaw / anyone else?

@elahehrashedi's comment seems to imply that the issue is in the right place.

The behaviour changed between 1.5.1 and 1.6.0; from @ennorehling's comment, it still seems be an issue in 1.8.5; and it seems to be a genuine issue, affecting some people's ability to use the tool effectively.

mikebeaton avatar Feb 10 '22 15:02 mikebeaton

I'm facing a similar issue on VS too. I hate cwd set in the launch.vs.json file, but the debugger won't start in that directory. Using msvc_x64_x64 compiler in the CMakeSettings and the default debugger the VS provides.

arsdever avatar Feb 24 '22 20:02 arsdever

Have the same Issue with python and linux. I think its a vscode problem not a plugin one.

b-reich avatar Mar 12 '22 15:03 b-reich

Same for me. Have the same Issue with python.

clumdee avatar Apr 26 '22 10:04 clumdee

My understanding is that the cwd value is passed along to the debugger, and there is a known issue with lldb-mi (needed to debug with clang+lldb) not propagating the cwd value from its -environment-cd argument to the process being debugged. https://github.com/llvm/llvm-project/issues/29613

Colengms avatar Apr 27 '22 00:04 Colengms

@Colengms - That proposed source of the problem doesn't fit with the issue depending on the version of VS Code.

mikebeaton avatar Apr 27 '22 09:04 mikebeaton

Hi @mikebeaton . Some code was changed between these versions such that the issue with lldb-mi was exposed. We can use this issue to track implementing a work around, but the ideal fix would come from lldb-mi.

Colengms avatar Apr 27 '22 19:04 Colengms

Might not be relevant to finding the source of the problem but I thought i would mention that i have similar issues on Ubuntu when running a gdb debug launch

Bonkt avatar Jul 28 '22 18:07 Bonkt

I found that when pressing "debug" button on toolbar, right side of screen, it does not respect launch.js However F5 and play button on left side in "run and debug" sidebar, in front of configuration drop-down work as expected. image

version 1.70.1 on win10

blindb avatar Aug 11 '22 06:08 blindb

I found that when pressing "debug" button on toolbar, right side of screen, it does not respect launch.js However F5 and play button on left side in "run and debug" sidebar, in front of configuration drop-down work as expected. image

version 1.70.1 on win10

CORRECT!!!!!!!Thank you very much And the reason follows(please search the url): https://stackoverflow.com/questions/72037468/different-behavior-when-using-debug-run-button-and-f5-ctrlf5-in-visual-studio-c

Uncle-Yuanl avatar Sep 29 '22 09:09 Uncle-Yuanl

This one is hitting me, too. Visual Studio 2022 with latest updated workloads for C/C++ and CMake. The workaround doesn't work for me either - pressing F5 just launches in debug and "cwd" is still ignored.

Is there any solution?

JayAtlis avatar Oct 01 '22 14:10 JayAtlis

We are having the same issue with the Python (3.10) debugger. The cwd key is not respected.

tasansal avatar Oct 12 '22 22:10 tasansal

Having the same issue debugging a C++ application. Cwd is completely ignored

francescotaioli avatar Nov 26 '22 10:11 francescotaioli

Same issue debugging a rust app with lldb.

i5hi avatar Nov 30 '22 15:11 i5hi

in my case, putting"cwd" option in the launch.json does not start debugging at all! when I remove the "cwd" option, then it starts debugging. this is weird. I am using Python debugger

MovingKyu avatar Dec 22 '22 01:12 MovingKyu

I found that when pressing "debug" button on toolbar, right side of screen, it does not respect launch.js However F5 and play button on left side in "run and debug" sidebar, in front of configuration drop-down work as expected. image

version 1.70.1 on win10

Same issue WHy?

b-y-f avatar Dec 27 '22 11:12 b-y-f

Just to keep question alive, I can confirm the mentioned behavior by "b-y-f". Starting debug from drop-down-arrow (top right of Studio Code in the tool bar) ignores at least cwd setting in launch.js. Using F5 to start debug session respects the settings in launch.json and therefore work as expected. At least from my side this behaviour is not expected.

MikeErd avatar Jan 11 '23 10:01 MikeErd

@elahehrashedi Is this a build task issue?

sean-mcmanus avatar Jan 18 '23 02:01 sean-mcmanus

@sean-mcmanus I tested this, and I beleive this is not a task issue. I don't repro this using "cppvsdbg" or "cppdbg" with "MIMode": "lldb" or "MIMode": "gdb". We need more info to investigate this issue.

elahehrashedi avatar Jan 19 '23 22:01 elahehrashedi

This is also happening to me in Visual Studio 2022 17.5.1, debugging a CMake target. All programs start in my home folder.

a-gn avatar Mar 10 '23 15:03 a-gn

@sean-mcmanus I tested this, and I beleive this is not a task issue. I don't repro this using "cppvsdbg" or "cppdbg" with "MIMode": "lldb" or "MIMode": "gdb". We need more info to investigate this issue.

@elahehrashedi @sean-mcmanus What more info do you need? I am happy to re-check and re-test and gather any info, if it will help.

mikebeaton avatar Mar 10 '23 16:03 mikebeaton

@mikebeaton I don't know. I don't repro the issue. @WardenGnaw Do you have any idea? I'm guessing this is a debugger issue?

sean-mcmanus avatar Mar 10 '23 18:03 sean-mcmanus

I was having this issue, and noticed there was a cd statement in my .bashrc After removing that, the debugger worked with the cwd option (VS Code 1.76.0)

dangffn avatar Mar 10 '23 18:03 dangffn

Latest macos, latest vscode. Can confirm: cwd is not respected when clicking on the top-right debug button but it does work when you click debug on the left panel. Interestingly, both work fine on ubuntu.

pochtar avatar Mar 31 '23 22:03 pochtar

Issue seems to be present for rust debugging via lldb, whether activated via F5, or the debug play button.

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "lldb",
            "request": "launch",
            "name": "Debug unit tests in example 'hot_reload'",
            "cargo": {
                "args": [
                    "test",
                    "--no-run",
                    "--example=theme",
                    "--package=tomt_bevycss"
                ],
                "filter": {
                    "name": "theme",
                    "kind": "example"
                }
            },
            "args": [],
            "cwd": "${workspaceFolder}"
        },
    ]
}

Application output snippet:

2023-04-06T19:01:03.523749Z  WARN bevy_asset::asset_server: encountered an error while reading an asset: path not found: /<my-local-drive>/tomt-bevycss/target/debug/examples/assets/sheets/dark_theme.css

Where ${workspaceFolder} = /<my-local-drive>/tomt-bevycss

VSCode: 1.77.1 CodeLLDB: v1.9.0 rust-analyzer: v0.3.1463 C/C++: v1.14.5

System Info Ubuntu 22.04.2 LTS (Jammy JellyFish) Kernel 5.15.0-69-generic

Any more details I can provide please let me know.

TheBeardedQuack avatar Apr 06 '23 19:04 TheBeardedQuack

I noticed that it does not work, even when using from the debug panel (top left button) if the "Python Debug Console" is not already open. Once the "Python Debug Console" is open, it will work (if you hit the debug button again).

willjhenry avatar May 11 '23 19:05 willjhenry