Working directory¶
The rule: without an explicit cwd, the working directory is the project
root.
Not the program's directory. .env, migrations/, configs/ and templates/
live at the repository root, and that is where you run the program by hand.
A package directory is a convention of tests — go test and cargo test
start there — not of running. In a layout with several cmd/* binaries it would
give as many different working directories as there are binaries, and none of
them right.
Resolution order¶
- the profile's explicit
cwd; - the project root;
- the directory you launched
bugsaurfrom — only for a manual--adapter/--programlaunch, which has no project and therefore no root.
Setting it explicitly¶
A relative cwd resolves from the project root.
The most common reason to set it is a test that reads testdata/ from its own
package directory — which is exactly where go test and cargo test would have
started it.
It is sent to the adapter, not just set on the process¶
The working directory goes to the adapter in the DAP request body, rather than only being the adapter process's own directory.
The difference shows up wherever the adapter and the debuggee are separate
processes: dlv passes its own directory down to the debuggee by inheritance,
while debugpy does not.
For a manual launch¶
PHP does not have one¶
cwd does not apply to PHP: the adapter starts no process, so there is nothing
to give a working directory to. The PHP process gets its directory from whoever
starts it — PHP-FPM, Docker, the CLI. See
Languages → PHP.
Seeing the difference¶
The behaviour is easy to check on the Rust fixture in the repository, which
prints its cwd and whether Cargo.toml is next to it:
make fixture-rust
# The old default — the program's directory, i.e. target/debug:
cd fixtures/rust-hello/target/debug && ./rust-hello # Cargo.toml alongside: false
# The current default — the package root:
cd fixtures/rust-hello && ./target/debug/rust-hello # Cargo.toml alongside: true
Under the debugger with no explicit cwd you get the second. To get the first,
add cwd = "target/debug" to the profile.